Skip to content

Commit 1651282

Browse files
authored
Fix AsyncGenerator.prototype.return error handling (#109)
A poisoned .constructor property is observable and the resulting exception should be delivered to the catch handler, not silently dropped, otherwise the generator hangs.
1 parent 8d496b3 commit 1651282

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

quickjs.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17407,10 +17407,19 @@ static int js_async_generator_completed_return(JSContext *ctx,
1740717407
JSValue promise, resolving_funcs[2], resolving_funcs1[2];
1740817408
int res;
1740917409

17410-
promise = js_promise_resolve(ctx, ctx->promise_ctor,
17411-
1, (JSValueConst *)&value, 0);
17412-
if (JS_IsException(promise))
17413-
return -1;
17410+
// Can fail looking up JS_ATOM_constructor when is_reject==0.
17411+
promise = js_promise_resolve(ctx, ctx->promise_ctor, 1, &value,
17412+
/*is_reject*/0);
17413+
// A poisoned .constructor property is observable and the resulting
17414+
// exception should be delivered to the catch handler.
17415+
if (JS_IsException(promise)) {
17416+
JSValue err = JS_GetException(ctx);
17417+
promise = js_promise_resolve(ctx, ctx->promise_ctor, 1, &err,
17418+
/*is_reject*/1);
17419+
JS_FreeValue(ctx, err);
17420+
if (JS_IsException(promise))
17421+
return -1;
17422+
}
1741417423
if (js_async_generator_resolve_function_create(ctx,
1741517424
JS_MKPTR(JS_TAG_OBJECT, s->generator),
1741617425
resolving_funcs1,

test262_errors.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
test262/test/annexB/language/eval-code/direct/script-decl-lex-collision-in-sloppy-mode.js:13: Test262Error: Expected a SyntaxError to be thrown but no exception was thrown at all
2-
test262/test/built-ins/AsyncGeneratorPrototype/return/return-state-completed-broken-promise.js:53: TypeError: $DONE() not called
3-
test262/test/built-ins/AsyncGeneratorPrototype/return/return-state-completed-broken-promise.js:53: strict mode: TypeError: $DONE() not called
4-
test262/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-broken-promise.js:34: TypeError: $DONE() not called
5-
test262/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedStart-broken-promise.js:34: strict mode: TypeError: $DONE() not called
62
test262/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-broken-promise-try-catch.js:39: TypeError: $DONE() not called
73
test262/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-broken-promise-try-catch.js:39: strict mode: TypeError: $DONE() not called
84
test262/test/built-ins/RegExp/lookahead-quantifier-match-groups.js:27: Test262Error: Expected [a, abc] and [a, undefined] to have the same contents. ? quantifier

0 commit comments

Comments
 (0)