Skip to content

Commit 195b0d3

Browse files
authored
Fix duplicated argument validation for default arguments (#3178)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent e9664b7 commit 195b0d3

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

jerry-core/parser/js/js-parser.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,7 @@ parser_parse_function_arguments (parser_context_t *context_p, /**< context */
22722272
lexer_literal_t *literal_p;
22732273

22742274
#if ENABLED (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER)
2275-
if (initializer_found)
2275+
if (initializer_found && (context_p->lit_object.literal_p->status_flags & LEXER_FLAG_FUNCTION_ARGUMENT))
22762276
{
22772277
parser_raise_error (context_p, PARSER_ERR_DUPLICATED_ARGUMENT_NAMES);
22782278
}
@@ -2296,6 +2296,9 @@ parser_parse_function_arguments (parser_context_t *context_p, /**< context */
22962296
* since no byte code has been emitted yet. Therefore there is no
22972297
* need to set the index field. */
22982298
context_p->lit_object.literal_p->type = LEXER_UNUSED_LITERAL;
2299+
#if ENABLED (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER)
2300+
context_p->lit_object.literal_p->prop.index = context_p->literal_count;
2301+
#endif /* ENABLED (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER) */
22992302

23002303
/* Only the LEXER_FLAG_FUNCTION_ARGUMENT flag is kept. */
23012304
context_p->lit_object.literal_p->status_flags &= LEXER_FLAG_FUNCTION_ARGUMENT;

tests/jerry/es2015/function-param-init.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,11 @@ f();
8888

8989
var f = new Function (str, "return (a + c) * (b == undefined ? 1 : 0)");
9090
assert (f() == 9);
91+
92+
function duplicatedArg (a = c, b = d, c) {
93+
assert(a === 1);
94+
assert(b === 2);
95+
assert(c === 3);
96+
}
97+
98+
duplicatedArg(1, 2, 3);

0 commit comments

Comments
 (0)