[njs] Shell: stopping events handling for uncaught exception in file mode.

Dmitry Volyntsev xeioex at nginx.com
Thu Dec 26 11:54:46 UTC 2019


details:   https://hg.nginx.org/njs/rev/5fbc49bc5a7e
branches:  
changeset: 1291:5fbc49bc5a7e
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Dec 26 14:53:52 2019 +0300
description:
Shell: stopping events handling for uncaught exception in file mode.

This closes #269 issue on Github.

diffstat:

 src/njs_shell.c          |   8 ++++++++
 test/njs_expect_test.exp |  11 +++++++++++
 2 files changed, 19 insertions(+), 0 deletions(-)

diffs (46 lines):

diff -r 0f31637138ce -r 5fbc49bc5a7e src/njs_shell.c
--- a/src/njs_shell.c	Fri Dec 13 12:47:37 2019 +0800
+++ b/src/njs_shell.c	Thu Dec 26 14:53:52 2019 +0300
@@ -809,6 +809,10 @@ njs_process_script(njs_opts_t *opts, njs
 
     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
 
         if (ret == NJS_ERROR) {
             njs_output(opts, vm, ret);
+
+            if (!opts->interactive) {
+                return NJS_ERROR;
+            }
         }
     }
 
diff -r 0f31637138ce -r 5fbc49bc5a7e test/njs_expect_test.exp
--- a/test/njs_expect_test.exp	Fri Dec 13 12:47:37 2019 +0800
+++ b/test/njs_expect_test.exp	Thu Dec 26 14:53:52 2019 +0300
@@ -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"} \


More information about the nginx-devel mailing list