]> git.kaiwu.me - njs.git/commitdiff
Fixed constructor property of an iterator object.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 27 Jun 2024 01:50:43 +0000 (18:50 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 2 Jul 2024 02:33:19 +0000 (19:33 -0700)
This fixes #737 issue on Github.

src/njs_object.c
src/test/njs_unit_test.c

index 5a5970c9d86ef4c9f939dbf0b04d2936b3dc8cfd..f2aa46a360125ea399540ae80d02ef20ed9fc617 100644 (file)
@@ -2168,6 +2168,10 @@ njs_object_prototype_create_constructor(njs_vm_t *vm, njs_object_prop_t *prop,
 
 found:
 
+    if (njs_flathsh_is_empty(&vm->constructors[index].object.shared_hash)) {
+        index = NJS_OBJ_TYPE_OBJECT;
+    }
+
     njs_set_function(&constructor, &njs_vm_ctor(vm, index));
     setval = &constructor;
 
index 96c922bc54efd8a7e9b8257f08dd25638b378743..530cf6ff8f9daa3cb8e5e0035d21a83a911e4f56 100644 (file)
@@ -7450,6 +7450,9 @@ static njs_unit_test_t  njs_test[] =
               "[i.next(), i.next(), i.next(), i.next()].map((x) => x.value)"),
       njs_str("1,2,3,") },
 
+    { njs_str("[].values().constructor()"),
+      njs_str("[object Object]") },
+
     { njs_str("var a = [], i = a.values();"
               "a.push(1); a.push(2); a.push(3);"
               "[i.next(), i.next(), i.next(), i.next()].map((x) => x.value)"),