Welcome! Log In Create A New Profile

Advanced

[njs] Checking for duplicate function parameter names.

Dmitry Volyntsev
April 11, 2019 10:30AM
details: https://hg.nginx.org/njs/rev/4df50ca085e7
branches:
changeset: 879:4df50ca085e7
user: hongzhidao <hongzhidao@gmail.com>
date: Thu Apr 11 21:13:03 2019 +0800
description:
Checking for duplicate function parameter names.

This closes #80 issue on Github.

diffstat:

njs/njs_parser.c | 6 ++++++
njs/test/njs_unit_test.c | 21 +++++++++++++++++++++
2 files changed, 27 insertions(+), 0 deletions(-)

diffs (47 lines):

diff -r b9d619068453 -r 4df50ca085e7 njs/njs_parser.c
--- a/njs/njs_parser.c Thu Apr 11 16:32:06 2019 +0300
+++ b/njs/njs_parser.c Thu Apr 11 21:13:03 2019 +0800
@@ -837,6 +837,12 @@ njs_parser_lambda_argument(njs_vm_t *vm,
return NJS_TOKEN_ERROR;
}

+ if (arg->index > 0) {
+ njs_parser_syntax_error(vm, parser, "Duplicate parameter names");
+
+ return NJS_TOKEN_ILLEGAL;
+ }
+
arg->index = index;

ret = njs_name_copy(vm, &arg->name, njs_parser_text(parser));
diff -r b9d619068453 -r 4df50ca085e7 njs/test/njs_unit_test.c
--- a/njs/test/njs_unit_test.c Thu Apr 11 16:32:06 2019 +0300
+++ b/njs/test/njs_unit_test.c Thu Apr 11 21:13:03 2019 +0800
@@ -5716,6 +5716,27 @@ static njs_unit_test_t njs_test[] =
"binded.length"),
nxt_string("0") },

+ { nxt_string("function f(a,a) { };"),
+ nxt_string("SyntaxError: Duplicate parameter names in 1") },
+
+ { nxt_string("function f(a,b,a) { };"),
+ nxt_string("SyntaxError: Duplicate parameter names in 1") },
+
+ { nxt_string("function f(a, ...a) { };"),
+ nxt_string("SyntaxError: Duplicate parameter names in 1") },
+
+ { nxt_string("(function(a,a) { })"),
+ nxt_string("SyntaxError: Duplicate parameter names in 1") },
+
+ { nxt_string("(function(a,...a) { })"),
+ nxt_string("SyntaxError: Duplicate parameter names in 1") },
+
+ { nxt_string("(function f(a,a) { })"),
+ nxt_string("SyntaxError: Duplicate parameter names in 1") },
+
+ { nxt_string("(function f(a,...a) { })"),
+ nxt_string("SyntaxError: Duplicate parameter names in 1") },
+
{ nxt_string("function f(a,b) { }; f.length"),
nxt_string("2") },

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

[njs] Checking for duplicate function parameter names.

Dmitry Volyntsev 308 April 11, 2019 10:30AM



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

Online Users

Guests: 207
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