Welcome! Log In Create A New Profile

Advanced

[njs] Fixed JSON.stringify() for arrays resizable via getters.

Alexander Borisov
October 06, 2020 01:54PM
details: https://hg.nginx.org/njs/rev/036a4fbf9204
branches:
changeset: 1537:036a4fbf9204
user: Alexander Borisov <alexander.borisov@nginx.com>
date: Tue Oct 06 20:51:56 2020 +0300
description:
Fixed JSON.stringify() for arrays resizable via getters.

diffstat:

src/njs_json.c | 3 ++-
src/test/njs_unit_test.c | 4 ++++
2 files changed, 6 insertions(+), 1 deletions(-)

diffs (34 lines):

diff -r da7b98611f57 -r 036a4fbf9204 src/njs_json.c
--- a/src/njs_json.c Tue Oct 06 20:24:21 2020 +0300
+++ b/src/njs_json.c Tue Oct 06 20:51:56 2020 +0300
@@ -1077,6 +1077,7 @@ njs_json_push_stringify_state(njs_vm_t *
state->key = NULL;

if (njs_is_fast_array(value)) {
+ state->length = njs_array_len(value);
state->type = NJS_JSON_ARRAY;
state->array = 1;

@@ -1279,7 +1280,7 @@ njs_json_stringify_iterator(njs_vm_t *vm
njs_json_stringify_indent(stringify, &chain, 0);
}

- if (state->index >= njs_array_len(&state->value)) {
+ if (state->index >= state->length) {
njs_json_stringify_indent(stringify, &chain, -1);
njs_chb_append_literal(&chain,"]");

diff -r da7b98611f57 -r 036a4fbf9204 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Tue Oct 06 20:24:21 2020 +0300
+++ b/src/test/njs_unit_test.c Tue Oct 06 20:51:56 2020 +0300
@@ -16855,6 +16855,10 @@ static njs_unit_test_t njs_test[] =
"JSON.stringify(array)"),
njs_str("[1,{},10]") },

+ { njs_str("var array = [1];"
+ "array[1] = {get value() {array[10] = 10}}; JSON.stringify(array)"),
+ njs_str("[1,{}]") },
+
/* njs.dump(). */

{ njs_str("njs.dump({a:1, b:[1,,2,{c:new Boolean(1)}]})"),
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed JSON.stringify() for arrays resizable via getters.

Alexander Borisov 78 October 06, 2020 01:54PM



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

Online Users

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