[njs] Fixed array instance with a getter property dumping.

Dmitry Volyntsev xeioex at nginx.com
Tue Feb 28 06:15:43 UTC 2023


details:   https://hg.nginx.org/njs/rev/e4cef2c70d7c
branches:  
changeset: 2054:e4cef2c70d7c
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Feb 27 22:14:36 2023 -0800
description:
Fixed array instance with a getter property dumping.

This closes #618 issue on Github.

diffstat:

 src/njs_json.c           |  40 +++++++++++++++++++---------------------
 src/test/njs_unit_test.c |   3 +++
 2 files changed, 22 insertions(+), 21 deletions(-)

diffs (68 lines):

diff -r 1aa137411b09 -r e4cef2c70d7c src/njs_json.c
--- a/src/njs_json.c	Mon Feb 27 22:14:34 2023 -0800
+++ b/src/njs_json.c	Mon Feb 27 22:14:36 2023 -0800
@@ -2085,32 +2085,30 @@ njs_vm_value_dump(njs_vm_t *vm, njs_str_
 
         val = njs_prop_value(prop);
 
-        if (!state->fast_array) {
-            if (prop->type == NJS_PROPERTY_HANDLER) {
-                pq.scratch = *prop;
-                prop = &pq.scratch;
-                ret = njs_prop_handler(prop)(vm, prop, &state->value, NULL,
-                                             njs_prop_value(prop));
-
-                if (njs_slow_path(ret == NJS_ERROR)) {
-                    return ret;
-                }
-
-                val = njs_prop_value(prop);
+        if (prop->type == NJS_PROPERTY_HANDLER) {
+            pq.scratch = *prop;
+            prop = &pq.scratch;
+            ret = njs_prop_handler(prop)(vm, prop, &state->value, NULL,
+                                         njs_prop_value(prop));
+
+            if (njs_slow_path(ret == NJS_ERROR)) {
+                return ret;
             }
 
-            if (njs_is_accessor_descriptor(prop)) {
-                if (njs_prop_getter(prop) != NULL) {
-                    if (njs_prop_setter(prop) != NULL) {
-                        val = njs_value_arg(&string_get_set);
-
-                    } else {
-                        val = njs_value_arg(&string_get);
-                    }
+            val = njs_prop_value(prop);
+        }
+
+        if (njs_is_accessor_descriptor(prop)) {
+            if (njs_prop_getter(prop) != NULL) {
+                if (njs_prop_setter(prop) != NULL) {
+                    val = njs_value_arg(&string_get_set);
 
                 } else {
-                    val = njs_value_arg(&string_set);
+                    val = njs_value_arg(&string_get);
                 }
+
+            } else {
+                val = njs_value_arg(&string_set);
             }
         }
 
diff -r 1aa137411b09 -r e4cef2c70d7c src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Mon Feb 27 22:14:34 2023 -0800
+++ b/src/test/njs_unit_test.c	Mon Feb 27 22:14:36 2023 -0800
@@ -22852,6 +22852,9 @@ static njs_unit_test_t  njs_shell_test[]
     { njs_str("var e = Error(); e.name = {}; e" ENTER),
       njs_str("[object Object]") },
 
+    { njs_str("var a = []; Object.defineProperty(a, 'b', {enumerable: true, get: Object}); a" ENTER),
+      njs_str("[\n b: '[Getter]'\n]") },
+
     /* Temporary indexes */
 
     { njs_str("var a = [1,2,3], i; for (i in a) {Object.seal({});}" ENTER),


More information about the nginx-devel mailing list