]> git.kaiwu.me - njs.git/commitdiff
Fixed type of iteration variable in for-in with array values.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 4 Dec 2018 18:13:13 +0000 (21:13 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 4 Dec 2018 18:13:13 +0000 (21:13 +0300)
njs/njs_vm.c
njs/test/njs_unit_test.c

index 56737b4cb8f7a47945f46576c14df6f891fc4ce1..05c13b118bc2932c1a325589930d3d8c407a8d82 100644 (file)
@@ -829,7 +829,7 @@ njs_vmcode_property_next(njs_vm_t *vm, njs_value_t *object, njs_value_t *value)
                 n = next->index++;
 
                 if (njs_is_valid(&array->start[n])) {
-                    njs_value_number_set(retval, n);
+                    njs_uint32_to_string(retval, n);
 
                     return code->offset;
                 }
index 3f84c3b549ad552d671088f6c404f74e29a8a302..4953df583c5f5369f2f75c3b90337e7bc925f464 100644 (file)
@@ -2244,6 +2244,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("var s = ''; for (var p in [1,2]) {s += p}; s"),
       nxt_string("01") },
 
+    { nxt_string("var s; for (var p in [1]) {s = typeof(p)}; s"),
+      nxt_string("string") },
+
     { nxt_string("var s = ''; for (var p in {a:1, b:2}) {s += p}; s"),
       nxt_string("ab") },