Welcome! Log In Create A New Profile

Advanced

[njs] Added Object.is().

Dmitry Volyntsev
November 28, 2019 07:12AM
details: https://hg.nginx.org/njs/rev/9dfc67399ef5
branches:
changeset: 1268:9dfc67399ef5
user: Artem S. Povalyukhin <artem.povaluhin@gmail.com>
date: Thu Nov 28 09:59:10 2019 +0300
description:
Added Object.is().

This closes #260 issue on Github.

diffstat:

src/njs_object.c | 20 ++++++++++++++++++++
src/test/njs_unit_test.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 55 insertions(+), 0 deletions(-)

diffs (82 lines):

diff -r 24b5c0103726 -r 9dfc67399ef5 src/njs_object.c
--- a/src/njs_object.c Wed Nov 27 18:28:13 2019 +0300
+++ b/src/njs_object.c Thu Nov 28 09:59:10 2019 +0300
@@ -1761,6 +1761,17 @@ njs_object_assign(njs_vm_t *vm, njs_valu
}


+static njs_int_t
+njs_object_is(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs,
+ njs_index_t unused)
+{
+ njs_set_boolean(&vm->retval, njs_values_same(njs_arg(args, nargs, 1),
+ njs_arg(args, nargs, 2)));
+
+ return NJS_OK;
+}
+
+
/*
* The __proto__ property of booleans, numbers and strings primitives,
* of objects created by Boolean(), Number(), and String() constructors,
@@ -2052,6 +2063,15 @@ static const njs_object_prop_t njs_obje
.writable = 1,
.configurable = 1,
},
+
+ /* Object.is(). */
+ {
+ .type = NJS_PROPERTY,
+ .name = njs_string("is"),
+ .value = njs_native_function(njs_object_is, 2),
+ .writable = 1,
+ .configurable = 1,
+ },
};


diff -r 24b5c0103726 -r 9dfc67399ef5 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Wed Nov 27 18:28:13 2019 +0300
+++ b/src/test/njs_unit_test.c Thu Nov 28 09:59:10 2019 +0300
@@ -12036,6 +12036,41 @@ static njs_unit_test_t njs_test[] =
{ njs_str("Object.isExtensible(undefined)"),
njs_str("false") },

+ /* Object.is() */
+
+ { njs_str("typeof Object.is"),
+ njs_str("function") },
+
+ { njs_str("Object.is.length == 2"),
+ njs_str("true") },
+
+ { njs_str("Object.is()"),
+ njs_str("true") },
+
+ { njs_str("[undefined, null, false, NaN, '', Symbol(), {}]"
+ ".map((x) => Object.is(x, x))"
+ ".every((x) => x === true)"),
+ njs_str("true") },
+
+ { njs_str("[null, false, NaN, '', Symbol(), {}]"
+ ".map((x) => Object.is(x) || Object.is(void 0, x))"
+ ".every((x) => x === false)"),
+ njs_str("true") },
+
+ { njs_str("[false, NaN, '', Symbol()]"
+ ".map((x) => Object.is(Object(x), Object(x)))"
+ ".every((x) => x === false)"),
+ njs_str("true") },
+
+ { njs_str("Object.is(0, -0)"),
+ njs_str("false") },
+
+ { njs_str("Object.is(0, null)"),
+ njs_str("false") },
+
+ { njs_str("Object.is(42, '42')"),
+ njs_str("false") },
+
{ njs_str(
"var fail;"
"function isConfigurableMethods(o) {"
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Added Object.is().

Dmitry Volyntsev 62 November 28, 2019 07:12AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 76
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready