From 22de386ca4dd8c83d87e1e2a08f53d0dfe313c64 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Thu, 26 Dec 2019 14:53:52 +0300 Subject: [PATCH] Shell: stopping events handling for uncaught exception in file mode. This closes #269 issue on Github. --- src/njs_shell.c | 8 ++++++++ test/njs_expect_test.exp | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/njs_shell.c b/src/njs_shell.c index b68e058c..cad7e3ab 100644 --- a/src/njs_shell.c +++ b/src/njs_shell.c @@ -809,6 +809,10 @@ njs_process_script(njs_opts_t *opts, njs_console_t *console, njs_output(opts, vm, ret); + if (!opts->interactive && ret == NJS_ERROR) { + return NJS_ERROR; + } + for ( ;; ) { if (!njs_vm_pending(vm)) { break; @@ -833,6 +837,10 @@ njs_process_script(njs_opts_t *opts, njs_console_t *console, if (ret == NJS_ERROR) { njs_output(opts, vm, ret); + + if (!opts->interactive) { + return NJS_ERROR; + } } } diff --git a/test/njs_expect_test.exp b/test/njs_expect_test.exp index b3eb186f..574bc729 100644 --- a/test/njs_expect_test.exp +++ b/test/njs_expect_test.exp @@ -699,6 +699,17 @@ njs_test { "Error: Not a directory*"} } +njs_run {"-c" "setTimeout(() => {console.log('A'.repeat(1024))}, 0); ref"} \ +"^Thrown: +ReferenceError: \"ref\" is not defined in string:1 + at main \\\(native\\\)\n$" + +njs_run {"-c" "setTimeout(() => {ref}, 0); setTimeout(() => {console.log('A'.repeat(1024))}, 0)"} \ +"^Thrown: +ReferenceError: \"ref\" is not defined in string:1 + at anonymous \\\(native\\\) + at main \\\(native\\\)\n$" + # Modules njs_run {"-p" "test/module/libs" "./test/module/normal.js"} \ -- 2.47.3