Skip to content

Commit

Permalink
Fixed empty labelled statement in a function.
Browse files Browse the repository at this point in the history
  • Loading branch information
VadimZhestikov committed Jul 4, 2024
1 parent 53ee8af commit 9be84ef
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/njs_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -4617,8 +4617,8 @@ njs_parser_statement(njs_parser_t *parser, njs_lexer_token_t *token,


static njs_int_t
njs_parser_statement_wo_node(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
njs_parser_statement_wo_node_(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current, int labelled)
{
switch (token->type) {
case NJS_TOKEN_OPEN_BRACE:
Expand All @@ -4631,6 +4631,12 @@ njs_parser_statement_wo_node(njs_parser_t *parser, njs_lexer_token_t *token,

case NJS_TOKEN_SEMICOLON:
njs_lexer_consume_token(parser->lexer, 1);
if (labelled == 1) {
token = njs_lexer_token(parser->lexer, 0);
if (token->type != NJS_TOKEN_END) {
return NJS_OK;
}
}
return njs_parser_stack_pop(parser);

case NJS_TOKEN_IF:
Expand Down Expand Up @@ -4710,6 +4716,22 @@ njs_parser_statement_wo_node(njs_parser_t *parser, njs_lexer_token_t *token,
}


static njs_int_t
njs_parser_statement_wo_node(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
{
return njs_parser_statement_wo_node_(parser, token, current, 0);
}


static njs_int_t
njs_parser_statement_wo_node_labelled(njs_parser_t *parser,
njs_lexer_token_t *token, njs_queue_link_t *current)
{
return njs_parser_statement_wo_node_(parser, token, current, 1);
}


static njs_int_t
njs_parser_statement_after(njs_parser_t *parser, njs_lexer_token_t *token,
njs_queue_link_t *current)
Expand Down Expand Up @@ -6685,7 +6707,7 @@ njs_parser_labelled_statement(njs_parser_t *parser, njs_lexer_token_t *token,
return NJS_DONE;

} else {
njs_parser_next(parser, njs_parser_statement_wo_node);
njs_parser_next(parser, njs_parser_statement_wo_node_labelled);
}

return njs_parser_after(parser, current, (void *) unique_id, 1,
Expand Down
7 changes: 7 additions & 0 deletions src/test/njs_unit_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3494,6 +3494,13 @@ 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") },

/* jumping out of a nested try-catch block. */

{ njs_str("var r = 0; "
Expand Down

0 comments on commit 9be84ef

Please sign in to comment.