[njs] Now setting property of primitive type returns TypeError e...

Igor Sysoev igor at sysoev.ru
Mon Oct 10 12:40:02 UTC 2016


details:   http://hg.nginx.org/njs/rev/769173883f87
branches:  
changeset: 189:769173883f87
user:      Igor Sysoev <igor at sysoev.ru>
date:      Mon Oct 10 13:08:40 2016 +0300
description:
Now setting property of primitive type returns TypeError exception.

diffstat:

 njs/njs_vm.c             |  5 +++++
 njs/test/njs_unit_test.c |  9 ++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

diffs (50 lines):

diff -r 1261cc58591e -r 769173883f87 njs/njs_vm.c
--- a/njs/njs_vm.c	Tue Oct 04 11:28:29 2016 +0300
+++ b/njs/njs_vm.c	Mon Oct 10 13:08:40 2016 +0300
@@ -642,6 +642,11 @@ njs_vmcode_property_set(njs_vm_t *vm, nj
     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 -r 1261cc58591e -r 769173883f87 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Tue Oct 04 11:28:29 2016 +0300
+++ b/njs/test/njs_unit_test.c	Mon Oct 10 13:08:40 2016 +0300
@@ -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") },



More information about the nginx-devel mailing list