From c56ecd05c272cea21b5b4a348a5790c9e1c6112f Mon Sep 17 00:00:00 2001 From: Rizky Mirzaviandy Priambodo <142987522+Xavrir@users.noreply.github.com> Date: Wed, 18 Mar 2026 22:15:06 +0700 Subject: [PATCH 1/3] test: add coverage for JsTypedArray toReversed, toSorted, toLocaleString These methods were already implemented in both the builtins layer and the JsTypedArray wrapper but had no test coverage. Add three tests that verify: - toReversed returns a new reversed array without mutating the original - toSorted returns a new sorted array without mutating the original - toLocaleString returns a string containing the element values Ref #3252 --- .../src/object/builtins/jstypedarray.rs | 87 +++++++++++-------- 1 file changed, 50 insertions(+), 37 deletions(-) diff --git a/core/engine/src/object/builtins/jstypedarray.rs b/core/engine/src/object/builtins/jstypedarray.rs index 95838890a35..738c9bd515d 100644 --- a/core/engine/src/object/builtins/jstypedarray.rs +++ b/core/engine/src/object/builtins/jstypedarray.rs @@ -1,14 +1,14 @@ //! Rust API wrappers for the `TypedArray` Builtin ECMAScript Objects use crate::{ - Context, JsExpect, JsResult, JsString, JsValue, builtins::{ - BuiltInConstructor, array_buffer::AlignedVec, typed_array::{BuiltinTypedArray, TypedArray, TypedArrayKind}, + BuiltInConstructor, }, error::JsNativeError, object::{JsArrayBuffer, JsFunction, JsObject, JsSharedArrayBuffer}, value::{IntoOrUndefined, TryFromJs}, + Context, JsExpect, JsResult, JsString, JsValue, }; use boa_gc::{Finalize, Trace}; use std::ops::Deref; @@ -1513,40 +1513,53 @@ fn typed_array_values() { } #[test] -fn typed_array_iterator() { +fn typed_array_to_reversed() { let context = &mut Context::default(); - let vec = vec![1u8, 2]; - let array = JsUint8Array::from_iter(vec, context).unwrap(); - let values = array.iterator(context).unwrap(); - let mut values_vec = Vec::new(); - let next_str = crate::js_string!("next"); - loop { - let next_fn = values - .as_object() - .unwrap() - .get(next_str.clone(), context) - .unwrap(); - let result = next_fn - .as_object() - .unwrap() - .call(&values, &[], context) - .unwrap(); - if result - .as_object() - .unwrap() - .get(crate::js_string!("done"), context) - .unwrap() - .to_boolean() - { - break; - } - values_vec.push( - result - .as_object() - .unwrap() - .get(crate::js_string!("value"), context) - .unwrap(), - ); - } - assert_eq!(values_vec, vec![JsValue::new(1), JsValue::new(2)]); + let array = JsUint8Array::from_iter(vec![3u8, 1, 2], context).unwrap(); + + let reversed = array.to_reversed(context).unwrap(); + + // New array has reversed order + assert_eq!(reversed.at(0i64, context).unwrap(), JsValue::new(2)); + assert_eq!(reversed.at(1i64, context).unwrap(), JsValue::new(1)); + assert_eq!(reversed.at(2i64, context).unwrap(), JsValue::new(3)); + + // Original is unchanged + assert_eq!(array.at(0i64, context).unwrap(), JsValue::new(3)); + assert_eq!(array.at(1i64, context).unwrap(), JsValue::new(1)); + assert_eq!(array.at(2i64, context).unwrap(), JsValue::new(2)); +} + +#[test] +fn typed_array_to_sorted() { + let context = &mut Context::default(); + let array = JsUint8Array::from_iter(vec![3u8, 1, 2], context).unwrap(); + + let sorted = array.to_sorted(None, context).unwrap(); + + // New array is sorted + assert_eq!(sorted.at(0i64, context).unwrap(), JsValue::new(1)); + assert_eq!(sorted.at(1i64, context).unwrap(), JsValue::new(2)); + assert_eq!(sorted.at(2i64, context).unwrap(), JsValue::new(3)); + + // Original is unchanged + assert_eq!(array.at(0i64, context).unwrap(), JsValue::new(3)); + assert_eq!(array.at(1i64, context).unwrap(), JsValue::new(1)); + assert_eq!(array.at(2i64, context).unwrap(), JsValue::new(2)); +} + +#[test] +fn typed_array_to_locale_string() { + let context = &mut Context::default(); + let array = JsUint8Array::from_iter(vec![1u8, 2, 3], context).unwrap(); + + let result = array.to_locale_string(None, None, context).unwrap(); + + let result_str = result + .as_string() + .expect("toLocaleString should return a string"); + assert!( + result_str.to_std_string_escaped().contains('1'), + "result should contain element values" + ); } From 0ff4df2d174b231b76ff21cd46c788ca14912a31 Mon Sep 17 00:00:00 2001 From: Rizky Mirzaviandy Priambodo <142987522+Xavrir@users.noreply.github.com> Date: Thu, 19 Mar 2026 01:09:12 +0700 Subject: [PATCH 2/3] style: format JsTypedArray imports --- core/engine/src/object/builtins/jstypedarray.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/engine/src/object/builtins/jstypedarray.rs b/core/engine/src/object/builtins/jstypedarray.rs index 738c9bd515d..e6e0d2f4e22 100644 --- a/core/engine/src/object/builtins/jstypedarray.rs +++ b/core/engine/src/object/builtins/jstypedarray.rs @@ -1,14 +1,14 @@ //! Rust API wrappers for the `TypedArray` Builtin ECMAScript Objects use crate::{ + Context, JsExpect, JsResult, JsString, JsValue, builtins::{ + BuiltInConstructor, array_buffer::AlignedVec, typed_array::{BuiltinTypedArray, TypedArray, TypedArrayKind}, - BuiltInConstructor, }, error::JsNativeError, object::{JsArrayBuffer, JsFunction, JsObject, JsSharedArrayBuffer}, value::{IntoOrUndefined, TryFromJs}, - Context, JsExpect, JsResult, JsString, JsValue, }; use boa_gc::{Finalize, Trace}; use std::ops::Deref; From 375b13c5ef075f10746f5e6920915625d499ca5a Mon Sep 17 00:00:00 2001 From: Rizky Mirzaviandy Priambodo <142987522+Xavrir@users.noreply.github.com> Date: Thu, 19 Mar 2026 01:38:52 +0700 Subject: [PATCH 3/3] test: restore JsTypedArray iterator coverage Restore the typed_array_iterator unit test that was accidentally dropped while adding JsTypedArray coverage. Review comment: 2955394192 --- .../src/object/builtins/jstypedarray.rs | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/core/engine/src/object/builtins/jstypedarray.rs b/core/engine/src/object/builtins/jstypedarray.rs index e6e0d2f4e22..77ec287f050 100644 --- a/core/engine/src/object/builtins/jstypedarray.rs +++ b/core/engine/src/object/builtins/jstypedarray.rs @@ -1512,6 +1512,44 @@ fn typed_array_values() { assert_eq!(values_vec, vec![JsValue::new(1), JsValue::new(2)]); } +#[test] +fn typed_array_iterator() { + let context = &mut Context::default(); + let array = JsUint8Array::from_iter(vec![1u8, 2], context).unwrap(); + let values = array.iterator(context).unwrap(); + let mut values_vec = Vec::new(); + let next_str = crate::js_string!("next"); + loop { + let next_fn = values + .as_object() + .unwrap() + .get(next_str.clone(), context) + .unwrap(); + let result = next_fn + .as_object() + .unwrap() + .call(&values, &[], context) + .unwrap(); + if result + .as_object() + .unwrap() + .get(crate::js_string!("done"), context) + .unwrap() + .to_boolean() + { + break; + } + values_vec.push( + result + .as_object() + .unwrap() + .get(crate::js_string!("value"), context) + .unwrap(), + ); + } + assert_eq!(values_vec, vec![JsValue::new(1), JsValue::new(2)]); +} + #[test] fn typed_array_to_reversed() { let context = &mut Context::default();