[njs] Fixed type of iteration variable in for-in with array values.

Dmitry Volyntsev xeioex at nginx.com
Tue Dec 4 18:13:38 UTC 2018


details:   https://hg.nginx.org/njs/rev/1dbef01a6d6c
branches:  
changeset: 684:1dbef01a6d6c
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Dec 04 21:13:13 2018 +0300
description:
Fixed type of iteration variable in for-in with array values.

diffstat:

 njs/njs_vm.c             |  2 +-
 njs/test/njs_unit_test.c |  3 +++
 2 files changed, 4 insertions(+), 1 deletions(-)

diffs (25 lines):

diff -r ce3a943df9c4 -r 1dbef01a6d6c njs/njs_vm.c
--- a/njs/njs_vm.c	Mon Dec 03 19:23:27 2018 +0300
+++ b/njs/njs_vm.c	Tue Dec 04 21:13:13 2018 +0300
@@ -829,7 +829,7 @@ njs_vmcode_property_next(njs_vm_t *vm, n
                 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;
                 }
diff -r ce3a943df9c4 -r 1dbef01a6d6c njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Mon Dec 03 19:23:27 2018 +0300
+++ b/njs/test/njs_unit_test.c	Tue Dec 04 21:13:13 2018 +0300
@@ -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") },
 


More information about the nginx-devel mailing list