From 455f6d4f0447a60329c21928d67f61c79ac3b243 Mon Sep 17 00:00:00 2001 From: Vadim Zhestikov Date: Mon, 27 Feb 2023 18:39:44 -0800 Subject: [PATCH] Parser: fixed the detection of await in arguments. This fixes #619 issue on Github. --- src/njs_parser.c | 7 ++----- src/test/njs_unit_test.c | 3 +++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/njs_parser.c b/src/njs_parser.c index c05054fb..61f33d11 100644 --- a/src/njs_parser.c +++ b/src/njs_parser.c @@ -3565,17 +3565,14 @@ njs_parser_await(njs_parser_t *parser, njs_lexer_token_t *token, 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 --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 88e86f73..2afae7a1 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -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") }, -- 2.47.3