[njs] Parser: fixed flag setting when parsing function arguments.

Alexander Borisov alexander.borisov at nginx.com
Thu Sep 2 16:34:59 UTC 2021


details:   https://hg.nginx.org/njs/rev/cd87eaf03e4f
branches:  
changeset: 1701:cd87eaf03e4f
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Thu Sep 02 19:32:34 2021 +0300
description:
Parser: fixed flag setting when parsing function arguments.

The bug was introduced in 92d10cd761e2.

diffstat:

 src/njs_parser.c         |  8 ++++----
 src/njs_parser.h         |  2 +-
 src/test/njs_unit_test.c |  6 ++++++
 3 files changed, 11 insertions(+), 5 deletions(-)

diffs (72 lines):

diff -r 3a7ffe641a77 -r cd87eaf03e4f src/njs_parser.c
--- a/src/njs_parser.c	Thu Sep 02 19:32:27 2021 +0300
+++ b/src/njs_parser.c	Thu Sep 02 19:32:34 2021 +0300
@@ -2723,13 +2723,13 @@ njs_parser_arguments(njs_parser_t *parse
      * ArgumentList , )
      */
 
-    parser->in_args = 1;
-
     if (token->type == NJS_TOKEN_CLOSE_PARENTHESIS) {
         njs_lexer_consume_token(parser->lexer, 1);
         return njs_parser_stack_pop(parser);
     }
 
+    parser->scope->in_args = 1;
+
     njs_parser_next(parser, njs_parser_argument_list);
 
     return njs_parser_after(parser, current, NULL, 1,
@@ -2741,7 +2741,7 @@ static njs_int_t
 njs_parser_parenthesis_or_comma(njs_parser_t *parser, njs_lexer_token_t *token,
     njs_queue_link_t *current)
 {
-    parser->in_args = 0;
+    parser->scope->in_args = 0;
 
     if (token->type == NJS_TOKEN_CLOSE_PARENTHESIS) {
         njs_lexer_consume_token(parser->lexer, 1);
@@ -3479,7 +3479,7 @@ njs_parser_await(njs_parser_t *parser, n
 
     node = parser->node;
 
-    if (parser->in_args) {
+    if (scope->in_args) {
         njs_parser_syntax_error(parser, "await in arguments not supported");
         return NJS_ERROR;
     }
diff -r 3a7ffe641a77 -r cd87eaf03e4f src/njs_parser.h
--- a/src/njs_parser.h	Thu Sep 02 19:32:27 2021 +0300
+++ b/src/njs_parser.h	Thu Sep 02 19:32:34 2021 +0300
@@ -31,6 +31,7 @@ struct njs_parser_scope_s {
     uint8_t                         arrow_function;
     uint8_t                         dest_disable;
     uint8_t                         async;
+    uint8_t                         in_args;
 };
 
 
@@ -83,7 +84,6 @@ struct njs_parser_s {
     uintptr_t                       undefined_id;
     njs_bool_t                      strict_semicolon;
     uint32_t                        line;
-    njs_bool_t                      in_args;
 };
 
 
diff -r 3a7ffe641a77 -r cd87eaf03e4f src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Thu Sep 02 19:32:27 2021 +0300
+++ b/src/test/njs_unit_test.c	Thu Sep 02 19:32:34 2021 +0300
@@ -20504,6 +20504,12 @@ static njs_unit_test_t  njs_test[] =
               "(async function() {f(await 111)})"),
       njs_str("SyntaxError: await in arguments not supported in 1") },
 
+    { njs_str("Promise.all([async () => [await x('X')]])"),
+      njs_str("[object Promise]") },
+
+    { njs_str("async () => [await x(1)(),]; async () => [await x(1)()]"),
+      njs_str("[object AsyncFunction]") },
+
     { njs_str("function f(a, b, c) {}"
               "(async function() {f(1, 'a', await 111)})"),
       njs_str("SyntaxError: await in arguments not supported in 1") },


More information about the nginx-devel mailing list