fixed Promise return in the REPL by using a wrapper object in async std.evalScript() (github issue #231)

This commit is contained in:
Fabrice Bellard
2024-02-03 15:47:42 +01:00
parent c6cc6a9a5e
commit 00967aac24
4 changed files with 20 additions and 5 deletions

View File

@@ -34182,9 +34182,21 @@ static __exception int js_parse_program(JSParseState *s)
if (!s->is_module) {
/* return the value of the hidden variable eval_ret_idx */
emit_op(s, OP_get_loc);
emit_u16(s, fd->eval_ret_idx);
if (fd->func_kind == JS_FUNC_ASYNC) {
/* wrap the return value in an object so that promises can
be safely returned */
emit_op(s, OP_object);
emit_op(s, OP_dup);
emit_op(s, OP_get_loc);
emit_u16(s, fd->eval_ret_idx);
emit_op(s, OP_put_field);
emit_atom(s, JS_ATOM_value);
} else {
emit_op(s, OP_get_loc);
emit_u16(s, fd->eval_ret_idx);
}
emit_return(s, TRUE);
} else {
emit_return(s, FALSE);