[njs] Array.indexOf() and Array.lastIndexOf() have been fixed.

Igor Sysoev igor at sysoev.ru
Tue Oct 18 15:05:32 UTC 2016


details:   http://hg.nginx.org/njs/rev/fa9ced8246e5
branches:  
changeset: 208:fa9ced8246e5
user:      Igor Sysoev <igor at sysoev.ru>
date:      Tue Oct 18 17:44:01 2016 +0300
description:
Array.indexOf() and Array.lastIndexOf() have been fixed.

diffstat:

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

diffs (25 lines):

diff -r 59b3b4a0b535 -r fa9ced8246e5 njs/njs_array.c
--- a/njs/njs_array.c	Tue Oct 18 15:48:22 2016 +0300
+++ b/njs/njs_array.c	Tue Oct 18 17:44:01 2016 +0300
@@ -996,7 +996,7 @@ njs_array_index_of(njs_vm_t *vm, njs_val
 
     index = -1;
 
-    if (nargs > 1) {
+    if (nargs > 1 && njs_is_array(&args[0])) {
         i = 0;
         array = args[0].data.u.array;
         length = array->length;
diff -r 59b3b4a0b535 -r fa9ced8246e5 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c	Tue Oct 18 15:48:22 2016 +0300
+++ b/njs/test/njs_unit_test.c	Tue Oct 18 17:44:01 2016 +0300
@@ -2359,6 +2359,9 @@ static njs_unit_test_t  njs_test[] =
     { nxt_string("var a = [1,2,3,4,3,4]; a.indexOf(3, -10)"),
       nxt_string("2") },
 
+    { nxt_string("[].indexOf.bind(0)(0, 0)"),
+      nxt_string("-1") },
+
     { nxt_string("var a = [1,2,3,4]; a.lastIndexOf()"),
       nxt_string("-1") },
 



More information about the nginx-devel mailing list