From 8f4bbf19618bcd58bd242505375d841f16fcb2ff Mon Sep 17 00:00:00 2001 From: Aapo Alasuutari Date: Fri, 20 Feb 2026 17:08:46 +0200 Subject: [PATCH] fix(ecmascript): SharedTypedArray filter --- .../src/ecmascript/builtins/array_buffer.rs | 16 +++++---------- nova_vm/src/ecmascript/builtins/data_view.rs | 2 +- .../abstract_operations.rs | 1 + .../builtins/shared_array_buffer.rs | 6 +++--- .../typed_array/normal_typed_array.rs | 11 ++++------ .../typed_array/shared_typed_array.rs | 16 +++++++-------- tests/expectations.json | 20 +------------------ tests/metrics.json | 6 +++--- 8 files changed, 25 insertions(+), 53 deletions(-) diff --git a/nova_vm/src/ecmascript/builtins/array_buffer.rs b/nova_vm/src/ecmascript/builtins/array_buffer.rs index 605488be0..a0947335d 100644 --- a/nova_vm/src/ecmascript/builtins/array_buffer.rs +++ b/nova_vm/src/ecmascript/builtins/array_buffer.rs @@ -296,16 +296,6 @@ pub enum AnyArrayBuffer<'a> { } bindable_handle!(AnyArrayBuffer); -macro_rules! array_buffer_delegate { - ($value: ident, $method: ident, $($arg:expr),*) => { - match $value { - Self::ArrayBuffer(ta) => ta.$method($($arg),+), - #[cfg(feature = "shared-array-buffer")] - Self::SharedArrayBuffer(sta) => sta.$method($($arg),+), - } - }; -} - impl<'ab> AnyArrayBuffer<'ab> { /// Returns true if the ArrayBuffer is a SharedArrayBuffer. #[inline(always)] @@ -320,7 +310,11 @@ impl<'ab> AnyArrayBuffer<'ab> { /// Returns true if the ArrayBuffer is detached. #[inline(always)] pub fn is_detached(self, agent: &Agent) -> bool { - array_buffer_delegate!(self, is_detached, agent) + match self { + Self::ArrayBuffer(ta) => ta.is_detached(agent), + #[cfg(feature = "shared-array-buffer")] + Self::SharedArrayBuffer(_) => false, + } } /// Returns true if the ArrayBuffer is resizable or growable. diff --git a/nova_vm/src/ecmascript/builtins/data_view.rs b/nova_vm/src/ecmascript/builtins/data_view.rs index c233f079e..3145a82d2 100644 --- a/nova_vm/src/ecmascript/builtins/data_view.rs +++ b/nova_vm/src/ecmascript/builtins/data_view.rs @@ -205,7 +205,7 @@ impl<'gc> SharedDataView<'gc> { ) -> T { let array_buffer = self.viewed_array_buffer(agent); // 1. Assert: IsDetachedBuffer(arrayBuffer) is false. - debug_assert!(!array_buffer.is_detached(agent)); + debug_assert!(!array_buffer.is_detached()); // 2. Assert: There are sufficient bytes in arrayBuffer starting at byteIndex to represent a value of type. // 4. Let elementSize be the Element Size value specified in Table 71 for Element Type type. // 3. Let block be arrayBuffer.[[ArrayBufferData]]. diff --git a/nova_vm/src/ecmascript/builtins/indexed_collections/typed_array_objects/abstract_operations.rs b/nova_vm/src/ecmascript/builtins/indexed_collections/typed_array_objects/abstract_operations.rs index c81b85988..b562c86c3 100644 --- a/nova_vm/src/ecmascript/builtins/indexed_collections/typed_array_objects/abstract_operations.rs +++ b/nova_vm/src/ecmascript/builtins/indexed_collections/typed_array_objects/abstract_operations.rs @@ -701,6 +701,7 @@ pub(crate) fn initialize_typed_array_from_array_buffer<'gc, T: Viewable>( // 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception. if buffer.is_detached(agent) { + eprintln!("{buffer:?}"); return Err(agent.throw_exception_with_static_message( ExceptionType::TypeError, "attempting to access detached ArrayBuffer", diff --git a/nova_vm/src/ecmascript/builtins/shared_array_buffer.rs b/nova_vm/src/ecmascript/builtins/shared_array_buffer.rs index fba31e075..59ff0af04 100644 --- a/nova_vm/src/ecmascript/builtins/shared_array_buffer.rs +++ b/nova_vm/src/ecmascript/builtins/shared_array_buffer.rs @@ -64,9 +64,9 @@ impl<'sab> SharedArrayBuffer<'sab> { /// Returns `true` if the SharedArrayBuffer has a 0 length. /// /// Note: this is wrong and will be going away. - #[inline] - pub fn is_detached(self, agent: &Agent) -> bool { - self.get(agent).data_block.is_dangling() + #[inline(always)] + pub fn is_detached(self) -> bool { + false } /// Returns true if the SharedArrayBuffer is growable. diff --git a/nova_vm/src/ecmascript/builtins/typed_array/normal_typed_array.rs b/nova_vm/src/ecmascript/builtins/typed_array/normal_typed_array.rs index f79caace7..e115df0e5 100644 --- a/nova_vm/src/ecmascript/builtins/typed_array/normal_typed_array.rs +++ b/nova_vm/src/ecmascript/builtins/typed_array/normal_typed_array.rs @@ -1439,13 +1439,10 @@ impl<'a, T: Viewable> TypedArrayAbstractOperations<'a> for GenericTypedArray<'a, let scoped_buffer = buffer.scope(agent, gc.nogc()); // 5. Let kept be a new empty List. - let mut kept = create_byte_data_block( - agent, - (len as u64).saturating_mul(size_of::() as u64), - gc.nogc(), - ) - .unbind()? - .bind(gc.nogc()); + let mut kept = + create_byte_data_block(agent, len.saturating_mul(size_of::()) as u64, gc.nogc()) + .unbind()? + .bind(gc.nogc()); // SAFETY: All viewable types are trivially transmutable. let (head, kept_slice, _) = unsafe { kept.align_to_mut::() }; // Should be properly aligned for all T. diff --git a/nova_vm/src/ecmascript/builtins/typed_array/shared_typed_array.rs b/nova_vm/src/ecmascript/builtins/typed_array/shared_typed_array.rs index fe64fe614..dc7cf0191 100644 --- a/nova_vm/src/ecmascript/builtins/typed_array/shared_typed_array.rs +++ b/nova_vm/src/ecmascript/builtins/typed_array/shared_typed_array.rs @@ -1273,11 +1273,8 @@ impl<'a, T: Viewable> TypedArrayAbstractOperations<'a> for GenericSharedTypedArr type ElementType = T; #[inline(always)] - fn is_detached(self, agent: &Agent) -> bool { - self.into_void_array() - .get(agent) - .viewed_array_buffer - .is_detached(agent) + fn is_detached(self, _: &Agent) -> bool { + false } #[inline(always)] @@ -1361,7 +1358,7 @@ impl<'a, T: Viewable> TypedArrayAbstractOperations<'a> for GenericSharedTypedArr let buffer = self.into_void_array().get(agent).viewed_array_buffer; // 2. If IsDetachedBuffer(buffer) is true, then - if buffer.is_detached(agent) { + if buffer.is_detached() { // a. Let byteLength be detached. CachedBufferByteLength::detached() } else { @@ -1423,9 +1420,10 @@ impl<'a, T: Viewable> TypedArrayAbstractOperations<'a> for GenericSharedTypedArr let byte_length = o.byte_length(agent); // 5. Let kept be a new empty List. - let mut kept = create_byte_data_block(agent, len as u64, gc.nogc()) - .unbind()? - .bind(gc.nogc()); + let mut kept = + create_byte_data_block(agent, len.saturating_mul(size_of::()) as u64, gc.nogc()) + .unbind()? + .bind(gc.nogc()); // SAFETY: All viewable types are trivially transmutable. let (head, kept_slice, _) = unsafe { kept.align_to_mut::() }; // Should be properly aligned for all T. diff --git a/tests/expectations.json b/tests/expectations.json index 161c5d5d4..40e13f944 100644 --- a/tests/expectations.json +++ b/tests/expectations.json @@ -5547,14 +5547,12 @@ "built-ins/Temporal/getOwnPropertyNames.js": "FAIL", "built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm-sab.js": "FAIL", "built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm.js": "FAIL", - "built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance-sab.js": "FAIL", "built-ins/TypedArrayConstructors/ctors-bigint/length-arg/proto-from-ctor-realm.js": "FAIL", "built-ins/TypedArrayConstructors/ctors-bigint/no-args/proto-from-ctor-realm.js": "FAIL", "built-ins/TypedArrayConstructors/ctors-bigint/object-arg/proto-from-ctor-realm.js": "FAIL", "built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/proto-from-ctor-realm.js": "FAIL", "built-ins/TypedArrayConstructors/ctors/buffer-arg/proto-from-ctor-realm-sab.js": "FAIL", "built-ins/TypedArrayConstructors/ctors/buffer-arg/proto-from-ctor-realm.js": "FAIL", - "built-ins/TypedArrayConstructors/ctors/buffer-arg/returns-new-instance-sab.js": "FAIL", "built-ins/TypedArrayConstructors/ctors/length-arg/proto-from-ctor-realm.js": "FAIL", "built-ins/TypedArrayConstructors/ctors/no-args/proto-from-ctor-realm.js": "FAIL", "built-ins/TypedArrayConstructors/ctors/no-species.js": "FAIL", @@ -6913,34 +6911,18 @@ "staging/sm/Temporal/PlainMonthDay/from-coptic.js": "FAIL", "staging/sm/Temporal/PlainMonthDay/from-gregory.js": "FAIL", "staging/sm/Temporal/ZonedDateTime/zones-and-links.js": "FAIL", - "staging/sm/TypedArray/at.js": "FAIL", - "staging/sm/TypedArray/constructor-typedarray-species-other-global.js": "FAIL", - "staging/sm/TypedArray/entries.js": "FAIL", - "staging/sm/TypedArray/every-and-some.js": "FAIL", - "staging/sm/TypedArray/fill.js": "FAIL", "staging/sm/TypedArray/filter-species.js": "FAIL", - "staging/sm/TypedArray/forEach.js": "FAIL", - "staging/sm/TypedArray/from_basics.js": "FAIL", - "staging/sm/TypedArray/from_errors.js": "FAIL", "staging/sm/TypedArray/from_surfaces.js": "FAIL", "staging/sm/TypedArray/has-property-op.js": "FAIL", - "staging/sm/TypedArray/includes.js": "FAIL", "staging/sm/TypedArray/indexOf-and-lastIndexOf.js": "FAIL", - "staging/sm/TypedArray/join.js": "FAIL", - "staging/sm/TypedArray/keys.js": "FAIL", - "staging/sm/TypedArray/map-and-filter.js": "FAIL", "staging/sm/TypedArray/of.js": "FAIL", "staging/sm/TypedArray/prototype-constructor-identity.js": "FAIL", - "staging/sm/TypedArray/reverse.js": "FAIL", "staging/sm/TypedArray/slice-conversion.js": "FAIL", - "staging/sm/TypedArray/slice.js": "FAIL", "staging/sm/TypedArray/sort-negative-nan.js": "FAIL", "staging/sm/TypedArray/sort-non-function.js": "FAIL", "staging/sm/TypedArray/test-integrity-level-detached.js": "FAIL", "staging/sm/TypedArray/toLocaleString-detached.js": "FAIL", - "staging/sm/TypedArray/toLocaleString.js": "FAIL", "staging/sm/TypedArray/toString.js": "FAIL", - "staging/sm/TypedArray/values.js": "FAIL", "staging/sm/async-functions/await-error.js": "CRASH", "staging/sm/async-functions/await-in-arrow-parameters.js": "FAIL", "staging/sm/async-functions/await-in-parameters-of-async-func.js": "FAIL", @@ -7065,4 +7047,4 @@ "staging/sm/syntax/yield-as-identifier.js": "FAIL", "staging/source-phase-imports/import-source-source-text-module.js": "FAIL", "staging/top-level-await/tla-hang-entry.js": "FAIL" -} +} \ No newline at end of file diff --git a/tests/metrics.json b/tests/metrics.json index a98986a42..753cb3d11 100644 --- a/tests/metrics.json +++ b/tests/metrics.json @@ -1,11 +1,11 @@ { "results": { "crash": 52, - "fail": 6959, - "pass": 40349, + "fail": 6941, + "pass": 40359, "skip": 3326, "timeout": 18, "unresolved": 37 }, "total": 50733 -} +} \ No newline at end of file