]> git.kaiwu.me - njs.git/commitdiff
Fixed Array.prototype.slice() for primitive types.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 3 Jul 2019 14:16:40 +0000 (17:16 +0300)
committerDmitry Volyntsev <xeioex@nginx.com>
Wed, 3 Jul 2019 14:16:40 +0000 (17:16 +0300)
This closes #188 issue on Github.

njs/njs_array.c
njs/test/njs_unit_test.c

index b418b74f8e77030e563afadb34a0e70e34222f03..2571dcd0b2b650ddd0b5622bfb592046cadc3e73 100644 (file)
@@ -683,6 +683,17 @@ njs_array_prototype_slice_copy(njs_vm_t *vm, njs_value_t *this,
 
                 length--;
             } while (length != 0);
+
+        } else {
+
+            /* Primitive types. */
+
+            value = array->start;
+
+            do {
+                *value++ = njs_value_invalid;
+                length--;
+            } while (length != 0);
         }
     }
 
index 24ecf85793195f0d02bb11bb9484982feb2a5424..b3607d484cfe9d3881b6f1fd9affe484f4933421 100644 (file)
@@ -3687,6 +3687,10 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("Array.prototype.slice.call(new String('αβZγ'))"),
       nxt_string("α,β,Z,γ") },
 
+    { nxt_string("1..__proto__.length = '2';"
+                 "Array.prototype.slice.call(1, 0, 2)"),
+      nxt_string(",") },
+
     { nxt_string("Array.prototype.pop()"),
       nxt_string("undefined") },