44
44
* @{
45
45
*/
46
46
47
+ /* *
48
+ * Helper function to set an object's length property
49
+ *
50
+ * @return completion value (return value of the [[Put]] method)
51
+ * Returned value must be freed with ecma_free_completion_value.
52
+ */
53
+ static ecma_completion_value_t
54
+ ecma_builtin_array_prototype_helper_set_length (ecma_object_t *object, /* *< object*/
55
+ uint32_t length) /* *< new length */
56
+ {
57
+ ecma_completion_value_t ret_value;
58
+ ecma_string_t *magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
59
+
60
+ ecma_number_t *len_p = ecma_alloc_number ();
61
+ *len_p = ecma_uint32_to_number (length);
62
+
63
+ ret_value = ecma_op_object_put (object,
64
+ magic_string_length_p,
65
+ ecma_make_number_value (len_p),
66
+ true ),
67
+
68
+ ecma_dealloc_number (len_p);
69
+ ecma_deref_ecma_string (magic_string_length_p);
70
+
71
+ return ret_value;
72
+ } /* ecma_builtin_array_prototype_helper_set_length */
73
+
47
74
/* *
48
75
* The Array.prototype object's 'toString' routine
49
76
*
@@ -59,6 +86,85 @@ ecma_builtin_array_prototype_object_to_string (ecma_value_t this_arg) /**< this
59
86
ECMA_BUILTIN_CP_UNIMPLEMENTED (this_arg);
60
87
} /* ecma_builtin_array_prototype_object_to_string */
61
88
89
+ /* *
90
+ * The Array.prototype object's 'pop' routine
91
+ *
92
+ * See also:
93
+ * ECMA-262 v5, 15.4.4.6
94
+ *
95
+ * @return completion value
96
+ * Returned value must be freed with ecma_free_completion_value.
97
+ */
98
+ static ecma_completion_value_t
99
+ ecma_builtin_array_prototype_object_pop (ecma_value_t this_arg) /* *< this argument */
100
+ {
101
+ ecma_completion_value_t ret_value = ecma_make_empty_completion_value ();
102
+
103
+ /* 1. */
104
+ ECMA_TRY_CATCH (obj_this,
105
+ ecma_op_to_object (this_arg),
106
+ ret_value);
107
+
108
+ ecma_object_t *obj_p = ecma_get_object_from_value (obj_this);
109
+ ecma_string_t *magic_string_length_p = ecma_get_magic_string (ECMA_MAGIC_STRING_LENGTH);
110
+
111
+ /* 2. */
112
+ ECMA_TRY_CATCH (len_value,
113
+ ecma_op_object_get (obj_p, magic_string_length_p),
114
+ ret_value);
115
+
116
+ ECMA_OP_TO_NUMBER_TRY_CATCH (len_number, len_value, ret_value);
117
+
118
+ /* 3. */
119
+ uint32_t len = ecma_number_to_uint32 (len_number);
120
+
121
+ /* 4. */
122
+ if (len == 0 )
123
+ {
124
+ /* 4.a */
125
+ ECMA_TRY_CATCH (set_length_value,
126
+ ecma_builtin_array_prototype_helper_set_length (obj_p, 0 ),
127
+ ret_value);
128
+
129
+ /* 4.b */
130
+ ret_value = ecma_make_simple_completion_value (ECMA_SIMPLE_VALUE_UNDEFINED);
131
+
132
+ ECMA_FINALIZE (set_length_value)
133
+ }
134
+ else
135
+ {
136
+ len--;
137
+ /* 5.a */
138
+ ecma_string_t *index_str_p = ecma_new_ecma_string_from_uint32 (len);
139
+
140
+ /* 5.b */
141
+ ECMA_TRY_CATCH (get_value, ecma_op_object_get (obj_p, index_str_p), ret_value);
142
+
143
+ /* 5.c */
144
+ ECMA_TRY_CATCH (del_value, ecma_op_object_delete (obj_p, index_str_p, true ), ret_value);
145
+
146
+ /* 5.d */
147
+ ECMA_TRY_CATCH (set_length_value,
148
+ ecma_builtin_array_prototype_helper_set_length (obj_p, len),
149
+ ret_value);
150
+
151
+ ret_value = ecma_make_normal_completion_value (ecma_copy_value (get_value, true ));
152
+
153
+ ECMA_FINALIZE (set_length_value);
154
+ ECMA_FINALIZE (del_value);
155
+ ECMA_FINALIZE (get_value);
156
+
157
+ ecma_deref_ecma_string (index_str_p);
158
+ }
159
+
160
+ ECMA_OP_TO_NUMBER_FINALIZE (len_number);
161
+ ECMA_FINALIZE (len_value);
162
+ ecma_deref_ecma_string (magic_string_length_p);
163
+ ECMA_FINALIZE (obj_this);
164
+
165
+ return ret_value;
166
+ } /* ecma_builtin_array_prototype_object_pop */
167
+
62
168
/* *
63
169
* The Array.prototype object's 'push' routine
64
170
*
0 commit comments