diff --git a/core/engine/src/object/builtins/jstypedarray.rs b/core/engine/src/object/builtins/jstypedarray.rs index c4d1a21e033..1b6be0e37e0 100644 --- a/core/engine/src/object/builtins/jstypedarray.rs +++ b/core/engine/src/object/builtins/jstypedarray.rs @@ -137,7 +137,32 @@ impl JsTypedArray { BuiltinTypedArray::constructor(&self.inner.clone().into(), &[], context) } + /// Shallow copies part of this typed array to another location in the same typed + /// array and returns this typed array without modifying its length. + /// /// Returns `TypedArray.prototype.copyWithin()`. + /// + /// # Examples + /// + /// ``` + /// # use boa_engine::{JsResult, JsValue, object::{builtins::{JsUint8Array}}, Context}; + /// # fn main() -> JsResult<()> { + /// + /// let context = &mut Context::default(); + /// let array = JsUint8Array::from_iter(vec![1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8], context)?; + /// array.copy_within(3, 1, Some(3), context)?; + /// assert_eq!(array.get(0, context)?, JsValue::new(1.0)); + /// assert_eq!(array.get(1, context)?, JsValue::new(2.0)); + /// assert_eq!(array.get(2, context)?, JsValue::new(3.0)); + /// assert_eq!(array.get(3, context)?, JsValue::new(2.0)); + /// assert_eq!(array.get(4, context)?, JsValue::new(3.0)); + /// assert_eq!(array.get(5, context)?, JsValue::new(6.0)); + /// assert_eq!(array.get(6, context)?, JsValue::new(7.0)); + /// assert_eq!(array.get(7, context)?, JsValue::new(8.0)); + /// + /// # Ok(()) + /// # } + /// ``` #[inline] pub fn copy_within( &self,