[njs] Improved Array.prototype.includes().

Dmitry Volyntsev xeioex at nginx.com
Wed Nov 27 14:15:30 UTC 2019


details:   https://hg.nginx.org/njs/rev/4b2b845c3bad
branches:  
changeset: 1266:4b2b845c3bad
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Nov 27 16:51:29 2019 +0300
description:
Improved Array.prototype.includes().

diffstat:

 src/njs_array.c |  30 ++++--------------------------
 1 files changed, 4 insertions(+), 26 deletions(-)

diffs (47 lines):

diff -r ba1499515923 -r 4b2b845c3bad src/njs_array.c
--- a/src/njs_array.c	Wed Nov 27 15:48:32 2019 +0300
+++ b/src/njs_array.c	Wed Nov 27 16:51:29 2019 +0300
@@ -1886,21 +1886,7 @@ njs_array_handler_includes(njs_vm_t *vm,
         entry = njs_value_arg(&njs_value_undefined);
     }
 
-    if (njs_values_strict_equal(args->argument, entry)) {
-        njs_set_true(&vm->retval);
-
-        return 1;
-    }
-
-    return NJS_OK;
-}
-
-
-static njs_int_t
-njs_array_handler_includes_nan(njs_vm_t *vm, njs_array_iterator_args_t *args,
-    njs_value_t *entry, uint32_t n)
-{
-    if (njs_is_numeric(entry) && isnan(njs_number(entry))) {
+    if (njs_values_same_zero(args->argument, entry)) {
         njs_set_true(&vm->retval);
 
         return 1;
@@ -1953,17 +1939,9 @@ njs_array_prototype_includes(njs_vm_t *v
     iargs.from = (uint32_t) from;
     iargs.to = length;
 
-    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;
-        }
-
-    } else {
-        ret = njs_array_iterator(vm, &iargs, njs_array_handler_includes);
-        if (njs_fast_path(ret == NJS_DECLINED)) {
-            return NJS_OK;
-        }
+    ret = njs_array_iterator(vm, &iargs, njs_array_handler_includes);
+    if (njs_fast_path(ret == NJS_DECLINED)) {
+        return NJS_OK;
     }
 
 not_found:


More information about the nginx-devel mailing list