From 7bc86fa8690762b27af76c12d91c76625f9b42b2 Mon Sep 17 00:00:00 2001 From: Dean Srebnik <49134864+load1n9@users.noreply.github.com> Date: Wed, 9 Oct 2024 21:28:43 -0400 Subject: [PATCH 1/3] feat: array buffer feature --- nova_vm/Cargo.toml | 6 +-- nova_vm/src/ecmascript/builtins.rs | 3 ++ nova_vm/src/ecmascript/builtins/ordinary.rs | 7 +++- .../ecmascript/builtins/structured_data.rs | 1 + nova_vm/src/ecmascript/execution/realm.rs | 25 +++++++----- .../ecmascript/execution/realm/intrinsics.rs | 17 ++++++-- .../src/ecmascript/types/language/object.rs | 40 +++++++++++++++---- .../src/ecmascript/types/language/value.rs | 11 ++++- nova_vm/src/ecmascript/types/spec.rs | 2 +- nova_vm/src/engine/bytecode/vm.rs | 3 +- nova_vm/src/heap.rs | 7 +++- nova_vm/src/heap/heap_bits.rs | 14 ++++++- nova_vm/src/heap/heap_gc.rs | 35 ++++++++++------ nova_vm/src/heap/indexes.rs | 5 ++- 14 files changed, 129 insertions(+), 47 deletions(-) diff --git a/nova_vm/Cargo.toml b/nova_vm/Cargo.toml index b08b1acf5..88abdaacb 100644 --- a/nova_vm/Cargo.toml +++ b/nova_vm/Cargo.toml @@ -19,15 +19,15 @@ oxc_syntax = { workspace = true } rand = { workspace = true } ryu-js = { workspace = true } small_string = { path = "../small_string" } -sonic-rs = { workspace = true, optional = true} +sonic-rs = { workspace = true, optional = true } wtf8 = { workspace = true } [features] -default = ["math", "json", "date"] +default = ["math", "json", "date", "array-buffer"] math = [] json = ["sonic-rs"] date = [] - +array-buffer = [] typescript = [] [build-dependencies] diff --git a/nova_vm/src/ecmascript/builtins.rs b/nova_vm/src/ecmascript/builtins.rs index 34b86bb5c..038293666 100644 --- a/nova_vm/src/ecmascript/builtins.rs +++ b/nova_vm/src/ecmascript/builtins.rs @@ -10,6 +10,7 @@ pub(crate) mod arguments; mod array; +#[cfg(feature = "array-buffer")] mod array_buffer; pub mod bound_function; mod builtin_constructor; @@ -49,7 +50,9 @@ pub(crate) use arguments::*; pub(crate) use array::abstract_operations::*; pub use array::Array; pub(crate) use array::{ArrayHeapData, SealableElementsVector}; +#[cfg(feature = "array-buffer")] pub use array_buffer::ArrayBuffer; +#[cfg(feature = "array-buffer")] pub(crate) use array_buffer::ArrayBufferHeapData; pub use builtin_constructor::BuiltinConstructorFunction; pub(crate) use builtin_constructor::{create_builtin_constructor, BuiltinConstructorArgs}; diff --git a/nova_vm/src/ecmascript/builtins/ordinary.rs b/nova_vm/src/ecmascript/builtins/ordinary.rs index 93862cfca..6e5f72de6 100644 --- a/nova_vm/src/ecmascript/builtins/ordinary.rs +++ b/nova_vm/src/ecmascript/builtins/ordinary.rs @@ -46,9 +46,12 @@ use super::{ weak_map::data::WeakMapHeapData, weak_ref::data::WeakRefHeapData, weak_set::data::WeakSetHeapData, - ArrayBufferHeapData, ArrayHeapData, + ArrayHeapData, }; +#[cfg(feature = "array-buffer")] +use super::ArrayBufferHeapData; + impl Index for Agent { type Output = ObjectHeapData; @@ -801,6 +804,7 @@ pub(crate) fn ordinary_object_create_with_intrinsics( let object = match proto_intrinsics { ProtoIntrinsics::Array => agent.heap.create(ArrayHeapData::default()).into_object(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::ArrayBuffer => agent .heap .create(ArrayBufferHeapData::default()) @@ -1033,6 +1037,7 @@ pub(crate) fn get_prototype_from_constructor( ProtoIntrinsics::AggregateError => Some(intrinsics.aggregate_error().into_function()), ProtoIntrinsics::Array => Some(intrinsics.array().into_function()), ProtoIntrinsics::ArrayIterator => None, + #[cfg(feature = "array-buffer")] ProtoIntrinsics::ArrayBuffer => Some(intrinsics.array_buffer().into_function()), ProtoIntrinsics::AsyncFunction => Some(intrinsics.async_function().into_function()), ProtoIntrinsics::AsyncGeneratorFunction => { diff --git a/nova_vm/src/ecmascript/builtins/structured_data.rs b/nova_vm/src/ecmascript/builtins/structured_data.rs index f7d3dd392..50fe679e1 100644 --- a/nova_vm/src/ecmascript/builtins/structured_data.rs +++ b/nova_vm/src/ecmascript/builtins/structured_data.rs @@ -2,6 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#[cfg(feature = "array-buffer")] pub(crate) mod array_buffer_objects; pub(crate) mod atomics_object; pub(crate) mod data_view_objects; diff --git a/nova_vm/src/ecmascript/execution/realm.rs b/nova_vm/src/ecmascript/execution/realm.rs index 22618ac0d..225dc7d10 100644 --- a/nova_vm/src/ecmascript/execution/realm.rs +++ b/nova_vm/src/ecmascript/execution/realm.rs @@ -503,17 +503,19 @@ pub(crate) fn set_default_global_bindings( define_property_or_throw(agent, global, name, desc)?; // 19.3.3 ArrayBuffer ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.ArrayBuffer); - let value = agent.get_realm(realm_id).intrinsics().array_buffer(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; - + #[cfg(feature = "array-buffer")] + { + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.ArrayBuffer); + let value = agent.get_realm(realm_id).intrinsics().array_buffer(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; + } // 19.3.4 BigInt ( . . . ) let name = PropertyKey::from(BUILTIN_STRING_MEMORY.BigInt); let value = agent.get_realm(realm_id).intrinsics().big_int(); @@ -1159,6 +1161,7 @@ mod test { .builtin_function_index_base, BuiltinFunctionIndex::from_index(0) ); + #[cfg(feature = "array-buffer")] assert!(agent.heap.array_buffers.is_empty()); // Array prototype is itself an Array :/ assert_eq!(agent.heap.arrays.len(), 1); diff --git a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs index bfc16bf4f..754bb159e 100644 --- a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs +++ b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs @@ -73,10 +73,6 @@ use crate::{ primitive_objects::PrimitiveObject, reflection::{proxy_constructor::ProxyConstructor, reflect_object::ReflectObject}, structured_data::{ - array_buffer_objects::{ - array_buffer_constructor::ArrayBufferConstructor, - array_buffer_prototype::ArrayBufferPrototype, - }, atomics_object::AtomicsObject, data_view_objects::{ data_view_constructor::DataViewConstructor, @@ -148,6 +144,10 @@ use crate::ecmascript::builtins::numbers_and_dates::date_objects::{ }; #[cfg(feature = "math")] use crate::ecmascript::builtins::numbers_and_dates::math_object::MathObject; +#[cfg(feature = "array-buffer")] +use crate::ecmascript::builtins::structured_data::array_buffer_objects::{ + array_buffer_constructor::ArrayBufferConstructor, array_buffer_prototype::ArrayBufferPrototype, +}; #[cfg(feature = "json")] use crate::ecmascript::builtins::structured_data::json_object::JSONObject; @@ -167,6 +167,7 @@ pub(crate) struct Intrinsics { pub enum ProtoIntrinsics { AggregateError, Array, + #[cfg(feature = "array-buffer")] ArrayBuffer, ArrayIterator, AsyncFunction, @@ -294,7 +295,9 @@ impl Intrinsics { WeakMapConstructor::create_intrinsic(agent, realm); WeakSetPrototype::create_intrinsic(agent, realm); WeakSetConstructor::create_intrinsic(agent, realm); + #[cfg(feature = "array-buffer")] ArrayBufferPrototype::create_intrinsic(agent, realm); + #[cfg(feature = "array-buffer")] ArrayBufferConstructor::create_intrinsic(agent, realm); SharedArrayBufferPrototype::create_intrinsic(agent, realm); SharedArrayBufferConstructor::create_intrinsic(agent, realm); @@ -333,6 +336,7 @@ impl Intrinsics { ) -> Object { match intrinsic_default_proto { ProtoIntrinsics::Array => self.array_prototype().into(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::ArrayBuffer => self.array_buffer_prototype().into(), ProtoIntrinsics::ArrayIterator => self.array_iterator_prototype().into(), ProtoIntrinsics::BigInt => self.big_int_prototype().into(), @@ -470,6 +474,7 @@ impl Intrinsics { IntrinsicConstructorIndexes::Array.get_object_index(self.object_index_base) } + #[cfg(feature = "array-buffer")] /// %ArrayBuffer.prototype% pub(crate) fn array_buffer_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::ArrayBufferPrototype @@ -477,6 +482,7 @@ impl Intrinsics { .into() } + #[cfg(feature = "array-buffer")] /// %ArrayBuffer% pub(crate) fn array_buffer(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::ArrayBuffer @@ -484,6 +490,7 @@ impl Intrinsics { .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn array_buffer_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::ArrayBuffer.get_object_index(self.object_index_base) } @@ -1502,7 +1509,9 @@ impl HeapMarkAndSweep for Intrinsics { self.array_prototype_values().mark_values(queues); self.array_prototype().mark_values(queues); self.array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.array_buffer_prototype().mark_values(queues); + #[cfg(feature = "array-buffer")] self.array_buffer().mark_values(queues); self.array_iterator_prototype().mark_values(queues); self.async_from_sync_iterator_prototype() diff --git a/nova_vm/src/ecmascript/types/language/object.rs b/nova_vm/src/ecmascript/types/language/object.rs index e9838396d..e868a666a 100644 --- a/nova_vm/src/ecmascript/types/language/object.rs +++ b/nova_vm/src/ecmascript/types/language/object.rs @@ -11,16 +11,17 @@ mod property_storage; use std::hash::Hash; +#[cfg(feature = "array-buffer")] +use super::value::ARRAY_BUFFER_DISCRIMINANT; #[cfg(feature = "date")] use super::value::DATE_DISCRIMINANT; use super::{ value::{ - ARGUMENTS_DISCRIMINANT, ARRAY_BUFFER_DISCRIMINANT, ARRAY_DISCRIMINANT, - ARRAY_ITERATOR_DISCRIMINANT, ASYNC_FROM_SYNC_ITERATOR_DISCRIMINANT, - ASYNC_ITERATOR_DISCRIMINANT, BIGINT_64_ARRAY_DISCRIMINANT, BIGUINT_64_ARRAY_DISCRIMINANT, - BOUND_FUNCTION_DISCRIMINANT, BUILTIN_CONSTRUCTOR_FUNCTION_DISCRIMINANT, - BUILTIN_FUNCTION_DISCRIMINANT, BUILTIN_GENERATOR_FUNCTION_DISCRIMINANT, - BUILTIN_PROMISE_COLLECTOR_FUNCTION_DISCRIMINANT, + ARGUMENTS_DISCRIMINANT, ARRAY_DISCRIMINANT, ARRAY_ITERATOR_DISCRIMINANT, + ASYNC_FROM_SYNC_ITERATOR_DISCRIMINANT, ASYNC_ITERATOR_DISCRIMINANT, + BIGINT_64_ARRAY_DISCRIMINANT, BIGUINT_64_ARRAY_DISCRIMINANT, BOUND_FUNCTION_DISCRIMINANT, + BUILTIN_CONSTRUCTOR_FUNCTION_DISCRIMINANT, BUILTIN_FUNCTION_DISCRIMINANT, + BUILTIN_GENERATOR_FUNCTION_DISCRIMINANT, BUILTIN_PROMISE_COLLECTOR_FUNCTION_DISCRIMINANT, BUILTIN_PROMISE_RESOLVING_FUNCTION_DISCRIMINANT, BUILTIN_PROXY_REVOKER_FUNCTION, DATA_VIEW_DISCRIMINANT, ECMASCRIPT_FUNCTION_DISCRIMINANT, EMBEDDER_OBJECT_DISCRIMINANT, ERROR_DISCRIMINANT, FINALIZATION_REGISTRY_DISCRIMINANT, FLOAT_32_ARRAY_DISCRIMINANT, @@ -38,6 +39,8 @@ use super::{ #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; +#[cfg(feature = "array-buffer")] +use crate::ecmascript::builtins::ArrayBuffer; use crate::{ ecmascript::{ builtins::{ @@ -67,8 +70,7 @@ use crate::{ weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, - ArgumentsList, Array, ArrayBuffer, BuiltinConstructorFunction, BuiltinFunction, - ECMAScriptFunction, + ArgumentsList, Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, }, execution::{Agent, JsResult}, types::PropertyDescriptor, @@ -106,6 +108,7 @@ pub enum Object { PrimitiveObject(PrimitiveObject) = PRIMITIVE_OBJECT_DISCRIMINANT, Arguments(OrdinaryObject) = ARGUMENTS_DISCRIMINANT, Array(Array) = ARRAY_DISCRIMINANT, + #[cfg(feature = "array-buffer")] ArrayBuffer(ArrayBuffer) = ARRAY_BUFFER_DISCRIMINANT, DataView(DataView) = DATA_VIEW_DISCRIMINANT, #[cfg(feature = "date")] @@ -163,6 +166,7 @@ impl IntoValue for Object { Object::PrimitiveObject(data) => Value::PrimitiveObject(data), Object::Arguments(data) => Value::Arguments(data), Object::Array(data) => Value::Array(data), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => Value::ArrayBuffer(data), Object::DataView(data) => Value::DataView(data), #[cfg(feature = "date")] @@ -340,6 +344,7 @@ impl From for Value { Object::PrimitiveObject(data) => Value::PrimitiveObject(data), Object::Arguments(data) => Value::Arguments(data), Object::Array(data) => Value::Array(data), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => Value::ArrayBuffer(data), Object::DataView(data) => Value::DataView(data), #[cfg(feature = "date")] @@ -411,6 +416,7 @@ impl TryFrom for Object { Value::BuiltinProxyRevokerFunction => Ok(Object::BuiltinProxyRevokerFunction), Value::PrimitiveObject(data) => Ok(Object::PrimitiveObject(data)), Value::Arguments(data) => Ok(Object::Arguments(data)), + #[cfg(feature = "array-buffer")] Value::ArrayBuffer(idx) => Ok(Object::ArrayBuffer(idx)), Value::DataView(data) => Ok(Object::DataView(data)), Value::FinalizationRegistry(data) => Ok(Object::FinalizationRegistry(data)), @@ -473,6 +479,7 @@ impl Hash for Object { Object::PrimitiveObject(data) => data.get_index().hash(state), Object::Arguments(data) => data.get_index().hash(state), Object::Array(data) => data.get_index().hash(state), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.get_index().hash(state), Object::DataView(data) => data.get_index().hash(state), #[cfg(feature = "date")] @@ -529,6 +536,7 @@ impl InternalSlots for Object { match self { Object::Object(data) => data.internal_extensible(agent), Object::Array(data) => data.internal_extensible(agent), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_extensible(agent), #[cfg(feature = "date")] Object::Date(data) => data.internal_extensible(agent), @@ -587,6 +595,7 @@ impl InternalSlots for Object { match self { Object::Object(data) => data.internal_set_extensible(agent, value), Object::Array(data) => data.internal_set_extensible(agent, value), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_set_extensible(agent, value), #[cfg(feature = "date")] Object::Date(data) => data.internal_set_extensible(agent, value), @@ -663,6 +672,7 @@ impl InternalSlots for Object { match self { Object::Object(data) => data.internal_prototype(agent), Object::Array(data) => data.internal_prototype(agent), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_prototype(agent), #[cfg(feature = "date")] Object::Date(data) => data.internal_prototype(agent), @@ -721,6 +731,7 @@ impl InternalSlots for Object { match self { Object::Object(data) => data.internal_set_prototype(agent, prototype), Object::Array(data) => data.internal_set_prototype(agent, prototype), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_set_prototype(agent, prototype), #[cfg(feature = "date")] Object::Date(data) => data.internal_set_prototype(agent, prototype), @@ -801,6 +812,7 @@ impl InternalMethods for Object { match self { Object::Object(data) => data.internal_get_prototype_of(agent), Object::Array(data) => data.internal_get_prototype_of(agent), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_get_prototype_of(agent), #[cfg(feature = "date")] Object::Date(data) => data.internal_get_prototype_of(agent), @@ -877,6 +889,7 @@ impl InternalMethods for Object { match self { Object::Object(data) => data.internal_set_prototype_of(agent, prototype), Object::Array(data) => data.internal_set_prototype_of(agent, prototype), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_set_prototype_of(agent, prototype), #[cfg(feature = "date")] Object::Date(data) => data.internal_set_prototype_of(agent, prototype), @@ -955,6 +968,7 @@ impl InternalMethods for Object { match self { Object::Object(data) => data.internal_is_extensible(agent), Object::Array(data) => data.internal_is_extensible(agent), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_is_extensible(agent), #[cfg(feature = "date")] Object::Date(data) => data.internal_is_extensible(agent), @@ -1021,6 +1035,7 @@ impl InternalMethods for Object { match self { Object::Object(data) => data.internal_prevent_extensions(agent), Object::Array(data) => data.internal_prevent_extensions(agent), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_prevent_extensions(agent), #[cfg(feature = "date")] Object::Date(data) => data.internal_prevent_extensions(agent), @@ -1101,6 +1116,7 @@ impl InternalMethods for Object { match self { Object::Object(data) => data.internal_get_own_property(agent, property_key), Object::Array(data) => data.internal_get_own_property(agent, property_key), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_get_own_property(agent, property_key), #[cfg(feature = "date")] Object::Date(data) => data.internal_get_own_property(agent, property_key), @@ -1190,6 +1206,7 @@ impl InternalMethods for Object { Object::Array(idx) => { idx.internal_define_own_property(agent, property_key, property_descriptor) } + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(idx) => { idx.internal_define_own_property(agent, property_key, property_descriptor) } @@ -1319,6 +1336,7 @@ impl InternalMethods for Object { match self { Object::Object(data) => data.internal_has_property(agent, property_key), Object::Array(data) => data.internal_has_property(agent, property_key), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_has_property(agent, property_key), #[cfg(feature = "date")] Object::Date(data) => data.internal_has_property(agent, property_key), @@ -1402,6 +1420,7 @@ impl InternalMethods for Object { match self { Object::Object(data) => data.internal_get(agent, property_key, receiver), Object::Array(data) => data.internal_get(agent, property_key, receiver), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_get(agent, property_key, receiver), #[cfg(feature = "date")] Object::Date(data) => data.internal_get(agent, property_key, receiver), @@ -1486,6 +1505,7 @@ impl InternalMethods for Object { match self { Object::Object(data) => data.internal_set(agent, property_key, value, receiver), Object::Array(data) => data.internal_set(agent, property_key, value, receiver), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_set(agent, property_key, value, receiver), #[cfg(feature = "date")] Object::Date(data) => data.internal_set(agent, property_key, value, receiver), @@ -1577,6 +1597,7 @@ impl InternalMethods for Object { match self { Object::Object(data) => data.internal_delete(agent, property_key), Object::Array(data) => data.internal_delete(agent, property_key), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_delete(agent, property_key), #[cfg(feature = "date")] Object::Date(data) => data.internal_delete(agent, property_key), @@ -1653,6 +1674,7 @@ impl InternalMethods for Object { match self { Object::Object(data) => data.internal_own_property_keys(agent), Object::Array(data) => data.internal_own_property_keys(agent), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.internal_own_property_keys(agent), #[cfg(feature = "date")] Object::Date(data) => data.internal_own_property_keys(agent), @@ -1766,6 +1788,7 @@ impl HeapMarkAndSweep for Object { match self { Object::Object(data) => data.mark_values(queues), Object::Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.mark_values(queues), #[cfg(feature = "date")] Object::Date(data) => data.mark_values(queues), @@ -1828,6 +1851,7 @@ impl HeapMarkAndSweep for Object { Object::PrimitiveObject(data) => data.sweep_values(compactions), Object::Arguments(data) => data.sweep_values(compactions), Object::Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.sweep_values(compactions), Object::DataView(data) => data.sweep_values(compactions), #[cfg(feature = "date")] diff --git a/nova_vm/src/ecmascript/types/language/value.rs b/nova_vm/src/ecmascript/types/language/value.rs index f25548f44..d738bf0d3 100644 --- a/nova_vm/src/ecmascript/types/language/value.rs +++ b/nova_vm/src/ecmascript/types/language/value.rs @@ -11,6 +11,9 @@ use super::{ }; #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; +#[cfg(feature = "array-buffer")] +use crate::ecmascript::builtins::ArrayBuffer; + use crate::{ ecmascript::{ abstract_operations::type_conversion::{ @@ -42,7 +45,7 @@ use crate::{ weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, - Array, ArrayBuffer, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, + Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, }, execution::{Agent, JsResult}, types::BUILTIN_STRING_MEMORY, @@ -144,6 +147,7 @@ pub enum Value { Arguments(OrdinaryObject), // TODO: MappedArguments(MappedArgumentsObject), Array(Array), + #[cfg(feature = "array-buffer")] ArrayBuffer(ArrayBuffer), DataView(DataView), #[cfg(feature = "date")] @@ -226,6 +230,7 @@ pub(crate) const SMALL_BIGINT_DISCRIMINANT: u8 = pub(crate) const OBJECT_DISCRIMINANT: u8 = value_discriminant(Value::Object(OrdinaryObject::_def())); pub(crate) const ARRAY_DISCRIMINANT: u8 = value_discriminant(Value::Array(Array::_def())); +#[cfg(feature = "array-buffer")] pub(crate) const ARRAY_BUFFER_DISCRIMINANT: u8 = value_discriminant(Value::ArrayBuffer(ArrayBuffer::_def())); #[cfg(feature = "date")] @@ -572,6 +577,7 @@ impl Value { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::ArrayBuffer(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); @@ -775,6 +781,7 @@ impl Value { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::ArrayBuffer(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); @@ -1013,6 +1020,7 @@ impl HeapMarkAndSweep for Value { Value::BigInt(data) => data.mark_values(queues), Value::Object(data) => data.mark_values(queues), Value::Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::ArrayBuffer(data) => data.mark_values(queues), #[cfg(feature = "date")] Value::Date(data) => data.mark_values(queues), @@ -1078,6 +1086,7 @@ impl HeapMarkAndSweep for Value { Value::BigInt(data) => data.sweep_values(compactions), Value::Object(data) => data.sweep_values(compactions), Value::Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::ArrayBuffer(data) => data.sweep_values(compactions), #[cfg(feature = "date")] Value::Date(data) => data.sweep_values(compactions), diff --git a/nova_vm/src/ecmascript/types/spec.rs b/nova_vm/src/ecmascript/types/spec.rs index 486fa43ba..c1f8e97cc 100644 --- a/nova_vm/src/ecmascript/types/spec.rs +++ b/nova_vm/src/ecmascript/types/spec.rs @@ -5,7 +5,7 @@ mod data_block; mod property_descriptor; mod reference; - +#[cfg(feature = "array-buffer")] pub(crate) use data_block::DataBlock; pub use property_descriptor::PropertyDescriptor; pub(crate) use reference::*; diff --git a/nova_vm/src/engine/bytecode/vm.rs b/nova_vm/src/engine/bytecode/vm.rs index 3b5b3dd34..8fcffec03 100644 --- a/nova_vm/src/engine/bytecode/vm.rs +++ b/nova_vm/src/engine/bytecode/vm.rs @@ -2089,7 +2089,6 @@ fn typeof_operator(_: &mut Agent, val: Value) -> String { // 12. NOTE: This step is replaced in section B.3.6.3. Value::Object(_) | Value::Array(_) | - Value::ArrayBuffer(_) | Value::Error(_) | // 14. Return "object". Value::PrimitiveObject(_) | @@ -2124,6 +2123,8 @@ fn typeof_operator(_: &mut Agent, val: Value) -> String { Value::Generator(_) | Value::Module(_) | Value::EmbedderObject(_) => BUILTIN_STRING_MEMORY.object, + #[cfg(feature = "array-buffer")] + Value::ArrayBuffer(_) => BUILTIN_STRING_MEMORY.object, #[cfg(feature = "date")] Value::Date(_) => BUILTIN_STRING_MEMORY.object, // 13. If val has a [[Call]] internal slot, return "function". diff --git a/nova_vm/src/heap.rs b/nova_vm/src/heap.rs index 3348e5941..dc0b0ac03 100644 --- a/nova_vm/src/heap.rs +++ b/nova_vm/src/heap.rs @@ -70,9 +70,10 @@ use crate::ecmascript::{ #[cfg(feature = "date")] use crate::ecmascript::builtins::date::data::DateHeapData; - +#[cfg(feature = "array-buffer")] +use crate::ecmascript::builtins::ArrayBufferHeapData; use crate::ecmascript::{ - builtins::{ArrayBufferHeapData, ArrayHeapData}, + builtins::ArrayHeapData, execution::{Environments, Realm, RealmIdentifier}, scripts_and_modules::{ module::ModuleIdentifier, @@ -87,6 +88,7 @@ pub(crate) use heap_bits::{CompactionLists, HeapMarkAndSweep, WorkQueues}; #[derive(Debug)] pub struct Heap { + #[cfg(feature = "array-buffer")] pub array_buffers: Vec>, pub arrays: Vec>, pub array_iterators: Vec>, @@ -169,6 +171,7 @@ impl CreateHeapData for Heap { impl Heap { pub fn new() -> Heap { let mut heap = Heap { + #[cfg(feature = "array-buffer")] array_buffers: Vec::with_capacity(1024), arrays: Vec::with_capacity(1024), array_iterators: Vec::with_capacity(256), diff --git a/nova_vm/src/heap/heap_bits.rs b/nova_vm/src/heap/heap_bits.rs index be780789a..58695226e 100644 --- a/nova_vm/src/heap/heap_bits.rs +++ b/nova_vm/src/heap/heap_bits.rs @@ -10,6 +10,8 @@ use super::{ }; #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; +#[cfg(feature = "array-buffer")] +use crate::ecmascript::builtins::ArrayBuffer; use crate::ecmascript::{ builtins::{ bound_function::BoundFunction, @@ -41,7 +43,7 @@ use crate::ecmascript::{ weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, - Array, ArrayBuffer, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, + Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, }, execution::{ DeclarativeEnvironmentIndex, EnvironmentIndex, FunctionEnvironmentIndex, @@ -56,6 +58,7 @@ use crate::ecmascript::{ #[derive(Debug)] pub struct HeapBits { + #[cfg(feature = "array-buffer")] pub array_buffers: Box<[bool]>, pub arrays: Box<[bool]>, pub array_iterators: Box<[bool]>, @@ -111,6 +114,7 @@ pub struct HeapBits { #[derive(Debug)] pub(crate) struct WorkQueues { + #[cfg(feature = "array-buffer")] pub array_buffers: Vec, pub arrays: Vec, pub array_iterators: Vec, @@ -166,6 +170,7 @@ pub(crate) struct WorkQueues { impl HeapBits { pub fn new(heap: &Heap) -> Self { + #[cfg(feature = "array-buffer")] let array_buffers = vec![false; heap.array_buffers.len()]; let arrays = vec![false; heap.arrays.len()]; let array_iterators = vec![false; heap.array_iterators.len()]; @@ -218,6 +223,7 @@ impl HeapBits { let weak_refs = vec![false; heap.weak_refs.len()]; let weak_sets = vec![false; heap.weak_sets.len()]; Self { + #[cfg(feature = "array-buffer")] array_buffers: array_buffers.into_boxed_slice(), arrays: arrays.into_boxed_slice(), array_iterators: array_iterators.into_boxed_slice(), @@ -276,6 +282,7 @@ impl HeapBits { impl WorkQueues { pub fn new(heap: &Heap) -> Self { Self { + #[cfg(feature = "array-buffer")] array_buffers: Vec::with_capacity(heap.array_buffers.len() / 4), arrays: Vec::with_capacity(heap.arrays.len() / 4), array_iterators: Vec::with_capacity(heap.array_iterators.len() / 4), @@ -357,6 +364,7 @@ impl WorkQueues { pub fn is_empty(&self) -> bool { let Self { + #[cfg(feature = "array-buffer")] array_buffers, arrays, array_iterators, @@ -412,6 +420,8 @@ impl WorkQueues { #[cfg(not(feature = "date"))] let dates: &[bool; 0] = &[]; + #[cfg(not(feature = "array-buffer"))] + let array_buffers: &[bool; 0] = &[]; array_buffers.is_empty() && arrays.is_empty() @@ -605,6 +615,7 @@ impl Default for CompactionListBuilder { } pub(crate) struct CompactionLists { + #[cfg(feature = "array-buffer")] pub array_buffers: CompactionList, pub arrays: CompactionList, pub array_iterators: CompactionList, @@ -688,6 +699,7 @@ impl CompactionLists { e_2_24: CompactionList::from_mark_u32s(&bits.e_2_24), e_2_32: CompactionList::from_mark_u32s(&bits.e_2_32), arrays: CompactionList::from_mark_bits(&bits.arrays), + #[cfg(feature = "array-buffer")] array_buffers: CompactionList::from_mark_bits(&bits.array_buffers), array_iterators: CompactionList::from_mark_bits(&bits.array_iterators), await_reactions: CompactionList::from_mark_bits(&bits.await_reactions), diff --git a/nova_vm/src/heap/heap_gc.rs b/nova_vm/src/heap/heap_gc.rs index 0d2b911b4..a229f0015 100644 --- a/nova_vm/src/heap/heap_gc.rs +++ b/nova_vm/src/heap/heap_gc.rs @@ -17,6 +17,8 @@ use super::{ }; #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; +#[cfg(feature = "array-buffer")] +use crate::ecmascript::builtins::ArrayBuffer; use crate::ecmascript::{ builtins::{ bound_function::BoundFunction, @@ -48,7 +50,7 @@ use crate::ecmascript::{ weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, - Array, ArrayBuffer, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, + Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, }, execution::{ DeclarativeEnvironmentIndex, Environments, FunctionEnvironmentIndex, @@ -103,6 +105,7 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { while !queues.is_empty() { let Heap { + #[cfg(feature = "array-buffer")] array_buffers, arrays, array_iterators, @@ -273,19 +276,23 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { arrays.get(index).mark_values(&mut queues); } }); - let mut array_buffer_marks: Box<[ArrayBuffer]> = queues.array_buffers.drain(..).collect(); - array_buffer_marks.sort(); - array_buffer_marks.iter().for_each(|&idx| { - let index = idx.get_index(); - if let Some(marked) = bits.array_buffers.get_mut(index) { - if *marked { - // Already marked, ignore - return; + #[cfg(feature = "array-buffer")] + { + let mut array_buffer_marks: Box<[ArrayBuffer]> = + queues.array_buffers.drain(..).collect(); + array_buffer_marks.sort(); + array_buffer_marks.iter().for_each(|&idx| { + let index = idx.get_index(); + if let Some(marked) = bits.array_buffers.get_mut(index) { + if *marked { + // Already marked, ignore + return; + } + *marked = true; + array_buffers.get(index).mark_values(&mut queues); } - *marked = true; - array_buffers.get(index).mark_values(&mut queues); - } - }); + }); + } let mut array_iterator_marks: Box<[ArrayIterator]> = queues.array_iterators.drain(..).collect(); array_iterator_marks.sort(); @@ -915,6 +922,7 @@ fn sweep(heap: &mut Heap, bits: &HeapBits, root_realms: &mut [Option Default for BaseIndex { } } +#[cfg(feature = "array-buffer")] pub type ArrayBufferIndex = BaseIndex; pub type ArrayIndex = BaseIndex; pub type ArrayIteratorIndex = BaseIndex; From 8d7b1592dd9a5bb3fb11816d6dabd381c0c5571a Mon Sep 17 00:00:00 2001 From: Dean Srebnik <49134864+load1n9@users.noreply.github.com> Date: Wed, 9 Oct 2024 22:39:05 -0400 Subject: [PATCH 2/3] feat: add dataview --- nova_vm/Cargo.toml | 2 +- nova_vm/src/ecmascript/builtins.rs | 1 + nova_vm/src/ecmascript/builtins/ordinary.rs | 6 ++-- .../ecmascript/builtins/structured_data.rs | 1 + nova_vm/src/ecmascript/execution/realm.rs | 24 +++++++------- .../ecmascript/execution/realm/intrinsics.rs | 29 +++++++++++----- .../src/ecmascript/types/language/object.rs | 33 +++++++++++++++---- .../src/ecmascript/types/language/value.rs | 10 ++++-- nova_vm/src/engine/bytecode/vm.rs | 4 +-- nova_vm/src/heap.rs | 5 +-- nova_vm/src/heap/heap_bits.rs | 13 ++++++-- nova_vm/src/heap/heap_constants.rs | 4 +++ nova_vm/src/heap/heap_gc.rs | 33 +++++++++++-------- nova_vm/src/heap/indexes.rs | 4 +-- 14 files changed, 114 insertions(+), 55 deletions(-) diff --git a/nova_vm/Cargo.toml b/nova_vm/Cargo.toml index 88abdaacb..071dea10b 100644 --- a/nova_vm/Cargo.toml +++ b/nova_vm/Cargo.toml @@ -23,7 +23,7 @@ sonic-rs = { workspace = true, optional = true } wtf8 = { workspace = true } [features] -default = ["math", "json", "date", "array-buffer"] +default = ["math", "json", "date"] math = [] json = ["sonic-rs"] date = [] diff --git a/nova_vm/src/ecmascript/builtins.rs b/nova_vm/src/ecmascript/builtins.rs index 038293666..0cfda000d 100644 --- a/nova_vm/src/ecmascript/builtins.rs +++ b/nova_vm/src/ecmascript/builtins.rs @@ -16,6 +16,7 @@ pub mod bound_function; mod builtin_constructor; mod builtin_function; pub(crate) mod control_abstraction_objects; +#[cfg(feature = "array-buffer")] pub(crate) mod data_view; #[cfg(feature = "date")] pub mod date; diff --git a/nova_vm/src/ecmascript/builtins/ordinary.rs b/nova_vm/src/ecmascript/builtins/ordinary.rs index 6e5f72de6..6abef3596 100644 --- a/nova_vm/src/ecmascript/builtins/ordinary.rs +++ b/nova_vm/src/ecmascript/builtins/ordinary.rs @@ -28,7 +28,6 @@ use crate::{ use super::date::data::DateHeapData; use super::{ control_abstraction_objects::generator_objects::GeneratorHeapData, - data_view::data::DataViewHeapData, error::ErrorHeapData, finalization_registry::data::FinalizationRegistryHeapData, indexed_collections::array_objects::array_iterator_objects::array_iterator::ArrayIteratorHeapData, @@ -48,9 +47,8 @@ use super::{ weak_set::data::WeakSetHeapData, ArrayHeapData, }; - #[cfg(feature = "array-buffer")] -use super::ArrayBufferHeapData; +use super::{data_view::data::DataViewHeapData, ArrayBufferHeapData}; impl Index for Agent { type Output = ObjectHeapData; @@ -901,6 +899,7 @@ pub(crate) fn ordinary_object_create_with_intrinsics( .heap .create(TypedArrayHeapData::default()) .into_object(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::DataView => agent.heap.create(DataViewHeapData::default()).into_object(), ProtoIntrinsics::FinalizationRegistry => agent .heap @@ -1047,6 +1046,7 @@ pub(crate) fn get_prototype_from_constructor( ProtoIntrinsics::BigInt64Array => Some(intrinsics.big_int64_array().into_function()), ProtoIntrinsics::BigUint64Array => Some(intrinsics.big_uint64_array().into_function()), ProtoIntrinsics::Boolean => Some(intrinsics.boolean().into_function()), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::DataView => Some(intrinsics.data_view().into_function()), #[cfg(feature = "date")] ProtoIntrinsics::Date => Some(intrinsics.date().into_function()), diff --git a/nova_vm/src/ecmascript/builtins/structured_data.rs b/nova_vm/src/ecmascript/builtins/structured_data.rs index 50fe679e1..65f7e8742 100644 --- a/nova_vm/src/ecmascript/builtins/structured_data.rs +++ b/nova_vm/src/ecmascript/builtins/structured_data.rs @@ -5,6 +5,7 @@ #[cfg(feature = "array-buffer")] pub(crate) mod array_buffer_objects; pub(crate) mod atomics_object; +#[cfg(feature = "array-buffer")] pub(crate) mod data_view_objects; #[cfg(feature = "json")] pub(crate) mod json_object; diff --git a/nova_vm/src/ecmascript/execution/realm.rs b/nova_vm/src/ecmascript/execution/realm.rs index 225dc7d10..d68e21f76 100644 --- a/nova_vm/src/ecmascript/execution/realm.rs +++ b/nova_vm/src/ecmascript/execution/realm.rs @@ -565,17 +565,19 @@ pub(crate) fn set_default_global_bindings( define_property_or_throw(agent, global, name, desc)?; // 19.3.8 DataView ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.DataView); - let value = agent.get_realm(realm_id).intrinsics().data_view(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; - + #[cfg(feature = "array-buffer")] + { + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.DataView); + let value = agent.get_realm(realm_id).intrinsics().data_view(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; + } #[cfg(feature = "date")] { // 19.3.9 Date ( . . . ) diff --git a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs index 754bb159e..2182459ff 100644 --- a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs +++ b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs @@ -74,10 +74,6 @@ use crate::{ reflection::{proxy_constructor::ProxyConstructor, reflect_object::ReflectObject}, structured_data::{ atomics_object::AtomicsObject, - data_view_objects::{ - data_view_constructor::DataViewConstructor, - data_view_prototype::DataViewPrototype, - }, shared_array_buffer_objects::{ shared_array_buffer_constructor::SharedArrayBufferConstructor, shared_array_buffer_prototype::SharedArrayBufferPrototype, @@ -144,12 +140,18 @@ use crate::ecmascript::builtins::numbers_and_dates::date_objects::{ }; #[cfg(feature = "math")] use crate::ecmascript::builtins::numbers_and_dates::math_object::MathObject; -#[cfg(feature = "array-buffer")] -use crate::ecmascript::builtins::structured_data::array_buffer_objects::{ - array_buffer_constructor::ArrayBufferConstructor, array_buffer_prototype::ArrayBufferPrototype, -}; #[cfg(feature = "json")] use crate::ecmascript::builtins::structured_data::json_object::JSONObject; +#[cfg(feature = "array-buffer")] +use crate::ecmascript::builtins::structured_data::{ + array_buffer_objects::{ + array_buffer_constructor::ArrayBufferConstructor, + array_buffer_prototype::ArrayBufferPrototype, + }, + data_view_objects::{ + data_view_constructor::DataViewConstructor, data_view_prototype::DataViewPrototype, + }, +}; #[derive(Debug, Clone)] pub(crate) struct Intrinsics { @@ -176,6 +178,7 @@ pub enum ProtoIntrinsics { BigInt64Array, BigUint64Array, Boolean, + #[cfg(feature = "array-buffer")] DataView, #[cfg(feature = "date")] Date, @@ -301,7 +304,9 @@ impl Intrinsics { ArrayBufferConstructor::create_intrinsic(agent, realm); SharedArrayBufferPrototype::create_intrinsic(agent, realm); SharedArrayBufferConstructor::create_intrinsic(agent, realm); + #[cfg(feature = "array-buffer")] DataViewPrototype::create_intrinsic(agent, realm); + #[cfg(feature = "array-buffer")] DataViewConstructor::create_intrinsic(agent, realm); AtomicsObject::create_intrinsic(agent, realm); #[cfg(feature = "json")] @@ -362,6 +367,7 @@ impl Intrinsics { } ProtoIntrinsics::BigInt64Array => self.big_int64_array_prototype().into(), ProtoIntrinsics::BigUint64Array => self.big_int64_array_prototype().into(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::DataView => self.data_view_prototype().into(), ProtoIntrinsics::FinalizationRegistry => self.finalization_registry_prototype().into(), ProtoIntrinsics::Float32Array => self.float32_array_prototype().into(), @@ -650,6 +656,7 @@ impl Intrinsics { } /// %DataView.prototype% + #[cfg(feature = "array-buffer")] pub(crate) fn data_view_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::DataViewPrototype .get_object_index(self.object_index_base) @@ -657,12 +664,14 @@ impl Intrinsics { } /// %DataView% + #[cfg(feature = "array-buffer")] pub(crate) fn data_view(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::DataView .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn data_view_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::DataView.get_object_index(self.object_index_base) } @@ -1000,8 +1009,8 @@ impl Intrinsics { .into() } - #[cfg(feature = "math")] /// %Math% + #[cfg(feature = "math")] pub(crate) fn math(&self) -> OrdinaryObject { IntrinsicObjectIndexes::MathObject .get_object_index(self.object_index_base) @@ -1532,7 +1541,9 @@ impl HeapMarkAndSweep for Intrinsics { self.big_uint64_array_prototype().mark_values(queues); self.boolean_prototype().mark_values(queues); self.boolean().mark_values(queues); + #[cfg(feature = "array-buffer")] self.data_view_prototype().mark_values(queues); + #[cfg(feature = "array-buffer")] self.data_view().mark_values(queues); #[cfg(feature = "date")] self.date_prototype_to_utcstring().mark_values(queues); diff --git a/nova_vm/src/ecmascript/types/language/object.rs b/nova_vm/src/ecmascript/types/language/object.rs index e868a666a..5b6403012 100644 --- a/nova_vm/src/ecmascript/types/language/object.rs +++ b/nova_vm/src/ecmascript/types/language/object.rs @@ -11,10 +11,10 @@ mod property_storage; use std::hash::Hash; -#[cfg(feature = "array-buffer")] -use super::value::ARRAY_BUFFER_DISCRIMINANT; #[cfg(feature = "date")] use super::value::DATE_DISCRIMINANT; +#[cfg(feature = "array-buffer")] +use super::value::{ARRAY_BUFFER_DISCRIMINANT, DATA_VIEW_DISCRIMINANT}; use super::{ value::{ ARGUMENTS_DISCRIMINANT, ARRAY_DISCRIMINANT, ARRAY_ITERATOR_DISCRIMINANT, @@ -23,8 +23,8 @@ use super::{ BUILTIN_CONSTRUCTOR_FUNCTION_DISCRIMINANT, BUILTIN_FUNCTION_DISCRIMINANT, BUILTIN_GENERATOR_FUNCTION_DISCRIMINANT, BUILTIN_PROMISE_COLLECTOR_FUNCTION_DISCRIMINANT, BUILTIN_PROMISE_RESOLVING_FUNCTION_DISCRIMINANT, BUILTIN_PROXY_REVOKER_FUNCTION, - DATA_VIEW_DISCRIMINANT, ECMASCRIPT_FUNCTION_DISCRIMINANT, EMBEDDER_OBJECT_DISCRIMINANT, - ERROR_DISCRIMINANT, FINALIZATION_REGISTRY_DISCRIMINANT, FLOAT_32_ARRAY_DISCRIMINANT, + ECMASCRIPT_FUNCTION_DISCRIMINANT, EMBEDDER_OBJECT_DISCRIMINANT, ERROR_DISCRIMINANT, + FINALIZATION_REGISTRY_DISCRIMINANT, FLOAT_32_ARRAY_DISCRIMINANT, FLOAT_64_ARRAY_DISCRIMINANT, GENERATOR_DISCRIMINANT, INT_16_ARRAY_DISCRIMINANT, INT_32_ARRAY_DISCRIMINANT, INT_8_ARRAY_DISCRIMINANT, ITERATOR_DISCRIMINANT, MAP_DISCRIMINANT, MAP_ITERATOR_DISCRIMINANT, MODULE_DISCRIMINANT, OBJECT_DISCRIMINANT, @@ -40,7 +40,7 @@ use super::{ #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; #[cfg(feature = "array-buffer")] -use crate::ecmascript::builtins::ArrayBuffer; +use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer}; use crate::{ ecmascript::{ builtins::{ @@ -49,7 +49,6 @@ use crate::{ generator_objects::Generator, promise_objects::promise_abstract_operations::promise_resolving_functions::BuiltinPromiseResolvingFunction, }, - data_view::DataView, embedder_object::EmbedderObject, error::Error, finalization_registry::FinalizationRegistry, @@ -110,6 +109,7 @@ pub enum Object { Array(Array) = ARRAY_DISCRIMINANT, #[cfg(feature = "array-buffer")] ArrayBuffer(ArrayBuffer) = ARRAY_BUFFER_DISCRIMINANT, + #[cfg(feature = "array-buffer")] DataView(DataView) = DATA_VIEW_DISCRIMINANT, #[cfg(feature = "date")] Date(Date) = DATE_DISCRIMINANT, @@ -168,6 +168,7 @@ impl IntoValue for Object { Object::Array(data) => Value::Array(data), #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => Value::ArrayBuffer(data), + #[cfg(feature = "array-buffer")] Object::DataView(data) => Value::DataView(data), #[cfg(feature = "date")] Object::Date(data) => Value::Date(data), @@ -346,6 +347,7 @@ impl From for Value { Object::Array(data) => Value::Array(data), #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => Value::ArrayBuffer(data), + #[cfg(feature = "array-buffer")] Object::DataView(data) => Value::DataView(data), #[cfg(feature = "date")] Object::Date(data) => Value::Date(data), @@ -418,6 +420,7 @@ impl TryFrom for Object { Value::Arguments(data) => Ok(Object::Arguments(data)), #[cfg(feature = "array-buffer")] Value::ArrayBuffer(idx) => Ok(Object::ArrayBuffer(idx)), + #[cfg(feature = "array-buffer")] Value::DataView(data) => Ok(Object::DataView(data)), Value::FinalizationRegistry(data) => Ok(Object::FinalizationRegistry(data)), Value::Map(data) => Ok(Object::Map(data)), @@ -481,6 +484,7 @@ impl Hash for Object { Object::Array(data) => data.get_index().hash(state), #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.get_index().hash(state), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.get_index().hash(state), #[cfg(feature = "date")] Object::Date(data) => data.get_index().hash(state), @@ -551,6 +555,7 @@ impl InternalSlots for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_extensible(agent), Object::Arguments(data) => data.internal_extensible(agent), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_extensible(agent), Object::FinalizationRegistry(data) => data.internal_extensible(agent), Object::Map(data) => data.internal_extensible(agent), @@ -612,6 +617,7 @@ impl InternalSlots for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_set_extensible(agent, value), Object::Arguments(data) => data.internal_set_extensible(agent, value), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_set_extensible(agent, value), Object::FinalizationRegistry(data) => data.internal_set_extensible(agent, value), Object::Map(data) => data.internal_set_extensible(agent, value), @@ -687,6 +693,7 @@ impl InternalSlots for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_prototype(agent), Object::Arguments(data) => data.internal_prototype(agent), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_prototype(agent), Object::FinalizationRegistry(data) => data.internal_prototype(agent), Object::Map(data) => data.internal_prototype(agent), @@ -750,6 +757,7 @@ impl InternalSlots for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_set_prototype(agent, prototype), Object::Arguments(data) => data.internal_set_prototype(agent, prototype), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_set_prototype(agent, prototype), Object::FinalizationRegistry(data) => data.internal_set_prototype(agent, prototype), Object::Map(data) => data.internal_set_prototype(agent, prototype), @@ -827,6 +835,7 @@ impl InternalMethods for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_get_prototype_of(agent), Object::Arguments(data) => data.internal_get_prototype_of(agent), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_get_prototype_of(agent), Object::FinalizationRegistry(data) => data.internal_get_prototype_of(agent), Object::Map(data) => data.internal_get_prototype_of(agent), @@ -908,6 +917,7 @@ impl InternalMethods for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_set_prototype_of(agent, prototype), Object::Arguments(data) => data.internal_set_prototype_of(agent, prototype), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_set_prototype_of(agent, prototype), Object::FinalizationRegistry(data) => data.internal_set_prototype_of(agent, prototype), Object::Map(data) => data.internal_set_prototype_of(agent, prototype), @@ -983,6 +993,7 @@ impl InternalMethods for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_is_extensible(agent), Object::Arguments(data) => data.internal_is_extensible(agent), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_is_extensible(agent), Object::FinalizationRegistry(data) => data.internal_is_extensible(agent), Object::Map(data) => data.internal_is_extensible(agent), @@ -1052,6 +1063,7 @@ impl InternalMethods for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_prevent_extensions(agent), Object::Arguments(data) => data.internal_prevent_extensions(agent), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_prevent_extensions(agent), Object::FinalizationRegistry(data) => data.internal_prevent_extensions(agent), Object::Map(data) => data.internal_prevent_extensions(agent), @@ -1135,6 +1147,7 @@ impl InternalMethods for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_get_own_property(agent, property_key), Object::Arguments(data) => data.internal_get_own_property(agent, property_key), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_get_own_property(agent, property_key), Object::FinalizationRegistry(data) => { data.internal_get_own_property(agent, property_key) @@ -1241,6 +1254,7 @@ impl InternalMethods for Object { Object::Arguments(data) => { data.internal_define_own_property(agent, property_key, property_descriptor) } + #[cfg(feature = "array-buffer")] Object::DataView(data) => { data.internal_define_own_property(agent, property_key, property_descriptor) } @@ -1355,6 +1369,7 @@ impl InternalMethods for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_has_property(agent, property_key), Object::Arguments(data) => data.internal_has_property(agent, property_key), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_has_property(agent, property_key), Object::FinalizationRegistry(data) => data.internal_has_property(agent, property_key), Object::Map(data) => data.internal_has_property(agent, property_key), @@ -1439,6 +1454,7 @@ impl InternalMethods for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_get(agent, property_key, receiver), Object::Arguments(data) => data.internal_get(agent, property_key, receiver), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_get(agent, property_key, receiver), Object::FinalizationRegistry(data) => data.internal_get(agent, property_key, receiver), Object::Map(data) => data.internal_get(agent, property_key, receiver), @@ -1530,6 +1546,7 @@ impl InternalMethods for Object { data.internal_set(agent, property_key, value, receiver) } Object::Arguments(data) => data.internal_set(agent, property_key, value, receiver), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_set(agent, property_key, value, receiver), Object::FinalizationRegistry(data) => { data.internal_set(agent, property_key, value, receiver) @@ -1614,6 +1631,7 @@ impl InternalMethods for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_delete(agent, property_key), Object::Arguments(data) => data.internal_delete(agent, property_key), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_delete(agent, property_key), Object::FinalizationRegistry(data) => data.internal_delete(agent, property_key), Object::Map(data) => data.internal_delete(agent, property_key), @@ -1689,6 +1707,7 @@ impl InternalMethods for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.internal_own_property_keys(agent), Object::Arguments(data) => data.internal_own_property_keys(agent), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.internal_own_property_keys(agent), Object::FinalizationRegistry(data) => data.internal_own_property_keys(agent), Object::Map(data) => data.internal_own_property_keys(agent), @@ -1803,6 +1822,7 @@ impl HeapMarkAndSweep for Object { Object::BuiltinProxyRevokerFunction => todo!(), Object::PrimitiveObject(data) => data.mark_values(queues), Object::Arguments(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.mark_values(queues), Object::FinalizationRegistry(data) => data.mark_values(queues), Object::Map(data) => data.mark_values(queues), @@ -1853,6 +1873,7 @@ impl HeapMarkAndSweep for Object { Object::Array(data) => data.sweep_values(compactions), #[cfg(feature = "array-buffer")] Object::ArrayBuffer(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::DataView(data) => data.sweep_values(compactions), #[cfg(feature = "date")] Object::Date(data) => data.sweep_values(compactions), diff --git a/nova_vm/src/ecmascript/types/language/value.rs b/nova_vm/src/ecmascript/types/language/value.rs index d738bf0d3..284c722d5 100644 --- a/nova_vm/src/ecmascript/types/language/value.rs +++ b/nova_vm/src/ecmascript/types/language/value.rs @@ -12,8 +12,7 @@ use super::{ #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; #[cfg(feature = "array-buffer")] -use crate::ecmascript::builtins::ArrayBuffer; - +use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer}; use crate::{ ecmascript::{ abstract_operations::type_conversion::{ @@ -25,7 +24,6 @@ use crate::{ generator_objects::Generator, promise_objects::promise_abstract_operations::promise_resolving_functions::BuiltinPromiseResolvingFunction, }, - data_view::DataView, embedder_object::EmbedderObject, error::Error, finalization_registry::FinalizationRegistry, @@ -149,6 +147,7 @@ pub enum Value { Array(Array), #[cfg(feature = "array-buffer")] ArrayBuffer(ArrayBuffer), + #[cfg(feature = "array-buffer")] DataView(DataView), #[cfg(feature = "date")] Date(Date), @@ -260,6 +259,7 @@ pub(crate) const PRIMITIVE_OBJECT_DISCRIMINANT: u8 = value_discriminant(Value::PrimitiveObject(PrimitiveObject::_def())); pub(crate) const ARGUMENTS_DISCRIMINANT: u8 = value_discriminant(Value::Arguments(OrdinaryObject::_def())); +#[cfg(feature = "array-buffer")] pub(crate) const DATA_VIEW_DISCRIMINANT: u8 = value_discriminant(Value::DataView(DataView::_def())); pub(crate) const FINALIZATION_REGISTRY_DISCRIMINANT: u8 = value_discriminant(Value::FinalizationRegistry(FinalizationRegistry::_def())); @@ -582,6 +582,7 @@ impl Value { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::DataView(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); @@ -786,6 +787,7 @@ impl Value { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::DataView(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); @@ -1031,6 +1033,7 @@ impl HeapMarkAndSweep for Value { Value::RegExp(data) => data.mark_values(queues), Value::PrimitiveObject(data) => data.mark_values(queues), Value::Arguments(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::DataView(data) => data.mark_values(queues), Value::FinalizationRegistry(data) => data.mark_values(queues), Value::Map(data) => data.mark_values(queues), @@ -1097,6 +1100,7 @@ impl HeapMarkAndSweep for Value { Value::RegExp(data) => data.sweep_values(compactions), Value::PrimitiveObject(data) => data.sweep_values(compactions), Value::Arguments(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::DataView(data) => data.sweep_values(compactions), Value::FinalizationRegistry(data) => data.sweep_values(compactions), Value::Map(data) => data.sweep_values(compactions), diff --git a/nova_vm/src/engine/bytecode/vm.rs b/nova_vm/src/engine/bytecode/vm.rs index 8fcffec03..5ce447ff4 100644 --- a/nova_vm/src/engine/bytecode/vm.rs +++ b/nova_vm/src/engine/bytecode/vm.rs @@ -2094,7 +2094,6 @@ fn typeof_operator(_: &mut Agent, val: Value) -> String { Value::PrimitiveObject(_) | Value::RegExp(_) | Value::Arguments(_) | - Value::DataView(_) | Value::FinalizationRegistry(_) | Value::Map(_) | Value::Promise(_) | @@ -2124,7 +2123,8 @@ fn typeof_operator(_: &mut Agent, val: Value) -> String { Value::Module(_) | Value::EmbedderObject(_) => BUILTIN_STRING_MEMORY.object, #[cfg(feature = "array-buffer")] - Value::ArrayBuffer(_) => BUILTIN_STRING_MEMORY.object, + Value::ArrayBuffer(_) | + Value::DataView(_) => BUILTIN_STRING_MEMORY.object, #[cfg(feature = "date")] Value::Date(_) => BUILTIN_STRING_MEMORY.object, // 13. If val has a [[Call]] internal slot, return "function". diff --git a/nova_vm/src/heap.rs b/nova_vm/src/heap.rs index dc0b0ac03..8d2a83008 100644 --- a/nova_vm/src/heap.rs +++ b/nova_vm/src/heap.rs @@ -39,7 +39,6 @@ use crate::ecmascript::{ promise_resolving_functions::PromiseResolvingFunctionHeapData, }, }, - data_view::data::DataViewHeapData, embedder_object::data::EmbedderObjectHeapData, error::ErrorHeapData, finalization_registry::data::FinalizationRegistryHeapData, @@ -71,7 +70,7 @@ use crate::ecmascript::{ #[cfg(feature = "date")] use crate::ecmascript::builtins::date::data::DateHeapData; #[cfg(feature = "array-buffer")] -use crate::ecmascript::builtins::ArrayBufferHeapData; +use crate::ecmascript::builtins::{data_view::data::DataViewHeapData, ArrayBufferHeapData}; use crate::ecmascript::{ builtins::ArrayHeapData, execution::{Environments, Realm, RealmIdentifier}, @@ -97,6 +96,7 @@ pub struct Heap { pub bound_functions: Vec>, pub builtin_constructors: Vec>, pub builtin_functions: Vec>, + #[cfg(feature = "array-buffer")] pub data_views: Vec>, #[cfg(feature = "date")] pub dates: Vec>, @@ -180,6 +180,7 @@ impl Heap { bound_functions: Vec::with_capacity(256), builtin_constructors: Vec::with_capacity(256), builtin_functions: Vec::with_capacity(1024), + #[cfg(feature = "array-buffer")] data_views: Vec::with_capacity(0), #[cfg(feature = "date")] dates: Vec::with_capacity(1024), diff --git a/nova_vm/src/heap/heap_bits.rs b/nova_vm/src/heap/heap_bits.rs index 58695226e..736789344 100644 --- a/nova_vm/src/heap/heap_bits.rs +++ b/nova_vm/src/heap/heap_bits.rs @@ -11,7 +11,7 @@ use super::{ #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; #[cfg(feature = "array-buffer")] -use crate::ecmascript::builtins::ArrayBuffer; +use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer}; use crate::ecmascript::{ builtins::{ bound_function::BoundFunction, @@ -23,7 +23,6 @@ use crate::ecmascript::{ promise_resolving_functions::BuiltinPromiseResolvingFunction, }, }, - data_view::DataView, embedder_object::EmbedderObject, error::Error, finalization_registry::FinalizationRegistry, @@ -67,6 +66,7 @@ pub struct HeapBits { pub bound_functions: Box<[bool]>, pub builtin_constructors: Box<[bool]>, pub builtin_functions: Box<[bool]>, + #[cfg(feature = "array-buffer")] pub data_views: Box<[bool]>, #[cfg(feature = "date")] pub dates: Box<[bool]>, @@ -123,6 +123,7 @@ pub(crate) struct WorkQueues { pub bound_functions: Vec, pub builtin_constructors: Vec, pub builtin_functions: Vec, + #[cfg(feature = "array-buffer")] pub data_views: Vec, #[cfg(feature = "date")] pub dates: Vec, @@ -179,6 +180,7 @@ impl HeapBits { let bound_functions = vec![false; heap.bound_functions.len()]; let builtin_constructors = vec![false; heap.builtin_constructors.len()]; let builtin_functions = vec![false; heap.builtin_functions.len()]; + #[cfg(feature = "array-buffer")] let data_views = vec![false; heap.data_views.len()]; #[cfg(feature = "date")] let dates = vec![false; heap.dates.len()]; @@ -232,6 +234,7 @@ impl HeapBits { bound_functions: bound_functions.into_boxed_slice(), builtin_constructors: builtin_constructors.into_boxed_slice(), builtin_functions: builtin_functions.into_boxed_slice(), + #[cfg(feature = "array-buffer")] data_views: data_views.into_boxed_slice(), #[cfg(feature = "date")] dates: dates.into_boxed_slice(), @@ -291,6 +294,7 @@ impl WorkQueues { bound_functions: Vec::with_capacity(heap.bound_functions.len() / 4), builtin_constructors: Vec::with_capacity(heap.builtin_constructors.len() / 4), builtin_functions: Vec::with_capacity(heap.builtin_functions.len() / 4), + #[cfg(feature = "array-buffer")] data_views: Vec::with_capacity(heap.data_views.len() / 4), #[cfg(feature = "date")] dates: Vec::with_capacity(heap.dates.len() / 4), @@ -373,6 +377,7 @@ impl WorkQueues { bound_functions, builtin_constructors, builtin_functions, + #[cfg(feature = "array-buffer")] data_views, #[cfg(feature = "date")] dates, @@ -421,6 +426,8 @@ impl WorkQueues { #[cfg(not(feature = "date"))] let dates: &[bool; 0] = &[]; #[cfg(not(feature = "array-buffer"))] + let data_views: &[bool; 0] = &[]; + #[cfg(not(feature = "array-buffer"))] let array_buffers: &[bool; 0] = &[]; array_buffers.is_empty() @@ -624,6 +631,7 @@ pub(crate) struct CompactionLists { pub bound_functions: CompactionList, pub builtin_constructors: CompactionList, pub builtin_functions: CompactionList, + #[cfg(feature = "array-buffer")] pub data_views: CompactionList, #[cfg(feature = "date")] pub dates: CompactionList, @@ -732,6 +740,7 @@ impl CompactionLists { strings: CompactionList::from_mark_bits(&bits.strings), shared_array_buffers: CompactionList::from_mark_bits(&bits.shared_array_buffers), symbols: CompactionList::from_mark_bits(&bits.symbols), + #[cfg(feature = "array-buffer")] data_views: CompactionList::from_mark_bits(&bits.data_views), finalization_registrys: CompactionList::from_mark_bits(&bits.finalization_registrys), proxys: CompactionList::from_mark_bits(&bits.proxys), diff --git a/nova_vm/src/heap/heap_constants.rs b/nova_vm/src/heap/heap_constants.rs index e49278a08..05f22d3d4 100644 --- a/nova_vm/src/heap/heap_constants.rs +++ b/nova_vm/src/heap/heap_constants.rs @@ -26,6 +26,7 @@ pub(crate) enum IntrinsicObjectIndexes { // Numbers and dates BigIntPrototype, + #[cfg(feature = "math")] MathObject, #[cfg(feature = "date")] DatePrototype, @@ -55,8 +56,10 @@ pub(crate) enum IntrinsicObjectIndexes { WeakSetPrototype, // Structured data + #[cfg(feature = "array-buffer")] ArrayBufferPrototype, SharedArrayBufferPrototype, + #[cfg(feature = "array-buffer")] DataViewPrototype, AtomicsObject, JSONObject, @@ -164,6 +167,7 @@ pub(crate) enum IntrinsicConstructorIndexes { // Structured data ArrayBuffer, SharedArrayBuffer, + #[cfg(feature = "array-buffer")] DataView, // Managing memory diff --git a/nova_vm/src/heap/heap_gc.rs b/nova_vm/src/heap/heap_gc.rs index a229f0015..1a178258d 100644 --- a/nova_vm/src/heap/heap_gc.rs +++ b/nova_vm/src/heap/heap_gc.rs @@ -18,7 +18,7 @@ use super::{ #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; #[cfg(feature = "array-buffer")] -use crate::ecmascript::builtins::ArrayBuffer; +use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer}; use crate::ecmascript::{ builtins::{ bound_function::BoundFunction, @@ -30,7 +30,6 @@ use crate::ecmascript::{ promise_resolving_functions::BuiltinPromiseResolvingFunction, }, }, - data_view::DataView, embedder_object::EmbedderObject, error::Error, finalization_registry::FinalizationRegistry, @@ -114,6 +113,7 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { bound_functions, builtin_constructors, builtin_functions, + #[cfg(feature = "array-buffer")] data_views, #[cfg(feature = "date")] dates, @@ -416,19 +416,22 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { builtin_functions.get(index).mark_values(&mut queues); } }); - let mut data_view_marks: Box<[DataView]> = queues.data_views.drain(..).collect(); - data_view_marks.sort(); - data_view_marks.iter().for_each(|&idx| { - let index = idx.get_index(); - if let Some(marked) = bits.data_views.get_mut(index) { - if *marked { - // Already marked, ignore - return; + #[cfg(feature = "array-buffer")] + { + let mut data_view_marks: Box<[DataView]> = queues.data_views.drain(..).collect(); + data_view_marks.sort(); + data_view_marks.iter().for_each(|&idx| { + let index = idx.get_index(); + if let Some(marked) = bits.data_views.get_mut(index) { + if *marked { + // Already marked, ignore + return; + } + *marked = true; + data_views.get(index).mark_values(&mut queues); } - *marked = true; - data_views.get(index).mark_values(&mut queues); - } - }); + }); + } #[cfg(feature = "date")] { let mut date_marks: Box<[Date]> = queues.dates.drain(..).collect(); @@ -931,6 +934,7 @@ fn sweep(heap: &mut Heap, bits: &HeapBits, root_realms: &mut [Option; pub type BoundFunctionIndex = BaseIndex; pub type BuiltinFunctionIndex = BaseIndex; pub type BuiltinConstructorIndex = BaseIndex; +#[cfg(feature = "array-buffer")] pub type DataViewIndex = BaseIndex; #[cfg(feature = "date")] pub type DateIndex = BaseIndex; From e3c6559ac4f9383fcedd541c7a5755d97e64fa15 Mon Sep 17 00:00:00 2001 From: Dean Srebnik <49134864+load1n9@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:24:13 -0400 Subject: [PATCH 3/3] feat: typedarray --- nova_vm/Cargo.toml | 2 +- nova_vm/src/ecmascript/builtins.rs | 1 + .../builtins/indexed_collections.rs | 1 + .../array_iterator_prototype.rs | 1 + nova_vm/src/ecmascript/builtins/ordinary.rs | 25 +- nova_vm/src/ecmascript/execution/realm.rs | 251 ++++++++-------- .../ecmascript/execution/realm/intrinsics.rs | 121 ++++++-- nova_vm/src/ecmascript/types/language.rs | 17 +- .../src/ecmascript/types/language/object.rs | 273 +++++++++++++++++- .../src/ecmascript/types/language/value.rs | 73 ++++- nova_vm/src/engine/bytecode/vm.rs | 22 +- nova_vm/src/heap.rs | 7 +- nova_vm/src/heap/heap_bits.rs | 14 +- nova_vm/src/heap/heap_constants.rs | 26 ++ nova_vm/src/heap/heap_gc.rs | 36 ++- nova_vm/src/heap/indexes.rs | 6 +- 16 files changed, 681 insertions(+), 195 deletions(-) diff --git a/nova_vm/Cargo.toml b/nova_vm/Cargo.toml index 071dea10b..88abdaacb 100644 --- a/nova_vm/Cargo.toml +++ b/nova_vm/Cargo.toml @@ -23,7 +23,7 @@ sonic-rs = { workspace = true, optional = true } wtf8 = { workspace = true } [features] -default = ["math", "json", "date"] +default = ["math", "json", "date", "array-buffer"] math = [] json = ["sonic-rs"] date = [] diff --git a/nova_vm/src/ecmascript/builtins.rs b/nova_vm/src/ecmascript/builtins.rs index 0cfda000d..a14169c0a 100644 --- a/nova_vm/src/ecmascript/builtins.rs +++ b/nova_vm/src/ecmascript/builtins.rs @@ -42,6 +42,7 @@ pub(crate) mod set; pub(crate) mod shared_array_buffer; pub(crate) mod structured_data; pub(crate) mod text_processing; +#[cfg(feature = "array-buffer")] pub(crate) mod typed_array; pub(crate) mod weak_map; pub(crate) mod weak_ref; diff --git a/nova_vm/src/ecmascript/builtins/indexed_collections.rs b/nova_vm/src/ecmascript/builtins/indexed_collections.rs index b1bfb63f0..f1b71d4ab 100644 --- a/nova_vm/src/ecmascript/builtins/indexed_collections.rs +++ b/nova_vm/src/ecmascript/builtins/indexed_collections.rs @@ -3,4 +3,5 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. pub(crate) mod array_objects; +#[cfg(feature = "array-buffer")] pub(crate) mod typed_array_objects; diff --git a/nova_vm/src/ecmascript/builtins/indexed_collections/array_objects/array_iterator_objects/array_iterator_prototype.rs b/nova_vm/src/ecmascript/builtins/indexed_collections/array_objects/array_iterator_objects/array_iterator_prototype.rs index 327e8f504..48311e8eb 100644 --- a/nova_vm/src/ecmascript/builtins/indexed_collections/array_objects/array_iterator_objects/array_iterator_prototype.rs +++ b/nova_vm/src/ecmascript/builtins/indexed_collections/array_objects/array_iterator_objects/array_iterator_prototype.rs @@ -53,6 +53,7 @@ impl ArrayIteratorPrototype { let len: i64 = match array { // i. If array has a [[TypedArrayName]] internal slot, then // TODO! + #[cfg(feature = "array-buffer")] Object::Int8Array(_) | Object::Uint8Array(_) | Object::Uint8ClampedArray(_) diff --git a/nova_vm/src/ecmascript/builtins/ordinary.rs b/nova_vm/src/ecmascript/builtins/ordinary.rs index 6abef3596..531e90a2c 100644 --- a/nova_vm/src/ecmascript/builtins/ordinary.rs +++ b/nova_vm/src/ecmascript/builtins/ordinary.rs @@ -41,14 +41,15 @@ use super::{ regexp::RegExpHeapData, set::data::SetHeapData, shared_array_buffer::data::SharedArrayBufferHeapData, - typed_array::data::TypedArrayHeapData, weak_map::data::WeakMapHeapData, weak_ref::data::WeakRefHeapData, weak_set::data::WeakSetHeapData, ArrayHeapData, }; #[cfg(feature = "array-buffer")] -use super::{data_view::data::DataViewHeapData, ArrayBufferHeapData}; +use super::{ + data_view::data::DataViewHeapData, typed_array::data::TypedArrayHeapData, ArrayBufferHeapData, +}; impl Index for Agent { type Output = ObjectHeapData; @@ -891,10 +892,12 @@ pub(crate) fn ordinary_object_create_with_intrinsics( .into_object(), ProtoIntrinsics::AsyncFunction => todo!(), ProtoIntrinsics::AsyncGeneratorFunction => todo!(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::BigInt64Array => agent .heap .create(TypedArrayHeapData::default()) .into_object(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::BigUint64Array => agent .heap .create(TypedArrayHeapData::default()) @@ -905,10 +908,12 @@ pub(crate) fn ordinary_object_create_with_intrinsics( .heap .create(FinalizationRegistryHeapData::default()) .into_object(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Float32Array => agent .heap .create(TypedArrayHeapData::default()) .into_object(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Float64Array => agent .heap .create(TypedArrayHeapData::default()) @@ -918,14 +923,17 @@ pub(crate) fn ordinary_object_create_with_intrinsics( .create(GeneratorHeapData::default()) .into_object(), ProtoIntrinsics::GeneratorFunction => todo!(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Int16Array => agent .heap .create(TypedArrayHeapData::default()) .into_object(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Int32Array => agent .heap .create(TypedArrayHeapData::default()) .into_object(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Int8Array => agent .heap .create(TypedArrayHeapData::default()) @@ -946,14 +954,17 @@ pub(crate) fn ordinary_object_create_with_intrinsics( .heap .create(SharedArrayBufferHeapData::default()) .into_object(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Uint16Array => agent .heap .create(TypedArrayHeapData::default()) .into_object(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Uint32Array => agent .heap .create(TypedArrayHeapData::default()) .into_object(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Uint8Array => agent .heap .create(TypedArrayHeapData::default()) @@ -1043,7 +1054,9 @@ pub(crate) fn get_prototype_from_constructor( Some(intrinsics.async_generator_function().into_function()) } ProtoIntrinsics::BigInt => Some(intrinsics.big_int().into_function()), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::BigInt64Array => Some(intrinsics.big_int64_array().into_function()), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::BigUint64Array => Some(intrinsics.big_uint64_array().into_function()), ProtoIntrinsics::Boolean => Some(intrinsics.boolean().into_function()), #[cfg(feature = "array-buffer")] @@ -1055,15 +1068,20 @@ pub(crate) fn get_prototype_from_constructor( ProtoIntrinsics::FinalizationRegistry => { Some(intrinsics.finalization_registry().into_function()) } + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Float32Array => Some(intrinsics.float32_array().into_function()), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Float64Array => Some(intrinsics.float64_array().into_function()), ProtoIntrinsics::Function => Some(intrinsics.function().into_function()), ProtoIntrinsics::Generator => None, ProtoIntrinsics::GeneratorFunction => { Some(intrinsics.generator_function().into_function()) } + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Int16Array => Some(intrinsics.int16_array().into_function()), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Int32Array => Some(intrinsics.int32_array().into_function()), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Int8Array => Some(intrinsics.int8_array().into_function()), ProtoIntrinsics::Map => Some(intrinsics.map().into_function()), ProtoIntrinsics::MapIterator => None, @@ -1082,8 +1100,11 @@ pub(crate) fn get_prototype_from_constructor( ProtoIntrinsics::Symbol => Some(intrinsics.symbol().into_function()), ProtoIntrinsics::SyntaxError => Some(intrinsics.syntax_error().into_function()), ProtoIntrinsics::TypeError => Some(intrinsics.type_error().into_function()), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Uint16Array => Some(intrinsics.uint16_array().into_function()), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Uint32Array => Some(intrinsics.uint32_array().into_function()), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Uint8Array => Some(intrinsics.uint8_array().into_function()), ProtoIntrinsics::UriError => Some(intrinsics.uri_error().into_function()), ProtoIntrinsics::WeakMap => Some(intrinsics.weak_map().into_function()), diff --git a/nova_vm/src/ecmascript/execution/realm.rs b/nova_vm/src/ecmascript/execution/realm.rs index d68e21f76..470b0f89f 100644 --- a/nova_vm/src/ecmascript/execution/realm.rs +++ b/nova_vm/src/ecmascript/execution/realm.rs @@ -529,29 +529,31 @@ pub(crate) fn set_default_global_bindings( define_property_or_throw(agent, global, name, desc)?; // 19.3.5 BigInt64Array ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.BigInt64Array); - let value = agent.get_realm(realm_id).intrinsics().big_int64_array(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; - - // 19.3.6 BigUint64Array ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.BigUint64Array); - let value = agent.get_realm(realm_id).intrinsics().big_uint64_array(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; + #[cfg(feature = "array-buffer")] + { + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.BigInt64Array); + let value = agent.get_realm(realm_id).intrinsics().big_int64_array(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; + // 19.3.6 BigUint64Array ( . . . ) + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.BigUint64Array); + let value = agent.get_realm(realm_id).intrinsics().big_uint64_array(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; + } // 19.3.7 Boolean ( . . . ) let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Boolean); let value = agent.get_realm(realm_id).intrinsics().boolean(); @@ -632,29 +634,31 @@ pub(crate) fn set_default_global_bindings( define_property_or_throw(agent, global, name, desc)?; // 19.3.13 Float32Array ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Float32Array); - let value = agent.get_realm(realm_id).intrinsics().float32_array(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; - - // 19.3.14 Float64Array ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Float64Array); - let value = agent.get_realm(realm_id).intrinsics().float64_array(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; + #[cfg(feature = "array-buffer")] + { + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Float32Array); + let value = agent.get_realm(realm_id).intrinsics().float32_array(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; + // 19.3.14 Float64Array ( . . . ) + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Float64Array); + let value = agent.get_realm(realm_id).intrinsics().float64_array(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; + } // 19.3.15 Function ( . . . ) let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Function); let value = agent.get_realm(realm_id).intrinsics().function(); @@ -666,43 +670,44 @@ pub(crate) fn set_default_global_bindings( ..Default::default() }; define_property_or_throw(agent, global, name, desc)?; - // 19.3.16 Int8Array ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Int8Array); - let value = agent.get_realm(realm_id).intrinsics().int8_array(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; - - // 19.3.17 Int16Array ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Int16Array); - let value = agent.get_realm(realm_id).intrinsics().int16_array(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; + #[cfg(feature = "array-buffer")] + { + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Int8Array); + let value = agent.get_realm(realm_id).intrinsics().int8_array(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; - // 19.3.18 Int32Array ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Int32Array); - let value = agent.get_realm(realm_id).intrinsics().int32_array(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; + // 19.3.17 Int16Array ( . . . ) + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Int16Array); + let value = agent.get_realm(realm_id).intrinsics().int16_array(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; + // 19.3.18 Int32Array ( . . . ) + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Int32Array); + let value = agent.get_realm(realm_id).intrinsics().int32_array(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; + } // 19.3.19 Map ( . . . ) let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Map); let value = agent.get_realm(realm_id).intrinsics().map(); @@ -872,53 +877,55 @@ pub(crate) fn set_default_global_bindings( define_property_or_throw(agent, global, name, desc)?; // 19.3.33 Uint8Array ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Uint8Array); - let value = agent.get_realm(realm_id).intrinsics().uint8_array(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; - - // 19.3.34 Uint8ClampedArray ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Uint8ClampedArray); - let value = agent.get_realm(realm_id).intrinsics().uint8_clamped_array(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; + #[cfg(feature = "array-buffer")] + { + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Uint8Array); + let value = agent.get_realm(realm_id).intrinsics().uint8_array(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; - // 19.3.35 Uint16Array ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Uint16Array); - let value = agent.get_realm(realm_id).intrinsics().uint16_array(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; + // 19.3.34 Uint8ClampedArray ( . . . ) + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Uint8ClampedArray); + let value = agent.get_realm(realm_id).intrinsics().uint8_clamped_array(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; - // 19.3.36 Uint32Array ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Uint32Array); - let value = agent.get_realm(realm_id).intrinsics().uint32_array(); - let desc = PropertyDescriptor { - value: Some(value.into_value()), - writable: Some(true), - enumerable: Some(false), - configurable: Some(true), - ..Default::default() - }; - define_property_or_throw(agent, global, name, desc)?; + // 19.3.35 Uint16Array ( . . . ) + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Uint16Array); + let value = agent.get_realm(realm_id).intrinsics().uint16_array(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; + // 19.3.36 Uint32Array ( . . . ) + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Uint32Array); + let value = agent.get_realm(realm_id).intrinsics().uint32_array(); + let desc = PropertyDescriptor { + value: Some(value.into_value()), + writable: Some(true), + enumerable: Some(false), + configurable: Some(true), + ..Default::default() + }; + define_property_or_throw(agent, global, name, desc)?; + } // 19.3.37 URIError ( . . . ) let name = PropertyKey::from(BUILTIN_STRING_MEMORY.URIError); let value = agent.get_realm(realm_id).intrinsics().uri_error(); diff --git a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs index 2182459ff..a26a3dba8 100644 --- a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs +++ b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs @@ -30,18 +30,10 @@ use crate::{ }, }, global_object::GlobalObject, - indexed_collections::{ - array_objects::{ - array_constructor::ArrayConstructor, - array_iterator_objects::array_iterator_prototype::ArrayIteratorPrototype, - array_prototype::ArrayPrototype, - }, - typed_array_objects::{ - typed_array_constructors::{TypedArrayConstructors, TypedArrayPrototypes}, - typed_array_intrinsic_object::{ - TypedArrayIntrinsicObject, TypedArrayPrototype, - }, - }, + indexed_collections::array_objects::{ + array_constructor::ArrayConstructor, + array_iterator_objects::array_iterator_prototype::ArrayIteratorPrototype, + array_prototype::ArrayPrototype, }, keyed_collections::{ map_objects::{ @@ -143,13 +135,19 @@ use crate::ecmascript::builtins::numbers_and_dates::math_object::MathObject; #[cfg(feature = "json")] use crate::ecmascript::builtins::structured_data::json_object::JSONObject; #[cfg(feature = "array-buffer")] -use crate::ecmascript::builtins::structured_data::{ - array_buffer_objects::{ - array_buffer_constructor::ArrayBufferConstructor, - array_buffer_prototype::ArrayBufferPrototype, +use crate::ecmascript::builtins::{ + indexed_collections::typed_array_objects::{ + typed_array_constructors::{TypedArrayConstructors, TypedArrayPrototypes}, + typed_array_intrinsic_object::{TypedArrayIntrinsicObject, TypedArrayPrototype}, }, - data_view_objects::{ - data_view_constructor::DataViewConstructor, data_view_prototype::DataViewPrototype, + structured_data::{ + array_buffer_objects::{ + array_buffer_constructor::ArrayBufferConstructor, + array_buffer_prototype::ArrayBufferPrototype, + }, + data_view_objects::{ + data_view_constructor::DataViewConstructor, data_view_prototype::DataViewPrototype, + }, }, }; @@ -175,7 +173,9 @@ pub enum ProtoIntrinsics { AsyncFunction, AsyncGeneratorFunction, BigInt, + #[cfg(feature = "array-buffer")] BigInt64Array, + #[cfg(feature = "array-buffer")] BigUint64Array, Boolean, #[cfg(feature = "array-buffer")] @@ -185,13 +185,18 @@ pub enum ProtoIntrinsics { Error, EvalError, FinalizationRegistry, + #[cfg(feature = "array-buffer")] Float32Array, + #[cfg(feature = "array-buffer")] Float64Array, Function, Generator, GeneratorFunction, + #[cfg(feature = "array-buffer")] Int16Array, + #[cfg(feature = "array-buffer")] Int32Array, + #[cfg(feature = "array-buffer")] Int8Array, Map, MapIterator, @@ -208,8 +213,11 @@ pub enum ProtoIntrinsics { Symbol, SyntaxError, TypeError, + #[cfg(feature = "array-buffer")] Uint16Array, + #[cfg(feature = "array-buffer")] Uint32Array, + #[cfg(feature = "array-buffer")] Uint8Array, UriError, WeakMap, @@ -284,9 +292,13 @@ impl Intrinsics { ArrayPrototype::create_intrinsic(agent, realm); ArrayConstructor::create_intrinsic(agent, realm); ArrayIteratorPrototype::create_intrinsic(agent, realm); + #[cfg(feature = "array-buffer")] TypedArrayPrototype::create_intrinsic(agent, realm); + #[cfg(feature = "array-buffer")] TypedArrayIntrinsicObject::create_intrinsic(agent, realm); + #[cfg(feature = "array-buffer")] TypedArrayPrototypes::create_intrinsic(agent, realm); + #[cfg(feature = "array-buffer")] TypedArrayConstructors::create_intrinsic(agent, realm); MapPrototype::create_intrinsic(agent, realm); MapConstructor::create_intrinsic(agent, realm); @@ -365,17 +377,24 @@ impl Intrinsics { ProtoIntrinsics::AsyncGeneratorFunction => { self.async_generator_function_prototype().into() } + #[cfg(feature = "array-buffer")] ProtoIntrinsics::BigInt64Array => self.big_int64_array_prototype().into(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::BigUint64Array => self.big_int64_array_prototype().into(), #[cfg(feature = "array-buffer")] ProtoIntrinsics::DataView => self.data_view_prototype().into(), ProtoIntrinsics::FinalizationRegistry => self.finalization_registry_prototype().into(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Float32Array => self.float32_array_prototype().into(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Float64Array => self.float64_array_prototype().into(), ProtoIntrinsics::Generator => self.generator_prototype().into(), ProtoIntrinsics::GeneratorFunction => self.generator_function_prototype().into(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Int16Array => self.int16_array_prototype().into(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Int32Array => self.int32_array_prototype().into(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Int8Array => self.int8_array_prototype().into(), ProtoIntrinsics::Map => self.map_prototype().into(), ProtoIntrinsics::MapIterator => self.map_iterator_prototype().into(), @@ -384,8 +403,11 @@ impl Intrinsics { ProtoIntrinsics::Set => self.set_prototype().into(), ProtoIntrinsics::SetIterator => self.set_iterator_prototype().into(), ProtoIntrinsics::SharedArrayBuffer => self.shared_array_buffer_prototype().into(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Uint16Array => self.uint16_array_prototype().into(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Uint32Array => self.uint32_array_prototype().into(), + #[cfg(feature = "array-buffer")] ProtoIntrinsics::Uint8Array => self.uint8_array_prototype().into(), ProtoIntrinsics::WeakMap => self.weak_map_prototype().into(), ProtoIntrinsics::WeakRef => self.weak_ref_prototype().into(), @@ -600,35 +622,41 @@ impl Intrinsics { } /// %BigInt64Array% + #[cfg(feature = "array-buffer")] pub(crate) fn big_int64_array_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::BigInt64ArrayPrototype .get_object_index(self.object_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn big_int64_array(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::BigInt64Array .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn big_int64_array_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::BigInt64Array.get_object_index(self.object_index_base) } /// %BigUint64Array% + #[cfg(feature = "array-buffer")] pub(crate) fn big_uint64_array_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::BigUint64ArrayPrototype .get_object_index(self.object_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn big_uint64_array(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::BigUint64Array .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn big_uint64_array_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::BigUint64Array.get_object_index(self.object_index_base) } @@ -802,35 +830,41 @@ impl Intrinsics { } /// %Float32Array% + #[cfg(feature = "array-buffer")] pub(crate) fn float32_array_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::Float32ArrayPrototype .get_object_index(self.object_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn float32_array(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::Float32Array .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn float32_array_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::Float32Array.get_object_index(self.object_index_base) } /// %Float64Array% + #[cfg(feature = "array-buffer")] pub(crate) fn float64_array_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::Float64ArrayPrototype .get_object_index(self.object_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn float64_array(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::Float64Array .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn float64_array_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::Float64Array.get_object_index(self.object_index_base) } @@ -898,52 +932,61 @@ impl Intrinsics { } /// %Int16Array% + #[cfg(feature = "array-buffer")] pub(crate) fn int16_array_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::Int16ArrayPrototype .get_object_index(self.object_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn int16_array(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::Int16Array .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn int16_array_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::Int16Array.get_object_index(self.object_index_base) } /// %Int32Array% + #[cfg(feature = "array-buffer")] pub(crate) fn int32_array_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::Int32ArrayPrototype .get_object_index(self.object_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn int32_array(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::Int32Array .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn int32_array_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::Int32Array.get_object_index(self.object_index_base) } /// %Int8Array% + #[cfg(feature = "array-buffer")] pub(crate) fn int8_array_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::Int8ArrayPrototype .get_object_index(self.object_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn int8_array(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::Int8Array .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn int8_array_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::Int8Array.get_object_index(self.object_index_base) } @@ -1319,6 +1362,7 @@ impl Intrinsics { } /// %TypedArray.prototype.values% + #[cfg(feature = "array-buffer")] pub(crate) fn typed_array_prototype_values(&self) -> BuiltinFunction { IntrinsicFunctionIndexes::TypedArrayPrototypeValues .get_builtin_function_index(self.builtin_function_index_base) @@ -1326,6 +1370,7 @@ impl Intrinsics { } /// %TypedArray.prototype% + #[cfg(feature = "array-buffer")] pub(crate) fn typed_array_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::TypedArrayPrototype .get_object_index(self.object_index_base) @@ -1333,12 +1378,14 @@ impl Intrinsics { } /// %TypedArray% + #[cfg(feature = "array-buffer")] pub(crate) fn typed_array(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::TypedArray .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn typed_array_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::TypedArray.get_object_index(self.object_index_base) } @@ -1362,69 +1409,81 @@ impl Intrinsics { } /// %Uint16Array% + #[cfg(feature = "array-buffer")] pub(crate) fn uint16_array_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::Uint16ArrayPrototype .get_object_index(self.object_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn uint16_array(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::Uint16Array .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn uint16_array_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::Uint16Array.get_object_index(self.object_index_base) } /// %Uint32Array% + #[cfg(feature = "array-buffer")] pub(crate) fn uint32_array_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::Uint32ArrayPrototype .get_object_index(self.object_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn uint32_array(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::Uint32Array .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn uint32_array_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::Uint32Array.get_object_index(self.object_index_base) } /// %Uint8Array% + #[cfg(feature = "array-buffer")] pub(crate) fn uint8_array_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::Uint8ArrayPrototype .get_object_index(self.object_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn uint8_array(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::Uint8Array .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn uint8_array_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::Uint8Array.get_object_index(self.object_index_base) } /// %Uint8ClampedArray% + #[cfg(feature = "array-buffer")] pub(crate) fn uint8_clamped_array_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::Uint8ClampedArrayPrototype .get_object_index(self.object_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn uint8_clamped_array(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::Uint8ClampedArray .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "array-buffer")] pub(crate) fn uint8_clamped_array_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::Uint8ClampedArray.get_object_index(self.object_index_base) } @@ -1535,9 +1594,13 @@ impl HeapMarkAndSweep for Intrinsics { self.atomics().mark_values(queues); self.big_int_prototype().mark_values(queues); self.big_int().mark_values(queues); + #[cfg(feature = "array-buffer")] self.big_int64_array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.big_int64_array_prototype().mark_values(queues); + #[cfg(feature = "array-buffer")] self.big_uint64_array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.big_uint64_array_prototype().mark_values(queues); self.boolean_prototype().mark_values(queues); self.boolean().mark_values(queues); @@ -1563,9 +1626,13 @@ impl HeapMarkAndSweep for Intrinsics { self.eval_error().mark_values(queues); self.finalization_registry_prototype().mark_values(queues); self.finalization_registry().mark_values(queues); + #[cfg(feature = "array-buffer")] self.float32_array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.float32_array_prototype().mark_values(queues); + #[cfg(feature = "array-buffer")] self.float64_array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.float64_array_prototype().mark_values(queues); self.function_prototype().mark_values(queues); self.function().mark_values(queues); @@ -1574,11 +1641,17 @@ impl HeapMarkAndSweep for Intrinsics { self.generator_function_prototype().mark_values(queues); self.generator_function().mark_values(queues); self.generator_prototype().mark_values(queues); + #[cfg(feature = "array-buffer")] self.int16_array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.int16_array_prototype().mark_values(queues); + #[cfg(feature = "array-buffer")] self.int32_array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.int32_array_prototype().mark_values(queues); + #[cfg(feature = "array-buffer")] self.int8_array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.int8_array_prototype().mark_values(queues); self.is_finite().mark_values(queues); self.is_nan().mark_values(queues); @@ -1626,20 +1699,32 @@ impl HeapMarkAndSweep for Intrinsics { self.syntax_error_prototype().mark_values(queues); self.syntax_error().mark_values(queues); self.throw_type_error().mark_values(queues); + #[cfg(feature = "array-buffer")] self.typed_array_prototype_values().mark_values(queues); + #[cfg(feature = "array-buffer")] self.typed_array_prototype().mark_values(queues); + #[cfg(feature = "array-buffer")] self.typed_array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.typed_array_prototype().mark_values(queues); self.type_error_prototype().mark_values(queues); self.type_error().mark_values(queues); self.type_error_prototype().mark_values(queues); + #[cfg(feature = "array-buffer")] self.uint16_array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.uint16_array_prototype().mark_values(queues); + #[cfg(feature = "array-buffer")] self.uint32_array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.uint32_array_prototype().mark_values(queues); + #[cfg(feature = "array-buffer")] self.uint8_array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.uint8_array_prototype().mark_values(queues); + #[cfg(feature = "array-buffer")] self.uint8_clamped_array().mark_values(queues); + #[cfg(feature = "array-buffer")] self.uint8_clamped_array_prototype().mark_values(queues); self.unescape().mark_values(queues); self.uri_error_prototype().mark_values(queues); diff --git a/nova_vm/src/ecmascript/types/language.rs b/nova_vm/src/ecmascript/types/language.rs index f521f285f..c2b2c0b96 100644 --- a/nova_vm/src/ecmascript/types/language.rs +++ b/nova_vm/src/ecmascript/types/language.rs @@ -39,12 +39,15 @@ pub use primitive::Primitive; pub use string::{HeapString, String, StringHeapData, BUILTIN_STRINGS_LIST, BUILTIN_STRING_MEMORY}; pub use symbol::{Symbol, SymbolHeapData}; pub use value::Value; +#[cfg(feature = "array-buffer")] pub(crate) use value::{ - BIGINT_64_ARRAY_DISCRIMINANT, BIGINT_DISCRIMINANT, BIGUINT_64_ARRAY_DISCRIMINANT, - BOOLEAN_DISCRIMINANT, FLOAT_32_ARRAY_DISCRIMINANT, FLOAT_64_ARRAY_DISCRIMINANT, - FLOAT_DISCRIMINANT, INTEGER_DISCRIMINANT, INT_16_ARRAY_DISCRIMINANT, INT_32_ARRAY_DISCRIMINANT, - INT_8_ARRAY_DISCRIMINANT, NUMBER_DISCRIMINANT, SMALL_BIGINT_DISCRIMINANT, - SMALL_STRING_DISCRIMINANT, STRING_DISCRIMINANT, SYMBOL_DISCRIMINANT, - UINT_16_ARRAY_DISCRIMINANT, UINT_32_ARRAY_DISCRIMINANT, UINT_8_ARRAY_DISCRIMINANT, - UINT_8_CLAMPED_ARRAY_DISCRIMINANT, + BIGINT_64_ARRAY_DISCRIMINANT, BIGUINT_64_ARRAY_DISCRIMINANT, FLOAT_32_ARRAY_DISCRIMINANT, + FLOAT_64_ARRAY_DISCRIMINANT, INT_16_ARRAY_DISCRIMINANT, INT_32_ARRAY_DISCRIMINANT, + INT_8_ARRAY_DISCRIMINANT, UINT_16_ARRAY_DISCRIMINANT, UINT_32_ARRAY_DISCRIMINANT, + UINT_8_ARRAY_DISCRIMINANT, UINT_8_CLAMPED_ARRAY_DISCRIMINANT, +}; +pub(crate) use value::{ + BIGINT_DISCRIMINANT, BOOLEAN_DISCRIMINANT, FLOAT_DISCRIMINANT, INTEGER_DISCRIMINANT, + NUMBER_DISCRIMINANT, SMALL_BIGINT_DISCRIMINANT, SMALL_STRING_DISCRIMINANT, STRING_DISCRIMINANT, + SYMBOL_DISCRIMINANT, }; diff --git a/nova_vm/src/ecmascript/types/language/object.rs b/nova_vm/src/ecmascript/types/language/object.rs index 5b6403012..05c916344 100644 --- a/nova_vm/src/ecmascript/types/language/object.rs +++ b/nova_vm/src/ecmascript/types/language/object.rs @@ -14,25 +14,28 @@ use std::hash::Hash; #[cfg(feature = "date")] use super::value::DATE_DISCRIMINANT; #[cfg(feature = "array-buffer")] -use super::value::{ARRAY_BUFFER_DISCRIMINANT, DATA_VIEW_DISCRIMINANT}; +use super::value::{ + ARRAY_BUFFER_DISCRIMINANT, BIGINT_64_ARRAY_DISCRIMINANT, BIGUINT_64_ARRAY_DISCRIMINANT, + DATA_VIEW_DISCRIMINANT, FLOAT_32_ARRAY_DISCRIMINANT, FLOAT_64_ARRAY_DISCRIMINANT, + INT_16_ARRAY_DISCRIMINANT, INT_32_ARRAY_DISCRIMINANT, INT_8_ARRAY_DISCRIMINANT, + UINT_16_ARRAY_DISCRIMINANT, UINT_32_ARRAY_DISCRIMINANT, UINT_8_ARRAY_DISCRIMINANT, + UINT_8_CLAMPED_ARRAY_DISCRIMINANT, +}; use super::{ value::{ ARGUMENTS_DISCRIMINANT, ARRAY_DISCRIMINANT, ARRAY_ITERATOR_DISCRIMINANT, ASYNC_FROM_SYNC_ITERATOR_DISCRIMINANT, ASYNC_ITERATOR_DISCRIMINANT, - BIGINT_64_ARRAY_DISCRIMINANT, BIGUINT_64_ARRAY_DISCRIMINANT, BOUND_FUNCTION_DISCRIMINANT, - BUILTIN_CONSTRUCTOR_FUNCTION_DISCRIMINANT, BUILTIN_FUNCTION_DISCRIMINANT, - BUILTIN_GENERATOR_FUNCTION_DISCRIMINANT, BUILTIN_PROMISE_COLLECTOR_FUNCTION_DISCRIMINANT, + BOUND_FUNCTION_DISCRIMINANT, BUILTIN_CONSTRUCTOR_FUNCTION_DISCRIMINANT, + BUILTIN_FUNCTION_DISCRIMINANT, BUILTIN_GENERATOR_FUNCTION_DISCRIMINANT, + BUILTIN_PROMISE_COLLECTOR_FUNCTION_DISCRIMINANT, BUILTIN_PROMISE_RESOLVING_FUNCTION_DISCRIMINANT, BUILTIN_PROXY_REVOKER_FUNCTION, ECMASCRIPT_FUNCTION_DISCRIMINANT, EMBEDDER_OBJECT_DISCRIMINANT, ERROR_DISCRIMINANT, - FINALIZATION_REGISTRY_DISCRIMINANT, FLOAT_32_ARRAY_DISCRIMINANT, - FLOAT_64_ARRAY_DISCRIMINANT, GENERATOR_DISCRIMINANT, INT_16_ARRAY_DISCRIMINANT, - INT_32_ARRAY_DISCRIMINANT, INT_8_ARRAY_DISCRIMINANT, ITERATOR_DISCRIMINANT, + FINALIZATION_REGISTRY_DISCRIMINANT, GENERATOR_DISCRIMINANT, ITERATOR_DISCRIMINANT, MAP_DISCRIMINANT, MAP_ITERATOR_DISCRIMINANT, MODULE_DISCRIMINANT, OBJECT_DISCRIMINANT, PRIMITIVE_OBJECT_DISCRIMINANT, PROMISE_DISCRIMINANT, PROXY_DISCRIMINANT, REGEXP_DISCRIMINANT, SET_DISCRIMINANT, SET_ITERATOR_DISCRIMINANT, - SHARED_ARRAY_BUFFER_DISCRIMINANT, UINT_16_ARRAY_DISCRIMINANT, UINT_32_ARRAY_DISCRIMINANT, - UINT_8_ARRAY_DISCRIMINANT, UINT_8_CLAMPED_ARRAY_DISCRIMINANT, WEAK_MAP_DISCRIMINANT, - WEAK_REF_DISCRIMINANT, WEAK_SET_DISCRIMINANT, + SHARED_ARRAY_BUFFER_DISCRIMINANT, WEAK_MAP_DISCRIMINANT, WEAK_REF_DISCRIMINANT, + WEAK_SET_DISCRIMINANT, }, Function, IntoValue, Value, }; @@ -40,7 +43,10 @@ use super::{ #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; #[cfg(feature = "array-buffer")] -use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer}; +use crate::{ + ecmascript::builtins::{data_view::DataView, typed_array::TypedArray, ArrayBuffer}, + heap::indexes::TypedArrayIndex, +}; use crate::{ ecmascript::{ builtins::{ @@ -65,7 +71,6 @@ use crate::{ regexp::RegExp, set::Set, shared_array_buffer::SharedArrayBuffer, - typed_array::TypedArray, weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, @@ -75,7 +80,7 @@ use crate::{ types::PropertyDescriptor, }, heap::{ - indexes::{ArrayIndex, ObjectIndex, TypedArrayIndex}, + indexes::{ArrayIndex, ObjectIndex}, CompactionLists, CreateHeapData, Heap, HeapMarkAndSweep, WorkQueues, }, }; @@ -124,16 +129,27 @@ pub enum Object { WeakMap(WeakMap) = WEAK_MAP_DISCRIMINANT, WeakRef(WeakRef) = WEAK_REF_DISCRIMINANT, WeakSet(WeakSet) = WEAK_SET_DISCRIMINANT, + #[cfg(feature = "array-buffer")] Int8Array(TypedArrayIndex) = INT_8_ARRAY_DISCRIMINANT, + #[cfg(feature = "array-buffer")] Uint8Array(TypedArrayIndex) = UINT_8_ARRAY_DISCRIMINANT, + #[cfg(feature = "array-buffer")] Uint8ClampedArray(TypedArrayIndex) = UINT_8_CLAMPED_ARRAY_DISCRIMINANT, + #[cfg(feature = "array-buffer")] Int16Array(TypedArrayIndex) = INT_16_ARRAY_DISCRIMINANT, + #[cfg(feature = "array-buffer")] Uint16Array(TypedArrayIndex) = UINT_16_ARRAY_DISCRIMINANT, + #[cfg(feature = "array-buffer")] Int32Array(TypedArrayIndex) = INT_32_ARRAY_DISCRIMINANT, + #[cfg(feature = "array-buffer")] Uint32Array(TypedArrayIndex) = UINT_32_ARRAY_DISCRIMINANT, + #[cfg(feature = "array-buffer")] BigInt64Array(TypedArrayIndex) = BIGINT_64_ARRAY_DISCRIMINANT, + #[cfg(feature = "array-buffer")] BigUint64Array(TypedArrayIndex) = BIGUINT_64_ARRAY_DISCRIMINANT, + #[cfg(feature = "array-buffer")] Float32Array(TypedArrayIndex) = FLOAT_32_ARRAY_DISCRIMINANT, + #[cfg(feature = "array-buffer")] Float64Array(TypedArrayIndex) = FLOAT_64_ARRAY_DISCRIMINANT, AsyncFromSyncIterator = ASYNC_FROM_SYNC_ITERATOR_DISCRIMINANT, AsyncIterator = ASYNC_ITERATOR_DISCRIMINANT, @@ -183,16 +199,27 @@ impl IntoValue for Object { Object::WeakMap(data) => Value::WeakMap(data), Object::WeakRef(data) => Value::WeakRef(data), Object::WeakSet(data) => Value::WeakSet(data), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => Value::Int8Array(data), + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => Value::Uint8Array(data), + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => Value::Uint8ClampedArray(data), + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => Value::Int16Array(data), + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => Value::Uint16Array(data), + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => Value::Int32Array(data), + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => Value::Uint32Array(data), + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => Value::BigInt64Array(data), + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => Value::BigUint64Array(data), + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => Value::Float32Array(data), + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => Value::Float64Array(data), Object::AsyncFromSyncIterator => todo!(), Object::AsyncIterator => todo!(), @@ -362,16 +389,27 @@ impl From for Value { Object::WeakMap(data) => Value::WeakMap(data), Object::WeakRef(data) => Value::WeakRef(data), Object::WeakSet(data) => Value::WeakSet(data), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => Value::Int8Array(data), + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => Value::Uint8Array(data), + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => Value::Uint8ClampedArray(data), + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => Value::Int16Array(data), + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => Value::Uint16Array(data), + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => Value::Int32Array(data), + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => Value::Uint32Array(data), + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => Value::BigInt64Array(data), + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => Value::BigUint64Array(data), + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => Value::Float32Array(data), + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => Value::Float64Array(data), Object::AsyncFromSyncIterator => Value::AsyncFromSyncIterator, Object::AsyncIterator => Value::AsyncIterator, @@ -432,16 +470,27 @@ impl TryFrom for Object { Value::WeakMap(data) => Ok(Object::WeakMap(data)), Value::WeakRef(data) => Ok(Object::WeakRef(data)), Value::WeakSet(data) => Ok(Object::WeakSet(data)), + #[cfg(feature = "array-buffer")] Value::Int8Array(data) => Ok(Object::Int8Array(data)), + #[cfg(feature = "array-buffer")] Value::Uint8Array(data) => Ok(Object::Uint8Array(data)), + #[cfg(feature = "array-buffer")] Value::Uint8ClampedArray(data) => Ok(Object::Uint8ClampedArray(data)), + #[cfg(feature = "array-buffer")] Value::Int16Array(data) => Ok(Object::Int16Array(data)), + #[cfg(feature = "array-buffer")] Value::Uint16Array(data) => Ok(Object::Uint16Array(data)), + #[cfg(feature = "array-buffer")] Value::Int32Array(data) => Ok(Object::Int32Array(data)), + #[cfg(feature = "array-buffer")] Value::Uint32Array(data) => Ok(Object::Uint32Array(data)), + #[cfg(feature = "array-buffer")] Value::BigInt64Array(data) => Ok(Object::BigInt64Array(data)), + #[cfg(feature = "array-buffer")] Value::BigUint64Array(data) => Ok(Object::BigUint64Array(data)), + #[cfg(feature = "array-buffer")] Value::Float32Array(data) => Ok(Object::Float32Array(data)), + #[cfg(feature = "array-buffer")] Value::Float64Array(data) => Ok(Object::Float64Array(data)), Value::AsyncFromSyncIterator => Ok(Object::AsyncFromSyncIterator), Value::AsyncIterator => Ok(Object::AsyncIterator), @@ -499,16 +548,27 @@ impl Hash for Object { Object::WeakMap(data) => data.get_index().hash(state), Object::WeakRef(data) => data.get_index().hash(state), Object::WeakSet(data) => data.get_index().hash(state), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => data.into_index().hash(state), + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => data.into_index().hash(state), + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => data.into_index().hash(state), + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => data.into_index().hash(state), + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => data.into_index().hash(state), + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => data.into_index().hash(state), + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => data.into_index().hash(state), + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => data.into_index().hash(state), + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => data.into_index().hash(state), + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => data.into_index().hash(state), + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => data.into_index().hash(state), Object::AsyncFromSyncIterator => {} Object::AsyncIterator => {} @@ -567,22 +627,33 @@ impl InternalSlots for Object { Object::WeakMap(data) => data.internal_extensible(agent), Object::WeakRef(data) => data.internal_extensible(agent), Object::WeakSet(data) => data.internal_extensible(agent), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => TypedArray::Int8Array(data).internal_extensible(agent), + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => TypedArray::Uint8Array(data).internal_extensible(agent), + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_extensible(agent) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => TypedArray::Int16Array(data).internal_extensible(agent), + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => TypedArray::Uint16Array(data).internal_extensible(agent), + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => TypedArray::Int32Array(data).internal_extensible(agent), + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => TypedArray::Uint32Array(data).internal_extensible(agent), + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_extensible(agent) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_extensible(agent) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => TypedArray::Float32Array(data).internal_extensible(agent), + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => TypedArray::Float64Array(data).internal_extensible(agent), Object::AsyncFromSyncIterator => todo!(), Object::AsyncIterator => todo!(), @@ -629,36 +700,47 @@ impl InternalSlots for Object { Object::WeakMap(data) => data.internal_set_extensible(agent, value), Object::WeakRef(data) => data.internal_set_extensible(agent, value), Object::WeakSet(data) => data.internal_set_extensible(agent, value), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { TypedArray::Int8Array(data).internal_set_extensible(agent, value) } + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => { TypedArray::Uint8Array(data).internal_set_extensible(agent, value) } + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_set_extensible(agent, value) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => { TypedArray::Int16Array(data).internal_set_extensible(agent, value) } + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => { TypedArray::Uint16Array(data).internal_set_extensible(agent, value) } + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => { TypedArray::Int32Array(data).internal_set_extensible(agent, value) } + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => { TypedArray::Uint32Array(data).internal_set_extensible(agent, value) } + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_set_extensible(agent, value) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_set_extensible(agent, value) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => { TypedArray::Float32Array(data).internal_set_extensible(agent, value) } + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => { TypedArray::Float64Array(data).internal_set_extensible(agent, value) } @@ -705,22 +787,33 @@ impl InternalSlots for Object { Object::WeakMap(data) => data.internal_prototype(agent), Object::WeakRef(data) => data.internal_prototype(agent), Object::WeakSet(data) => data.internal_prototype(agent), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => TypedArray::Int8Array(data).internal_prototype(agent), + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => TypedArray::Uint8Array(data).internal_prototype(agent), + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_prototype(agent) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => TypedArray::Int16Array(data).internal_prototype(agent), + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => TypedArray::Uint16Array(data).internal_prototype(agent), + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => TypedArray::Int32Array(data).internal_prototype(agent), + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => TypedArray::Uint32Array(data).internal_prototype(agent), + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_prototype(agent) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_prototype(agent) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => TypedArray::Float32Array(data).internal_prototype(agent), + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => TypedArray::Float64Array(data).internal_prototype(agent), Object::AsyncFromSyncIterator => todo!(), Object::AsyncIterator => todo!(), @@ -769,36 +862,47 @@ impl InternalSlots for Object { Object::WeakMap(data) => data.internal_set_prototype(agent, prototype), Object::WeakRef(data) => data.internal_set_prototype(agent, prototype), Object::WeakSet(data) => data.internal_set_prototype(agent, prototype), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { TypedArray::Int8Array(data).internal_set_prototype(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => { TypedArray::Uint8Array(data).internal_set_prototype(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_set_prototype(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => { TypedArray::Int16Array(data).internal_set_prototype(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => { TypedArray::Uint16Array(data).internal_set_prototype(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => { TypedArray::Int32Array(data).internal_set_prototype(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => { TypedArray::Uint32Array(data).internal_set_prototype(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_set_prototype(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_set_prototype(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => { TypedArray::Float32Array(data).internal_set_prototype(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => { TypedArray::Float64Array(data).internal_set_prototype(agent, prototype) } @@ -847,34 +951,45 @@ impl InternalMethods for Object { Object::WeakMap(data) => data.internal_get_prototype_of(agent), Object::WeakRef(data) => data.internal_get_prototype_of(agent), Object::WeakSet(data) => data.internal_get_prototype_of(agent), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => TypedArray::Int8Array(data).internal_get_prototype_of(agent), + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => { TypedArray::Uint8Array(data).internal_get_prototype_of(agent) } + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_get_prototype_of(agent) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => { TypedArray::Int16Array(data).internal_get_prototype_of(agent) } + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => { TypedArray::Uint16Array(data).internal_get_prototype_of(agent) } + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => { TypedArray::Int32Array(data).internal_get_prototype_of(agent) } + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => { TypedArray::Uint32Array(data).internal_get_prototype_of(agent) } + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_get_prototype_of(agent) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_get_prototype_of(agent) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => { TypedArray::Float32Array(data).internal_get_prototype_of(agent) } + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => { TypedArray::Float64Array(data).internal_get_prototype_of(agent) } @@ -929,36 +1044,47 @@ impl InternalMethods for Object { Object::WeakMap(data) => data.internal_set_prototype_of(agent, prototype), Object::WeakRef(data) => data.internal_set_prototype_of(agent, prototype), Object::WeakSet(data) => data.internal_set_prototype_of(agent, prototype), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { TypedArray::Int8Array(data).internal_set_prototype_of(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => { TypedArray::Uint8Array(data).internal_set_prototype_of(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_set_prototype_of(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => { TypedArray::Int16Array(data).internal_set_prototype_of(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => { TypedArray::Uint16Array(data).internal_set_prototype_of(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => { TypedArray::Int32Array(data).internal_set_prototype_of(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => { TypedArray::Uint32Array(data).internal_set_prototype_of(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_set_prototype_of(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_set_prototype_of(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => { TypedArray::Float32Array(data).internal_set_prototype_of(agent, prototype) } + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => { TypedArray::Float64Array(data).internal_set_prototype_of(agent, prototype) } @@ -1005,28 +1131,39 @@ impl InternalMethods for Object { Object::WeakMap(data) => data.internal_is_extensible(agent), Object::WeakRef(data) => data.internal_is_extensible(agent), Object::WeakSet(data) => data.internal_is_extensible(agent), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => TypedArray::Int8Array(data).internal_is_extensible(agent), + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => TypedArray::Uint8Array(data).internal_is_extensible(agent), + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_is_extensible(agent) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => TypedArray::Int16Array(data).internal_is_extensible(agent), + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => { TypedArray::Uint16Array(data).internal_is_extensible(agent) } + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => TypedArray::Int32Array(data).internal_is_extensible(agent), + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => { TypedArray::Uint32Array(data).internal_is_extensible(agent) } + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_is_extensible(agent) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_is_extensible(agent) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => { TypedArray::Float32Array(data).internal_is_extensible(agent) } + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => { TypedArray::Float64Array(data).internal_is_extensible(agent) } @@ -1075,36 +1212,47 @@ impl InternalMethods for Object { Object::WeakMap(data) => data.internal_prevent_extensions(agent), Object::WeakRef(data) => data.internal_prevent_extensions(agent), Object::WeakSet(data) => data.internal_prevent_extensions(agent), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { TypedArray::Int8Array(data).internal_prevent_extensions(agent) } + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => { TypedArray::Uint8Array(data).internal_prevent_extensions(agent) } + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_prevent_extensions(agent) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => { TypedArray::Int16Array(data).internal_prevent_extensions(agent) } + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => { TypedArray::Uint16Array(data).internal_prevent_extensions(agent) } + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => { TypedArray::Int32Array(data).internal_prevent_extensions(agent) } + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => { TypedArray::Uint32Array(data).internal_prevent_extensions(agent) } + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_prevent_extensions(agent) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_prevent_extensions(agent) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => { TypedArray::Float32Array(data).internal_prevent_extensions(agent) } + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => { TypedArray::Float64Array(data).internal_prevent_extensions(agent) } @@ -1161,36 +1309,47 @@ impl InternalMethods for Object { Object::WeakMap(data) => data.internal_get_own_property(agent, property_key), Object::WeakRef(data) => data.internal_get_own_property(agent, property_key), Object::WeakSet(data) => data.internal_get_own_property(agent, property_key), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { TypedArray::Int8Array(data).internal_get_own_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => { TypedArray::Uint8Array(data).internal_get_own_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_get_own_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => { TypedArray::Int16Array(data).internal_get_own_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => { TypedArray::Uint16Array(data).internal_get_own_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => { TypedArray::Int32Array(data).internal_get_own_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => { TypedArray::Uint32Array(data).internal_get_own_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_get_own_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_get_own_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => { TypedArray::Float32Array(data).internal_get_own_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => { TypedArray::Float64Array(data).internal_get_own_property(agent, property_key) } @@ -1288,38 +1447,49 @@ impl InternalMethods for Object { Object::WeakSet(data) => { data.internal_define_own_property(agent, property_key, property_descriptor) } + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => TypedArray::Int8Array(data).internal_define_own_property( agent, property_key, property_descriptor, ), + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => TypedArray::Uint8Array(data).internal_define_own_property( agent, property_key, property_descriptor, ), + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => TypedArray::Uint8ClampedArray(data) .internal_define_own_property(agent, property_key, property_descriptor), + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => TypedArray::Int16Array(data).internal_define_own_property( agent, property_key, property_descriptor, ), + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => TypedArray::Uint16Array(data) .internal_define_own_property(agent, property_key, property_descriptor), + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => TypedArray::Int32Array(data).internal_define_own_property( agent, property_key, property_descriptor, ), + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => TypedArray::Uint32Array(data) .internal_define_own_property(agent, property_key, property_descriptor), + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => TypedArray::BigInt64Array(data) .internal_define_own_property(agent, property_key, property_descriptor), + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => TypedArray::BigUint64Array(data) .internal_define_own_property(agent, property_key, property_descriptor), + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => TypedArray::Float32Array(data) .internal_define_own_property(agent, property_key, property_descriptor), + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => TypedArray::Float64Array(data) .internal_define_own_property(agent, property_key, property_descriptor), Object::AsyncFromSyncIterator => todo!(), @@ -1381,36 +1551,47 @@ impl InternalMethods for Object { Object::WeakMap(data) => data.internal_has_property(agent, property_key), Object::WeakRef(data) => data.internal_has_property(agent, property_key), Object::WeakSet(data) => data.internal_has_property(agent, property_key), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { TypedArray::Int8Array(data).internal_has_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => { TypedArray::Uint8Array(data).internal_has_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_has_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => { TypedArray::Int16Array(data).internal_has_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => { TypedArray::Uint16Array(data).internal_has_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => { TypedArray::Int32Array(data).internal_has_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => { TypedArray::Uint32Array(data).internal_has_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_has_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_has_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => { TypedArray::Float32Array(data).internal_has_property(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => { TypedArray::Float64Array(data).internal_has_property(agent, property_key) } @@ -1466,36 +1647,47 @@ impl InternalMethods for Object { Object::WeakMap(data) => data.internal_get(agent, property_key, receiver), Object::WeakRef(data) => data.internal_get(agent, property_key, receiver), Object::WeakSet(data) => data.internal_get(agent, property_key, receiver), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { TypedArray::Int8Array(data).internal_get(agent, property_key, receiver) } + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => { TypedArray::Uint8Array(data).internal_get(agent, property_key, receiver) } + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_get(agent, property_key, receiver) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => { TypedArray::Int16Array(data).internal_get(agent, property_key, receiver) } + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => { TypedArray::Uint16Array(data).internal_get(agent, property_key, receiver) } + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => { TypedArray::Int32Array(data).internal_get(agent, property_key, receiver) } + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => { TypedArray::Uint32Array(data).internal_get(agent, property_key, receiver) } + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_get(agent, property_key, receiver) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_get(agent, property_key, receiver) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => { TypedArray::Float32Array(data).internal_get(agent, property_key, receiver) } + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => { TypedArray::Float64Array(data).internal_get(agent, property_key, receiver) } @@ -1562,39 +1754,50 @@ impl InternalMethods for Object { Object::WeakMap(data) => data.internal_set(agent, property_key, value, receiver), Object::WeakRef(data) => data.internal_set(agent, property_key, value, receiver), Object::WeakSet(data) => data.internal_set(agent, property_key, value, receiver), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { TypedArray::Int8Array(data).internal_set(agent, property_key, value, receiver) } + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => { TypedArray::Uint8Array(data).internal_set(agent, property_key, value, receiver) } + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => TypedArray::Uint8ClampedArray(data).internal_set( agent, property_key, value, receiver, ), + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => { TypedArray::Int16Array(data).internal_set(agent, property_key, value, receiver) } + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => { TypedArray::Uint16Array(data).internal_set(agent, property_key, value, receiver) } + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => { TypedArray::Int32Array(data).internal_set(agent, property_key, value, receiver) } + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => { TypedArray::Uint32Array(data).internal_set(agent, property_key, value, receiver) } + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_set(agent, property_key, value, receiver) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_set(agent, property_key, value, receiver) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => { TypedArray::Float32Array(data).internal_set(agent, property_key, value, receiver) } + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => { TypedArray::Float64Array(data).internal_set(agent, property_key, value, receiver) } @@ -1643,36 +1846,47 @@ impl InternalMethods for Object { Object::WeakMap(data) => data.internal_delete(agent, property_key), Object::WeakRef(data) => data.internal_delete(agent, property_key), Object::WeakSet(data) => data.internal_delete(agent, property_key), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { TypedArray::Int8Array(data).internal_delete(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => { TypedArray::Uint8Array(data).internal_delete(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_delete(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => { TypedArray::Int16Array(data).internal_delete(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => { TypedArray::Uint16Array(data).internal_delete(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => { TypedArray::Int32Array(data).internal_delete(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => { TypedArray::Uint32Array(data).internal_delete(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_delete(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_delete(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => { TypedArray::Float32Array(data).internal_delete(agent, property_key) } + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => { TypedArray::Float64Array(data).internal_delete(agent, property_key) } @@ -1719,36 +1933,47 @@ impl InternalMethods for Object { Object::WeakMap(data) => data.internal_own_property_keys(agent), Object::WeakRef(data) => data.internal_own_property_keys(agent), Object::WeakSet(data) => data.internal_own_property_keys(agent), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { TypedArray::Int8Array(data).internal_own_property_keys(agent) } + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => { TypedArray::Uint8Array(data).internal_own_property_keys(agent) } + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => { TypedArray::Uint8ClampedArray(data).internal_own_property_keys(agent) } + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => { TypedArray::Int16Array(data).internal_own_property_keys(agent) } + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => { TypedArray::Uint16Array(data).internal_own_property_keys(agent) } + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => { TypedArray::Int32Array(data).internal_own_property_keys(agent) } + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => { TypedArray::Uint32Array(data).internal_own_property_keys(agent) } + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => { TypedArray::BigInt64Array(data).internal_own_property_keys(agent) } + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => { TypedArray::BigUint64Array(data).internal_own_property_keys(agent) } + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => { TypedArray::Float32Array(data).internal_own_property_keys(agent) } + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => { TypedArray::Float64Array(data).internal_own_property_keys(agent) } @@ -1834,16 +2059,27 @@ impl HeapMarkAndSweep for Object { Object::WeakMap(data) => data.mark_values(queues), Object::WeakRef(data) => data.mark_values(queues), Object::WeakSet(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => data.mark_values(queues), Object::AsyncFromSyncIterator => todo!(), Object::AsyncIterator => todo!(), @@ -1888,16 +2124,27 @@ impl HeapMarkAndSweep for Object { Object::WeakMap(data) => data.sweep_values(compactions), Object::WeakRef(data) => data.sweep_values(compactions), Object::WeakSet(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::Int8Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::Uint8Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::Uint8ClampedArray(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::Int16Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::Uint16Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::Int32Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::Uint32Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::BigInt64Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::BigUint64Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::Float32Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Object::Float64Array(data) => data.sweep_values(compactions), Object::AsyncFromSyncIterator => todo!(), Object::AsyncIterator => todo!(), diff --git a/nova_vm/src/ecmascript/types/language/value.rs b/nova_vm/src/ecmascript/types/language/value.rs index 284c722d5..b888ea0cb 100644 --- a/nova_vm/src/ecmascript/types/language/value.rs +++ b/nova_vm/src/ecmascript/types/language/value.rs @@ -12,7 +12,10 @@ use super::{ #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; #[cfg(feature = "array-buffer")] -use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer}; +use crate::{ + ecmascript::builtins::{data_view::DataView, ArrayBuffer}, + heap::indexes::TypedArrayIndex, +}; use crate::{ ecmascript::{ abstract_operations::type_conversion::{ @@ -49,7 +52,7 @@ use crate::{ types::BUILTIN_STRING_MEMORY, }, engine::small_f64::SmallF64, - heap::{indexes::TypedArrayIndex, CompactionLists, HeapMarkAndSweep, WorkQueues}, + heap::{CompactionLists, HeapMarkAndSweep, WorkQueues}, SmallInteger, SmallString, }; @@ -164,16 +167,27 @@ pub enum Value { WeakSet(WeakSet), // TypedArrays + #[cfg(feature = "array-buffer")] Int8Array(TypedArrayIndex), + #[cfg(feature = "array-buffer")] Uint8Array(TypedArrayIndex), + #[cfg(feature = "array-buffer")] Uint8ClampedArray(TypedArrayIndex), + #[cfg(feature = "array-buffer")] Int16Array(TypedArrayIndex), + #[cfg(feature = "array-buffer")] Uint16Array(TypedArrayIndex), + #[cfg(feature = "array-buffer")] Int32Array(TypedArrayIndex), + #[cfg(feature = "array-buffer")] Uint32Array(TypedArrayIndex), + #[cfg(feature = "array-buffer")] BigInt64Array(TypedArrayIndex), + #[cfg(feature = "array-buffer")] BigUint64Array(TypedArrayIndex), + #[cfg(feature = "array-buffer")] Float32Array(TypedArrayIndex), + #[cfg(feature = "array-buffer")] Float64Array(TypedArrayIndex), // Iterator objects @@ -272,26 +286,37 @@ pub(crate) const SHARED_ARRAY_BUFFER_DISCRIMINANT: u8 = pub(crate) const WEAK_MAP_DISCRIMINANT: u8 = value_discriminant(Value::WeakMap(WeakMap::_def())); pub(crate) const WEAK_REF_DISCRIMINANT: u8 = value_discriminant(Value::WeakRef(WeakRef::_def())); pub(crate) const WEAK_SET_DISCRIMINANT: u8 = value_discriminant(Value::WeakSet(WeakSet::_def())); +#[cfg(feature = "array-buffer")] pub(crate) const INT_8_ARRAY_DISCRIMINANT: u8 = value_discriminant(Value::Int8Array(TypedArrayIndex::from_u32_index(0))); +#[cfg(feature = "array-buffer")] pub(crate) const UINT_8_ARRAY_DISCRIMINANT: u8 = value_discriminant(Value::Uint8Array(TypedArrayIndex::from_u32_index(0))); +#[cfg(feature = "array-buffer")] pub(crate) const UINT_8_CLAMPED_ARRAY_DISCRIMINANT: u8 = value_discriminant(Value::Uint8ClampedArray(TypedArrayIndex::from_u32_index(0))); +#[cfg(feature = "array-buffer")] pub(crate) const INT_16_ARRAY_DISCRIMINANT: u8 = value_discriminant(Value::Int16Array(TypedArrayIndex::from_u32_index(0))); +#[cfg(feature = "array-buffer")] pub(crate) const UINT_16_ARRAY_DISCRIMINANT: u8 = value_discriminant(Value::Uint16Array(TypedArrayIndex::from_u32_index(0))); +#[cfg(feature = "array-buffer")] pub(crate) const INT_32_ARRAY_DISCRIMINANT: u8 = value_discriminant(Value::Int32Array(TypedArrayIndex::from_u32_index(0))); +#[cfg(feature = "array-buffer")] pub(crate) const UINT_32_ARRAY_DISCRIMINANT: u8 = value_discriminant(Value::Uint32Array(TypedArrayIndex::from_u32_index(0))); +#[cfg(feature = "array-buffer")] pub(crate) const BIGINT_64_ARRAY_DISCRIMINANT: u8 = value_discriminant(Value::BigInt64Array(TypedArrayIndex::from_u32_index(0))); +#[cfg(feature = "array-buffer")] pub(crate) const BIGUINT_64_ARRAY_DISCRIMINANT: u8 = value_discriminant(Value::BigUint64Array(TypedArrayIndex::from_u32_index(0))); +#[cfg(feature = "array-buffer")] pub(crate) const FLOAT_32_ARRAY_DISCRIMINANT: u8 = value_discriminant(Value::Float32Array(TypedArrayIndex::from_u32_index(0))); +#[cfg(feature = "array-buffer")] pub(crate) const FLOAT_64_ARRAY_DISCRIMINANT: u8 = value_discriminant(Value::Float64Array(TypedArrayIndex::from_u32_index(0))); pub(crate) const ASYNC_FROM_SYNC_ITERATOR_DISCRIMINANT: u8 = @@ -636,46 +661,57 @@ impl Value { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Int8Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Uint8Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Uint8ClampedArray(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Int16Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Uint16Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Int32Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Uint32Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::BigInt64Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::BigUint64Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Float32Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Float64Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); @@ -841,46 +877,57 @@ impl Value { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Int8Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Uint8Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Uint8ClampedArray(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Int16Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Uint16Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Int32Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Uint32Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::BigInt64Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::BigUint64Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Float32Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); } + #[cfg(feature = "array-buffer")] Value::Float64Array(data) => { discriminant.hash(hasher); data.into_index().hash(hasher); @@ -1044,16 +1091,27 @@ impl HeapMarkAndSweep for Value { Value::WeakMap(data) => data.mark_values(queues), Value::WeakRef(data) => data.mark_values(queues), Value::WeakSet(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::Int8Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::Uint8Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::Uint8ClampedArray(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::Int16Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::Uint16Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::Int32Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::Uint32Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::BigInt64Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::BigUint64Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::Float32Array(data) => data.mark_values(queues), + #[cfg(feature = "array-buffer")] Value::Float64Array(data) => data.mark_values(queues), Value::BuiltinGeneratorFunction => todo!(), Value::BuiltinConstructorFunction(data) => data.mark_values(queues), @@ -1111,16 +1169,27 @@ impl HeapMarkAndSweep for Value { Value::WeakMap(data) => data.sweep_values(compactions), Value::WeakRef(data) => data.sweep_values(compactions), Value::WeakSet(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::Int8Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::Uint8Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::Uint8ClampedArray(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::Int16Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::Uint16Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::Int32Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::Uint32Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::BigInt64Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::BigUint64Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::Float32Array(data) => data.sweep_values(compactions), + #[cfg(feature = "array-buffer")] Value::Float64Array(data) => data.sweep_values(compactions), Value::BuiltinGeneratorFunction => todo!(), Value::BuiltinConstructorFunction(data) => data.sweep_values(compactions), diff --git a/nova_vm/src/engine/bytecode/vm.rs b/nova_vm/src/engine/bytecode/vm.rs index 5ce447ff4..29b6018c8 100644 --- a/nova_vm/src/engine/bytecode/vm.rs +++ b/nova_vm/src/engine/bytecode/vm.rs @@ -2102,17 +2102,6 @@ fn typeof_operator(_: &mut Agent, val: Value) -> String { Value::WeakMap(_) | Value::WeakRef(_) | Value::WeakSet(_) | - Value::Int8Array(_) | - Value::Uint8Array(_) | - Value::Uint8ClampedArray(_) | - Value::Int16Array(_) | - Value::Uint16Array(_) | - Value::Int32Array(_) | - Value::Uint32Array(_) | - Value::BigInt64Array(_) | - Value::BigUint64Array(_) | - Value::Float32Array(_) | - Value::Float64Array(_) | Value::AsyncFromSyncIterator | Value::AsyncIterator | Value::Iterator | @@ -2124,6 +2113,17 @@ fn typeof_operator(_: &mut Agent, val: Value) -> String { Value::EmbedderObject(_) => BUILTIN_STRING_MEMORY.object, #[cfg(feature = "array-buffer")] Value::ArrayBuffer(_) | + Value::Int8Array(_) | + Value::Uint8Array(_) | + Value::Uint8ClampedArray(_) | + Value::Int16Array(_) | + Value::Uint16Array(_) | + Value::Int32Array(_) | + Value::Uint32Array(_) | + Value::BigInt64Array(_) | + Value::BigUint64Array(_) | + Value::Float32Array(_) | + Value::Float64Array(_) | Value::DataView(_) => BUILTIN_STRING_MEMORY.object, #[cfg(feature = "date")] Value::Date(_) => BUILTIN_STRING_MEMORY.object, diff --git a/nova_vm/src/heap.rs b/nova_vm/src/heap.rs index 8d2a83008..ae17882fc 100644 --- a/nova_vm/src/heap.rs +++ b/nova_vm/src/heap.rs @@ -55,7 +55,6 @@ use crate::ecmascript::{ regexp::RegExpHeapData, set::data::SetHeapData, shared_array_buffer::data::SharedArrayBufferHeapData, - typed_array::data::TypedArrayHeapData, weak_map::data::WeakMapHeapData, weak_ref::data::WeakRefHeapData, weak_set::data::WeakSetHeapData, @@ -70,7 +69,9 @@ use crate::ecmascript::{ #[cfg(feature = "date")] use crate::ecmascript::builtins::date::data::DateHeapData; #[cfg(feature = "array-buffer")] -use crate::ecmascript::builtins::{data_view::data::DataViewHeapData, ArrayBufferHeapData}; +use crate::ecmascript::builtins::{ + data_view::data::DataViewHeapData, typed_array::data::TypedArrayHeapData, ArrayBufferHeapData, +}; use crate::ecmascript::{ builtins::ArrayHeapData, execution::{Environments, Realm, RealmIdentifier}, @@ -126,6 +127,7 @@ pub struct Heap { pub set_iterators: Vec>, pub shared_array_buffers: Vec>, pub symbols: Vec>, + #[cfg(feature = "array-buffer")] pub typed_arrays: Vec>, pub weak_maps: Vec>, pub weak_refs: Vec>, @@ -220,6 +222,7 @@ impl Heap { shared_array_buffers: Vec::with_capacity(0), strings: Vec::with_capacity(1024), symbols: Vec::with_capacity(1024), + #[cfg(feature = "array-buffer")] typed_arrays: Vec::with_capacity(0), weak_maps: Vec::with_capacity(0), weak_refs: Vec::with_capacity(0), diff --git a/nova_vm/src/heap/heap_bits.rs b/nova_vm/src/heap/heap_bits.rs index 736789344..5b3e8a4fb 100644 --- a/nova_vm/src/heap/heap_bits.rs +++ b/nova_vm/src/heap/heap_bits.rs @@ -3,9 +3,11 @@ use ahash::AHashMap; // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. +#[cfg(feature = "array-buffer")] +use super::indexes::TypedArrayIndex; use super::{ element_array::{ElementArrayKey, ElementDescriptor, ElementsVector}, - indexes::{BaseIndex, ElementIndex, TypedArrayIndex}, + indexes::{BaseIndex, ElementIndex}, Heap, }; #[cfg(feature = "date")] @@ -106,6 +108,7 @@ pub struct HeapBits { pub shared_array_buffers: Box<[bool]>, pub strings: Box<[bool]>, pub symbols: Box<[bool]>, + #[cfg(feature = "array-buffer")] pub typed_arrays: Box<[bool]>, pub weak_maps: Box<[bool]>, pub weak_refs: Box<[bool]>, @@ -163,6 +166,7 @@ pub(crate) struct WorkQueues { pub shared_array_buffers: Vec, pub strings: Vec, pub symbols: Vec, + #[cfg(feature = "array-buffer")] pub typed_arrays: Vec, pub weak_maps: Vec, pub weak_refs: Vec, @@ -220,6 +224,7 @@ impl HeapBits { let shared_array_buffers = vec![false; heap.shared_array_buffers.len()]; let strings = vec![false; heap.strings.len()]; let symbols = vec![false; heap.symbols.len()]; + #[cfg(feature = "array-buffer")] let typed_arrays = vec![false; heap.typed_arrays.len()]; let weak_maps = vec![false; heap.weak_maps.len()]; let weak_refs = vec![false; heap.weak_refs.len()]; @@ -274,6 +279,7 @@ impl HeapBits { shared_array_buffers: shared_array_buffers.into_boxed_slice(), strings: strings.into_boxed_slice(), symbols: symbols.into_boxed_slice(), + #[cfg(feature = "array-buffer")] typed_arrays: typed_arrays.into_boxed_slice(), weak_maps: weak_maps.into_boxed_slice(), weak_refs: weak_refs.into_boxed_slice(), @@ -336,6 +342,7 @@ impl WorkQueues { shared_array_buffers: Vec::with_capacity(heap.shared_array_buffers.len() / 4), strings: Vec::with_capacity((heap.strings.len() / 4).max(BUILTIN_STRINGS_LIST.len())), symbols: Vec::with_capacity((heap.symbols.len() / 4).max(13)), + #[cfg(feature = "array-buffer")] typed_arrays: Vec::with_capacity(heap.typed_arrays.len() / 4), weak_maps: Vec::with_capacity(heap.weak_maps.len() / 4), weak_refs: Vec::with_capacity(heap.weak_refs.len() / 4), @@ -417,6 +424,7 @@ impl WorkQueues { shared_array_buffers, strings, symbols, + #[cfg(feature = "array-buffer")] typed_arrays, weak_maps, weak_refs, @@ -429,6 +437,8 @@ impl WorkQueues { let data_views: &[bool; 0] = &[]; #[cfg(not(feature = "array-buffer"))] let array_buffers: &[bool; 0] = &[]; + #[cfg(not(feature = "array-buffer"))] + let typed_arrays: &[bool; 0] = &[]; array_buffers.is_empty() && arrays.is_empty() @@ -671,6 +681,7 @@ pub(crate) struct CompactionLists { pub shared_array_buffers: CompactionList, pub strings: CompactionList, pub symbols: CompactionList, + #[cfg(feature = "array-buffer")] pub typed_arrays: CompactionList, pub weak_maps: CompactionList, pub weak_refs: CompactionList, @@ -747,6 +758,7 @@ impl CompactionLists { weak_maps: CompactionList::from_mark_bits(&bits.weak_maps), weak_refs: CompactionList::from_mark_bits(&bits.weak_refs), weak_sets: CompactionList::from_mark_bits(&bits.weak_sets), + #[cfg(feature = "array-buffer")] typed_arrays: CompactionList::from_mark_bits(&bits.typed_arrays), } } diff --git a/nova_vm/src/heap/heap_constants.rs b/nova_vm/src/heap/heap_constants.rs index 05f22d3d4..a059b2a13 100644 --- a/nova_vm/src/heap/heap_constants.rs +++ b/nova_vm/src/heap/heap_constants.rs @@ -36,17 +36,29 @@ pub(crate) enum IntrinsicObjectIndexes { // Indexed collections ArrayPrototype, + #[cfg(feature = "array-buffer")] TypedArrayPrototype, + #[cfg(feature = "array-buffer")] Int8ArrayPrototype, + #[cfg(feature = "array-buffer")] Uint8ArrayPrototype, + #[cfg(feature = "array-buffer")] Uint8ClampedArrayPrototype, + #[cfg(feature = "array-buffer")] Int16ArrayPrototype, + #[cfg(feature = "array-buffer")] Uint16ArrayPrototype, + #[cfg(feature = "array-buffer")] Int32ArrayPrototype, + #[cfg(feature = "array-buffer")] Uint32ArrayPrototype, + #[cfg(feature = "array-buffer")] BigInt64ArrayPrototype, + #[cfg(feature = "array-buffer")] BigUint64ArrayPrototype, + #[cfg(feature = "array-buffer")] Float32ArrayPrototype, + #[cfg(feature = "array-buffer")] Float64ArrayPrototype, // Keyed collections @@ -145,17 +157,29 @@ pub(crate) enum IntrinsicConstructorIndexes { // Indexed collections Array, + #[cfg(feature = "array-buffer")] TypedArray, + #[cfg(feature = "array-buffer")] Int8Array, + #[cfg(feature = "array-buffer")] Uint8Array, + #[cfg(feature = "array-buffer")] Uint8ClampedArray, + #[cfg(feature = "array-buffer")] Int16Array, + #[cfg(feature = "array-buffer")] Uint16Array, + #[cfg(feature = "array-buffer")] Int32Array, + #[cfg(feature = "array-buffer")] Uint32Array, + #[cfg(feature = "array-buffer")] BigInt64Array, + #[cfg(feature = "array-buffer")] BigUint64Array, + #[cfg(feature = "array-buffer")] Float32Array, + #[cfg(feature = "array-buffer")] Float64Array, // Keyed collections @@ -165,6 +189,7 @@ pub(crate) enum IntrinsicConstructorIndexes { WeakSet, // Structured data + #[cfg(feature = "array-buffer")] ArrayBuffer, SharedArrayBuffer, #[cfg(feature = "array-buffer")] @@ -226,6 +251,7 @@ pub(crate) enum IntrinsicFunctionIndexes { StringPrototypeTrimEnd, StringPrototypeTrimStart, ThrowTypeError, + #[cfg(feature = "array-buffer")] TypedArrayPrototypeValues, Unescape, } diff --git a/nova_vm/src/heap/heap_gc.rs b/nova_vm/src/heap/heap_gc.rs index 1a178258d..9a7e9a5e1 100644 --- a/nova_vm/src/heap/heap_gc.rs +++ b/nova_vm/src/heap/heap_gc.rs @@ -4,6 +4,8 @@ use std::thread; +#[cfg(feature = "array-buffer")] +use super::indexes::TypedArrayIndex; use super::{ element_array::ElementArrays, heap_bits::{ @@ -12,7 +14,7 @@ use super::{ sweep_heap_u8_elements_vector_values, sweep_heap_vector_values, CompactionLists, HeapBits, HeapMarkAndSweep, WorkQueues, }, - indexes::{ElementIndex, StringIndex, TypedArrayIndex}, + indexes::{ElementIndex, StringIndex}, Heap, WellKnownSymbolIndexes, }; #[cfg(feature = "date")] @@ -144,6 +146,7 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { shared_array_buffers, strings, symbols, + #[cfg(feature = "array-buffer")] typed_arrays, weak_maps, weak_refs, @@ -691,20 +694,23 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { symbols.get(index).mark_values(&mut queues); } }); - let mut typed_arrays_marks: Box<[TypedArrayIndex]> = - queues.typed_arrays.drain(..).collect(); - typed_arrays_marks.sort(); - typed_arrays_marks.iter().for_each(|&idx| { - let index = idx.into_index(); - if let Some(marked) = bits.typed_arrays.get_mut(index) { - if *marked { - // Already marked, ignore - return; + #[cfg(feature = "array-buffer")] + { + let mut typed_arrays_marks: Box<[TypedArrayIndex]> = + queues.typed_arrays.drain(..).collect(); + typed_arrays_marks.sort(); + typed_arrays_marks.iter().for_each(|&idx| { + let index = idx.into_index(); + if let Some(marked) = bits.typed_arrays.get_mut(index) { + if *marked { + // Already marked, ignore + return; + } + *marked = true; + typed_arrays.get(index).mark_values(&mut queues); } - *marked = true; - typed_arrays.get(index).mark_values(&mut queues); - } - }); + }); + } let mut weak_map_marks: Box<[WeakMap]> = queues.weak_maps.drain(..).collect(); weak_map_marks.sort(); weak_map_marks.iter().for_each(|&idx| { @@ -965,6 +971,7 @@ fn sweep(heap: &mut Heap, bits: &HeapBits, root_realms: &mut [Option; pub type SharedArrayBufferIndex = BaseIndex; pub type StringIndex = BaseIndex; pub type SymbolIndex = BaseIndex; +#[cfg(feature = "array-buffer")] pub type TypedArrayIndex = BaseIndex; pub type WeakMapIndex = BaseIndex; pub type WeakRefIndex = BaseIndex;