about summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorFabrice Bellard <fabrice@bellard.org>2024-01-02 16:09:30 +0100
committerbptato <nincsnevem662@gmail.com>2024-01-11 18:41:36 +0100
commitb3d63266e43d628e5135ce751820ea0d62596c04 (patch)
tree25e2a76686f2c925726b780ad8db5b19d16c6311 /lib
parentef449571b8e9be4eb098369d05fd679b432ba4f6 (diff)
downloadchawan-b3d63266e43d628e5135ce751820ea0d62596c04.tar.gz
allow 'await' in the REPL and added os.sleepAsync()
Diffstat (limited to 'lib')
-rw-r--r--lib/quickjs/quickjs.c4
-rw-r--r--lib/quickjs/quickjs.h3
2 files changed, 5 insertions, 2 deletions
diff --git a/lib/quickjs/quickjs.c b/lib/quickjs/quickjs.c
index 87859259..0c90815e 100644
--- a/lib/quickjs/quickjs.c
+++ b/lib/quickjs/quickjs.c
@@ -33943,7 +33943,7 @@ static __exception int js_parse_program(JSParseState *s)
         emit_op(s, OP_get_loc);
         emit_u16(s, fd->eval_ret_idx);
 
-        emit_op(s, OP_return);
+        emit_return(s, TRUE);
     } else {
         emit_return(s, FALSE);
     }
@@ -34075,7 +34075,7 @@ static JSValue __JS_EvalInternal(JSContext *ctx, JSValueConst this_obj,
             goto fail;
     }
     fd->module = m;
-    if (m != NULL) {
+    if (m != NULL || (flags & JS_EVAL_FLAG_ASYNC)) {
         fd->in_function_body = TRUE;
         fd->func_kind = JS_FUNC_ASYNC;
     }
diff --git a/lib/quickjs/quickjs.h b/lib/quickjs/quickjs.h
index abb5eb46..9590e36c 100644
--- a/lib/quickjs/quickjs.h
+++ b/lib/quickjs/quickjs.h
@@ -308,6 +308,9 @@ static inline JS_BOOL JS_VALUE_IS_NAN(JSValue v)
 #define JS_EVAL_FLAG_COMPILE_ONLY (1 << 5)
 /* don't include the stack frames before this eval in the Error() backtraces */
 #define JS_EVAL_FLAG_BACKTRACE_BARRIER (1 << 6)
+/* allow top-level await in normal script. JS_Eval() returns a
+   promise. Only allowed with JS_EVAL_TYPE_GLOBAL */
+#define JS_EVAL_FLAG_ASYNC (1 << 7) 
 
 typedef JSValue JSCFunction(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv);
 typedef JSValue JSCFunctionMagic(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv, int magic);