]> git.kaiwu.me - njs.git/commitdiff
Fixed array instance with a getter property dumping.
authorDmitry Volyntsev <xeioex@nginx.com>
Tue, 28 Feb 2023 06:14:36 +0000 (22:14 -0800)
committerDmitry Volyntsev <xeioex@nginx.com>
Tue, 28 Feb 2023 06:14:36 +0000 (22:14 -0800)
This closes #618 issue on Github.

src/njs_json.c
src/test/njs_unit_test.c

index 6e53286ccd8723eb192e789c12f2c40930d7335a..6a37f76de57233a558e9add9eed0205b6db69a96 100644 (file)
@@ -2085,32 +2085,30 @@ njs_vm_value_dump(njs_vm_t *vm, njs_str_t *retval, njs_value_t *value,
 
         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 (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 (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);
+            val = njs_prop_value(prop);
+        }
 
-                    } else {
-                        val = njs_value_arg(&string_get);
-                    }
+        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);
             }
         }
 
index be627dbc738d19eaea2f54d1e1a6a8c37713fee5..ec432b35696afca21afb620ccd8a60b03351c68b 100644 (file)
@@ -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),