From: hongzhidao Date: Thu, 11 Apr 2019 13:13:03 +0000 (+0800) Subject: Checking for duplicate function parameter names. X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=c4372a3a2b940b940c761dbecb7eaaaed40b9f27;p=njs.git Checking for duplicate function parameter names. This closes #80 issue on Github. --- diff --git a/njs/njs_parser.c b/njs/njs_parser.c index 5a2394f3..d53cfab7 100644 --- a/njs/njs_parser.c +++ b/njs/njs_parser.c @@ -837,6 +837,12 @@ njs_parser_lambda_argument(njs_vm_t *vm, njs_parser_t *parser, 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 --git a/njs/test/njs_unit_test.c b/njs/test/njs_unit_test.c index b1903164..ede03192 100644 --- a/njs/test/njs_unit_test.c +++ b/njs/test/njs_unit_test.c @@ -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") },