[njs] Checking for duplicate function parameter names.
Dmitry Volyntsev
xeioex at nginx.com
Thu Apr 11 14:29:00 UTC 2019
details: https://hg.nginx.org/njs/rev/4df50ca085e7
branches:
changeset: 879:4df50ca085e7
user: hongzhidao <hongzhidao at 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") },
More information about the nginx-devel
mailing list