Skip to content

Commit

Permalink
Fix ArrayBuffer.isView() (#2019)
Browse files Browse the repository at this point in the history
`ArrayBuffer.isView()` should check whether the object contains a `[[ViewedArrayBuffer]]` internal slot, which `DataView` has.

It changes the following:
- Fix `ArrayBuffer.isView()`
  • Loading branch information
HalidOdat committed Apr 8, 2022
1 parent a1b5191 commit 3007531
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion boa_engine/src/builtins/array_buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl ArrayBuffer {
Ok(args
.get_or_undefined(0)
.as_object()
.map(|obj| obj.borrow().is_typed_array())
.map(|obj| obj.borrow().has_viewed_array_buffer())
.unwrap_or_default()
.into())
}
Expand Down
17 changes: 17 additions & 0 deletions boa_engine/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,23 @@ impl Object {
}
}

#[inline]
pub(crate) fn has_viewed_array_buffer(&self) -> bool {
self.is_typed_array() || self.is_data_view()
}

/// Checks if it an `DataView` object.
#[inline]
pub fn is_data_view(&self) -> bool {
matches!(
self.data,
ObjectData {
kind: ObjectKind::DataView(_),
..
}
)
}

/// Checks if it an `ArrayBuffer` object.
#[inline]
pub fn is_array_buffer(&self) -> bool {
Expand Down

0 comments on commit 3007531

Please sign in to comment.