Browse Source

Implement `DataView` built-in object (#1662)

Co-authored-by: João Borges <rageknify@gmail.com>
pull/1686/head
LaBaguette 3 years ago committed by GitHub
parent
commit
35d75c68b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1010
      boa/src/builtins/dataview/mod.rs
  2. 3
      boa/src/builtins/mod.rs
  3. 7
      boa/src/builtins/typed_array/mod.rs
  4. 7
      boa/src/context.rs
  5. 34
      boa/src/object/mod.rs
  6. 1
      test_ignore.txt

1010
boa/src/builtins/dataview/mod.rs

File diff suppressed because it is too large Load Diff

3
boa/src/builtins/mod.rs

@ -6,6 +6,7 @@ pub mod bigint;
pub mod boolean;
#[cfg(feature = "console")]
pub mod console;
pub mod dataview;
pub mod date;
pub mod error;
pub mod function;
@ -32,6 +33,7 @@ pub(crate) use self::{
array::{array_iterator::ArrayIterator, Array},
bigint::BigInt,
boolean::Boolean,
dataview::DataView,
date::Date,
error::{Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, UriError},
function::BuiltInFunctionObject,
@ -129,6 +131,7 @@ pub fn init(context: &mut Context) {
BigInt,
Boolean,
Date,
DataView,
Map,
Number,
Set,

7
boa/src/builtins/typed_array/mod.rs

@ -3353,6 +3353,13 @@ impl TypedArrayName {
TypedArrayName::Float64Array => "Float64Array",
}
}
pub(crate) fn is_big_int_element_type(&self) -> bool {
matches!(
self,
TypedArrayName::BigUint64Array | TypedArrayName::BigInt64Array
)
}
}
typed_array!(Int8Array, "Int8Array", typed_int8_array_object);

7
boa/src/context.rs

@ -110,6 +110,7 @@ pub struct StandardObjects {
typed_float32_array: StandardConstructor,
typed_float64_array: StandardConstructor,
array_buffer: StandardConstructor,
data_view: StandardConstructor,
}
impl Default for StandardObjects {
@ -156,6 +157,7 @@ impl Default for StandardObjects {
typed_float32_array: StandardConstructor::default(),
typed_float64_array: StandardConstructor::default(),
array_buffer: StandardConstructor::default(),
data_view: StandardConstructor::default(),
}
}
}
@ -320,6 +322,11 @@ impl StandardObjects {
pub fn array_buffer_object(&self) -> &StandardConstructor {
&self.array_buffer
}
#[inline]
pub fn data_view_object(&self) -> &StandardConstructor {
&self.data_view
}
}
/// Internal representation of the strict mode types.

34
boa/src/object/mod.rs

@ -15,7 +15,7 @@ use crate::{
set::set_iterator::SetIterator,
string::string_iterator::StringIterator,
typed_array::integer_indexed_object::IntegerIndexed,
Date, RegExp,
DataView, Date, RegExp,
},
context::StandardConstructor,
gc::{Finalize, Trace},
@ -116,6 +116,7 @@ pub enum ObjectKind {
RegExpStringIterator(RegExpStringIterator),
BigInt(JsBigInt),
Boolean(bool),
DataView(DataView),
ForInIterator(ForInIterator),
Function(Function),
BoundFunction(BoundFunction),
@ -208,6 +209,14 @@ impl ObjectData {
}
}
/// Create the `DataView` object data
pub fn data_view(data_view: DataView) -> Self {
Self {
kind: ObjectKind::DataView(data_view),
internal_methods: &ORDINARY_INTERNAL_METHODS,
}
}
/// Create the `ForInIterator` object data
pub fn for_in_iterator(for_in_iterator: ForInIterator) -> Self {
Self {
@ -392,6 +401,7 @@ impl Display for ObjectKind {
Self::Arguments(_) => "Arguments",
Self::NativeObject(_) => "NativeObject",
Self::IntegerIndexed(_) => "TypedArray",
Self::DataView(_) => "DataView",
})
}
}
@ -911,6 +921,28 @@ impl Object {
)
}
#[inline]
pub fn as_data_view(&self) -> Option<&DataView> {
match &self.data {
ObjectData {
kind: ObjectKind::DataView(data_view),
..
} => Some(data_view),
_ => None,
}
}
#[inline]
pub fn as_data_view_mut(&mut self) -> Option<&mut DataView> {
match &mut self.data {
ObjectData {
kind: ObjectKind::DataView(data_view),
..
} => Some(data_view),
_ => None,
}
}
/// Checks if it is an `Arguments` object.
#[inline]
pub fn is_arguments(&self) -> bool {

1
test_ignore.txt

@ -4,7 +4,6 @@ flag:async
// Non-implemented features:
feature:json-modules
feature:DataView
feature:SharedArrayBuffer
feature:resizable-arraybuffer
feature:Temporal

Loading…
Cancel
Save