Welcome! Log In Create A New Profile

Advanced

[njs] Fixed Object.defineProperty() when a recursive descriptor is provided.

Dmitry Volyntsev
May 06, 2022 10:00PM
details: https://hg.nginx.org/njs/rev/3f6f3ba16741
branches:
changeset: 1851:3f6f3ba16741
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Fri May 06 18:55:07 2022 -0700
description:
Fixed Object.defineProperty() when a recursive descriptor is provided.

This closes #481 issue on Github.

diffstat:

src/njs_array.c | 4 ++++
src/test/njs_unit_test.c | 10 ++++++++++
2 files changed, 14 insertions(+), 0 deletions(-)

diffs (34 lines):

diff -r ded5304adaf0 -r 3f6f3ba16741 src/njs_array.c
--- a/src/njs_array.c Thu May 05 20:25:05 2022 -0700
+++ b/src/njs_array.c Fri May 06 18:55:07 2022 -0700
@@ -142,6 +142,10 @@ njs_array_convert_to_slow_array(njs_vm_t
njs_value_t index, value;
njs_object_prop_t *prop;

+ if (njs_slow_path(!array->object.fast_array)) {
+ return NJS_OK;
+ }
+
njs_set_array(&value, array);
array->object.fast_array = 0;

diff -r ded5304adaf0 -r 3f6f3ba16741 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Thu May 05 20:25:05 2022 -0700
+++ b/src/test/njs_unit_test.c Fri May 06 18:55:07 2022 -0700
@@ -13837,6 +13837,16 @@ static njs_unit_test_t njs_test[] =
"d.enumerable && d.writable && d.configurable"),
njs_str("true") },

+ { njs_str("const arr = [1,2];"
+ "function f(arg) {"
+ " const desc = {get: arg};"
+ " Object.defineProperty(desc, 'set', desc);"
+ " Object.defineProperty(arr, 1, desc);"
+ "}"
+ "f(f);"
+ "njs.dump(arr)"),
+ njs_str("[1,'[Getter]']") },
+
{ njs_str("Object.defineProperties()"),
njs_str("TypeError: Object.defineProperties is called on non-object") },

_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Fixed Object.defineProperty() when a recursive descriptor is provided.

Dmitry Volyntsev 173 May 06, 2022 10:00PM



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

Online Users

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