Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Exit qjs on unhandled promise rejections #791

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions qjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ void help(void)
" --exe select the executable to use as the base, defaults to the current one\n"
" --memory-limit n limit the memory usage to 'n' Kbytes\n"
" --stack-size n limit the stack size to 'n' Kbytes\n"
" --unhandled-rejection dump unhandled promise rejections\n"
"-q --quit just instantiate the interpreter and quit\n", JS_GetVersion());
exit(1);
}
Expand All @@ -414,7 +413,6 @@ int main(int argc, char **argv)
int empty_run = 0;
int module = -1;
int load_std = 0;
int dump_unhandled_promise_rejection = 0;
char *include_list[32];
int i, include_count = 0;
int64_t memory_limit = -1;
Expand Down Expand Up @@ -514,10 +512,6 @@ int main(int argc, char **argv)
load_std = 1;
continue;
}
if (!strcmp(longopt, "unhandled-rejection")) {
dump_unhandled_promise_rejection = 1;
continue;
}
if (opt == 'q' || !strcmp(longopt, "quit")) {
empty_run++;
continue;
Expand Down Expand Up @@ -622,10 +616,8 @@ int main(int argc, char **argv)
/* loader for ES6 modules */
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);

if (dump_unhandled_promise_rejection) {
JS_SetHostPromiseRejectionTracker(rt, js_std_promise_rejection_tracker,
NULL);
}
/* exit on unhandled promise rejections */
JS_SetHostPromiseRejectionTracker(rt, js_std_promise_rejection_tracker, NULL);

if (!empty_run) {
js_std_add_helpers(ctx, argc - optind, argv + optind);
Expand Down
2 changes: 2 additions & 0 deletions quickjs-libc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4172,6 +4172,8 @@ void js_std_promise_rejection_tracker(JSContext *ctx, JSValue promise,
if (!is_handled) {
fprintf(stderr, "Possibly unhandled promise rejection: ");
js_std_dump_error1(ctx, reason);
fflush(stderr);
exit(1);
}
}

Expand Down
Loading