]> git.kaiwu.me - njs.git/commitdiff
Function declaration should return "undefined".
authorIgor Sysoev <igor@sysoev.ru>
Tue, 4 Apr 2017 07:47:12 +0000 (10:47 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Tue, 4 Apr 2017 07:47:12 +0000 (10:47 +0300)
njs/njs_generator.c
njs/test/njs_unit_test.c

index ceeb12a4526595425e9c830f3a2fc38cdfab815b..ceb40ae66bba3aca3ca6c93795616b30a3d5dcbf 100644 (file)
@@ -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) {
index 5584a6a1f27b51d1573f07446805b12a54862ca1..81f729c5d5cc6765c9a86df5892a4cdb0ef92222 100644 (file)
@@ -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") },