Read function's scope flags only in ecma_op_create_function_object instead of call sites of the routine.

JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
Ruben Ayrapetyan
2015-10-26 15:45:17 +03:00
parent 4d2ad40475
commit f24effa629
5 changed files with 38 additions and 65 deletions
@@ -214,13 +214,30 @@ ecma_op_create_function_object (ecma_collection_header_t *formal_params_collecti
* by caller after passing it
* to the routine */
ecma_object_t *scope_p, /**< function's scope */
bool is_strict, /**< 'strict' flag */
bool do_instantiate_arguments_object, /**< should an Arguments object be instantiated
* for the function object upon call */
const bytecode_data_header_t *bytecode_data_p, /**< byte-code array */
bool is_decl_in_strict_mode, /**< is function declared in strict mode code? */
const bytecode_data_header_t *bytecode_header_p, /**< byte-code */
vm_instr_counter_t first_instr_pos) /**< position of first instruction
* of function's body */
{
bool is_strict_mode_code = is_decl_in_strict_mode;
bool do_instantiate_arguments_object = true;
vm_instr_counter_t instr_pos = first_instr_pos;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (bytecode_header_p, instr_pos++);
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
{
is_strict_mode_code = true;
}
if ((scope_flags & OPCODE_SCOPE_CODE_FLAGS_NOT_REF_ARGUMENTS_IDENTIFIER)
&& (scope_flags & OPCODE_SCOPE_CODE_FLAGS_NOT_REF_EVAL_IDENTIFIER))
{
/* the code doesn't use 'arguments' identifier
* and doesn't perform direct call to eval,
* so Arguments object can't be referenced */
do_instantiate_arguments_object = false;
}
// 1., 4., 13.
ecma_object_t *prototype_obj_p = ecma_builtin_get (ECMA_BUILTIN_ID_FUNCTION_PROTOTYPE);
@@ -253,12 +270,12 @@ ecma_op_create_function_object (ecma_collection_header_t *formal_params_collecti
// 12.
ecma_property_t *bytecode_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_CODE_BYTECODE);
MEM_CP_SET_NON_NULL_POINTER (bytecode_prop_p->u.internal_property.value, bytecode_data_p);
MEM_CP_SET_NON_NULL_POINTER (bytecode_prop_p->u.internal_property.value, bytecode_header_p);
ecma_property_t *code_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_CODE_FLAGS_AND_OFFSET);
code_prop_p->u.internal_property.value = ecma_pack_code_internal_property_value (is_strict,
code_prop_p->u.internal_property.value = ecma_pack_code_internal_property_value (is_strict_mode_code,
do_instantiate_arguments_object,
first_instr_pos);
instr_pos);
// 14.
// 15.
@@ -273,7 +290,7 @@ ecma_op_create_function_object (ecma_collection_header_t *formal_params_collecti
*/
// 19.
if (is_strict)
if (is_strict_mode_code)
{
ecma_object_t *thrower_p = ecma_builtin_get (ECMA_BUILTIN_ID_TYPE_ERROR_THROWER);
@@ -1132,18 +1149,15 @@ ecma_op_function_declaration (ecma_object_t *lex_env_p, /**< lexical environment
* be changed / used / freed
* by caller after passing it
* to the routine */
bool is_strict, /**< flag indicating if function is declared in strict mode code */
bool do_instantiate_arguments_object, /**< flag, indicating whether an Arguments object
* should be instantiated for the function object
* upon call */
bool is_decl_in_strict_mode, /**< flag, indicating if function is
* declared in strict mode code */
bool is_configurable_bindings) /**< flag indicating whether function
* is declared in eval code */
{
// b.
ecma_object_t *func_obj_p = ecma_op_create_function_object (formal_params_collection_p,
lex_env_p,
is_strict,
do_instantiate_arguments_object,
is_decl_in_strict_mode,
bytecode_data_p,
function_first_instr_pos);
@@ -1205,7 +1219,7 @@ ecma_op_function_declaration (ecma_object_t *lex_env_p, /**< lexical environment
ret_value = ecma_op_set_mutable_binding (lex_env_p,
function_name_p,
ecma_make_object_value (func_obj_p),
is_strict);
is_decl_in_strict_mode);
}
else
{
@@ -31,7 +31,7 @@ extern bool ecma_is_constructor (ecma_value_t);
extern ecma_object_t *
ecma_op_create_function_object (ecma_collection_header_t *, ecma_object_t *,
bool, bool, const bytecode_data_header_t *, vm_instr_counter_t);
bool, const bytecode_data_header_t *, vm_instr_counter_t);
extern void
ecma_op_function_list_lazy_property_names (bool,
@@ -60,7 +60,7 @@ ecma_op_function_has_instance (ecma_object_t *, ecma_value_t);
extern ecma_completion_value_t
ecma_op_function_declaration (ecma_object_t *, ecma_string_t *, const bytecode_data_header_t *, vm_instr_counter_t,
ecma_collection_header_t *, bool, bool, bool);
ecma_collection_header_t *, bool, bool);
/**
* @}
+2 -41
View File
@@ -487,30 +487,12 @@ function_declaration (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
lit_cpointer_t function_name_lit_cp, /**< compressed pointer to literal with function name */
ecma_collection_header_t *formal_params_collection_p) /** formal parameters collection */
{
bool is_strict = frame_ctx_p->is_strict;
bool do_instantiate_arguments_object = true;
const bool is_configurable_bindings = frame_ctx_p->is_eval_code;
const vm_instr_counter_t function_code_end_oc = (vm_instr_counter_t) (
vm_read_instr_counter_from_meta (OPCODE_META_TYPE_FUNCTION_END, frame_ctx_p) + frame_ctx_p->pos);
frame_ctx_p->pos++;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (frame_ctx_p->bytecode_header_p->instrs_p,
frame_ctx_p->pos++);
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
{
is_strict = true;
}
if ((scope_flags & OPCODE_SCOPE_CODE_FLAGS_NOT_REF_ARGUMENTS_IDENTIFIER)
&& (scope_flags & OPCODE_SCOPE_CODE_FLAGS_NOT_REF_EVAL_IDENTIFIER))
{
/* the code doesn't use 'arguments' identifier
* and doesn't perform direct call to eval,
* so Arguments object can't be referenced */
do_instantiate_arguments_object = false;
}
ecma_string_t *function_name_string_p = ecma_new_ecma_string_from_lit_cp (function_name_lit_cp);
ecma_completion_value_t ret_value = ecma_op_function_declaration (frame_ctx_p->lex_env_p,
@@ -518,8 +500,7 @@ function_declaration (vm_frame_ctx_t *frame_ctx_p, /**< interpreter context */
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos,
formal_params_collection_p,
is_strict,
do_instantiate_arguments_object,
frame_ctx_p->is_strict,
is_configurable_bindings);
ecma_deref_ecma_string (function_name_string_p);
@@ -587,29 +568,10 @@ opfunc_func_expr_n (vm_instr_t instr, /**< instruction */
vm_fill_params_list (frame_ctx_p, params_number, formal_params_collection_p);
bool is_strict = frame_ctx_p->is_strict;
bool do_instantiate_arguments_object = true;
function_code_end_oc = (vm_instr_counter_t) (vm_read_instr_counter_from_meta (OPCODE_META_TYPE_FUNCTION_END,
frame_ctx_p) + frame_ctx_p->pos);
frame_ctx_p->pos++;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (frame_ctx_p->bytecode_header_p->instrs_p,
frame_ctx_p->pos++);
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
{
is_strict = true;
}
if ((scope_flags & OPCODE_SCOPE_CODE_FLAGS_NOT_REF_ARGUMENTS_IDENTIFIER)
&& (scope_flags & OPCODE_SCOPE_CODE_FLAGS_NOT_REF_EVAL_IDENTIFIER))
{
/* the code doesn't use 'arguments' identifier
* and doesn't perform direct call to eval,
* so Arguments object can't be referenced */
do_instantiate_arguments_object = false;
}
ecma_object_t *scope_p;
ecma_string_t *function_name_string_p = NULL;
if (is_named_func_expr)
@@ -632,8 +594,7 @@ opfunc_func_expr_n (vm_instr_t instr, /**< instruction */
ecma_object_t *func_obj_p = ecma_op_create_function_object (formal_params_collection_p,
scope_p,
is_strict,
do_instantiate_arguments_object,
frame_ctx_p->is_strict,
frame_ctx_p->bytecode_header_p,
frame_ctx_p->pos);
+4 -6
View File
@@ -396,8 +396,7 @@ vm_run_global (void)
bool is_strict = false;
vm_instr_counter_t start_pos = 0;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (__program->instrs_p,
start_pos++);
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (__program, start_pos++);
if (scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT)
{
@@ -449,8 +448,7 @@ vm_run_eval (const bytecode_data_header_t *bytecode_data_p, /**< byte-code data
bool is_direct) /**< is eval called in direct mode? */
{
vm_instr_counter_t first_instr_index = 0u;
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (bytecode_data_p->instrs_p,
first_instr_index++);
opcode_scope_code_flags_t scope_flags = vm_get_scope_flags (bytecode_data_p, first_instr_index++);
bool is_strict = ((scope_flags & OPCODE_SCOPE_CODE_FLAGS_STRICT) != 0);
ecma_value_t this_binding;
@@ -669,10 +667,10 @@ vm_get_instr (const vm_instr_t *instrs_p, /**< byte-code array */
* @return mask of scope code flags
*/
opcode_scope_code_flags_t
vm_get_scope_flags (const vm_instr_t *instrs_p, /**< byte-code array */
vm_get_scope_flags (const bytecode_data_header_t *bytecode_header_p, /**< byte-code data */
vm_instr_counter_t counter) /**< instruction counter */
{
vm_instr_t flags_instr = vm_get_instr (instrs_p, counter);
vm_instr_t flags_instr = vm_get_instr (bytecode_header_p->instrs_p, counter);
JERRY_ASSERT (flags_instr.op_idx == VM_OP_META
&& flags_instr.data.meta.type == OPCODE_META_TYPE_SCOPE_CODE_FLAGS);
return (opcode_scope_code_flags_t) flags_instr.data.meta.data_1;
+1 -1
View File
@@ -30,7 +30,7 @@ extern ecma_completion_value_t vm_run_from_pos (const bytecode_data_header_t *,
ecma_value_t, ecma_object_t *, bool, bool);
extern vm_instr_t vm_get_instr (const vm_instr_t *, vm_instr_counter_t);
extern opcode_scope_code_flags_t vm_get_scope_flags (const vm_instr_t *, vm_instr_counter_t);
extern opcode_scope_code_flags_t vm_get_scope_flags (const bytecode_data_header_t *, vm_instr_counter_t);
extern bool vm_is_strict_mode (void);
extern bool vm_is_direct_eval_form_call (void);