From 08721015097a9a02d1e78d2c78b35b338e124fd2 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Mon, 10 Oct 2016 13:08:40 +0300 Subject: [PATCH] Now setting property of primitive type returns TypeError exception. --- njs/njs_vm.c | 5 +++++ njs/test/njs_unit_test.c | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) 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") }, -- 2.47.3