Implement eval support for functions with arguments lexical env. (#3806)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-06-08 12:11:54 +02:00
committed by GitHub
parent fed1b0c827
commit 2058ea1286
11 changed files with 214 additions and 44 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ JERRY_STATIC_ASSERT ((sizeof (cbc_uint16_arguments_t) % sizeof (jmem_cpointer_t)
*/
JERRY_STATIC_ASSERT (CBC_END == 238,
number_of_cbc_opcodes_changed);
JERRY_STATIC_ASSERT (CBC_EXT_END == 116,
JERRY_STATIC_ASSERT (CBC_EXT_END == 118,
number_of_cbc_ext_opcodes_changed);
#if ENABLED (JERRY_PARSER)
+4
View File
@@ -566,6 +566,10 @@
VM_OC_PUSH_LIT_POS_BYTE | VM_OC_GET_LITERAL) \
CBC_OPCODE (CBC_EXT_PUSH_LITERAL_PUSH_NUMBER_NEG_BYTE, CBC_HAS_LITERAL_ARG | CBC_HAS_BYTE_ARG, 2, \
VM_OC_PUSH_LIT_NEG_BYTE | VM_OC_GET_LITERAL) \
CBC_OPCODE (CBC_EXT_CREATE_VAR_EVAL, CBC_HAS_LITERAL_ARG, 0, \
VM_OC_EXT_VAR_EVAL) \
CBC_OPCODE (CBC_EXT_CREATE_VAR_FUNC_EVAL, CBC_HAS_LITERAL_ARG | CBC_HAS_LITERAL_ARG2, 0, \
VM_OC_EXT_VAR_EVAL) \
CBC_OPCODE (CBC_EXT_STRING_CONCAT, CBC_NO_FLAG, -1, \
VM_OC_STRING_CONCAT | VM_OC_GET_STACK_STACK | VM_OC_PUT_STACK) \
CBC_OPCODE (CBC_EXT_STRING_CONCAT_RIGHT_LITERAL, CBC_HAS_LITERAL_ARG, 0, \
+12 -5
View File
@@ -2224,16 +2224,23 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED;
#if ENABLED (JERRY_ES2015)
uint16_t eval_flags = PARSER_SAVE_STATUS_FLAGS (context_p->status_flags);
const uint32_t required_flags = PARSER_IS_FUNCTION | PARSER_LEXICAL_BLOCK_NEEDED;
if (context_p->status_flags & PARSER_FUNCTION_IS_PARSING_ARGS)
{
context_p->status_flags |= PARSER_LEXICAL_BLOCK_NEEDED;
}
if (context_p->status_flags & (PARSER_ALLOW_SUPER_CALL | PARSER_ALLOW_SUPER | PARSER_ALLOW_NEW_TARGET))
else if (((context_p->status_flags & (required_flags | PARSER_IS_STRICT)) == required_flags)
|| ((context_p->global_status_flags & ECMA_PARSE_FUNCTION_CONTEXT)
&& !(context_p->status_flags & PARSER_IS_FUNCTION)))
{
parser_emit_cbc_ext_call (context_p,
CBC_EXT_LOCAL_EVAL,
PARSER_SAVE_STATUS_FLAGS (context_p->status_flags));
eval_flags |= PARSER_GET_EVAL_FLAG (ECMA_PARSE_FUNCTION_CONTEXT);
}
if (eval_flags != 0)
{
parser_emit_cbc_ext_call (context_p, CBC_EXT_LOCAL_EVAL, eval_flags);
}
else
{
+31 -19
View File
@@ -67,9 +67,9 @@ typedef enum
PARSER_FUNCTION_IS_PARSING_ARGS = (1u << 17), /**< set when parsing function arguments */
PARSER_FUNCTION_HAS_NON_SIMPLE_PARAM = (1u << 18), /**< function has a non simple parameter */
PARSER_FUNCTION_HAS_REST_PARAM = (1u << 19), /**< function has rest parameter */
/* These 4 status flags must be in this order. See PARSER_SAVED_FLAGS_OFFSET. */
PARSER_CLASS_CONSTRUCTOR = (1u << 20), /**< a class constructor is parsed
* Note: PARSER_ALLOW_SUPER must be present */
/* These three status flags must be in this order. See PARSER_SAVED_FLAGS_OFFSET. */
PARSER_ALLOW_SUPER = (1u << 21), /**< allow super property access */
PARSER_ALLOW_SUPER_CALL = (1u << 22), /**< allow super constructor call
* Note: PARSER_CLASS_CONSTRUCTOR must be present */
@@ -154,34 +154,40 @@ typedef enum
#if ENABLED (JERRY_ES2015)
/**
* Offset between PARSER_CLASS_CONSTRUCTOR and ECMA_PARSE_CLASS_CONSTRUCTOR
* Offset of PARSER_ALLOW_SUPER
*/
#define PARSER_SAVED_FLAGS_OFFSET \
(JERRY_LOG2 (PARSER_CLASS_CONSTRUCTOR) - JERRY_LOG2 (ECMA_PARSE_CLASS_CONSTRUCTOR))
JERRY_LOG2 (PARSER_ALLOW_SUPER)
/**
* Count of ecma_parse_opts_t class parsing options related bits
* Mask of saved flags
*/
#define PARSER_SAVED_FLAGS_COUNT \
(JERRY_LOG2 (ECMA_PARSE_ALLOW_NEW_TARGET) - JERRY_LOG2 (ECMA_PARSE_CLASS_CONSTRUCTOR) + 1)
/**
* Mask for get class option bits from ecma_parse_opts_t
*/
#define PARSER_CLASS_ECMA_PARSE_OPTS_TO_PARSER_OPTS_MASK \
(((1 << PARSER_SAVED_FLAGS_COUNT) - 1) << JERRY_LOG2 (ECMA_PARSE_CLASS_CONSTRUCTOR))
/**
* Get class option bits from ecma_parse_opts_t
*/
#define PARSER_GET_SAVED_FLAGS(opts) \
(((opts) & PARSER_CLASS_ECMA_PARSE_OPTS_TO_PARSER_OPTS_MASK) << PARSER_SAVED_FLAGS_OFFSET)
#define PARSER_SAVED_FLAGS_MASK \
((1 << (JERRY_LOG2 (PARSER_ALLOW_NEW_TARGET) - JERRY_LOG2 (PARSER_ALLOW_SUPER) + 1)) - 1)
/**
* Get class option bits from parser_general_flags_t
*/
#define PARSER_SAVE_STATUS_FLAGS(opts) \
((uint16_t) (((opts) >> PARSER_SAVED_FLAGS_OFFSET) & PARSER_CLASS_ECMA_PARSE_OPTS_TO_PARSER_OPTS_MASK))
((uint16_t) (((opts) >> PARSER_SAVED_FLAGS_OFFSET) & PARSER_SAVED_FLAGS_MASK))
/**
* Mask for get class option bits from ecma_parse_opts_t
*/
#define PARSER_RESTORE_STATUS_FLAGS_MASK \
(((ECMA_PARSE_ALLOW_NEW_TARGET << 1) - 1) - (ECMA_PARSE_ALLOW_SUPER - 1))
/**
* Shift for get class option bits from ecma_parse_opts_t
*/
#define PARSER_RESTORE_STATUS_FLAGS_SHIFT \
(JERRY_LOG2 (PARSER_ALLOW_SUPER) - JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER))
/**
* Get class option bits from ecma_parse_opts_t
*/
#define PARSER_RESTORE_STATUS_FLAGS(opts) \
(((opts) & PARSER_RESTORE_STATUS_FLAGS_MASK) << PARSER_RESTORE_STATUS_FLAGS_SHIFT)
/**
* All flags that affect exotic arguments object creation.
@@ -189,6 +195,12 @@ typedef enum
#define PARSER_ARGUMENTS_RELATED_FLAGS \
(PARSER_ARGUMENTS_NEEDED | PARSER_FUNCTION_HAS_NON_SIMPLE_PARAM | PARSER_IS_STRICT)
/**
* Get the corresponding eval flag for a ecma_parse_opts_t flag
*/
#define PARSER_GET_EVAL_FLAG(type) \
((type) >> JERRY_LOG2 (ECMA_PARSE_ALLOW_SUPER))
#else /* !ENABLED (JERRY_ES2015) */
/**
+8 -3
View File
@@ -27,8 +27,13 @@ JERRY_STATIC_ASSERT ((int) ECMA_PARSE_STRICT_MODE == (int) PARSER_IS_STRICT,
ecma_parse_strict_mode_must_be_equal_to_parser_is_strict);
#if ENABLED (JERRY_ES2015)
JERRY_STATIC_ASSERT ((ECMA_PARSE_CLASS_CONSTRUCTOR << PARSER_SAVED_FLAGS_OFFSET) == PARSER_CLASS_CONSTRUCTOR,
ecma_saved_parse_options_must_be_transformed_to_ecma_general_flags);
JERRY_STATIC_ASSERT (PARSER_SAVE_STATUS_FLAGS (PARSER_ALLOW_SUPER) == 0x1,
incorrect_saving_of_ecma_parse_allow_super);
JERRY_STATIC_ASSERT (PARSER_RESTORE_STATUS_FLAGS (ECMA_PARSE_ALLOW_SUPER) == PARSER_ALLOW_SUPER,
incorrect_restoring_of_ecma_parse_allow_super);
JERRY_STATIC_ASSERT (PARSER_RESTORE_STATUS_FLAGS (ECMA_PARSE_FUNCTION_CONTEXT) == 0,
ecma_parse_function_context_must_not_be_transformed);
#endif /* ENABLED (JERRY_ES2015) */
/** \addtogroup parser Parser
@@ -2016,7 +2021,7 @@ parser_parse_source (const uint8_t *arg_list_p, /**< function argument list */
}
#if ENABLED (JERRY_ES2015)
context.status_flags |= PARSER_GET_SAVED_FLAGS (parse_opts);
context.status_flags |= PARSER_RESTORE_STATUS_FLAGS (parse_opts);
context.tagged_template_literal_cp = JMEM_CP_NULL;
#endif /* ENABLED (JERRY_ES2015) */
+30 -5
View File
@@ -2227,9 +2227,9 @@ scanner_create_variables (parser_context_t *context_p, /**< context */
context_p->scope_stack_top = (uint16_t) (scope_stack_p - context_p->scope_stack_p);
#endif /* ENABLED (JERRY_PARSER_DUMP_BYTE_CODE) */
uint16_t opcode = ((option_flags & SCANNER_CREATE_VARS_IS_SCRIPT) ? CBC_CREATE_VAR_EVAL
: CBC_CREATE_VAR);
#if ENABLED (JERRY_ES2015)
uint16_t opcode;
switch (type)
{
case SCANNER_STREAM_TYPE_LET:
@@ -2242,14 +2242,34 @@ scanner_create_variables (parser_context_t *context_p, /**< context */
opcode = CBC_CREATE_CONST;
break;
}
case SCANNER_STREAM_TYPE_LOCAL:
case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG:
case SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC:
case SCANNER_STREAM_TYPE_VAR:
{
opcode = CBC_CREATE_VAR;
if (option_flags & SCANNER_CREATE_VARS_IS_SCRIPT)
{
opcode = CBC_CREATE_VAR_EVAL;
if (context_p->global_status_flags & ECMA_PARSE_FUNCTION_CONTEXT)
{
opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_CREATE_VAR_EVAL);
}
}
break;
}
default:
{
JERRY_ASSERT (type == SCANNER_STREAM_TYPE_LOCAL
|| type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG
|| type == SCANNER_STREAM_TYPE_DESTRUCTURED_ARG_FUNC);
opcode = CBC_CREATE_LOCAL;
break;
}
}
#else /* !ENABLED (JERRY_ES2015) */
uint16_t opcode = ((option_flags & SCANNER_CREATE_VARS_IS_SCRIPT) ? CBC_CREATE_VAR_EVAL
: CBC_CREATE_VAR);
#endif /* ENABLED (JERRY_ES2015) */
parser_emit_cbc_literal (context_p, opcode, map_to);
@@ -2323,6 +2343,11 @@ scanner_create_variables (parser_context_t *context_p, /**< context */
|| !scanner_scope_find_let_declaration (context_p, &literal))
{
func_init_opcode = CBC_CREATE_VAR_FUNC_EVAL;
if (context_p->global_status_flags & ECMA_PARSE_FUNCTION_CONTEXT)
{
func_init_opcode = PARSER_TO_EXT_OPCODE (CBC_EXT_CREATE_VAR_FUNC_EVAL);
}
}
literal.char_p += data_p[1];
#else /* !ENABLED (JERRY_ES2015) */