Welcome! Log In Create A New Profile

Advanced

[njs] Corrected error message when parsing "var" inside "for".

Valentin Bartenev
May 02, 2019 04:52PM
details: https://hg.nginx.org/njs/rev/ae95d2637819
branches:
changeset: 940:ae95d2637819
user: Valentin Bartenev <vbart@nginx.com>
date: Thu May 02 11:08:44 2019 +0300
description:
Corrected error message when parsing "var" inside "for".

The "var_in" flag indicates parsing inside the "for" statement with expectation
of the "in" token, but it doesn't define the loop as a for-in one. In fact,
that's unknown at the moment when this particular error message is emitted.

As a result, the following code:

for (var eval = 10; eval; eval--);

produces the error message about for-in loop:

SyntaxError: Identifier "eval" is forbidden in for-in var declaration

Actually, according to the specification "eval" isn't a keyword and shouldn't
cause any errors here. But this bug is beyond the scope of the current fix.

diffstat:

njs/njs_parser.c | 5 ++---
njs/test/njs_unit_test.c | 2 +-
2 files changed, 3 insertions(+), 4 deletions(-)

diffs (27 lines):

diff -r 601a52c421d1 -r ae95d2637819 njs/njs_parser.c
--- a/njs/njs_parser.c Mon Apr 29 15:57:36 2019 +0300
+++ b/njs/njs_parser.c Thu May 02 11:08:44 2019 +0300
@@ -1057,9 +1057,8 @@ njs_parser_var_statement(njs_vm_t *vm, n
if (token != NJS_TOKEN_NAME) {
if (token == NJS_TOKEN_ARGUMENTS || token == NJS_TOKEN_EVAL) {
njs_parser_syntax_error(vm, parser, "Identifier \"%V\" "
- "is forbidden in %s declaration",
- njs_parser_text(parser),
- var_in ? "for-in var" : "var");
+ "is forbidden in var declaration",
+ njs_parser_text(parser));
}

return NJS_TOKEN_ILLEGAL;
diff -r 601a52c421d1 -r ae95d2637819 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Mon Apr 29 15:57:36 2019 +0300
+++ b/njs/test/njs_unit_test.c Thu May 02 11:08:44 2019 +0300
@@ -6737,7 +6737,7 @@ static njs_unit_test_t njs_test[] =
nxt_string("SyntaxError: Identifier \"arguments\" is forbidden in var declaration in 1") },

{ nxt_string("for (var arguments in []) {}"),
- nxt_string("SyntaxError: Identifier \"arguments\" is forbidden in for-in var declaration in 1") },
+ nxt_string("SyntaxError: Identifier \"arguments\" is forbidden in var declaration in 1") },

{ nxt_string("function arguments(){}"),
nxt_string("SyntaxError: Identifier \"arguments\" is forbidden in function declaration in 1") },
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Corrected error message when parsing "var" inside "for".

Valentin Bartenev 300 May 02, 2019 04:52PM



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

Online Users

Guests: 236
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready