From: Dmitry Volyntsev Date: Tue, 28 Feb 2023 06:14:36 +0000 (-0800) Subject: Fixed array instance with a getter property dumping. X-Git-Tag: 0.7.11~15 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=1f54b79cabd1d112624ebba4d0a5f07cb3f70e95;p=njs.git Fixed array instance with a getter property dumping. This closes #618 issue on Github. --- diff --git a/src/njs_json.c b/src/njs_json.c index 6e53286c..6a37f76d 100644 --- a/src/njs_json.c +++ b/src/njs_json.c @@ -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); } } diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index be627dbc..ec432b35 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -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),