Skip to content

Commit dae6590

Browse files
author
Robert Fancsik
committed
Fix arguments object detection in non-complex param list
This patch is the followup of jerryscript-project#4849. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 55acdf2 commit dae6590

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

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

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,45 +1237,41 @@ scanner_filter_arguments (parser_context_t *context_p, /**< context */
12371237

12381238
JERRY_ASSERT (SCANNER_LITERAL_POOL_MAY_HAVE_ARGUMENTS (literal_pool_p->status_flags));
12391239

1240-
if (can_eval)
1240+
if (JERRY_UNLIKELY (can_eval))
12411241
{
12421242
if (prev_literal_pool_p != NULL)
12431243
{
12441244
prev_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_CAN_EVAL;
12451245
}
12461246

1247-
if (has_arguments)
1248-
{
1249-
/* Force the lexically stored arguments object creation */
1250-
literal_pool_p->status_flags |= (SCANNER_LITERAL_POOL_ARGUMENTS_IN_ARGS | SCANNER_LITERAL_POOL_NO_ARGUMENTS);
1251-
}
1247+
literal_pool_p->status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_CAN_EVAL;
12521248
}
1253-
1254-
literal_pool_p->status_flags &= (uint16_t) ~SCANNER_LITERAL_POOL_CAN_EVAL;
1255-
1256-
parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator);
1257-
1258-
while (true)
1249+
else
12591250
{
1260-
literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator);
1251+
parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator);
12611252

1262-
if (literal_p == NULL)
1253+
while (true)
12631254
{
1264-
return;
1265-
}
1255+
literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator);
12661256

1267-
if (can_eval || (literal_p->type & SCANNER_LITERAL_EARLY_CREATE))
1268-
{
1269-
literal_p->type |= SCANNER_LITERAL_NO_REG | SCANNER_LITERAL_EARLY_CREATE;
1270-
}
1257+
if (literal_p == NULL)
1258+
{
1259+
return;
1260+
}
12711261

1272-
uint8_t type = literal_p->type;
1273-
const uint8_t mask =
1274-
(SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_DESTRUCTURED_ARG | SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG);
1262+
if (can_eval || (literal_p->type & SCANNER_LITERAL_EARLY_CREATE))
1263+
{
1264+
literal_p->type |= SCANNER_LITERAL_NO_REG | SCANNER_LITERAL_EARLY_CREATE;
1265+
}
12751266

1276-
if ((type & mask) != SCANNER_LITERAL_IS_ARG)
1277-
{
1278-
break;
1267+
uint8_t type = literal_p->type;
1268+
const uint8_t mask =
1269+
(SCANNER_LITERAL_IS_ARG | SCANNER_LITERAL_IS_DESTRUCTURED_ARG | SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG);
1270+
1271+
if ((type & mask) != SCANNER_LITERAL_IS_ARG)
1272+
{
1273+
break;
1274+
}
12791275
}
12801276
}
12811277

@@ -1309,10 +1305,7 @@ scanner_filter_arguments (parser_context_t *context_p, /**< context */
13091305

13101306
if (has_arguments && scanner_literal_is_arguments (literal_p))
13111307
{
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));
1308+
has_arguments = false;
13161309
}
13171310

13181311
if (type & (SCANNER_LITERAL_IS_DESTRUCTURED_ARG | SCANNER_LITERAL_IS_ARROW_DESTRUCTURED_ARG))
@@ -1371,6 +1364,12 @@ scanner_filter_arguments (parser_context_t *context_p, /**< context */
13711364
}
13721365
}
13731366

1367+
if (has_arguments)
1368+
{
1369+
/* Force the lexically stored arguments object creation */
1370+
new_literal_pool_p->status_flags |= (SCANNER_LITERAL_POOL_ARGUMENTS_IN_ARGS | SCANNER_LITERAL_POOL_NO_ARGUMENTS);
1371+
}
1372+
13741373
new_literal_pool_p->prev_p = prev_literal_pool_p;
13751374

13761375
parser_list_free (&literal_pool_p->literal_pool);

tests/jerry/es.next/arguments.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,8 @@ function f22 (arguments, [a = arguments]) {
217217
assert(arguments === 3.1);
218218
}
219219
f22(3.1, []);
220+
221+
function f23(arguments, eval = () => eval()) {
222+
assert(arguments === undefined);
223+
}
224+
f23(undefined);

0 commit comments

Comments
 (0)