]> git.kaiwu.me - njs.git/commitdiff
Now setting property of primitive type returns TypeError exception.
authorIgor Sysoev <igor@sysoev.ru>
Mon, 10 Oct 2016 10:08:40 +0000 (13:08 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 10 Oct 2016 10:08:40 +0000 (13:08 +0300)
njs/njs_vm.c
njs/test/njs_unit_test.c

index f701afc7becc35fd1374dc19015c165180ccbb94..e8b150741c6c76e0f87e83bfd48d48d6aa94f142 100644 (file)
@@ -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);
 
index 4adf174bdd703c1e5e16e78362ef255e357a55e9..ab5c9c0da54f2e50b9c0698dcbae5e50a2d76ba4 100644 (file)
@@ -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") },