Welcome! Log In Create A New Profile

Advanced

[njs] Added externals support in JSON.stringify().

Dmitry Volyntsev
November 25, 2019 09:56AM
details: https://hg.nginx.org/njs/rev/3eb134dfa896
branches:
changeset: 1255:3eb134dfa896
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Mon Nov 25 17:53:19 2019 +0300
description:
Added externals support in JSON.stringify().

diffstat:

src/njs_json.c | 10 +++-------
src/test/njs_unit_test.c | 5 +++--
2 files changed, 6 insertions(+), 9 deletions(-)

diffs (42 lines):

diff -r cb81e4469b2c -r 3eb134dfa896 src/njs_json.c
--- a/src/njs_json.c Sat Nov 23 12:52:06 2019 +0300
+++ b/src/njs_json.c Mon Nov 25 17:53:19 2019 +0300
@@ -1092,13 +1092,8 @@ njs_json_push_stringify_state(njs_vm_t *
state->keys = njs_array(&stringify->replacer);

} else {
- if (njs_is_external(value)) {
- state->keys = njs_extern_keys_array(vm, value->external.proto);
-
- } else {
- state->keys = njs_value_own_enumerate(vm, value, NJS_ENUM_KEYS,
- stringify->keys_type, 0);
- }
+ state->keys = njs_value_own_enumerate(vm, value, NJS_ENUM_KEYS,
+ stringify->keys_type, 0);

if (njs_slow_path(state->keys == NULL)) {
return NULL;
@@ -1129,6 +1124,7 @@ njs_json_pop_stringify_state(njs_json_st
#define njs_json_is_object(value) \
(((value)->type == NJS_OBJECT) \
|| ((value)->type == NJS_OBJECT_SYMBOL) \
+ || ((value)->type == NJS_EXTERNAL) \
|| ((value)->type == NJS_ARRAY) \
|| ((value)->type >= NJS_REGEXP))

diff -r cb81e4469b2c -r 3eb134dfa896 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Sat Nov 23 12:52:06 2019 +0300
+++ b/src/test/njs_unit_test.c Mon Nov 25 17:53:19 2019 +0300
@@ -14317,8 +14317,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("var e = URIError('e'); e.foo = 'E'; JSON.stringify(e)"),
njs_str("{\"foo\":\"E\"}") },

- { njs_str("JSON.stringify([$r])"),
- njs_str("[null]") },
+ { njs_str("var r = JSON.parse(JSON.stringify($r));"
+ "[r.uri, r.host, r.props.a, njs.dump(r.vars), njs.dump(r.consts), r.header['02']]"),
+ njs_str("АБВ,АБВГДЕЁЖЗИЙ,1,{},{},02|АБВ") },

{ njs_str("JSON.stringify({get key() {throw new Error('Oops')}})"),
njs_str("Error: Oops") },
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Added externals support in JSON.stringify().

Dmitry Volyntsev 44 November 25, 2019 09:56AM



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

Online Users

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