From: Vadim Zhestikov Date: Tue, 28 Feb 2023 02:39:44 +0000 (-0800) Subject: Parser: fixed the detection of await in arguments. X-Git-Tag: 0.7.11~18 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=455f6d4f0447a60329c21928d67f61c79ac3b243;p=njs.git Parser: fixed the detection of await in arguments. This fixes #619 issue on Github. --- 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") },