From 53ee8af07d33feb79c1c196ded4e34ad21986413 Mon Sep 17 00:00:00 2001 From: Vadim Zhestikov Date: Tue, 2 Jul 2024 14:55:03 -0700 Subject: [PATCH 1/2] Fixed Function w/o args called relative an object. --- src/njs_function.c | 8 +++++--- src/test/njs_unit_test.c | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/njs_function.c b/src/njs_function.c index bfdf3f355..c677be573 100644 --- a/src/njs_function.c +++ b/src/njs_function.c @@ -1054,9 +1054,11 @@ njs_function_constructor(njs_vm_t *vm, njs_value_t *args, njs_uint_t nargs, njs_chb_append_literal(&chain, "){"); - ret = njs_value_to_chain(vm, &chain, njs_argument(args, nargs - 1)); - if (njs_slow_path(ret < NJS_OK)) { - return ret; + if (nargs > 1) { + ret = njs_value_to_chain(vm, &chain, njs_argument(args, nargs - 1)); + if (njs_slow_path(ret < NJS_OK)) { + return ret; + } } njs_chb_append_literal(&chain, "})"); diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 530cf6ff8..2f0e318c4 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -14147,6 +14147,9 @@ static njs_unit_test_t njs_test[] = { njs_str("Function.constructor === Function"), njs_str("true") }, + { njs_str("Function.constructor()"), + njs_str("[object Function]") }, + { njs_str("function f() {} f.__proto__ === Function.prototype"), njs_str("true") }, From 9be84effb600475f89a55f39cae6bf48e28ac88e Mon Sep 17 00:00:00 2001 From: Vadim Zhestikov Date: Wed, 3 Jul 2024 17:13:00 -0700 Subject: [PATCH 2/2] Fixed empty labelled statement in a function. --- src/njs_parser.c | 28 +++++++++++++++++++++++++--- src/test/njs_unit_test.c | 7 +++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/njs_parser.c b/src/njs_parser.c index dbd9169f2..66b6826f0 100644 --- a/src/njs_parser.c +++ b/src/njs_parser.c @@ -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: @@ -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: @@ -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) @@ -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, diff --git a/src/test/njs_unit_test.c b/src/test/njs_unit_test.c index 2f0e318c4..ce9d4a4cb 100644 --- a/src/test/njs_unit_test.c +++ b/src/test/njs_unit_test.c @@ -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; "