Skip to content

Commit 4b8057d

Browse files
committed
Exit qjs on unhandled promise rejections
Fixes: #790
1 parent 84d11c4 commit 4b8057d

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

qjs.c

+2-10
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,6 @@ void help(void)
389389
" --exe select the executable to use as the base, defaults to the current one\n"
390390
" --memory-limit n limit the memory usage to 'n' Kbytes\n"
391391
" --stack-size n limit the stack size to 'n' Kbytes\n"
392-
" --unhandled-rejection dump unhandled promise rejections\n"
393392
"-q --quit just instantiate the interpreter and quit\n", JS_GetVersion());
394393
exit(1);
395394
}
@@ -414,7 +413,6 @@ int main(int argc, char **argv)
414413
int empty_run = 0;
415414
int module = -1;
416415
int load_std = 0;
417-
int dump_unhandled_promise_rejection = 0;
418416
char *include_list[32];
419417
int i, include_count = 0;
420418
int64_t memory_limit = -1;
@@ -514,10 +512,6 @@ int main(int argc, char **argv)
514512
load_std = 1;
515513
continue;
516514
}
517-
if (!strcmp(longopt, "unhandled-rejection")) {
518-
dump_unhandled_promise_rejection = 1;
519-
continue;
520-
}
521515
if (opt == 'q' || !strcmp(longopt, "quit")) {
522516
empty_run++;
523517
continue;
@@ -622,10 +616,8 @@ int main(int argc, char **argv)
622616
/* loader for ES6 modules */
623617
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);
624618

625-
if (dump_unhandled_promise_rejection) {
626-
JS_SetHostPromiseRejectionTracker(rt, js_std_promise_rejection_tracker,
627-
NULL);
628-
}
619+
/* exit on unhandled promise rejections */
620+
JS_SetHostPromiseRejectionTracker(rt, js_std_promise_rejection_tracker, NULL);
629621

630622
if (!empty_run) {
631623
js_std_add_helpers(ctx, argc - optind, argv + optind);

quickjs-libc.c

+2
Original file line numberDiff line numberDiff line change
@@ -4172,6 +4172,8 @@ void js_std_promise_rejection_tracker(JSContext *ctx, JSValue promise,
41724172
if (!is_handled) {
41734173
fprintf(stderr, "Possibly unhandled promise rejection: ");
41744174
js_std_dump_error1(ctx, reason);
4175+
fflush(stderr);
4176+
exit(1);
41754177
}
41764178
}
41774179

0 commit comments

Comments
 (0)