Browse Source

Fix `ArrayBuffer.isView()` (#2019)

`ArrayBuffer.isView()` should check whether the object contains a `[[ViewedArrayBuffer]]` internal slot, which `DataView` has.

It changes the following:
- Fix `ArrayBuffer.isView()`
pull/2023/head
Halid Odat 3 years ago
parent
commit
3007531481
  1. 2
      boa_engine/src/builtins/array_buffer/mod.rs
  2. 17
      boa_engine/src/object/mod.rs

2
boa_engine/src/builtins/array_buffer/mod.rs

@ -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())
}

17
boa_engine/src/object/mod.rs

@ -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 {

Loading…
Cancel
Save