[njs] Fixed tracking of argument scope.
noreply at nginx.com
noreply at nginx.com
Mon Jun 10 22:21:03 UTC 2024
details: https://hg.nginx.org/njs/rev/81ff15b57343
branches:
changeset: 2354:81ff15b57343
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Fri Jun 07 21:46:30 2024 -0700
description:
Fixed tracking of argument scope.
This properly catches unsupported "await" in arguments.
This fixes #730 issue on Github.
diffstat:
src/njs_parser.c | 6 +++---
src/njs_parser.h | 2 +-
src/test/njs_unit_test.c | 12 ++++++------
3 files changed, 10 insertions(+), 10 deletions(-)
diffs (71 lines):
diff -r 23538ab89e41 -r 81ff15b57343 src/njs_parser.c
--- a/src/njs_parser.c Thu Jun 06 14:54:45 2024 -0700
+++ b/src/njs_parser.c Fri Jun 07 21:46:30 2024 -0700
@@ -2827,7 +2827,7 @@ njs_parser_arguments(njs_parser_t *parse
return njs_parser_stack_pop(parser);
}
- parser->scope->in_args = 1;
+ parser->scope->in_args++;
njs_parser_next(parser, njs_parser_argument_list);
@@ -2840,7 +2840,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->scope->in_args = 0;
+ parser->scope->in_args--;
if (token->type == NJS_TOKEN_CLOSE_PARENTHESIS) {
njs_lexer_consume_token(parser->lexer, 1);
@@ -3575,7 +3575,7 @@ njs_parser_await(njs_parser_t *parser, n
return NJS_ERROR;
}
- if (parser->scope->in_args) {
+ if (parser->scope->in_args > 0) {
njs_parser_syntax_error(parser, "await in arguments not supported");
return NJS_ERROR;
}
diff -r 23538ab89e41 -r 81ff15b57343 src/njs_parser.h
--- a/src/njs_parser.h Thu Jun 06 14:54:45 2024 -0700
+++ b/src/njs_parser.h Fri Jun 07 21:46:30 2024 -0700
@@ -26,7 +26,7 @@ struct njs_parser_scope_s {
uint8_t arrow_function;
uint8_t dest_disable;
uint8_t async;
- uint8_t in_args;
+ uint32_t in_args;
};
diff -r 23538ab89e41 -r 81ff15b57343 src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Thu Jun 06 14:54:45 2024 -0700
+++ b/src/test/njs_unit_test.c Fri Jun 07 21:46:30 2024 -0700
@@ -19938,19 +19938,19 @@ static njs_unit_test_t njs_test[] =
{ njs_str("(async function() {console.log('Number: ' + await 111)})"),
njs_str("SyntaxError: await in arguments not supported in 1") },
- { njs_str("function f(a) {}"
- "(async function() {f(await 111)})"),
+ { njs_str("(async function() {f(await 111)})"),
+ njs_str("SyntaxError: await in arguments not supported in 1") },
+
+ { njs_str("(async function() {f(f(1), await 111)})"),
njs_str("SyntaxError: await in arguments not supported in 1") },
{ 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("(async function() {f(1, 'a', await 111)})"),
njs_str("SyntaxError: await in arguments not supported in 1") },
- { njs_str("function f(a) {}"
- "(async function() {f('Number: ' + await 111)})"),
+ { njs_str("(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) {}}"),
More information about the nginx-devel
mailing list