Welcome! Log In Create A New Profile

Advanced

[njs] Checking extensible flag in ValidateAndApplyPropertyDescriptor().

Dmitry Volyntsev
November 27, 2019 09:16AM
details: https://hg.nginx.org/njs/rev/4e0d11660ce1
branches:
changeset: 1264:4e0d11660ce1
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Wed Nov 27 15:40:44 2019 +0300
description:
Checking extensible flag in ValidateAndApplyPropertyDescriptor().

diffstat:

src/njs_object.c | 19 +++----------------
src/njs_object_prop.c | 6 ++++++
src/njs_value.c | 4 ++++
src/test/njs_unit_test.c | 37 ++++++++++++++++++++++++++-----------
4 files changed, 39 insertions(+), 27 deletions(-)

diffs (192 lines):

diff -r facfa87548b6 -r 4e0d11660ce1 src/njs_object.c
--- a/src/njs_object.c Wed Nov 27 14:36:04 2019 +0300
+++ b/src/njs_object.c Wed Nov 27 15:40:44 2019 +0300
@@ -1232,15 +1232,7 @@ njs_object_define_property(njs_vm_t *vm,
njs_value_t *value, *name, *desc, lvalue;

if (!njs_is_object(njs_arg(args, nargs, 1))) {
- njs_type_error(vm, "cannot convert %s argument to object",
- njs_type_string(njs_arg(args, nargs, 1)->type));
- return NJS_ERROR;
- }
-
- value = njs_argument(args, 1);
-
- if (!njs_object(value)->extensible) {
- njs_type_error(vm, "object is not extensible");
+ njs_type_error(vm, "Object.defineProperty is called on non-object");
return NJS_ERROR;
}

@@ -1251,6 +1243,7 @@ njs_object_define_property(njs_vm_t *vm,
return NJS_ERROR;
}

+ value = njs_argument(args, 1);
name = njs_lvalue_arg(&lvalue, args, nargs, 2);

ret = njs_object_prop_define(vm, value, name, desc,
@@ -1276,18 +1269,12 @@ njs_object_define_properties(njs_vm_t *v
njs_object_prop_t *prop;

if (!njs_is_object(njs_arg(args, nargs, 1))) {
- njs_type_error(vm, "cannot convert %s argument to object",
- njs_type_string(njs_arg(args, nargs, 1)->type));
+ njs_type_error(vm, "Object.defineProperties is called on non-object");
return NJS_ERROR;
}

value = njs_argument(args, 1);

- if (!njs_object(value)->extensible) {
- njs_type_error(vm, "object is not extensible");
- return NJS_ERROR;
- }
-
desc = njs_arg(args, nargs, 2);

if (!njs_is_object(desc)) {
diff -r facfa87548b6 -r 4e0d11660ce1 src/njs_object_prop.c
--- a/src/njs_object_prop.c Wed Nov 27 14:36:04 2019 +0300
+++ b/src/njs_object_prop.c Wed Nov 27 15:40:44 2019 +0300
@@ -157,6 +157,12 @@ njs_object_prop_define(njs_vm_t *vm, njs

if (njs_fast_path(ret == NJS_DECLINED)) {

+ if (!njs_object(object)->extensible) {
+ njs_type_error(vm, "Cannot add property \"%V\", "
+ "object is not extensible", &pq.lhq.key);
+ return NJS_ERROR;
+ }
+
/* 6.2.5.6 CompletePropertyDescriptor */

if (njs_is_accessor_descriptor(prop)) {
diff -r facfa87548b6 -r 4e0d11660ce1 src/njs_value.c
--- a/src/njs_value.c Wed Nov 27 14:36:04 2019 +0300
+++ b/src/njs_value.c Wed Nov 27 15:40:44 2019 +0300
@@ -719,6 +719,10 @@ njs_array_property_query(njs_vm_t *vm, n
return NJS_DECLINED;
}

+ if (!array->object.extensible) {
+ return NJS_DECLINED;
+ }
+
size = index - array->length;

ret = njs_array_expand(vm, array, 0, size + 1);
diff -r facfa87548b6 -r 4e0d11660ce1 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Wed Nov 27 14:36:04 2019 +0300
+++ b/src/test/njs_unit_test.c Wed Nov 27 15:40:44 2019 +0300
@@ -11074,7 +11074,7 @@ static njs_unit_test_t njs_test[] =
njs_str("2") },

{ njs_str("var o = {}; Object.defineProperty()"),
- njs_str("TypeError: cannot convert undefined argument to object") },
+ njs_str("TypeError: Object.defineProperty is called on non-object") },

{ njs_str("var o = {}; Object.defineProperty(o)"),
njs_str("TypeError: descriptor is not an object") },
@@ -11187,14 +11187,23 @@ static njs_unit_test_t njs_test[] =
njs_str("true") },

{ njs_str("Object.defineProperties()"),
- njs_str("TypeError: cannot convert undefined argument to object") },
+ njs_str("TypeError: Object.defineProperties is called on non-object") },

{ njs_str("Object.defineProperties(1, {})"),
- njs_str("TypeError: cannot convert number argument to object") },
+ njs_str("TypeError: Object.defineProperties is called on non-object") },

{ njs_str("Object.defineProperties({}, 1)"),
njs_str("TypeError: descriptor is not an object") },

+ { njs_str("Object.defineProperties(Object.freeze({b:1}), {b:{value:1}}).b"),
+ njs_str("1") },
+
+ { njs_str("Object.defineProperties(Object.freeze({b:1}), {b:{value:2}})"),
+ njs_str("TypeError: Cannot redefine property: \"b\"") },
+
+ { njs_str("Object.defineProperties(Object.freeze({b:1}), {c:{value:1}})"),
+ njs_str("TypeError: Cannot add property \"c\", object is not extensible") },
+
{ njs_str("var o = {a:1}; o.hasOwnProperty('a')"),
njs_str("true") },

@@ -11679,10 +11688,10 @@ static njs_unit_test_t njs_test[] =
njs_str("name,length") },

{ njs_str("Object.defineProperty(Object.freeze({}), 'b', {})"),
- njs_str("TypeError: object is not extensible") },
+ njs_str("TypeError: Cannot add property \"b\", object is not extensible") },

{ njs_str("Object.defineProperties(Object.freeze({}), {b:{}})"),
- njs_str("TypeError: object is not extensible") },
+ njs_str("TypeError: Cannot add property \"b\", object is not extensible") },

{ njs_str("Object.freeze()"),
njs_str("undefined") },
@@ -11707,7 +11716,7 @@ static njs_unit_test_t njs_test[] =

{ njs_str("var a = Object.freeze([1,2]);"
"Object.defineProperty(a, 'a', {value:1}).a"),
- njs_str("TypeError: object is not extensible") },
+ njs_str("TypeError: Cannot add property \"a\", object is not extensible") },

{ njs_str("var a = [1,2]; a.a = 1; Object.freeze(a); delete a.a"),
njs_str("TypeError: Cannot delete property \"a\" of array") },
@@ -11723,7 +11732,7 @@ static njs_unit_test_t njs_test[] =

{ njs_str("var f = Object.freeze(function() {});"
"Object.defineProperty(f, 'a', {value:1}).a"),
- njs_str("TypeError: object is not extensible") },
+ njs_str("TypeError: Cannot add property \"a\", object is not extensible") },

{ njs_str("var f = function() {}; f.a = 1; Object.freeze(f); delete f.a"),
njs_str("TypeError: Cannot delete property \"a\" of function") },
@@ -11739,7 +11748,7 @@ static njs_unit_test_t njs_test[] =

{ njs_str("var d = Object.freeze(new Date(''));"
"Object.defineProperty(d, 'a', {value:1}).a"),
- njs_str("TypeError: object is not extensible") },
+ njs_str("TypeError: Cannot add property \"a\", object is not extensible") },

{ njs_str("var d = new Date(''); d.a = 1; Object.freeze(d);"
"delete d.a"),
@@ -11756,7 +11765,7 @@ static njs_unit_test_t njs_test[] =

{ njs_str("var r = Object.freeze(new RegExp(''));"
"Object.defineProperty(r, 'a', {value:1}).a"),
- njs_str("TypeError: object is not extensible") },
+ njs_str("TypeError: Cannot add property \"a\", object is not extensible") },

{ njs_str("var r = new RegExp(''); r.a = 1; Object.freeze(r); delete r.a"),
njs_str("TypeError: Cannot delete property \"a\" of regexp") },
@@ -11918,11 +11927,11 @@ static njs_unit_test_t njs_test[] =

{ njs_str("var o = Object.preventExtensions({a:1});"
"Object.defineProperty(o, 'b', {value:1})"),
- njs_str("TypeError: object is not extensible") },
+ njs_str("TypeError: Cannot add property \"b\", object is not extensible") },

{ njs_str("var o = Object.preventExtensions({a:1});"
"Object.defineProperties(o, {b:{value:1}})"),
- njs_str("TypeError: object is not extensible") },
+ njs_str("TypeError: Cannot add property \"b\", object is not extensible") },

{ njs_str("var o = Object.preventExtensions({a:1}); o.a = 2; o.a"),
njs_str("2") },
@@ -11948,6 +11957,12 @@ static njs_unit_test_t njs_test[] =
{ njs_str("Object.isExtensible([])"),
njs_str("true") },

+ { njs_str("var arrObj = [];Object.preventExtensions(arrObj); arrObj[1] = 1"),
+ njs_str("TypeError: Cannot add property \"1\", object is not extensible") },
+
+ { njs_str("var arrObj = [1,2];Object.preventExtensions(arrObj); arrObj[1] = 1"),
+ njs_str("1") },
+
{ njs_str("Object.isExtensible(function() {})"),
njs_str("true") },

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

[njs] Checking extensible flag in ValidateAndApplyPropertyDescriptor().

Dmitry Volyntsev 64 November 27, 2019 09:16AM



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

Online Users

Guests: 80
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