[njs] Fixed Array.prototype.includes() with "undefined" argument.

Alexander Borisov alexander.borisov at nginx.com
Wed Oct 30 13:43:43 UTC 2019


details:   https://hg.nginx.org/njs/rev/2f21b596ce15
branches:  
changeset: 1207:2f21b596ce15
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Wed Oct 30 16:43:10 2019 +0300
description:
Fixed Array.prototype.includes() with "undefined" argument.

This closes #230 issue on GitHub.

diffstat:

 src/njs_array.c          |  6 +++++-
 src/test/njs_unit_test.c |  3 +++
 2 files changed, 8 insertions(+), 1 deletions(-)

diffs (36 lines):

diff -r 926dfdd7a34c -r 2f21b596ce15 src/njs_array.c
--- a/src/njs_array.c	Wed Oct 30 16:43:09 2019 +0300
+++ b/src/njs_array.c	Wed Oct 30 16:43:10 2019 +0300
@@ -1880,6 +1880,10 @@ static njs_int_t
 njs_array_handler_includes(njs_vm_t *vm, njs_array_iterator_args_t *args,
     njs_value_t *entry, uint32_t n)
 {
+    if (!njs_is_valid(entry)) {
+        entry = njs_value_arg(&njs_value_undefined);
+    }
+
     if (njs_values_strict_equal(args->argument, entry)) {
         njs_set_true(&vm->retval);
 
@@ -1947,7 +1951,7 @@ njs_array_prototype_includes(njs_vm_t *v
     iargs.from = (uint32_t) from;
     iargs.to = length;
 
-    if (njs_is_numeric(iargs.argument) && isnan(njs_number(iargs.argument))) {
+    if (njs_is_number(iargs.argument) && isnan(njs_number(iargs.argument))) {
         ret = njs_array_iterator(vm, &iargs, njs_array_handler_includes_nan);
         if (njs_fast_path(ret == NJS_DECLINED)) {
             return NJS_OK;
diff -r 926dfdd7a34c -r 2f21b596ce15 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Wed Oct 30 16:43:09 2019 +0300
+++ b/src/test/njs_unit_test.c	Wed Oct 30 16:43:10 2019 +0300
@@ -6202,6 +6202,9 @@ static njs_unit_test_t  njs_test[] =
               "Array.prototype.includes.call(o); i"),
       njs_str("1") },
 
+    { njs_str("[,,,].includes(undefined)"),
+      njs_str("true") },
+
     { njs_str("''.startsWith('')"),
       njs_str("true") },
 


More information about the nginx-devel mailing list