15
15
16
16
#include "ecma-arraybuffer-object.h"
17
17
#include "ecma-try-catch-macro.h"
18
+ #include "ecma-typedarray-object.h"
18
19
#include "ecma-objects.h"
19
20
#include "ecma-builtins.h"
20
21
#include "ecma-exceptions.h"
@@ -173,7 +174,20 @@ ecma_is_arraybuffer (ecma_value_t target) /**< the target value */
173
174
ecma_length_t JERRY_ATTR_PURE
174
175
ecma_arraybuffer_get_length (ecma_object_t * object_p ) /**< pointer to the ArrayBuffer object */
175
176
{
176
- JERRY_ASSERT (ecma_object_class_is (object_p , LIT_MAGIC_STRING_ARRAY_BUFFER_UL ));
177
+ /**
178
+ * It is possible during the initialization of a TypedArray with another TypedArray,
179
+ * that the buffer is a TypedArray object, not an ArrayBuffer object. In these
180
+ * cases we should return with the internal TypedArray's buffer length.
181
+ */
182
+ if (!ecma_object_class_is (object_p , LIT_MAGIC_STRING_ARRAY_BUFFER_UL ))
183
+ {
184
+ if (ecma_is_typedarray (ecma_make_object_value (object_p )))
185
+ {
186
+ ecma_extended_object_t * buffer_object_p = (ecma_extended_object_t * ) object_p ;
187
+ ecma_value_t buffer = buffer_object_p -> u .pseudo_array .u2 .arraybuffer ;
188
+ object_p = ecma_get_object_from_value (buffer );
189
+ }
190
+ }
177
191
178
192
ecma_extended_object_t * ext_object_p = (ecma_extended_object_t * ) object_p ;
179
193
return ext_object_p -> u .class_prop .u .length ;
@@ -187,7 +201,20 @@ ecma_arraybuffer_get_length (ecma_object_t *object_p) /**< pointer to the ArrayB
187
201
inline lit_utf8_byte_t * JERRY_ATTR_PURE JERRY_ATTR_ALWAYS_INLINE
188
202
ecma_arraybuffer_get_buffer (ecma_object_t * object_p ) /**< pointer to the ArrayBuffer object */
189
203
{
190
- JERRY_ASSERT (ecma_object_class_is (object_p , LIT_MAGIC_STRING_ARRAY_BUFFER_UL ));
204
+ /**
205
+ * It is possible during the initialization of a TypedArray with another TypedArray,
206
+ * that the buffer is a TypedArray object, not an ArrayBuffer object. In these
207
+ * cases we should return with the internal TypedArray's buffer.
208
+ */
209
+ if (!ecma_object_class_is (object_p , LIT_MAGIC_STRING_ARRAY_BUFFER_UL ))
210
+ {
211
+ if (ecma_is_typedarray (ecma_make_object_value (object_p )))
212
+ {
213
+ ecma_extended_object_t * buffer_object_p = (ecma_extended_object_t * ) object_p ;
214
+ ecma_value_t buffer = buffer_object_p -> u .pseudo_array .u2 .arraybuffer ;
215
+ object_p = ecma_get_object_from_value (buffer );
216
+ }
217
+ }
191
218
192
219
ecma_extended_object_t * ext_object_p = (ecma_extended_object_t * ) object_p ;
193
220
0 commit comments