Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 755 from github #756

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/njs_function.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "})");
Expand Down
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
10 changes: 10 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 Expand Up @@ -14147,6 +14154,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") },

Expand Down