Welcome! Log In Create A New Profile

Advanced

[njs] Fixed parsing of for-statement.

Vadim Zhestikov via nginx-devel
January 29, 2024 12:00PM
details: https://hg.nginx.org/njs/rev/08d7391230be
branches:
changeset: 2274:08d7391230be
user: Vadim Zhestikov <v.zhestikov@f5.com>
date: Mon Jan 29 08:57:48 2024 -0800
description:
Fixed parsing of for-statement.

diffstat:

src/njs_parser.c | 37 +++++--------------------------------
src/test/njs_unit_test.c | 3 +++
2 files changed, 8 insertions(+), 32 deletions(-)

diffs (81 lines):

diff -r 6770c015efdc -r 08d7391230be src/njs_parser.c
--- a/src/njs_parser.c Thu Jan 25 14:48:05 2024 -0800
+++ b/src/njs_parser.c Mon Jan 29 08:57:48 2024 -0800
@@ -5491,23 +5491,9 @@ njs_parser_iteration_statement_for(njs_p


static njs_int_t
-njs_parser_for_var_in_of_expression_chk_fail(njs_parser_t *parser,
- njs_lexer_token_t *token, njs_queue_link_t *current)
-{
- if (parser->ret != NJS_OK) {
- return njs_parser_failed(parser);
- }
-
- return njs_parser_for_var_in_of_expression(parser, token, current);
-}
-
-
-static njs_int_t
njs_parser_for_expression_map_reparse(njs_parser_t *parser,
njs_lexer_token_t *token, njs_queue_link_t *current)
{
- njs_str_t *text;
-
if (parser->ret != NJS_OK && parser->node != NULL) {
return njs_parser_failed(parser);
}
@@ -5517,20 +5503,7 @@ njs_parser_for_expression_map_reparse(nj

njs_parser_next(parser, njs_parser_expression);

- /*
- * Here we pass not a node, but a token, this is important.
- * This is necessary for correct error output.
- */
-
- text = njs_mp_alloc(parser->vm->mem_pool, sizeof(njs_str_t));
- if (text == NULL) {
- return NJS_ERROR;
- }
-
- *text = token->text;
-
- return njs_parser_after(parser, current, text, 0,
- njs_parser_for_var_in_of_expression_chk_fail);
+ return NJS_OK;
}

return njs_parser_stack_pop(parser);
@@ -5793,14 +5766,14 @@ njs_parser_iteration_statement_for_map(n

*text = token->text;

- ret = njs_parser_after(parser, current, text, 1,
- njs_parser_for_expression_map_continue);
+ ret = njs_parser_after(parser, current, text, 0,
+ njs_parser_for_expression_map_reparse);
if (ret != NJS_OK) {
return NJS_ERROR;
}

- return njs_parser_after(parser, current, text, 0,
- njs_parser_for_expression_map_reparse);
+ return njs_parser_after(parser, current, text, 1,
+ njs_parser_for_expression_map_continue);
}

expression_after:
diff -r 6770c015efdc -r 08d7391230be src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Thu Jan 25 14:48:05 2024 -0800
+++ b/src/test/njs_unit_test.c Mon Jan 29 08:57:48 2024 -0800
@@ -2975,6 +2975,9 @@ static njs_unit_test_t njs_test[] =
{ njs_str("for(var``>0; 0 ;) ;"),
njs_str("SyntaxError: Unexpected token \"`\" in 1") },

+ { njs_str("for(1;;)for(-x;;)fr({-x;;)f"),
+ njs_str("SyntaxError: Unexpected token \"-\" in 1") },
+
{ njs_str("for(i;;)for(-new+3;;)break;"),
njs_str("SyntaxError: Unexpected token \"+\" in 1") },

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed parsing of for-statement.

Vadim Zhestikov via nginx-devel 299 January 29, 2024 12:00PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 205
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready