Skip to content

Commit 57105c7

Browse files
author
Fabrice Bellard
committed
fixed async generator in case of exception in the implicit await in the 'return' statement
1 parent a42681a commit 57105c7

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

quickjs.c

+20-9
Original file line numberDiff line numberDiff line change
@@ -19182,7 +19182,7 @@ static int js_async_generator_completed_return(JSContext *ctx,
1918219182
// exception should be delivered to the catch handler.
1918319183
if (JS_IsException(promise)) {
1918419184
JSValue err = JS_GetException(ctx);
19185-
promise = js_promise_resolve(ctx, ctx->promise_ctor, 1, &err,
19185+
promise = js_promise_resolve(ctx, ctx->promise_ctor, 1, (JSValueConst *)&err,
1918619186
/*is_reject*/1);
1918719187
JS_FreeValue(ctx, err);
1918819188
if (JS_IsException(promise))
@@ -19235,7 +19235,6 @@ static void js_async_generator_resume_next(JSContext *ctx,
1923519235
} else if (next->completion_type == GEN_MAGIC_RETURN) {
1923619236
s->state = JS_ASYNC_GENERATOR_STATE_AWAITING_RETURN;
1923719237
js_async_generator_completed_return(ctx, s, next->result);
19238-
goto done;
1923919238
} else {
1924019239
js_async_generator_reject(ctx, s, next->result);
1924119240
}
@@ -19266,7 +19265,7 @@ static void js_async_generator_resume_next(JSContext *ctx,
1926619265
js_async_generator_reject(ctx, s, value);
1926719266
JS_FreeValue(ctx, value);
1926819267
} else if (JS_VALUE_GET_TAG(func_ret) == JS_TAG_INT) {
19269-
int func_ret_code;
19268+
int func_ret_code, ret;
1927019269
value = s->func_state.frame.cur_sp[-1];
1927119270
s->func_state.frame.cur_sp[-1] = JS_UNDEFINED;
1927219271
func_ret_code = JS_VALUE_GET_INT(func_ret);
@@ -19281,8 +19280,13 @@ static void js_async_generator_resume_next(JSContext *ctx,
1928119280
JS_FreeValue(ctx, value);
1928219281
break;
1928319282
case FUNC_RET_AWAIT:
19284-
js_async_generator_await(ctx, s, value);
19283+
ret = js_async_generator_await(ctx, s, value);
1928519284
JS_FreeValue(ctx, value);
19285+
if (ret < 0) {
19286+
/* exception: throw it */
19287+
s->func_state.throw_flag = TRUE;
19288+
goto resume_exec;
19289+
}
1928619290
goto done;
1928719291
default:
1928819292
abort();
@@ -25436,6 +25440,18 @@ static void emit_return(JSParseState *s, BOOL hasval)
2543625440
BlockEnv *top;
2543725441
int drop_count;
2543825442

25443+
if (s->cur_func->func_kind != JS_FUNC_NORMAL) {
25444+
if (!hasval) {
25445+
/* no value: direct return in case of async generator */
25446+
emit_op(s, OP_undefined);
25447+
hasval = TRUE;
25448+
} else if (s->cur_func->func_kind == JS_FUNC_ASYNC_GENERATOR) {
25449+
/* the await must be done before handling the "finally" in
25450+
case it raises an exception */
25451+
emit_op(s, OP_await);
25452+
}
25453+
}
25454+
2543925455
drop_count = 0;
2544025456
top = s->cur_func->top_break;
2544125457
while (top != NULL) {
@@ -25514,11 +25530,6 @@ static void emit_return(JSParseState *s, BOOL hasval)
2551425530
emit_label(s, label_return);
2551525531
emit_op(s, OP_return);
2551625532
} else if (s->cur_func->func_kind != JS_FUNC_NORMAL) {
25517-
if (!hasval) {
25518-
emit_op(s, OP_undefined);
25519-
} else if (s->cur_func->func_kind == JS_FUNC_ASYNC_GENERATOR) {
25520-
emit_op(s, OP_await);
25521-
}
2552225533
emit_op(s, OP_return_async);
2552325534
} else {
2552425535
emit_op(s, hasval ? OP_return : OP_return_undef);

test262_errors.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +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-suspendedYield-broken-promise-try-catch.js:39: TypeError: $DONE() not called
3-
test262/test/built-ins/AsyncGeneratorPrototype/return/return-suspendedYield-broken-promise-try-catch.js:39: strict mode: TypeError: $DONE() not called
42
test262/test/built-ins/Function/internals/Construct/derived-this-uninitialized-realm.js:20: Test262Error: Expected a ReferenceError but got a different error constructor with the same name
53
test262/test/built-ins/Function/internals/Construct/derived-this-uninitialized-realm.js:20: strict mode: Test262Error: Expected a ReferenceError but got a different error constructor with the same name
64
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)