]> git.kaiwu.me - njs.git/commitdiff
Parser: fixed flag setting when parsing function arguments.
authorAlexander Borisov <alexander.borisov@nginx.com>
Thu, 2 Sep 2021 16:32:34 +0000 (19:32 +0300)
committerAlexander Borisov <alexander.borisov@nginx.com>
Thu, 2 Sep 2021 16:32:34 +0000 (19:32 +0300)
The bug was introduced in 92d10cd761e2.

src/njs_parser.c
src/njs_parser.h
src/test/njs_unit_test.c

index b8e64f717a4402d978b5c854a6260b0e62dc4a0c..24b4d53969d76626e795afddb02d1ca6a3871806 100644 (file)
@@ -2723,13 +2723,13 @@ njs_parser_arguments(njs_parser_t *parser, njs_lexer_token_t *token,
      * 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, njs_lexer_token_t *token,
 
     node = parser->node;
 
-    if (parser->in_args) {
+    if (scope->in_args) {
         njs_parser_syntax_error(parser, "await in arguments not supported");
         return NJS_ERROR;
     }
index 399a489b560aa000a515d20a8e995a7447c45f7d..49524c277916e6fc03e9534288c7cb5fc35a011d 100644 (file)
@@ -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;
 };
 
 
index 9875ba88f7c75dbaaaeece65d88157f828acba79..3b5cb67e2b69ecc15c8b62dcd3b7850853bd3fab 100644 (file)
@@ -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") },