@@ -59,6 +59,107 @@ ecma_builtin_array_prototype_object_to_string (ecma_value_t this_arg) /**< this
59
59
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
60
60
} /* ecma_builtin_array_prototype_object_to_string */
61
61
62
+ /* *
63
+ * The Array.prototype object's 'push' routine
64
+ *
65
+ * See also:
66
+ * ECMA-262 v5, 15.4.4.7
67
+ *
68
+ * @return completion value
69
+ * Returned value must be freed with ecma_free_completion_value.
70
+ */
71
+ static ecma_completion_value_t
72
+ ecma_builtin_array_prototype_object_push (ecma_value_t this_arg, /* *< this argument */
73
+ const ecma_value_t *argument_list_p, /* *< arguments list */
74
+ ecma_length_t arguments_number) /* *< number of arguments */
75
+ {
76
+ JERRY_ASSERT (argument_list_p == NULL || arguments_number > 0 );
77
+
78
+ ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
79
+
80
+ // 1.
81
+ ECMA_TRY_CATCH (obj_this_value, ecma_op_to_object (this_arg), ret_value);
82
+
83
+ ecma_object_t *obj_p = ecma_get_object_from_value (obj_this_value);
84
+
85
+ // 2.
86
+ ecma_string_t *length_str_p = ecma_new_ecma_string_from_magic_string_id (ECMA_MAGIC_STRING_LENGTH);
87
+
88
+ ECMA_TRY_CATCH (length_value, ecma_op_object_get (obj_p, length_str_p), ret_value);
89
+
90
+ // 3.
91
+ ECMA_OP_TO_NUMBER_TRY_CATCH (length_var, length_value, ret_value);
92
+
93
+ uint32_t n = ecma_number_to_uint32 (length_var);
94
+
95
+ // 5.
96
+ for (uint32_t index = 0 ;
97
+ index < arguments_number;
98
+ ++index, ++n)
99
+ {
100
+ // a.
101
+ ecma_value_t e_value = argument_list_p[index];
102
+
103
+ // b.
104
+ ecma_string_t *n_str_p = ecma_new_ecma_string_from_uint32 (n);
105
+
106
+ ecma_completion_value_t completion = ecma_op_object_put (obj_p, n_str_p, e_value, true );
107
+
108
+ ecma_deref_ecma_string (n_str_p);
109
+
110
+ if (unlikely (ecma_is_completion_value_throw (completion)
111
+ || ecma_is_completion_value_exit (completion)))
112
+ {
113
+ ret_value = completion;
114
+ break ;
115
+ }
116
+ else
117
+ {
118
+ JERRY_ASSERT (ecma_is_completion_value_normal (completion));
119
+ ecma_free_completion_value (completion);
120
+ }
121
+ }
122
+
123
+ // 6.
124
+ if (ecma_is_completion_value_empty (ret_value))
125
+ {
126
+ ecma_number_t *num_length_p = ecma_alloc_number ();
127
+ *num_length_p = ecma_uint32_to_number (n);
128
+
129
+ ecma_value_t num_length_value = ecma_make_number_value (num_length_p);
130
+
131
+ ecma_completion_value_t completion = ecma_op_object_put (obj_p,
132
+ length_str_p,
133
+ num_length_value,
134
+ true );
135
+
136
+ if (unlikely (ecma_is_completion_value_throw (completion)
137
+ || ecma_is_completion_value_exit (completion)))
138
+ {
139
+ ret_value = completion;
140
+
141
+ ecma_dealloc_number (num_length_p);
142
+ }
143
+ else
144
+ {
145
+ JERRY_ASSERT (ecma_is_completion_value_normal (completion));
146
+ ecma_free_completion_value (completion);
147
+
148
+ ret_value = ecma_make_normal_completion_value (num_length_value);
149
+ }
150
+ }
151
+
152
+ ECMA_OP_TO_NUMBER_FINALIZE (length_var);
153
+
154
+ ECMA_FINALIZE (length_value);
155
+
156
+ ecma_deref_ecma_string (length_str_p);
157
+
158
+ ECMA_FINALIZE (obj_this_value);
159
+
160
+ return ret_value;
161
+ } /* ecma_builtin_array_prototype_object_push */
162
+
62
163
/* *
63
164
* @}
64
165
* @}
0 commit comments