[njs] Fixed Object() constructor for object types arguments.

Dmitry Volyntsev xeioex at nginx.com
Wed Aug 29 17:48:49 UTC 2018


details:   http://hg.nginx.org/njs/rev/da97609863ff
branches:  
changeset: 593:da97609863ff
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Aug 29 20:32:11 2018 +0300
description:
Fixed Object() constructor for object types arguments.

diffstat:

 njs/njs_object.c         |  10 ++++++----
 njs/test/njs_unit_test.c |   3 +++
 2 files changed, 9 insertions(+), 4 deletions(-)

diffs (55 lines):

diff -r 3d4c542a162b -r da97609863ff njs/njs_object.c
--- a/njs/njs_object.c	Wed Aug 29 20:31:43 2018 +0300
+++ b/njs/njs_object.c	Wed Aug 29 20:32:11 2018 +0300
@@ -535,8 +535,8 @@ njs_object_constructor(njs_vm_t *vm, njs
     njs_object_t       *object;
     const njs_value_t  *value;
 
-    type = NJS_OBJECT;
     value = njs_arg(args, nargs, 1);
+    type = value->type;
 
     if (njs_is_null_or_void(value)) {
 
@@ -545,6 +545,8 @@ njs_object_constructor(njs_vm_t *vm, njs
             return NXT_ERROR;
         }
 
+        type = NJS_OBJECT;
+
     } else {
 
         if (njs_is_object(value)) {
@@ -553,16 +555,16 @@ njs_object_constructor(njs_vm_t *vm, njs
         } else if (njs_is_primitive(value)) {
 
             /* value->type is the same as prototype offset. */
-            object = njs_object_value_alloc(vm, value, value->type);
+            object = njs_object_value_alloc(vm, value, type);
             if (nxt_slow_path(object == NULL)) {
                 return NXT_ERROR;
             }
 
-            type = njs_object_value_type(value->type);
+            type = njs_object_value_type(type);
 
         } else {
             njs_type_error(vm, "unexpected constructor argument:%s",
-                           njs_type_string(value->type));
+                           njs_type_string(type));
 
             return NXT_ERROR;
         }
diff -r 3d4c542a162b -r da97609863ff njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Wed Aug 29 20:31:43 2018 +0300
+++ b/njs/test/njs_unit_test.c	Wed Aug 29 20:32:11 2018 +0300
@@ -6060,6 +6060,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("var o = {}; o === new Object(o)"),
       nxt_string("true") },
 
+    { nxt_string("var o = Object([]); Object.prototype.toString.call(o)"),
+      nxt_string("[object Array]") },
+
     { nxt_string("Object.name"),
       nxt_string("Object") },
 


More information about the nginx-devel mailing list