From 30075314818f09f8dd121f971e6c7462a25683ea Mon Sep 17 00:00:00 2001 From: Halid Odat Date: Fri, 8 Apr 2022 20:27:13 +0000 Subject: [PATCH] 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()` --- boa_engine/src/builtins/array_buffer/mod.rs | 2 +- boa_engine/src/object/mod.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/boa_engine/src/builtins/array_buffer/mod.rs b/boa_engine/src/builtins/array_buffer/mod.rs index b4d59d1f4b..e36ddf7a7f 100644 --- a/boa_engine/src/builtins/array_buffer/mod.rs +++ b/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()) } diff --git a/boa_engine/src/object/mod.rs b/boa_engine/src/object/mod.rs index 9b33d425c4..206e7d2c10 100644 --- a/boa_engine/src/object/mod.rs +++ b/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 {