#563·quickjs

await bypasses catch when PromiseResolve throws

Author: xeioexCreated Sep 25, 2026Updated Sep 25, 2026

Reproducer with the standalone qjs CLI (reproduced at d73189d, no embedding code):

bash
./qjs -e 'const p = Promise.resolve(1);
Object.defineProperty(p, "constructor", { get() { throw Error("boom"); } });
(async () => {
    try { await p; } catch (e) { print("caught: " + e.message); }
})();'

Instead of entering catch, qjs reports Possibly unhandled promise rejection: Error: boom.

Expected behavior

Output: caught: boom. PromiseResolve propagates an exception thrown by the promise's constructor getter; Await propagates that abrupt completion at the await expression, where the surrounding try/catch handles it. QuickJS already resumes an async generator with throw_flag when preparing its await fails (js_async_generator_resume_next()); Node.js 25 also prints caught: boom for the equivalent example.

Possible patch

In js_async_function_resume(), throw the PromiseResolve exception into the suspended async function instead of rejecting its outer promise before its catch can run:

diff
diff --git a/quickjs.c b/quickjs.c
--- a/quickjs.c
+++ b/quickjs.c
@@ -21056,1 +21056,2 @@ static void js_async_function_resume(JSContext *ctx, JSAsyncFunctionState *s)
+ resume:
     func_ret = async_func_resume(ctx, s);
@@ -21082,8 +21083,10 @@ static void js_async_function_resume(JSContext *ctx, JSAsyncFunctionState *s)
         promise = js_promise_resolve(ctx, ctx->promise_ctor,
                                      1, (JSValueConst *)&value, 0);
         JS_FreeValue(ctx, value);
-        if (JS_IsException(promise))
-            goto fail;
+        if (JS_IsException(promise)) {
+            s->throw_flag = TRUE;
+            goto resume;
+        }