Skip to content

Commit 030e2db

Browse files
authored
fix(ecmascript): SharedTypedArray filter (#968)
1 parent 10e8936 commit 030e2db

8 files changed

Lines changed: 25 additions & 53 deletions

File tree

nova_vm/src/ecmascript/builtins/array_buffer.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,6 @@ pub enum AnyArrayBuffer<'a> {
296296
}
297297
bindable_handle!(AnyArrayBuffer);
298298

299-
macro_rules! array_buffer_delegate {
300-
($value: ident, $method: ident, $($arg:expr),*) => {
301-
match $value {
302-
Self::ArrayBuffer(ta) => ta.$method($($arg),+),
303-
#[cfg(feature = "shared-array-buffer")]
304-
Self::SharedArrayBuffer(sta) => sta.$method($($arg),+),
305-
}
306-
};
307-
}
308-
309299
impl<'ab> AnyArrayBuffer<'ab> {
310300
/// Returns true if the ArrayBuffer is a SharedArrayBuffer.
311301
#[inline(always)]
@@ -320,7 +310,11 @@ impl<'ab> AnyArrayBuffer<'ab> {
320310
/// Returns true if the ArrayBuffer is detached.
321311
#[inline(always)]
322312
pub fn is_detached(self, agent: &Agent) -> bool {
323-
array_buffer_delegate!(self, is_detached, agent)
313+
match self {
314+
Self::ArrayBuffer(ta) => ta.is_detached(agent),
315+
#[cfg(feature = "shared-array-buffer")]
316+
Self::SharedArrayBuffer(_) => false,
317+
}
324318
}
325319

326320
/// Returns true if the ArrayBuffer is resizable or growable.

nova_vm/src/ecmascript/builtins/data_view.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'gc> SharedDataView<'gc> {
205205
) -> T {
206206
let array_buffer = self.viewed_array_buffer(agent);
207207
// 1. Assert: IsDetachedBuffer(arrayBuffer) is false.
208-
debug_assert!(!array_buffer.is_detached(agent));
208+
debug_assert!(!array_buffer.is_detached());
209209
// 2. Assert: There are sufficient bytes in arrayBuffer starting at byteIndex to represent a value of type.
210210
// 4. Let elementSize be the Element Size value specified in Table 71 for Element Type type.
211211
// 3. Let block be arrayBuffer.[[ArrayBufferData]].

nova_vm/src/ecmascript/builtins/indexed_collections/typed_array_objects/abstract_operations.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ pub(crate) fn initialize_typed_array_from_array_buffer<'gc, T: Viewable>(
701701

702702
// 6. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
703703
if buffer.is_detached(agent) {
704+
eprintln!("{buffer:?}");
704705
return Err(agent.throw_exception_with_static_message(
705706
ExceptionType::TypeError,
706707
"attempting to access detached ArrayBuffer",

nova_vm/src/ecmascript/builtins/shared_array_buffer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ impl<'sab> SharedArrayBuffer<'sab> {
6464
/// Returns `true` if the SharedArrayBuffer has a 0 length.
6565
///
6666
/// Note: this is wrong and will be going away.
67-
#[inline]
68-
pub fn is_detached(self, agent: &Agent) -> bool {
69-
self.get(agent).data_block.is_dangling()
67+
#[inline(always)]
68+
pub fn is_detached(self) -> bool {
69+
false
7070
}
7171

7272
/// Returns true if the SharedArrayBuffer is growable.

nova_vm/src/ecmascript/builtins/typed_array/normal_typed_array.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,13 +1439,10 @@ impl<'a, T: Viewable> TypedArrayAbstractOperations<'a> for GenericTypedArray<'a,
14391439
let scoped_buffer = buffer.scope(agent, gc.nogc());
14401440

14411441
// 5. Let kept be a new empty List.
1442-
let mut kept = create_byte_data_block(
1443-
agent,
1444-
(len as u64).saturating_mul(size_of::<T>() as u64),
1445-
gc.nogc(),
1446-
)
1447-
.unbind()?
1448-
.bind(gc.nogc());
1442+
let mut kept =
1443+
create_byte_data_block(agent, len.saturating_mul(size_of::<T>()) as u64, gc.nogc())
1444+
.unbind()?
1445+
.bind(gc.nogc());
14491446
// SAFETY: All viewable types are trivially transmutable.
14501447
let (head, kept_slice, _) = unsafe { kept.align_to_mut::<T>() };
14511448
// Should be properly aligned for all T.

nova_vm/src/ecmascript/builtins/typed_array/shared_typed_array.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,11 +1273,8 @@ impl<'a, T: Viewable> TypedArrayAbstractOperations<'a> for GenericSharedTypedArr
12731273
type ElementType = T;
12741274

12751275
#[inline(always)]
1276-
fn is_detached(self, agent: &Agent) -> bool {
1277-
self.into_void_array()
1278-
.get(agent)
1279-
.viewed_array_buffer
1280-
.is_detached(agent)
1276+
fn is_detached(self, _: &Agent) -> bool {
1277+
false
12811278
}
12821279

12831280
#[inline(always)]
@@ -1361,7 +1358,7 @@ impl<'a, T: Viewable> TypedArrayAbstractOperations<'a> for GenericSharedTypedArr
13611358
let buffer = self.into_void_array().get(agent).viewed_array_buffer;
13621359

13631360
// 2. If IsDetachedBuffer(buffer) is true, then
1364-
if buffer.is_detached(agent) {
1361+
if buffer.is_detached() {
13651362
// a. Let byteLength be detached.
13661363
CachedBufferByteLength::detached()
13671364
} else {
@@ -1423,9 +1420,10 @@ impl<'a, T: Viewable> TypedArrayAbstractOperations<'a> for GenericSharedTypedArr
14231420
let byte_length = o.byte_length(agent);
14241421

14251422
// 5. Let kept be a new empty List.
1426-
let mut kept = create_byte_data_block(agent, len as u64, gc.nogc())
1427-
.unbind()?
1428-
.bind(gc.nogc());
1423+
let mut kept =
1424+
create_byte_data_block(agent, len.saturating_mul(size_of::<T>()) as u64, gc.nogc())
1425+
.unbind()?
1426+
.bind(gc.nogc());
14291427
// SAFETY: All viewable types are trivially transmutable.
14301428
let (head, kept_slice, _) = unsafe { kept.align_to_mut::<T>() };
14311429
// Should be properly aligned for all T.

tests/expectations.json

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5547,14 +5547,12 @@
55475547
"built-ins/Temporal/getOwnPropertyNames.js": "FAIL",
55485548
"built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm-sab.js": "FAIL",
55495549
"built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/proto-from-ctor-realm.js": "FAIL",
5550-
"built-ins/TypedArrayConstructors/ctors-bigint/buffer-arg/returns-new-instance-sab.js": "FAIL",
55515550
"built-ins/TypedArrayConstructors/ctors-bigint/length-arg/proto-from-ctor-realm.js": "FAIL",
55525551
"built-ins/TypedArrayConstructors/ctors-bigint/no-args/proto-from-ctor-realm.js": "FAIL",
55535552
"built-ins/TypedArrayConstructors/ctors-bigint/object-arg/proto-from-ctor-realm.js": "FAIL",
55545553
"built-ins/TypedArrayConstructors/ctors-bigint/typedarray-arg/proto-from-ctor-realm.js": "FAIL",
55555554
"built-ins/TypedArrayConstructors/ctors/buffer-arg/proto-from-ctor-realm-sab.js": "FAIL",
55565555
"built-ins/TypedArrayConstructors/ctors/buffer-arg/proto-from-ctor-realm.js": "FAIL",
5557-
"built-ins/TypedArrayConstructors/ctors/buffer-arg/returns-new-instance-sab.js": "FAIL",
55585556
"built-ins/TypedArrayConstructors/ctors/length-arg/proto-from-ctor-realm.js": "FAIL",
55595557
"built-ins/TypedArrayConstructors/ctors/no-args/proto-from-ctor-realm.js": "FAIL",
55605558
"built-ins/TypedArrayConstructors/ctors/no-species.js": "FAIL",
@@ -6913,34 +6911,18 @@
69136911
"staging/sm/Temporal/PlainMonthDay/from-coptic.js": "FAIL",
69146912
"staging/sm/Temporal/PlainMonthDay/from-gregory.js": "FAIL",
69156913
"staging/sm/Temporal/ZonedDateTime/zones-and-links.js": "FAIL",
6916-
"staging/sm/TypedArray/at.js": "FAIL",
6917-
"staging/sm/TypedArray/constructor-typedarray-species-other-global.js": "FAIL",
6918-
"staging/sm/TypedArray/entries.js": "FAIL",
6919-
"staging/sm/TypedArray/every-and-some.js": "FAIL",
6920-
"staging/sm/TypedArray/fill.js": "FAIL",
69216914
"staging/sm/TypedArray/filter-species.js": "FAIL",
6922-
"staging/sm/TypedArray/forEach.js": "FAIL",
6923-
"staging/sm/TypedArray/from_basics.js": "FAIL",
6924-
"staging/sm/TypedArray/from_errors.js": "FAIL",
69256915
"staging/sm/TypedArray/from_surfaces.js": "FAIL",
69266916
"staging/sm/TypedArray/has-property-op.js": "FAIL",
6927-
"staging/sm/TypedArray/includes.js": "FAIL",
69286917
"staging/sm/TypedArray/indexOf-and-lastIndexOf.js": "FAIL",
6929-
"staging/sm/TypedArray/join.js": "FAIL",
6930-
"staging/sm/TypedArray/keys.js": "FAIL",
6931-
"staging/sm/TypedArray/map-and-filter.js": "FAIL",
69326918
"staging/sm/TypedArray/of.js": "FAIL",
69336919
"staging/sm/TypedArray/prototype-constructor-identity.js": "FAIL",
6934-
"staging/sm/TypedArray/reverse.js": "FAIL",
69356920
"staging/sm/TypedArray/slice-conversion.js": "FAIL",
6936-
"staging/sm/TypedArray/slice.js": "FAIL",
69376921
"staging/sm/TypedArray/sort-negative-nan.js": "FAIL",
69386922
"staging/sm/TypedArray/sort-non-function.js": "FAIL",
69396923
"staging/sm/TypedArray/test-integrity-level-detached.js": "FAIL",
69406924
"staging/sm/TypedArray/toLocaleString-detached.js": "FAIL",
6941-
"staging/sm/TypedArray/toLocaleString.js": "FAIL",
69426925
"staging/sm/TypedArray/toString.js": "FAIL",
6943-
"staging/sm/TypedArray/values.js": "FAIL",
69446926
"staging/sm/async-functions/await-error.js": "CRASH",
69456927
"staging/sm/async-functions/await-in-arrow-parameters.js": "FAIL",
69466928
"staging/sm/async-functions/await-in-parameters-of-async-func.js": "FAIL",
@@ -7065,4 +7047,4 @@
70657047
"staging/sm/syntax/yield-as-identifier.js": "FAIL",
70667048
"staging/source-phase-imports/import-source-source-text-module.js": "FAIL",
70677049
"staging/top-level-await/tla-hang-entry.js": "FAIL"
7068-
}
7050+
}

tests/metrics.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"results": {
33
"crash": 52,
4-
"fail": 6959,
5-
"pass": 40349,
4+
"fail": 6941,
5+
"pass": 40359,
66
"skip": 3326,
77
"timeout": 18,
88
"unresolved": 37
99
},
1010
"total": 50733
11-
}
11+
}

0 commit comments

Comments
 (0)