From: Igor Sysoev Date: Mon, 10 Oct 2016 10:08:40 +0000 (+0300) Subject: Now setting property of primitive type returns TypeError exception. X-Git-Tag: 0.1.3~2 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=08721015097a9a02d1e78d2c78b35b338e124fd2;p=njs.git Now setting property of primitive type returns TypeError exception. --- diff --git a/njs/njs_vm.c b/njs/njs_vm.c index f701afc7..e8b15074 100644 --- a/njs/njs_vm.c +++ b/njs/njs_vm.c @@ -642,6 +642,11 @@ njs_vmcode_property_set(njs_vm_t *vm, njs_value_t *object, njs_property_query_t pq; njs_vmcode_prop_set_t *code; + if (njs_is_primitive(object)) { + vm->exception = &njs_exception_type_error; + return NXT_ERROR; + } + code = (njs_vmcode_prop_set_t *) vm->current; value = njs_vmcode_operand(vm, code->value); diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 4adf174b..ab5c9c0d 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -1833,6 +1833,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("a = {}; a.b.c"), nxt_string("TypeError") }, + { nxt_string("'a'.b = 1"), + nxt_string("TypeError") }, + { nxt_string("a = {}; a.b = 1; a.b"), nxt_string("1") }, @@ -1867,10 +1870,10 @@ static njs_unit_test_t njs_test[] = nxt_string("TypeError") }, { nxt_string("a = true; a.b++; a.b"), - nxt_string("undefined") }, + nxt_string("TypeError") }, { nxt_string("a = 1; a.b++; a.b"), - nxt_string("undefined") }, + nxt_string("TypeError") }, { nxt_string("a = {}; a.b = {}; a.b.c = 1; a.b['c']"), nxt_string("1") }, @@ -1885,7 +1888,7 @@ static njs_unit_test_t njs_test[] = nxt_string("2 1") }, { nxt_string("a = 2; a.b = 1; c = a.b++; a +' '+ a.b +' '+ c"), - nxt_string("2 undefined NaN") }, + nxt_string("TypeError") }, { nxt_string("x = { a: 1 }; x.a"), nxt_string("1") },