From 99450b9eb73b3d64ce61b8256743be8fd69d7983 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Wed, 29 Aug 2018 20:32:11 +0300 Subject: [PATCH] Fixed Object() constructor for object types arguments. --- njs/njs_object.c | 10 ++++++---- njs/test/njs_unit_test.c | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/njs/njs_object.c b/njs/njs_object.c index 86e7b543..11d52eb7 100644 --- a/njs/njs_object.c +++ b/njs/njs_object.c @@ -535,8 +535,8 @@ njs_object_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, 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_value_t *args, nxt_uint_t nargs, return NXT_ERROR; } + type = NJS_OBJECT; + } else { if (njs_is_object(value)) { @@ -553,16 +555,16 @@ njs_object_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, } 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 --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 8d98e950..842d5afd 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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") }, -- 2.47.3