Welcome! Log In Create A New Profile

Advanced

[njs] Fixed empty labelled statement in a function.

Anonymous User
July 10, 2024 07:00PM
details: https://github.com/nginx/njs/commit/7f10ae251661656dfd4f40ac3347fba802c14399
branches: master
commit: 7f10ae251661656dfd4f40ac3347fba802c14399
user: Vadim Zhestikov <v.zhestikov@f5.com>
date: Fri, 5 Jul 2024 11:23:33 -0700
description:
Fixed empty labelled statement in a function.


---
src/njs_parser.c | 33 +++++++++++++++++++++------------
src/test/njs_unit_test.c | 16 ++++++++++++++++
2 files changed, 37 insertions(+), 12 deletions(-)

diff --git a/src/njs_parser.c b/src/njs_parser.c
index dbd9169f..7eb6292e 100644
--- a/src/njs_parser.c
+++ b/src/njs_parser.c
@@ -6699,23 +6699,32 @@ njs_parser_labelled_statement_after(njs_parser_t *parser,
{
njs_int_t ret;
uintptr_t unique_id;
+ njs_parser_node_t *node;
const njs_lexer_entry_t *entry;

- if (parser->node != NULL) {
- /* The statement is not empty block or just semicolon. */
-
- unique_id = (uintptr_t) parser->target;
- entry = (const njs_lexer_entry_t *) unique_id;
-
- ret = njs_name_copy(parser->vm, &parser->node->name, &entry->name);
- if (ret != NJS_OK) {
+ node = parser->node;
+ if (node == NULL) {
+ node = njs_parser_node_new(parser, NJS_TOKEN_BLOCK);
+ if (node == NULL) {
return NJS_ERROR;
}

- ret = njs_label_remove(parser->vm, parser->scope, unique_id);
- if (ret != NJS_OK) {
- return NJS_ERROR;
- }
+ node->token_line = token->line;
+
+ parser->node = node;
+ }
+
+ unique_id = (uintptr_t) parser->target;
+ entry = (const njs_lexer_entry_t *) unique_id;
+
+ ret = njs_name_copy(parser->vm, &parser->node->name, &entry->name);
+ if (ret != NJS_OK) {
+ return NJS_ERROR;
+ }
+
+ ret = njs_label_remove(parser->vm, parser->scope, unique_id);
+ if (ret != NJS_OK) {
+ return NJS_ERROR;
}

return njs_parser_stack_pop(parser);
diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c
index 2f0e318c..75933665 100644
--- a/src/test/njs_unit_test.c
+++ b/src/test/njs_unit_test.c
@@ -3494,6 +3494,22 @@ static njs_unit_test_t njs_test[] =
"} catch(e) {c = 10;}; [c, fin]"),
njs_str("1,1") },

+ { njs_str("function v1() {"
+ "function v2 () {}"
+ "v3:;"
+ "1;"
+ "} v1();"),
+ njs_str("undefined") },
+
+ { njs_str("function v1() {"
+ "function v2 () {}"
+ "v3:;"
+ "} v1();"),
+ njs_str("undefined") },
+
+ { njs_str("{v1:;}"),
+ njs_str("undefined") },
+
/* jumping out of a nested try-catch block. */

{ njs_str("var r = 0; "
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
https://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Fixed empty labelled statement in a function.

Anonymous User 75 July 10, 2024 07:00PM



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

Online Users

Guests: 178
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