[njs] Fixed Array.prototype.slice() for primitive types.

Dmitry Volyntsev xeioex at nginx.com
Wed Jul 3 14:21:45 UTC 2019


details:   https://hg.nginx.org/njs/rev/bf593c4b1c7f
branches:  
changeset: 1027:bf593c4b1c7f
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Jul 03 17:16:40 2019 +0300
description:
Fixed Array.prototype.slice() for primitive types.

This closes #188 issue on Github.

diffstat:

 njs/njs_array.c          |  11 +++++++++++
 njs/test/njs_unit_test.c |   4 ++++
 2 files changed, 15 insertions(+), 0 deletions(-)

diffs (35 lines):

diff -r 775430ca2cab -r bf593c4b1c7f njs/njs_array.c
--- a/njs/njs_array.c	Tue Jul 02 21:37:10 2019 +0300
+++ b/njs/njs_array.c	Wed Jul 03 17:16:40 2019 +0300
@@ -683,6 +683,17 @@ njs_array_prototype_slice_copy(njs_vm_t 
 
                 length--;
             } while (length != 0);
+
+        } else {
+
+            /* Primitive types. */
+
+            value = array->start;
+
+            do {
+                *value++ = njs_value_invalid;
+                length--;
+            } while (length != 0);
         }
     }
 
diff -r 775430ca2cab -r bf593c4b1c7f njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Tue Jul 02 21:37:10 2019 +0300
+++ b/njs/test/njs_unit_test.c	Wed Jul 03 17:16:40 2019 +0300
@@ -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") },
 


More information about the nginx-devel mailing list