From: Dmitry Volyntsev Date: Thu, 15 Mar 2018 12:15:25 +0000 (+0300) Subject: Improved the exception handling in njs_vmcode_method_frame(). X-Git-Tag: 0.2.0~21 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=227f5601919978e86227685a366785bddbd64524;p=njs.git Improved the exception handling in njs_vmcode_method_frame(). --- diff --git a/njs/njs_vm.c b/njs/njs_vm.c index 5fd09ba4..6701144b 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -2343,6 +2343,8 @@ njs_vmcode_method_frame(njs_vm_t *vm, njs_value_t *object, njs_value_t *name) 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, njs_value_t *object, njs_value_t *name) 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 --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index b7855372..1b457ba4 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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]") },