[njs] Removed support for functions in labelled statements.

Alexander Borisov alexander.borisov at nginx.com
Wed Jun 3 12:18:35 UTC 2020


details:   https://hg.nginx.org/njs/rev/4737eb75961e
branches:  
changeset: 1419:4737eb75961e
user:      Alexander Borisov <alexander.borisov at nginx.com>
date:      Wed Jun 03 15:17:51 2020 +0300
description:
Removed support for functions in labelled statements.

In strict mode, support for functions is prohibited.

The issue was introduced in 86f55a7dc4a4.

diffstat:

 src/njs_parser.c         |  13 +++----------
 src/test/njs_unit_test.c |   3 +++
 2 files changed, 6 insertions(+), 10 deletions(-)

diffs (43 lines):

diff -r c2fa0f18e58d -r 4737eb75961e src/njs_parser.c
--- a/src/njs_parser.c	Tue Jun 02 12:08:04 2020 +0000
+++ b/src/njs_parser.c	Wed Jun 03 15:17:51 2020 +0300
@@ -5976,7 +5976,6 @@ njs_parser_labelled_statement(njs_parser
 {
     uintptr_t          unique_id;
     njs_variable_t     *label;
-    njs_parser_node_t  *node;
 
     unique_id = token->unique_id;
 
@@ -6002,15 +6001,9 @@ njs_parser_labelled_statement(njs_parser
     parser->node = NULL;
 
     if (token->type == NJS_TOKEN_FUNCTION) {
-        node = njs_parser_node_new(parser, NJS_TOKEN_FUNCTION);
-        if (node == NULL) {
-            return NJS_ERROR;
-        }
-
-        node->token_line = token->line;
-
-        njs_lexer_consume_token(parser->lexer, 1);
-        njs_parser_next(parser, njs_parser_function_declaration);
+        njs_syntax_error(parser->vm, "In strict mode code, functions can only "
+                                "be declared at top level or inside a block.");
+        return NJS_DONE;
 
     } else {
         njs_parser_next(parser, njs_parser_statement_wo_node);
diff -r c2fa0f18e58d -r 4737eb75961e src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Tue Jun 02 12:08:04 2020 +0000
+++ b/src/test/njs_unit_test.c	Wed Jun 03 15:17:51 2020 +0300
@@ -2934,6 +2934,9 @@ static njs_unit_test_t  njs_test[] =
     { njs_str("a:{continue b}"),
       njs_str("SyntaxError: Undefined label \"b\" in 1") },
 
+    { njs_str("a:function name() {}"),
+      njs_str("SyntaxError: In strict mode code, functions can only be declared at top level or inside a block.") },
+
 #if 0 /* TODO */
     { njs_str("a:{1; break a}"),
       njs_str("1") },


More information about the nginx-devel mailing list