From 6d735e295dea65fee277997d0c6826398acec2e7 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Tue, 4 Apr 2017 10:47:12 +0300 Subject: [PATCH] Function declaration should return "undefined". --- njs/njs_generator.c | 5 +++-- njs/test/njs_unit_test.c | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/njs/njs_generator.c b/njs/njs_generator.c index ceeb12a4..ceb40ae6 100644 --- a/njs/njs_generator.c +++ b/njs/njs_generator.c @@ -1261,9 +1261,10 @@ njs_generate_stop_statement(njs_vm_t *vm, njs_parser_t *parser, stop->code.retval = NJS_VMCODE_NO_RETVAL; index = NJS_INDEX_NONE; + node = node->right; - if (node->right != NULL) { - index = node->right->index; + if (node != NULL && node->token != NJS_TOKEN_FUNCTION) { + index = node->index; } if (index == NJS_INDEX_NONE) { diff --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index 5584a6a1..81f729c5 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -4199,6 +4199,12 @@ static njs_unit_test_t njs_test[] = { nxt_string("function () { } f()"), nxt_string("SyntaxError: Unexpected token \"(\" in 1") }, + { nxt_string("function f() { }"), + nxt_string("undefined") }, + + { nxt_string("var x; function f() { }"), + nxt_string("undefined") }, + { nxt_string("function f() { } f()"), nxt_string("undefined") }, -- 2.47.3