[njs] Improved the exception handling in njs_vmcode_method_frame().

Dmitry Volyntsev xeioex at nginx.com
Thu Mar 15 12:15:47 UTC 2018


details:   http://hg.nginx.org/njs/rev/e8c08e05d18c
branches:  
changeset: 462:e8c08e05d18c
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Thu Mar 15 15:15:25 2018 +0300
description:
Improved the exception handling in njs_vmcode_method_frame().

diffstat:

 njs/njs_vm.c             |  8 ++++++++
 njs/test/njs_unit_test.c |  8 +++++++-
 2 files changed, 15 insertions(+), 1 deletions(-)

diffs (50 lines):

diff -r 7bf6d9ba52b9 -r e8c08e05d18c njs/njs_vm.c
--- a/njs/njs_vm.c	Thu Mar 15 15:15:24 2018 +0300
+++ b/njs/njs_vm.c	Thu Mar 15 15:15:25 2018 +0300
@@ -2343,6 +2343,8 @@ njs_vmcode_method_frame(njs_vm_t *vm, nj
 
     method = (njs_vmcode_method_frame_t *) vm->current;
 
+    pq.lhq.key.length = 0;
+    pq.lhq.key.start = NULL;
     pq.query = NJS_PROPERTY_QUERY_GET;
 
     ret = njs_property_query(vm, &pq, object, name);
@@ -2393,6 +2395,12 @@ njs_vmcode_method_frame(njs_vm_t *vm, nj
                                         method->nargs, 0, method->code.ctor);
         break;
 
+    case NXT_ERROR:
+
+        /* An exception was set in  njs_property_query(). */
+
+        return NXT_ERROR;
+
     default:
         njs_exception_internal_error(vm, "method '%.*s' query failed:%d",
                                      (int) pq.lhq.key.length, pq.lhq.key.start,
diff -r 7bf6d9ba52b9 -r e8c08e05d18c njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Thu Mar 15 15:15:24 2018 +0300
+++ b/njs/test/njs_unit_test.c	Thu Mar 15 15:15:25 2018 +0300
@@ -5543,6 +5543,12 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("try { throw null } catch (null) { throw e }"),
       nxt_string("SyntaxError: Unexpected token \"null\" in 1") },
 
+    { nxt_string("'a'.f()"),
+      nxt_string("InternalError: method 'f' query failed:2") },
+
+    { nxt_string("1..f()"),
+      nxt_string("InternalError: method 'f' query failed:-3") },
+
     { nxt_string("try {}"),
       nxt_string("SyntaxError: Missing catch or finally after try in 1") },
 
@@ -5707,7 +5713,7 @@ static njs_unit_test_t  njs_test[] =
       nxt_string("true") },
 
     { nxt_string("Object.prototype.__proto__.f()"),
-      nxt_string("InternalError: method 'f' query failed:-1") },
+      nxt_string("TypeError: cannot get property 'f' of undefined") },
 
     { nxt_string("Object.prototype.toString.call(Object.prototype)"),
       nxt_string("[object Object]") },


More information about the nginx-devel mailing list