37
37
*/
38
38
39
39
/* *
40
- * Pack 'is_strict' flag and opcode index to value
40
+ * Pack 'is_strict', 'do_instantiate_arguments_object' flags and opcode index to value
41
41
* that can be stored in an [[Code]] internal property.
42
42
*
43
43
* @return packed value
44
44
*/
45
45
static uint32_t
46
46
ecma_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 */
47
49
opcode_counter_t opcode_idx) /* *< index of first opcode */
48
50
{
49
51
uint32_t value = opcode_idx;
50
52
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 );
51
54
52
55
JERRY_ASSERT (((value) & (1u << is_strict_bit_offset)) == 0 );
56
+ JERRY_ASSERT (((value) & (1u << do_instantiate_arguments_object_bit_offset)) == 0 );
53
57
54
58
if (is_strict)
55
59
{
56
60
value |= (1u << is_strict_bit_offset);
57
61
}
62
+ if (do_instantiate_args_obj)
63
+ {
64
+ value |= (1u << do_instantiate_arguments_object_bit_offset);
65
+ }
58
66
59
67
return value;
60
68
} /* ecma_pack_code_internal_property_value */
61
69
62
70
/* *
63
- * Unpack 'is_strict' flag and opcode index from value
71
+ * Unpack 'is_strict', 'do_instantiate_arguments_object' flags and opcode index from value
64
72
* that can be stored in an [[Code]] internal property.
65
73
*
66
74
* @return opcode index
67
75
*/
68
76
static opcode_counter_t
69
77
ecma_unpack_code_internal_property_value (uint32_t value, /* *< packed value */
70
- bool * out_is_strict_p) /* *< out: is code strict? */
78
+ bool * out_is_strict_p, /* *< out: is code strict? */
79
+ bool * out_do_instantiate_args_obj_p) /* *< should an Arguments object be
80
+ * instantiated for the code */
71
81
{
72
82
JERRY_ASSERT (out_is_strict_p != NULL );
83
+ JERRY_ASSERT (out_do_instantiate_args_obj_p != NULL );
73
84
74
85
const uint32_t is_strict_bit_offset = (uint32_t ) (sizeof (value) * JERRY_BITSINBYTE - 1 );
86
+ const uint32_t do_instantiate_arguments_object_bit_offset = (uint32_t ) (sizeof (value) * JERRY_BITSINBYTE - 2 );
75
87
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));
88
+ *out_is_strict_p = ((value & (1u << is_strict_bit_offset)) != 0 );
89
+ *out_do_instantiate_args_obj_p = ((value & (1u << do_instantiate_arguments_object_bit_offset)) != 0 );
90
+ value &= ~((1u << is_strict_bit_offset) | (1u << do_instantiate_arguments_object_bit_offset));
80
91
81
- return opcode_idx ;
92
+ return ( opcode_counter_t ) value ;
82
93
} /* ecma_unpack_code_internal_property_value */
83
94
84
95
/* *
@@ -144,6 +155,8 @@ ecma_op_create_function_object (ecma_string_t* formal_parameter_list_p[], /**< f
144
155
ecma_length_t formal_parameters_number, /* *< formal parameters list's length */
145
156
ecma_object_t *scope_p, /* *< function's scope */
146
157
bool is_strict, /* *< 'strict' flag */
158
+ bool do_instantiate_arguments_object, /* *< should an Arguments object be instantiated
159
+ * for the function object upon call */
147
160
opcode_counter_t first_opcode_idx) /* *< index of first opcode of function's body */
148
161
{
149
162
// 1., 4., 13.
@@ -185,6 +198,7 @@ ecma_op_create_function_object (ecma_string_t* formal_parameter_list_p[], /**< f
185
198
// 12.
186
199
ecma_property_t *code_prop_p = ecma_create_internal_property (f, ECMA_INTERNAL_PROPERTY_CODE);
187
200
code_prop_p->u .internal_property .value = ecma_pack_code_internal_property_value (is_strict,
201
+ do_instantiate_arguments_object,
188
202
first_opcode_idx);
189
203
190
204
// 14.
@@ -339,10 +353,11 @@ ecma_op_create_external_function_object (ecma_external_pointer_t code_p) /**< po
339
353
} /* ecma_op_create_external_function_object */
340
354
341
355
/* *
342
- * Setup variables for arguments listed in formal parameter list.
356
+ * Setup variables for arguments listed in formal parameter list,
357
+ * and, if necessary, Arguments object with 'arguments' binding.
343
358
*
344
359
* See also:
345
- * Declaration binding instantiation (ECMA-262 v5, 10.5), block 4
360
+ * Declaration binding instantiation (ECMA-262 v5, 10.5), block 4 and 7
346
361
*
347
362
* @return completion value
348
363
* Returned value must be freed with ecma_free_completion_value
@@ -352,7 +367,10 @@ ecma_function_call_setup_args_variables (ecma_object_t *func_obj_p, /**< Functio
352
367
ecma_object_t *env_p, /* *< lexical environment */
353
368
const ecma_value_t *arguments_list_p, /* *< arguments list */
354
369
ecma_length_t arguments_list_len, /* *< length of argument list */
355
- bool is_strict) /* *< flag indicating strict mode */
370
+ bool is_strict, /* *< flag indicating strict mode */
371
+ bool do_instantiate_arguments_object) /* *< flag indicating whether
372
+ * Arguments object should be
373
+ * instantiated */
356
374
{
357
375
ecma_property_t *formal_parameters_prop_p = ecma_get_internal_property (func_obj_p,
358
376
ECMA_INTERNAL_PROPERTY_FORMAL_PARAMETERS);
@@ -417,6 +435,24 @@ ecma_function_call_setup_args_variables (ecma_object_t *func_obj_p, /**< Functio
417
435
}
418
436
}
419
437
438
+ if (do_instantiate_arguments_object)
439
+ {
440
+ /*
441
+ * According to ECMA-262 v5, 10.5, the Arguments object should be instantiated
442
+ * after instantiating declared functions, and only if there is no binding named 'arguments'
443
+ * by that time.
444
+ *
445
+ * However, we can setup Arguments object and 'arguments' binding here, because:
446
+ * - instantiation of Arguments object itself doesn't have any side effects;
447
+ * - if 'arguments' is name of a declared function in current scope,
448
+ * value of the binding would be overwritten, execution would proceed in correct state.
449
+ * - declaration of function, named 'arguments', is considered to be unrecommended (and so, rare) case,
450
+ * so instantiation of Arguments object here, in general, is supposed to not affect resource consumption
451
+ * significantly.
452
+ */
453
+ JERRY_UNIMPLEMENTED (" Instantiate Arguments object and setup 'arguments' implicit variable" );
454
+ }
455
+
420
456
return ecma_make_empty_completion_value ();
421
457
} /* ecma_function_call_setup_args_variables */
422
458
@@ -543,8 +579,11 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
543
579
uint32_t code_prop_value = code_prop_p->u .internal_property .value ;
544
580
545
581
bool is_strict;
582
+ bool do_instantiate_args_obj;
546
583
// 8.
547
- opcode_counter_t code_first_opcode_idx = ecma_unpack_code_internal_property_value (code_prop_value, &is_strict);
584
+ opcode_counter_t code_first_opcode_idx = ecma_unpack_code_internal_property_value (code_prop_value,
585
+ &is_strict,
586
+ &do_instantiate_args_obj);
548
587
549
588
ecma_value_t this_binding;
550
589
// 1.
@@ -576,7 +615,8 @@ ecma_op_function_call (ecma_object_t *func_obj_p, /**< Function object */
576
615
local_env_p,
577
616
arguments_list_p,
578
617
arguments_list_len,
579
- is_strict),
618
+ is_strict,
619
+ do_instantiate_args_obj),
580
620
ret_value);
581
621
582
622
ecma_completion_value_t completion = vm_run_from_pos (code_first_opcode_idx,
@@ -768,14 +808,18 @@ ecma_op_function_declaration (ecma_object_t *lex_env_p, /**< lexical environment
768
808
ecma_string_t * formal_parameter_list_p[], /* *< formal parameters list */
769
809
ecma_length_t formal_parameter_list_length, /* *< length of formal parameters list */
770
810
bool is_strict, /* *< flag indicating if function is declared in strict mode code */
811
+ bool do_instantiate_arguments_object, /* *< flag, indicating whether an Arguments object
812
+ * should be instantiated for the function object
813
+ * upon call */
771
814
bool is_configurable_bindings) /* *< flag indicating whether function
772
- is declared in eval code */
815
+ * is declared in eval code */
773
816
{
774
817
// b.
775
818
ecma_object_t *func_obj_p = ecma_op_create_function_object (formal_parameter_list_p,
776
819
formal_parameter_list_length,
777
820
lex_env_p,
778
821
is_strict,
822
+ do_instantiate_arguments_object,
779
823
function_code_opcode_idx);
780
824
781
825
// c.
0 commit comments