Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions nova_vm/src/ecmascript/builtins/array_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion nova_vm/src/ecmascript/builtins/data_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions nova_vm/src/ecmascript/builtins/shared_array_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T>() as u64),
gc.nogc(),
)
.unbind()?
.bind(gc.nogc());
let mut kept =
create_byte_data_block(agent, len.saturating_mul(size_of::<T>()) as u64, gc.nogc())
.unbind()?
.bind(gc.nogc());
// SAFETY: All viewable types are trivially transmutable.
let (head, kept_slice, _) = unsafe { kept.align_to_mut::<T>() };
// Should be properly aligned for all T.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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::<T>()) as u64, gc.nogc())
.unbind()?
.bind(gc.nogc());
// SAFETY: All viewable types are trivially transmutable.
let (head, kept_slice, _) = unsafe { kept.align_to_mut::<T>() };
// Should be properly aligned for all T.
Expand Down
20 changes: 1 addition & 19 deletions tests/expectations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
6 changes: 3 additions & 3 deletions tests/metrics.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"results": {
"crash": 52,
"fail": 6959,
"pass": 40349,
"fail": 6941,
"pass": 40359,
"skip": 3326,
"timeout": 18,
"unresolved": 37
},
"total": 50733
}
}