@@ -1589,28 +1589,55 @@ ecma_builtin_typedarray_prototype_slice (ecma_value_t this_arg, /**< this argume
1589
1589
ecma_value_t new_typedarray = ecma_typedarray_species_create (this_arg , & len , 1 );
1590
1590
ecma_free_value (len );
1591
1591
1592
- if (ECMA_IS_VALUE_ERROR (new_typedarray ))
1592
+ if (ECMA_IS_VALUE_ERROR (new_typedarray ) || count == 0 )
1593
1593
{
1594
1594
return new_typedarray ;
1595
1595
}
1596
1596
1597
- if (count > 0 )
1597
+ ecma_object_t * new_typedarray_p = ecma_get_object_from_value (new_typedarray );
1598
+
1599
+ if (ecma_arraybuffer_is_detached (info_p -> array_buffer_p ))
1598
1600
{
1599
- ecma_object_t * new_typedarray_p = ecma_get_object_from_value (new_typedarray );
1601
+ ecma_deref_object (new_typedarray_p );
1602
+ return ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_arraybuffer_is_detached ));
1603
+ }
1600
1604
1601
- if (ecma_arraybuffer_is_detached (info_p -> array_buffer_p ))
1602
- {
1603
- ecma_deref_object (new_typedarray_p );
1604
- return ecma_raise_type_error (ECMA_ERR_MSG (ecma_error_arraybuffer_is_detached ));
1605
- }
1605
+ ecma_typedarray_info_t new_typedarray_info = ecma_typedarray_get_info (new_typedarray_p );
1606
1606
1607
- lit_utf8_byte_t * new_typedarray_buffer_p = ecma_typedarray_get_buffer (new_typedarray_p );
1607
+ if (info_p -> id == new_typedarray_info .id )
1608
+ {
1609
+ // 22.2.3.23. Step 22. h-i.
1608
1610
uint32_t src_byte_index = (relative_start * info_p -> element_size );
1609
1611
1610
- memcpy (new_typedarray_buffer_p ,
1612
+ memcpy (new_typedarray_info . buffer_p ,
1611
1613
info_p -> buffer_p + src_byte_index ,
1612
1614
count * info_p -> element_size );
1613
1615
}
1616
+ else
1617
+ {
1618
+ // 22.2.3.23. Step 21. b.
1619
+ ecma_typedarray_getter_fn_t src_typedarray_getter_cb = ecma_get_typedarray_getter_fn (info_p -> id );
1620
+ ecma_typedarray_setter_fn_t new_typedarray_setter_cb = ecma_get_typedarray_setter_fn (new_typedarray_info .id );
1621
+
1622
+ uint32_t src_byte_index = (relative_start * info_p -> element_size );
1623
+ uint32_t dst_byte_index = 0 ;
1624
+
1625
+ for (uint32_t idx = 0 ; idx < count ; idx ++ )
1626
+ {
1627
+ ecma_value_t element = src_typedarray_getter_cb (info_p -> buffer_p + src_byte_index );
1628
+ ecma_value_t set_element = new_typedarray_setter_cb (new_typedarray_info .buffer_p + dst_byte_index , element );
1629
+ ecma_free_value (element );
1630
+
1631
+ if (ECMA_IS_VALUE_ERROR (set_element ))
1632
+ {
1633
+ ecma_deref_object (new_typedarray_p );
1634
+ return set_element ;
1635
+ }
1636
+
1637
+ src_byte_index += info_p -> element_size ;
1638
+ dst_byte_index += new_typedarray_info .element_size ;
1639
+ }
1640
+ }
1614
1641
1615
1642
return new_typedarray ;
1616
1643
} /* ecma_builtin_typedarray_prototype_slice */
0 commit comments