Skip to content

Commit 18dd9aa

Browse files
author
Robert Fancsik
authored
Prevent arguments object creation if 'arguments' function argument is present (#4849)
This patch fixes #4847. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent f8faf57 commit 18dd9aa

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,7 @@ scanner_filter_arguments (parser_context_t *context_p, /**< context */
12461246

12471247
if (has_arguments)
12481248
{
1249+
/* Force the lexically stored arguments object creation */
12491250
literal_pool_p->status_flags |= (SCANNER_LITERAL_POOL_ARGUMENTS_IN_ARGS | SCANNER_LITERAL_POOL_NO_ARGUMENTS);
12501251
}
12511252
}
@@ -1306,6 +1307,14 @@ scanner_filter_arguments (parser_context_t *context_p, /**< context */
13061307
literal_p->type = type;
13071308
}
13081309

1310+
if (has_arguments && scanner_literal_is_arguments (literal_p))
1311+
{
1312+
/* 'arguments' function argument existence should prevent the arguments object construction */
1313+
new_literal_pool_p->status_flags =
1314+
(uint16_t) (new_literal_pool_p->status_flags
1315+
& ~(SCANNER_LITERAL_POOL_ARGUMENTS_IN_ARGS | SCANNER_LITERAL_POOL_NO_ARGUMENTS));
1316+
}
1317+
13091318
if (type & (SCANNER_LITERAL_IS_DESTRUCTURED_ARG | SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG))
13101319
{
13111320
has_destructured_arg = true;
@@ -1328,6 +1337,7 @@ scanner_filter_arguments (parser_context_t *context_p, /**< context */
13281337
}
13291338
else if (has_arguments && scanner_literal_is_arguments (literal_p))
13301339
{
1340+
/* Arguments object is directly referenced from the function arguments */
13311341
new_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_ARGUMENTS_IN_ARGS;
13321342

13331343
if (type & SCANNER_LITERAL_NO_REG)

tests/jerry/es.next/arguments.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,21 @@ function f19(e = (v) => eval(v))
199199
assert(arguments === -12.5)
200200
}
201201
f19(undefined, "A");
202+
203+
function f20 (arguments, a = eval('arguments')) {
204+
assert(a === 3.1);
205+
assert(arguments === 3.1);
206+
}
207+
f20(3.1);
208+
209+
function f21 (arguments, a = arguments) {
210+
assert(a === 3.1);
211+
assert(arguments === 3.1);
212+
}
213+
f21(3.1);
214+
215+
function f22 (arguments, [a = arguments]) {
216+
assert(a === 3.1);
217+
assert(arguments === 3.1);
218+
}
219+
f22(3.1, []);

0 commit comments

Comments
 (0)