Welcome! Log In Create A New Profile

Advanced

[njs] Added support for accessor property descriptors in njs.dump().

Dmitry Volyntsev
August 08, 2019 07:22AM
details: https://hg.nginx.org/njs/rev/fd09c657f97d
branches:
changeset: 1117:fd09c657f97d
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Thu Aug 08 14:19:55 2019 +0300
description:
Added support for accessor property descriptors in njs.dump().

diffstat:

src/njs_json.c | 17 +++++++++++++++++
src/test/njs_unit_test.c | 9 +++++++++
2 files changed, 26 insertions(+), 0 deletions(-)

diffs (53 lines):

diff -r 6caf4d7c0846 -r fd09c657f97d src/njs_json.c
--- a/src/njs_json.c Thu Aug 08 14:19:54 2019 +0300
+++ b/src/njs_json.c Thu Aug 08 14:19:55 2019 +0300
@@ -2381,6 +2381,10 @@ njs_vm_value_dump(njs_vm_t *vm, njs_str_
njs_lvlhsh_query_t lhq;
njs_json_stringify_t *stringify;

+ const njs_value_t string_get = njs_string("[Getter]");
+ const njs_value_t string_set = njs_string("[Setter]");
+ const njs_value_t string_get_set = njs_long_string("[Getter/Setter]");
+
if (njs_vm_backtrace(vm) != NULL) {
goto exception;
}
@@ -2486,6 +2490,19 @@ njs_vm_value_dump(njs_vm_t *vm, njs_str_
if (prop->type == NJS_WHITEOUT || !prop->enumerable) {
break;
}
+
+ if (njs_is_accessor_descriptor(prop)) {
+ if (njs_is_defined(&prop->getter)) {
+ if (njs_is_defined(&prop->setter)) {
+ val = njs_value_arg(&string_get_set);
+ } else {
+ val = njs_value_arg(&string_get);
+ }
+
+ } else {
+ val = njs_value_arg(&string_set);
+ }
+ }
}

if (state->written) {
diff -r 6caf4d7c0846 -r fd09c657f97d src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Thu Aug 08 14:19:54 2019 +0300
+++ b/src/test/njs_unit_test.c Thu Aug 08 14:19:55 2019 +0300
@@ -12893,6 +12893,15 @@ static njs_unit_test_t njs_test[] =
{ njs_str("njs.dump(Array.prototype.slice.call({'1':'b', length:2}))"),
njs_str("[<empty>,'b']") },

+ { njs_str("var o = Object.defineProperty({}, 'a', { get: () => 1, enumerable: true }); njs.dump(o)"),
+ njs_str("{a:'[Getter]'}") },
+
+ { njs_str("var o = Object.defineProperty({}, 'a', { get: () => 1, set(){}, enumerable: true }); njs.dump(o)"),
+ njs_str("{a:'[Getter/Setter]'}") },
+
+ { njs_str("var o = Object.defineProperty({}, 'a', { set(){}, enumerable: true }); njs.dump(o)"),
+ njs_str("{a:'[Setter]'}") },
+
{ njs_str("njs.dump($r.props)"),
njs_str("{a:{type:\"property\",props:[\"getter\"]},b:{type:\"property\",props:[\"getter\"]}}") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Added support for accessor property descriptors in njs.dump().

Dmitry Volyntsev 52 August 08, 2019 07:22AM



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

Online Users

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