3737 */
3838
3939/* *
40- * Pack 'is_strict' flag and opcode index to value
40+ * Pack 'is_strict', 'do_instantiate_arguments_object' flags and opcode index to value
4141 * that can be stored in an [[Code]] internal property.
4242 *
4343 * @return packed value
4444 */
4545static uint32_t
4646ecma_pack_code_internal_property_value (bool is_strict, /* *< is code strict? */
47+ bool do_instantiate_args_obj, /* *< should an Arguments object be
48+ * instantiated for the code */
4749 opcode_counter_t opcode_idx) /* *< index of first opcode */
4850{
4951 uint32_t value = opcode_idx;
5052 const uint32_t is_strict_bit_offset = (uint32_t ) (sizeof (value) * JERRY_BITSINBYTE - 1 );
53+ const uint32_t do_instantiate_arguments_object_bit_offset = (uint32_t ) (sizeof (value) * JERRY_BITSINBYTE - 2 );
5154
5255 JERRY_ASSERT (((value) & (1u << is_strict_bit_offset)) == 0 );
56+ JERRY_ASSERT (((value) & (1u << do_instantiate_arguments_object_bit_offset)) == 0 );
5357
5458 if (is_strict)
5559 {
5660 value |= (1u << is_strict_bit_offset);
5761 }
5862
63+ if (do_instantiate_args_obj)
64+ {
65+ value |= (1u << do_instantiate_arguments_object_bit_offset);
66+ }
67+
5968 return value;
6069} /* ecma_pack_code_internal_property_value */
6170
6271/* *
63- * Unpack 'is_strict' flag and opcode index from value
72+ * Unpack 'is_strict', 'do_instantiate_arguments_object' flags and opcode index from value
6473 * that can be stored in an [[Code]] internal property.
6574 *
6675 * @return opcode index
6776 */
6877static opcode_counter_t
6978ecma_unpack_code_internal_property_value (uint32_t value, /* *< packed value */
70- bool * out_is_strict_p) /* *< out: is code strict? */
79+ bool * out_is_strict_p, /* *< out: is code strict? */
80+ bool * out_do_instantiate_args_obj_p) /* *< should an Arguments object be
81+ * instantiated for the code */
7182{
7283 JERRY_ASSERT (out_is_strict_p != NULL );
84+ JERRY_ASSERT (out_do_instantiate_args_obj_p != NULL );
7385
7486 const uint32_t is_strict_bit_offset = (uint32_t ) (sizeof (value) * JERRY_BITSINBYTE - 1 );
87+ const uint32_t do_instantiate_arguments_object_bit_offset = (uint32_t ) (sizeof (value) * JERRY_BITSINBYTE - 2 );
7588
76- bool is_strict = ((value & (1u << is_strict_bit_offset)) != 0 );
77- *out_is_strict_p = is_strict;
78-
79- opcode_counter_t opcode_idx = (opcode_counter_t ) (value & ~(1u << is_strict_bit_offset));
89+ *out_is_strict_p = ((value & (1u << is_strict_bit_offset)) != 0 );
90+ *out_do_instantiate_args_obj_p = ((value & (1u << do_instantiate_arguments_object_bit_offset)) != 0 );
91+ value &= ~((1u << is_strict_bit_offset) | (1u << do_instantiate_arguments_object_bit_offset));
8092
81- return opcode_idx ;
93+ return ( opcode_counter_t ) value ;
8294} /* ecma_unpack_code_internal_property_value */
8395
8496/* *
@@ -144,6 +156,8 @@ ecma_op_create_function_object (ecma_string_t* formal_parameter_list_p[], /**< f
144156 ecma_length_t formal_parameters_number, /* *< formal parameters list's length */
145157 ecma_object_t *scope_p, /* *< function's scope */
146158 bool is_strict, /* *< 'strict' flag */
159+ bool do_instantiate_arguments_object, /* *< should an Arguments object be instantiated
160+ * for the function object upon call */
147161 opcode_counter_t first_opcode_idx) /* *< index of first opcode of function's body */
148162{
149163 // 1., 4., 13.
@@ -185,6 +199,7 @@ ecma_op_create_function_object (ecma_string_t* formal_parameter_list_p[], /**< f
185199 // 12.
186200 ecma_property_t *code_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_CODE);
187201 code_prop_p->u .internal_property .value = ecma_pack_code_internal_property_value (is_strict,
202+ do_instantiate_arguments_object,
188203 first_opcode_idx);
189204
190205 // 14.
@@ -339,10 +354,11 @@ ecma_op_create_external_function_object (ecma_external_pointer_t code_p) /**< po
339354} /* ecma_op_create_external_function_object */
340355
341356/* *
342- * Setup variables for arguments listed in formal parameter list.
357+ * Setup variables for arguments listed in formal parameter list,
358+ * and, if necessary, Arguments object with 'arguments' binding.
343359 *
344360 * See also:
345- * Declaration binding instantiation (ECMA-262 v5, 10.5), block 4
361+ * Declaration binding instantiation (ECMA-262 v5, 10.5), block 4 and 7
346362 *
347363 * @return completion value
348364 * Returned value must be freed with ecma_free_completion_value
@@ -352,7 +368,10 @@ ecma_function_call_setup_args_variables (ecma_object_t *func_obj_p, /**< Functio
352368 ecma_object_t *env_p, /* *< lexical environment */
353369 const ecma_value_t *arguments_list_p, /* *< arguments list */
354370 ecma_length_t arguments_list_len, /* *< length of argument list */
355- bool is_strict) /* *< flag indicating strict mode */
371+ bool is_strict, /* *< flag indicating strict mode */
372+ bool do_instantiate_arguments_object) /* *< flag indicating whether
373+ * Arguments object should be
374+ * instantiated */
356375{
357376 ecma_property_t *formal_parameters_prop_p = ecma_get_internal_property (func_obj_p,
358377 ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS);
@@ -417,6 +436,24 @@ ecma_function_call_setup_args_variables (ecma_object_t *func_obj_p, /**< Functio
417436 }
418437 }
419438
439+ if (do_instantiate_arguments_object)
440+ {
441+ /*
442+ * According to ECMA-262 v5, 10.5, the Arguments object should be instantiated
443+ * after instantiating declared functions, and only if there is no binding named 'arguments'
444+ * by that time.
445+ *
446+ * However, we can setup Arguments object and 'arguments' binding here, because:
447+ * - instantiation of Arguments object itself doesn't have any side effects;
448+ * - if 'arguments' is name of a declared function in current scope,
449+ * value of the binding would be overwritten, execution would proceed in correct state.
450+ * - declaration of function, named 'arguments', is considered to be unrecommended (and so, rare) case,
451+ * so instantiation of Arguments object here, in general, is supposed to not affect resource consumption
452+ * significantly.
453+ */
454+ JERRY_UNIMPLEMENTED (" Instantiate Arguments object and setup 'arguments' implicit variable" );
455+ }
456+
420457 return ecma_make_empty_completion_value ();
421458} /* ecma_function_call_setup_args_variables */
422459
@@ -543,8 +580,11 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
543580 uint32_t code_prop_value = code_prop_p->u .internal_property .value ;
544581
545582 bool is_strict;
583+ bool do_instantiate_args_obj;
546584 // 8.
547- opcode_counter_t code_first_opcode_idx = ecma_unpack_code_internal_property_value (code_prop_value, &is_strict);
585+ opcode_counter_t code_first_opcode_idx = ecma_unpack_code_internal_property_value (code_prop_value,
586+ &is_strict,
587+ &do_instantiate_args_obj);
548588
549589 ecma_value_t this_binding;
550590 // 1.
@@ -576,7 +616,8 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
576616 local_env_p,
577617 arguments_list_p,
578618 arguments_list_len,
579- is_strict),
619+ is_strict,
620+ do_instantiate_args_obj),
580621 ret_value);
581622
582623 ecma_completion_value_t completion = vm_run_from_pos (code_first_opcode_idx,
@@ -769,14 +810,18 @@ ecma_op_function_declaration (ecma_object_t *lex_env_p, /**< lexical environment
769810 ecma_string_t * formal_parameter_list_p[], /* *< formal parameters list */
770811 ecma_length_t formal_parameter_list_length, /* *< length of formal parameters list */
771812 bool is_strict, /* *< flag indicating if function is declared in strict mode code */
813+ bool do_instantiate_arguments_object, /* *< flag, indicating whether an Arguments object
814+ * should be instantiated for the function object
815+ * upon call */
772816 bool is_configurable_bindings) /* *< flag indicating whether function
773- is declared in eval code */
817+ * is declared in eval code */
774818{
775819 // b.
776820 ecma_object_t *func_obj_p = ecma_op_create_function_object (formal_parameter_list_p,
777821 formal_parameter_list_length,
778822 lex_env_p,
779823 is_strict,
824+ do_instantiate_arguments_object,
780825 function_code_opcode_idx);
781826
782827 // c.
0 commit comments