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

Dmitry Volyntsev xeioex at nginx.com
Sat May 7 01:56:26 UTC 2022


details:   https://hg.nginx.org/njs/rev/3f6f3ba16741
branches:  
changeset: 1851:3f6f3ba16741
user:      Dmitry Volyntsev <xeioex at 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") },
 



More information about the nginx-devel mailing list