Welcome! Log In Create A New Profile

Advanced

[njs] Introduced reserved words in strict mode.

Alexander Borisov
April 30, 2021 09:06AM
details: https://hg.nginx.org/njs/rev/28f33155ad3f
branches:
changeset: 1630:28f33155ad3f
user: Alexander Borisov <alexander.borisov@nginx.com>
date: Fri Apr 30 16:02:20 2021 +0300
description:
Introduced reserved words in strict mode.

diffstat:

src/njs_lexer_tables.h | 16 ++++++++--------
src/njs_parser.c | 6 ++++++
src/test/njs_unit_test.c | 8 +++++++-
utils/lexer_keyword.py | 16 ++++++++--------
4 files changed, 29 insertions(+), 17 deletions(-)

diffs (134 lines):

diff -r 0a2a0b5a74f4 -r 28f33155ad3f src/njs_lexer_tables.h
--- a/src/njs_lexer_tables.h Fri Apr 30 16:02:08 2021 +0300
+++ b/src/njs_lexer_tables.h Fri Apr 30 16:02:20 2021 +0300
@@ -159,7 +159,7 @@ static const njs_keyword_t njs_lexer_kws
{
.entry = { njs_str("implements") },
.type = NJS_TOKEN_IMPLEMENTS,
- .reserved = 0
+ .reserved = 1
},

{
@@ -183,13 +183,13 @@ static const njs_keyword_t njs_lexer_kws
{
.entry = { njs_str("interface") },
.type = NJS_TOKEN_INTERFACE,
- .reserved = 0
+ .reserved = 1
},

{
.entry = { njs_str("let") },
.type = NJS_TOKEN_LET,
- .reserved = 0
+ .reserved = 1
},

{
@@ -219,25 +219,25 @@ static const njs_keyword_t njs_lexer_kws
{
.entry = { njs_str("package") },
.type = NJS_TOKEN_PACKAGE,
- .reserved = 0
+ .reserved = 1
},

{
.entry = { njs_str("private") },
.type = NJS_TOKEN_PRIVATE,
- .reserved = 0
+ .reserved = 1
},

{
.entry = { njs_str("protected") },
.type = NJS_TOKEN_PROTECTED,
- .reserved = 0
+ .reserved = 1
},

{
.entry = { njs_str("public") },
.type = NJS_TOKEN_PUBLIC,
- .reserved = 0
+ .reserved = 1
},

{
@@ -249,7 +249,7 @@ static const njs_keyword_t njs_lexer_kws
{
.entry = { njs_str("static") },
.type = NJS_TOKEN_STATIC,
- .reserved = 0
+ .reserved = 1
},

{
diff -r 0a2a0b5a74f4 -r 28f33155ad3f src/njs_parser.c
--- a/src/njs_parser.c Fri Apr 30 16:02:08 2021 +0300
+++ b/src/njs_parser.c Fri Apr 30 16:02:20 2021 +0300
@@ -4550,6 +4550,12 @@ njs_parser_declaration(njs_parser_t *par
break;

default:
+ if (njs_lexer_token_is_reserved(token)) {
+ njs_lexer_consume_token(parser->lexer, 1);
+ njs_parser_next(parser, njs_parser_failed_state);
+ return NJS_OK;
+ }
+
if (njs_lexer_token_is_binding_identifier(token)) {
njs_parser_next(parser, njs_parser_lexical_declaration);
break;
diff -r 0a2a0b5a74f4 -r 28f33155ad3f src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c Fri Apr 30 16:02:08 2021 +0300
+++ b/src/test/njs_unit_test.c Fri Apr 30 16:02:20 2021 +0300
@@ -9475,6 +9475,12 @@ static njs_unit_test_t njs_test[] =
{ njs_str("function f(){} typeof(f)"),
njs_str("function") },

+ { njs_str("function let() {}"),
+ njs_str("SyntaxError: Unexpected token \"let\" in 1") },
+
+ { njs_str("function static() {}"),
+ njs_str("SyntaxError: Unexpected token \"static\" in 1") },
+
/* Recursive factorial. */

{ njs_str("function f(a) {"
@@ -18101,7 +18107,7 @@ static njs_unit_test_t njs_test[] =

{ njs_str("var let = 123;"
"let"),
- njs_str("123") },
+ njs_str("SyntaxError: Unexpected token \"let\" in 1") },

{ njs_str("var const = 123"),
njs_str("SyntaxError: Unexpected token \"const\" in 1") },
diff -r 0a2a0b5a74f4 -r 28f33155ad3f utils/lexer_keyword.py
--- a/utils/lexer_keyword.py Fri Apr 30 16:02:08 2021 +0300
+++ b/utils/lexer_keyword.py Fri Apr 30 16:02:20 2021 +0300
@@ -64,14 +64,14 @@ global_keywords = {
"debugger": 1,
"enum": 1,
"extends": 1,
- "implements": 0,
- "interface": 0,
- "let": 0,
- "package": 0,
- "private": 0,
- "protected": 0,
- "public": 0,
- "static": 0,
+ "implements": 1,
+ "interface": 1,
+ "let": 1,
+ "package": 1,
+ "private": 1,
+ "protected": 1,
+ "public": 1,
+ "static": 1,
"super": 1
}

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Introduced reserved words in strict mode.

Alexander Borisov 73 April 30, 2021 09:06AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 73
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready