]> git.kaiwu.me - njs.git/commitdiff
A return statement has been disabled outside of function.
authorIgor Sysoev <igor@sysoev.ru>
Mon, 15 Aug 2016 08:33:37 +0000 (11:33 +0300)
committerIgor Sysoev <igor@sysoev.ru>
Mon, 15 Aug 2016 08:33:37 +0000 (11:33 +0300)
njs/njs_parser.c
njs/test/njs_unit_test.c

index 87159da3278d237e797ab726bf44d0e8b11aaf97..c5635f66d7188dec09f982f2749207372ee567e8 100644 (file)
@@ -584,6 +584,13 @@ njs_parser_return_statement(njs_vm_t *vm, njs_parser_t *parser)
     njs_token_t        token;
     njs_parser_node_t  *node;
 
+    if (parser->scope == NJS_SCOPE_GLOBAL) {
+        nxt_alert(&vm->trace, NXT_LEVEL_ERROR,
+                  "SyntaxError: Illegal return statement");
+
+        return NXT_ERROR;
+    }
+
     node = njs_parser_node_alloc(vm);
     if (nxt_slow_path(node == NULL)) {
         return NJS_TOKEN_ERROR;
index 1fae98b554fc0f250bb01b4c59e85d95e28ccb6d..9ec00ef08df403c4fcc8cbf67f3797f8f8fab37e 100644 (file)
@@ -3290,6 +3290,9 @@ static njs_unit_test_t  njs_test[] =
 
     /* Functions. */
 
+    { nxt_string("return"),
+      nxt_string("SyntaxError: Illegal return statement in 1") },
+
     { nxt_string("function () { } f()"),
       nxt_string("SyntaxError: Unexpected token \"(\" in 1") },