Welcome! Log In Create A New Profile

Advanced

[njs] Fixed parsing object literals.

Dmitry Volyntsev
February 01, 2019 10:28AM
details: https://hg.nginx.org/njs/rev/94fc00372558
branches:
changeset: 750:94fc00372558
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Fri Feb 01 18:09:02 2019 +0300
description:
Fixed parsing object literals.

diffstat:

njs/njs_parser.c | 15 ++++++++++-----
njs/test/njs_unit_test.c | 12 ++++++++++++
2 files changed, 22 insertions(+), 5 deletions(-)

diffs (56 lines):

diff -r 05379e4d6844 -r 94fc00372558 njs/njs_parser.c
--- a/njs/njs_parser.c Fri Feb 01 19:48:30 2019 +0800
+++ b/njs/njs_parser.c Fri Feb 01 18:09:02 2019 +0300
@@ -2163,9 +2163,18 @@ njs_parser_object(njs_vm_t *vm, njs_pars
token = njs_parser_property_name(vm, parser, token);
break;

- default:
+ case NJS_TOKEN_NUMBER:
+ case NJS_TOKEN_STRING:
+ case NJS_TOKEN_ESCAPE_STRING:
token = njs_parser_terminal(vm, parser, token);
break;
+
+ default:
+ return NJS_TOKEN_ILLEGAL;
+ }
+
+ if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
+ return token;
}

object = njs_parser_node_new(vm, parser, NJS_TOKEN_OBJECT_VALUE);
@@ -2183,10 +2192,6 @@ njs_parser_object(njs_vm_t *vm, njs_pars
propref->left = object;
propref->right = parser->node;

- if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
- return token;
- }
-
token = njs_parser_match(vm, parser, token, NJS_TOKEN_COLON);
if (nxt_slow_path(token <= NJS_TOKEN_ILLEGAL)) {
return token;
diff -r 05379e4d6844 -r 94fc00372558 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Fri Feb 01 19:48:30 2019 +0800
+++ b/njs/test/njs_unit_test.c Fri Feb 01 18:09:02 2019 +0300
@@ -2816,6 +2816,18 @@ static njs_unit_test_t njs_test[] =
{ nxt_string("var o = Object.create({a:1}); o.a = 2; delete o.a; o.a"),
nxt_string("1") },

+ { nxt_string("njs.dump({break:1,3:2,'a':4,\"b\":2,true:1,null:0})"),
+ nxt_string("{break:1,3:2,a:4,b:2,true:1,null:0}") },
+
+ { nxt_string("var o1 = {a:1,b:2}, o2 = {c:3}; o1.a + o2.c"),
+ nxt_string("4") },
+
+ { nxt_string("({[]:1})"),
+ nxt_string("SyntaxError: Unexpected token \"[\" in 1") },
+
+ { nxt_string("({'AB\n\\cd':1})['AB\n\\cd']"),
+ nxt_string("1") },
+
/* Inheritance. */

{ nxt_string("function Foo() {this.bar = 10;}; Foo.prototype.bar = 42; "
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed parsing object literals.

Dmitry Volyntsev 95 February 01, 2019 10:28AM



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

Online Users

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