Fix duplicated argument validation for default arguments (#3178)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -2272,7 +2272,7 @@ parser_parse_function_arguments (parser_context_t *context_p, /**< context */
|
|||||||
lexer_literal_t *literal_p;
|
lexer_literal_t *literal_p;
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER)
|
#if ENABLED (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER)
|
||||||
if (initializer_found)
|
if (initializer_found && (context_p->lit_object.literal_p->status_flags & LEXER_FLAG_FUNCTION_ARGUMENT))
|
||||||
{
|
{
|
||||||
parser_raise_error (context_p, PARSER_ERR_DUPLICATED_ARGUMENT_NAMES);
|
parser_raise_error (context_p, PARSER_ERR_DUPLICATED_ARGUMENT_NAMES);
|
||||||
}
|
}
|
||||||
@@ -2296,6 +2296,9 @@ parser_parse_function_arguments (parser_context_t *context_p, /**< context */
|
|||||||
* since no byte code has been emitted yet. Therefore there is no
|
* since no byte code has been emitted yet. Therefore there is no
|
||||||
* need to set the index field. */
|
* need to set the index field. */
|
||||||
context_p->lit_object.literal_p->type = LEXER_UNUSED_LITERAL;
|
context_p->lit_object.literal_p->type = LEXER_UNUSED_LITERAL;
|
||||||
|
#if ENABLED (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER)
|
||||||
|
context_p->lit_object.literal_p->prop.index = context_p->literal_count;
|
||||||
|
#endif /* ENABLED (JERRY_ES2015_FUNCTION_PARAMETER_INITIALIZER) */
|
||||||
|
|
||||||
/* Only the LEXER_FLAG_FUNCTION_ARGUMENT flag is kept. */
|
/* Only the LEXER_FLAG_FUNCTION_ARGUMENT flag is kept. */
|
||||||
context_p->lit_object.literal_p->status_flags &= LEXER_FLAG_FUNCTION_ARGUMENT;
|
context_p->lit_object.literal_p->status_flags &= LEXER_FLAG_FUNCTION_ARGUMENT;
|
||||||
|
|||||||
@@ -88,3 +88,11 @@ f();
|
|||||||
|
|
||||||
var f = new Function (str, "return (a + c) * (b == undefined ? 1 : 0)");
|
var f = new Function (str, "return (a + c) * (b == undefined ? 1 : 0)");
|
||||||
assert (f() == 9);
|
assert (f() == 9);
|
||||||
|
|
||||||
|
function duplicatedArg (a = c, b = d, c) {
|
||||||
|
assert(a === 1);
|
||||||
|
assert(b === 2);
|
||||||
|
assert(c === 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
duplicatedArg(1, 2, 3);
|
||||||
|
|||||||
Reference in New Issue
Block a user