Function declaration outside of blocks in direct eval must be ES5.1 compatible. (#3690)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg 2020-04-24 10:45:14 +02:00 committed by GitHub
parent 1b1460e61f
commit dcf8ccfd03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 31 deletions

View File

@ -698,7 +698,8 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */
JERRY_ASSERT (scope_stack_p[1].map_from == PARSER_SCOPE_STACK_FUNC);
#if ENABLED (JERRY_ES2015)
if (!(context_p->status_flags & PARSER_IS_STRICT))
if (!(context_p->status_flags & PARSER_IS_STRICT)
&& (scope_stack_p >= context_p->scope_stack_p + context_p->scope_stack_global_end))
{
bool copy_value = true;
@ -717,40 +718,25 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */
if (copy_value)
{
if (!(context_p->status_flags & PARSER_IS_FUNCTION)
&& (context_p->global_status_flags & ECMA_PARSE_DIRECT_EVAL))
stack_p = context_p->scope_stack_p;
while (stack_p < scope_stack_p)
{
if (!scanner_scope_find_let_declaration (context_p, &context_p->token.lit_location))
if (literal_index == stack_p->map_from)
{
context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_USED;
JERRY_ASSERT (!(stack_p->map_to & PARSER_SCOPE_STACK_IS_LEXICAL));
uint16_t map_to = scanner_decode_map_to (stack_p);
uint16_t opcode = ((map_to >= PARSER_REGISTER_START) ? CBC_ASSIGN_LITERAL_SET_IDENT
: CBC_COPY_TO_GLOBAL);
parser_emit_cbc_literal_value (context_p,
CBC_COPY_TO_GLOBAL,
opcode,
scanner_decode_map_to (scope_stack_p),
literal_index);
}
}
else
{
stack_p = context_p->scope_stack_p;
while (stack_p < scope_stack_p)
{
if (literal_index == stack_p->map_from)
{
JERRY_ASSERT (!(stack_p->map_to & PARSER_SCOPE_STACK_IS_LEXICAL));
uint16_t map_to = scanner_decode_map_to (stack_p);
uint16_t opcode = ((map_to >= PARSER_REGISTER_START) ? CBC_ASSIGN_LITERAL_SET_IDENT
: CBC_COPY_TO_GLOBAL);
parser_emit_cbc_literal_value (context_p,
opcode,
scanner_decode_map_to (scope_stack_p),
map_to);
break;
}
stack_p++;
map_to);
break;
}
stack_p++;
}
parser_flush_cbc (context_p);

View File

@ -2170,10 +2170,13 @@ scanner_create_variables (parser_context_t *context_p, /**< context */
if (func_init_opcode == CBC_INIT_LOCAL && (option_flags & SCANNER_CREATE_VARS_IS_SCRIPT))
{
#if ENABLED (JERRY_ES2015)
if (!(context_p->global_status_flags & ECMA_PARSE_DIRECT_EVAL))
literal.char_p -= data_p[1];
if (!(context_p->global_status_flags & ECMA_PARSE_DIRECT_EVAL)
|| !scanner_scope_find_let_declaration (context_p, &literal))
{
func_init_opcode = CBC_CREATE_VAR_FUNC_EVAL;
}
literal.char_p += data_p[1];
#else /* !ENABLED (JERRY_ES2015) */
func_init_opcode = CBC_CREATE_VAR_FUNC_EVAL;
#endif /* ENABLED (JERRY_ES2015) */

View File

@ -152,3 +152,10 @@ function f6() {
(((((e)))("assert(p1 === 0)")));
}
f6();
y = 1;
function f7() {
function x() { return y; }
eval("assert(x()() === 5); function y() { return 5 } assert(x()() === 5)");
}
f7()