mirror of
https://github.com/bellard/quickjs.git
synced 2025-09-30 15:04:24 +03:00
fixed Promise return in the REPL by using a wrapper object in async std.evalScript() (github issue #231)
This commit is contained in:
16
quickjs.c
16
quickjs.c
@@ -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);
|
||||
|
Reference in New Issue
Block a user