]> git.kaiwu.me - quickjs.git/commitdiff
exit by default on unhandled promise rejections (issue #305)
authorFabrice Bellard <fabrice@bellard.org>
Thu, 27 Mar 2025 13:22:58 +0000 (14:22 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Thu, 27 Mar 2025 13:22:58 +0000 (14:22 +0100)
qjs.c
quickjs-libc.c

diff --git a/qjs.c b/qjs.c
index f4efebe704140e0ba66bc71a9aa702c302b48df7..401bed0565ee6f6c130f809ba95241e1c6c80373 100644 (file)
--- a/qjs.c
+++ b/qjs.c
@@ -274,7 +274,7 @@ void help(void)
            "-d  --dump         dump the memory usage stats\n"
            "    --memory-limit n       limit the memory usage to 'n' bytes\n"
            "    --stack-size n         limit the stack size to 'n' bytes\n"
-           "    --unhandled-rejection  dump unhandled promise rejections\n"
+           "    --no-unhandled-rejection  ignore unhandled promise rejections\n"
            "-q  --quit         just instantiate the interpreter and quit\n");
     exit(1);
 }
@@ -292,7 +292,7 @@ int main(int argc, char **argv)
     int empty_run = 0;
     int module = -1;
     int load_std = 0;
-    int dump_unhandled_promise_rejection = 0;
+    int dump_unhandled_promise_rejection = 1;
     size_t memory_limit = 0;
     char *include_list[32];
     int i, include_count = 0;
@@ -371,8 +371,8 @@ int main(int argc, char **argv)
                 load_std = 1;
                 continue;
             }
-            if (!strcmp(longopt, "unhandled-rejection")) {
-                dump_unhandled_promise_rejection = 1;
+            if (!strcmp(longopt, "no-unhandled-rejection")) {
+                dump_unhandled_promise_rejection = 0;
                 continue;
             }
             if (opt == 'q' || !strcmp(longopt, "quit")) {
index 141f79f3c7ab2032a0d3ef81132b47d8ffd2531a..fd5d412aaaf9649ca2cbc5bf5815dfcb31c87450 100644 (file)
@@ -3961,6 +3961,7 @@ void js_std_promise_rejection_tracker(JSContext *ctx, JSValueConst promise,
     if (!is_handled) {
         fprintf(stderr, "Possibly unhandled promise rejection: ");
         js_std_dump_error1(ctx, reason);
+        exit(1);
     }
 }