[njs] Parser: fixed the detection of await in arguments.

Vadim Zhestikov v.zhestikov at f5.com
Tue Feb 28 02:41:38 UTC 2023


details:   https://hg.nginx.org/njs/rev/82e673ec5f19
branches:  
changeset: 2051:82e673ec5f19
user:      Vadim Zhestikov <v.zhestikov at f5.com>
date:      Mon Feb 27 18:39:44 2023 -0800
description:
Parser: fixed the detection of await in arguments.

This fixes #619 issue on Github.

diffstat:

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

diffs (37 lines):

diff -r 0f5b52a42f97 -r 82e673ec5f19 src/njs_parser.c
--- a/src/njs_parser.c	Mon Feb 27 18:16:01 2023 -0800
+++ b/src/njs_parser.c	Mon Feb 27 18:39:44 2023 -0800
@@ -3565,17 +3565,14 @@ njs_parser_await(njs_parser_t *parser, n
     njs_queue_link_t *current)
 {
     njs_parser_node_t   *node;
-    njs_parser_scope_t  *scope;
-
-    scope = njs_function_scope(parser->scope);
-
-    if (!scope->async) {
+
+    if (!njs_function_scope(parser->scope)->async) {
         njs_parser_syntax_error(parser,
                                 "await is only valid in async functions");
         return NJS_ERROR;
     }
 
-    if (scope->in_args) {
+    if (parser->scope->in_args) {
         njs_parser_syntax_error(parser, "await in arguments not supported");
         return NJS_ERROR;
     }
diff -r 0f5b52a42f97 -r 82e673ec5f19 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Mon Feb 27 18:16:01 2023 -0800
+++ b/src/test/njs_unit_test.c	Mon Feb 27 18:39:44 2023 -0800
@@ -19824,6 +19824,9 @@ static njs_unit_test_t  njs_test[] =
               "(async function() {f('Number: ' + await 111)})"),
       njs_str("SyntaxError: await in arguments not supported in 1") },
 
+    { njs_str("async function f1() {try {f(await f1)} catch(e) {}}"),
+      njs_str("SyntaxError: await in arguments not supported in 1") },
+
     { njs_str("async function af() {await encrypt({},}"),
       njs_str("SyntaxError: Unexpected token \"}\" in 1") },
 


More information about the nginx-devel mailing list