1515
1616#include "ecma-arraybuffer-object.h"
1717#include "ecma-try-catch-macro.h"
18+ #include "ecma-typedarray-object.h"
1819#include "ecma-objects.h"
1920#include "ecma-builtins.h"
2021#include "ecma-exceptions.h"
@@ -173,7 +174,20 @@ ecma_is_arraybuffer (ecma_value_t target) /**< the target value */
173174ecma_length_t JERRY_ATTR_PURE
174175ecma_arraybuffer_get_length (ecma_object_t * object_p ) /**< pointer to the ArrayBuffer object */
175176{
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+ }
177191
178192 ecma_extended_object_t * ext_object_p = (ecma_extended_object_t * ) object_p ;
179193 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
187201inline lit_utf8_byte_t * JERRY_ATTR_PURE JERRY_ATTR_ALWAYS_INLINE
188202ecma_arraybuffer_get_buffer (ecma_object_t * object_p ) /**< pointer to the ArrayBuffer object */
189203{
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+ }
191218
192219 ecma_extended_object_t * ext_object_p = (ecma_extended_object_t * ) object_p ;
193220
0 commit comments