Welcome! Log In Create A New Profile

Advanced

[njs] Object.isExtensible() method.

Dmitry Volyntsev
June 19, 2017 07:50AM
details: http://hg.nginx.org/njs/rev/bd6c05f66ea9
branches:
changeset: 369:bd6c05f66ea9
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon Jun 19 14:46:34 2017 +0300
description:
Object.isExtensible() method.

diffstat:

njs/njs_object.c | 28 ++++++++++++++++++++++++++++
njs/test/njs_unit_test.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 0 deletions(-)

diffs (88 lines):

diff -r b2ccd7673a5e -r bd6c05f66ea9 njs/njs_object.c
--- a/njs/njs_object.c Mon Jun 19 14:41:03 2017 +0300
+++ b/njs/njs_object.c Mon Jun 19 14:46:34 2017 +0300
@@ -819,6 +819,26 @@ njs_object_prevent_extensions(njs_vm_t *
}


+static njs_ret_t
+njs_object_is_extensible(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs,
+ njs_index_t unused)
+{
+ const njs_value_t *retval;
+
+ if (nargs < 2 || !njs_is_object(&args[1])) {
+ vm->exception = &njs_exception_type_error;
+ return NXT_ERROR;
+ }
+
+ retval = args[1].data.u.object->extensible ? &njs_string_true :
+ &njs_string_false;
+
+ vm->retval = *retval;
+
+ return NXT_OK;
+}
+
+
/*
* The __proto__ property of booleans, numbers and strings primitives,
* of objects created by Boolean(), Number(), and String() constructors,
@@ -1020,6 +1040,14 @@ static const njs_object_prop_t njs_obje
.value = njs_native_function(njs_object_prevent_extensions, 0,
NJS_SKIP_ARG, NJS_OBJECT_ARG),
},
+
+ /* Object.isExtensible(). */
+ {
+ .type = NJS_METHOD,
+ .name = njs_string("isExtensible"),
+ .value = njs_native_function(njs_object_is_extensible, 0,
+ NJS_SKIP_ARG, NJS_OBJECT_ARG),
+ },
};


diff -r b2ccd7673a5e -r bd6c05f66ea9 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Mon Jun 19 14:41:03 2017 +0300
+++ b/njs/test/njs_unit_test.c Mon Jun 19 14:46:34 2017 +0300
@@ -6232,6 +6232,39 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("var o = Object.preventExtensions({a:1}); o.b = 1; o.b"),
nxt_string("undefined") },

+ { nxt_string("Object.isExtensible({})"),
+ nxt_string("true") },
+
+ { nxt_string("Object.isExtensible([])"),
+ nxt_string("true") },
+
+ { nxt_string("Object.isExtensible(function() {})"),
+ nxt_string("true") },
+
+ { nxt_string("Object.isExtensible(new Date(''))"),
+ nxt_string("true") },
+
+ { nxt_string("Object.isExtensible(new RegExp(''))"),
+ nxt_string("true") },
+
+ { nxt_string("Object.isExtensible(1)"),
+ nxt_string("TypeError") },
+
+ { nxt_string("Object.isExtensible('')"),
+ nxt_string("TypeError") },
+
+ { nxt_string("Object.isExtensible(Object.preventExtensions({}))"),
+ nxt_string("false") },
+
+ { nxt_string("Object.isExtensible(Object.preventExtensions([]))"),
+ nxt_string("false") },
+
+ { nxt_string("Object.isExtensible(Object.freeze({}))"),
+ nxt_string("false") },
+
+ { nxt_string("Object.isExtensible(Object.freeze([]))"),
+ nxt_string("false") },
+
{ nxt_string("var d = new Date(''); d +' '+ d.getTime()"),
nxt_string("Invalid Date NaN") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Object.isExtensible() method.

Dmitry Volyntsev 353 June 19, 2017 07:50AM



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

Online Users

Guests: 328
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready