[njs] Parser: fixed broken object literals parsing.

Alexander Borisov alexander.borisov at nginx.com
Thu Jun 25 10:11:30 UTC 2020


details:   https://hg.nginx.org/njs/rev/d692284e0b9f
branches:  
changeset: 1439:d692284e0b9f
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Thu Jun 25 13:10:03 2020 +0300
description:
Parser: fixed broken object literals parsing.

diffstat:

 src/njs_parser.c         |   9 ++++++---
 src/test/njs_unit_test.c |  20 +++++++++++++++++++-
 2 files changed, 25 insertions(+), 4 deletions(-)

diffs (77 lines):

diff -r 7d24976ced90 -r d692284e0b9f src/njs_parser.c
--- a/src/njs_parser.c	Fri Jun 19 19:48:13 2020 +0300
+++ b/src/njs_parser.c	Thu Jun 25 13:10:03 2020 +0300
@@ -1694,7 +1694,7 @@ njs_parser_object_literal(njs_parser_t *
 
     njs_parser_next(parser, njs_parser_property_definition_list);
 
-    return njs_parser_after(parser, current, node, 0,
+    return njs_parser_after(parser, current, node, 1,
                             njs_parser_object_literal_after);
 }
 
@@ -1733,7 +1733,7 @@ njs_parser_property_definition_list(njs_
 {
     njs_parser_next(parser, njs_parser_property_definition);
 
-    return njs_parser_after(parser, current, parser->target, 0,
+    return njs_parser_after(parser, current, parser->target, 1,
                             njs_parser_property_definition_list_after);
 }
 
@@ -1750,7 +1750,7 @@ njs_parser_property_definition_list_afte
 
     njs_parser_next(parser, njs_parser_property_definition);
 
-    return njs_parser_after(parser, current, parser->target, 0,
+    return njs_parser_after(parser, current, parser->target, 1,
                             njs_parser_property_definition_list_after);
 }
 
@@ -1866,6 +1866,9 @@ njs_parser_property_definition(njs_parse
     temp = parser->target;
 
     switch (token->type) {
+    case NJS_TOKEN_CLOSE_BRACE:
+        return njs_parser_stack_pop(parser);
+
     /* PropertyName */
     case NJS_TOKEN_STRING:
     case NJS_TOKEN_ESCAPE_STRING:
diff -r 7d24976ced90 -r d692284e0b9f src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Fri Jun 19 19:48:13 2020 +0300
+++ b/src/test/njs_unit_test.c	Thu Jun 25 13:10:03 2020 +0300
@@ -11713,7 +11713,7 @@ static njs_unit_test_t  njs_test[] =
       njs_str("RangeError: Maximum call stack size exceeded") },
 
     { njs_str("new Function(\"{[\".repeat(2**13));"),
-      njs_str("SyntaxError: Unexpected token \")\" in runtime:1") },
+      njs_str("SyntaxError: Unexpected token \"}\" in runtime:1") },
 
     { njs_str("new Function(\"{;\".repeat(2**13));"),
       njs_str("SyntaxError: Unexpected token \")\" in runtime:1") },
@@ -17022,6 +17022,24 @@ static njs_unit_test_t  njs_test[] =
 
     { njs_str("object?."),
       njs_str("SyntaxError: Unexpected end of input in 1") },
+
+    { njs_str("`${{a: 1, b}}`"),
+      njs_str("ReferenceError: \"b\" is not defined in 1") },
+
+    { njs_str("`${{a: 1, b:}}`"),
+      njs_str("SyntaxError: Unexpected token \"}\" in 1") },
+
+    { njs_str("`${{a: 1, b:,}}`"),
+      njs_str("SyntaxError: Unexpected token \",\" in 1") },
+
+    { njs_str("`${{a: 1, b: 2,}}`"),
+      njs_str("[object Object]") },
+
+    { njs_str("`${{a: 1,, b: 2}}`"),
+      njs_str("SyntaxError: Unexpected token \",\" in 1") },
+
+    { njs_str("`${{f(){-} - {}}`"),
+      njs_str("SyntaxError: Unexpected token \"}\" in 1") },
 };
 
 


More information about the nginx-devel mailing list