await bypasses catch when PromiseResolve throws
Maintainers usually reply within 5 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- c, javascript
- Domain
- compilers
Research direction
Start in quickjs.c at js_async_function_resume() and trace how PromiseResolve exceptions are handled when resuming an async function. Run the supplied qjs command at commit d73189d; done means the reproducer prints “caught: boom” instead of an unhandled rejection, while preserving normal async-function behavior.
Written by the indexing model from the issue text.
Description
Reproducer with the standalone qjs CLI (reproduced at d73189d, no embedding code):
./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 --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;
+ }
- Dominant language
- C
- Stars
- 11.1k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bellard/quickjs
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Maintainers usually reply within 5 days
-
RegExp: patterns with more than 255 capture groups fail with "too many captures"Possibly taken @andreasrosdal claimed this 3 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
bellard/quickjs#624 · 1 comment ·
Maintainers usually reply within 5 days
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
bellard/quickjs#620 · 1 comment ·
Maintainers usually reply within 5 days
-
(comment on #611) `function g(a, d = (a = 10)) { return a; }` returns the argument instead of 10Open
Difficulty 4/5 3-5 days Newbie friendliness 30/100
Maintainers usually reply within 5 days
-
Difficulty 4/5 3-5 days Newbie friendliness 30/100
Maintainers usually reply within 5 days
Similar issues
-
documentation good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
JulianKemmerer/PipelineC#409 ·
-
Linux build fails without libspeechd-dev, which INSTALL.md doesn't list and CMake reports as foundOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
needs-playtest slice
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Life-Framework/Life-Framework#4861 ·
Maintainers usually reply within 1 day