diff --git a/nova_vm/Cargo.toml b/nova_vm/Cargo.toml index 88abdaacb..c2abba55b 100644 --- a/nova_vm/Cargo.toml +++ b/nova_vm/Cargo.toml @@ -23,11 +23,12 @@ sonic-rs = { workspace = true, optional = true } wtf8 = { workspace = true } [features] -default = ["math", "json", "date", "array-buffer"] +default = ["math", "json", "date", "array-buffer", "shared-array-buffer"] math = [] json = ["sonic-rs"] date = [] array-buffer = [] +shared-array-buffer = [] typescript = [] [build-dependencies] diff --git a/nova_vm/src/ecmascript/builtins.rs b/nova_vm/src/ecmascript/builtins.rs index a14169c0a..1042f8a0f 100644 --- a/nova_vm/src/ecmascript/builtins.rs +++ b/nova_vm/src/ecmascript/builtins.rs @@ -39,6 +39,7 @@ pub(crate) mod proxy; pub(crate) mod reflection; pub(crate) mod regexp; pub(crate) mod set; +#[cfg(feature = "shared-array-buffer")] pub(crate) mod shared_array_buffer; pub(crate) mod structured_data; pub(crate) mod text_processing; diff --git a/nova_vm/src/ecmascript/builtins/ordinary.rs b/nova_vm/src/ecmascript/builtins/ordinary.rs index 531e90a2c..1a223535f 100644 --- a/nova_vm/src/ecmascript/builtins/ordinary.rs +++ b/nova_vm/src/ecmascript/builtins/ordinary.rs @@ -26,6 +26,8 @@ use crate::{ #[cfg(feature = "date")] use super::date::data::DateHeapData; +#[cfg(feature = "shared-array-buffer")] +use super::shared_array_buffer::data::SharedArrayBufferHeapData; use super::{ control_abstraction_objects::generator_objects::GeneratorHeapData, error::ErrorHeapData, @@ -40,7 +42,6 @@ use super::{ promise::data::PromiseHeapData, regexp::RegExpHeapData, set::data::SetHeapData, - shared_array_buffer::data::SharedArrayBufferHeapData, weak_map::data::WeakMapHeapData, weak_ref::data::WeakRefHeapData, weak_set::data::WeakSetHeapData, @@ -950,6 +951,7 @@ pub(crate) fn ordinary_object_create_with_intrinsics( .heap .create(SetIteratorHeapData::default()) .into_object(), + #[cfg(feature = "shared-array-buffer")] ProtoIntrinsics::SharedArrayBuffer => agent .heap .create(SharedArrayBufferHeapData::default()) @@ -1093,6 +1095,7 @@ pub(crate) fn get_prototype_from_constructor( ProtoIntrinsics::RegExp => Some(intrinsics.reg_exp().into_function()), ProtoIntrinsics::Set => Some(intrinsics.set().into_function()), ProtoIntrinsics::SetIterator => None, + #[cfg(feature = "shared-array-buffer")] ProtoIntrinsics::SharedArrayBuffer => { Some(intrinsics.shared_array_buffer().into_function()) } diff --git a/nova_vm/src/ecmascript/builtins/structured_data.rs b/nova_vm/src/ecmascript/builtins/structured_data.rs index 65f7e8742..7f09afe82 100644 --- a/nova_vm/src/ecmascript/builtins/structured_data.rs +++ b/nova_vm/src/ecmascript/builtins/structured_data.rs @@ -9,4 +9,5 @@ pub(crate) mod atomics_object; pub(crate) mod data_view_objects; #[cfg(feature = "json")] pub(crate) mod json_object; +#[cfg(feature = "shared-array-buffer")] pub(crate) mod shared_array_buffer_objects; diff --git a/nova_vm/src/ecmascript/execution/realm.rs b/nova_vm/src/ecmascript/execution/realm.rs index 470b0f89f..352bd814c 100644 --- a/nova_vm/src/ecmascript/execution/realm.rs +++ b/nova_vm/src/ecmascript/execution/realm.rs @@ -817,17 +817,19 @@ pub(crate) fn set_default_global_bindings( define_property_or_throw(agent, global, name, desc)?; // 19.3.28 SharedArrayBuffer ( . . . ) - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.SharedArrayBuffer); - let value = agent.get_realm(realm_id).intrinsics().shared_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 = "shared-array-buffer")] + { + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.SharedArrayBuffer); + let value = agent.get_realm(realm_id).intrinsics().shared_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.29 String ( . . . ) let name = PropertyKey::from(BUILTIN_STRING_MEMORY.String); let value = agent.get_realm(realm_id).intrinsics().string(); diff --git a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs index a26a3dba8..94211bc0e 100644 --- a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs +++ b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs @@ -2,6 +2,36 @@ // 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/. +use super::RealmIdentifier; +#[cfg(feature = "date")] +use crate::ecmascript::builtins::numbers_and_dates::date_objects::{ + date_constructor::DateConstructor, date_prototype::DatePrototype, +}; +#[cfg(feature = "math")] +use crate::ecmascript::builtins::numbers_and_dates::math_object::MathObject; +#[cfg(feature = "json")] +use crate::ecmascript::builtins::structured_data::json_object::JSONObject; +#[cfg(feature = "shared-array-buffer")] +use crate::ecmascript::builtins::structured_data::shared_array_buffer_objects::{ + shared_array_buffer_constructor::SharedArrayBufferConstructor, + shared_array_buffer_prototype::SharedArrayBufferPrototype, +}; +#[cfg(feature = "array-buffer")] +use crate::ecmascript::builtins::{ + indexed_collections::typed_array_objects::{ + typed_array_constructors::{TypedArrayConstructors, TypedArrayPrototypes}, + typed_array_intrinsic_object::{TypedArrayIntrinsicObject, TypedArrayPrototype}, + }, + structured_data::{ + array_buffer_objects::{ + array_buffer_constructor::ArrayBufferConstructor, + array_buffer_prototype::ArrayBufferPrototype, + }, + data_view_objects::{ + data_view_constructor::DataViewConstructor, data_view_prototype::DataViewPrototype, + }, + }, +}; use crate::{ ecmascript::{ builtins::{ @@ -64,13 +94,7 @@ use crate::{ }, primitive_objects::PrimitiveObject, reflection::{proxy_constructor::ProxyConstructor, reflect_object::ReflectObject}, - structured_data::{ - atomics_object::AtomicsObject, - shared_array_buffer_objects::{ - shared_array_buffer_constructor::SharedArrayBufferConstructor, - shared_array_buffer_prototype::SharedArrayBufferPrototype, - }, - }, + structured_data::atomics_object::AtomicsObject, text_processing::{ regexp_objects::{ regexp_constructor::RegExpConstructor, regexp_prototype::RegExpPrototype, @@ -124,33 +148,6 @@ use crate::{ }, }; -use super::RealmIdentifier; - -#[cfg(feature = "date")] -use crate::ecmascript::builtins::numbers_and_dates::date_objects::{ - date_constructor::DateConstructor, date_prototype::DatePrototype, -}; -#[cfg(feature = "math")] -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::{ - indexed_collections::typed_array_objects::{ - typed_array_constructors::{TypedArrayConstructors, TypedArrayPrototypes}, - typed_array_intrinsic_object::{TypedArrayIntrinsicObject, TypedArrayPrototype}, - }, - 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 { pub(crate) object_index_base: ObjectIndex, @@ -208,6 +205,7 @@ pub enum ProtoIntrinsics { RegExp, Set, SetIterator, + #[cfg(feature = "shared-array-buffer")] SharedArrayBuffer, String, Symbol, @@ -314,7 +312,9 @@ impl Intrinsics { ArrayBufferPrototype::create_intrinsic(agent, realm); #[cfg(feature = "array-buffer")] ArrayBufferConstructor::create_intrinsic(agent, realm); + #[cfg(feature = "shared-array-buffer")] SharedArrayBufferPrototype::create_intrinsic(agent, realm); + #[cfg(feature = "shared-array-buffer")] SharedArrayBufferConstructor::create_intrinsic(agent, realm); #[cfg(feature = "array-buffer")] DataViewPrototype::create_intrinsic(agent, realm); @@ -402,6 +402,7 @@ impl Intrinsics { ProtoIntrinsics::RegExp => self.reg_exp_prototype().into(), ProtoIntrinsics::Set => self.set_prototype().into(), ProtoIntrinsics::SetIterator => self.set_iterator_prototype().into(), + #[cfg(feature = "shared-array-buffer")] ProtoIntrinsics::SharedArrayBuffer => self.shared_array_buffer_prototype().into(), #[cfg(feature = "array-buffer")] ProtoIntrinsics::Uint16Array => self.uint16_array_prototype().into(), @@ -1258,6 +1259,7 @@ impl Intrinsics { } /// %SharedArrayBuffer.prototype% + #[cfg(feature = "shared-array-buffer")] pub(crate) fn shared_array_buffer_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::SharedArrayBufferPrototype .get_object_index(self.object_index_base) @@ -1265,12 +1267,14 @@ impl Intrinsics { } /// %SharedArrayBuffer% + #[cfg(feature = "shared-array-buffer")] pub(crate) fn shared_array_buffer(&self) -> BuiltinFunction { IntrinsicConstructorIndexes::SharedArrayBuffer .get_builtin_function_index(self.builtin_function_index_base) .into() } + #[cfg(feature = "shared-array-buffer")] pub(crate) fn shared_array_buffer_base_object(&self) -> ObjectIndex { IntrinsicConstructorIndexes::SharedArrayBuffer.get_object_index(self.object_index_base) } @@ -1687,7 +1691,9 @@ impl HeapMarkAndSweep for Intrinsics { self.set_prototype().mark_values(queues); self.set().mark_values(queues); self.set_iterator_prototype().mark_values(queues); + #[cfg(feature = "shared-array-buffer")] self.shared_array_buffer_prototype().mark_values(queues); + #[cfg(feature = "shared-array-buffer")] self.shared_array_buffer().mark_values(queues); self.string_prototype_trim_end().mark_values(queues); self.string_prototype_trim_start().mark_values(queues); diff --git a/nova_vm/src/ecmascript/types/language/object.rs b/nova_vm/src/ecmascript/types/language/object.rs index 05c916344..db8a1b97b 100644 --- a/nova_vm/src/ecmascript/types/language/object.rs +++ b/nova_vm/src/ecmascript/types/language/object.rs @@ -13,6 +13,8 @@ use std::hash::Hash; #[cfg(feature = "date")] use super::value::DATE_DISCRIMINANT; +#[cfg(feature = "shared-array-buffer")] +use super::value::SHARED_ARRAY_BUFFER_DISCRIMINANT; #[cfg(feature = "array-buffer")] use super::value::{ ARRAY_BUFFER_DISCRIMINANT, BIGINT_64_ARRAY_DISCRIMINANT, BIGUINT_64_ARRAY_DISCRIMINANT, @@ -33,15 +35,16 @@ use super::{ 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, WEAK_MAP_DISCRIMINANT, WEAK_REF_DISCRIMINANT, - WEAK_SET_DISCRIMINANT, + REGEXP_DISCRIMINANT, SET_DISCRIMINANT, SET_ITERATOR_DISCRIMINANT, WEAK_MAP_DISCRIMINANT, + WEAK_REF_DISCRIMINANT, WEAK_SET_DISCRIMINANT, }, Function, IntoValue, Value, }; #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; +#[cfg(feature = "shared-array-buffer")] +use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer; #[cfg(feature = "array-buffer")] use crate::{ ecmascript::builtins::{data_view::DataView, typed_array::TypedArray, ArrayBuffer}, @@ -70,7 +73,6 @@ use crate::{ proxy::Proxy, regexp::RegExp, set::Set, - shared_array_buffer::SharedArrayBuffer, weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, @@ -125,6 +127,7 @@ pub enum Object { Proxy(Proxy) = PROXY_DISCRIMINANT, RegExp(RegExp) = REGEXP_DISCRIMINANT, Set(Set) = SET_DISCRIMINANT, + #[cfg(feature = "shared-array-buffer")] SharedArrayBuffer(SharedArrayBuffer) = SHARED_ARRAY_BUFFER_DISCRIMINANT, WeakMap(WeakMap) = WEAK_MAP_DISCRIMINANT, WeakRef(WeakRef) = WEAK_REF_DISCRIMINANT, @@ -195,6 +198,7 @@ impl IntoValue for Object { Object::Proxy(data) => Value::Proxy(data), Object::RegExp(data) => Value::RegExp(data), Object::Set(data) => Value::Set(data), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => Value::SharedArrayBuffer(data), Object::WeakMap(data) => Value::WeakMap(data), Object::WeakRef(data) => Value::WeakRef(data), @@ -385,6 +389,7 @@ impl From for Value { Object::Proxy(data) => Value::Proxy(data), Object::RegExp(data) => Value::RegExp(data), Object::Set(data) => Value::Set(data), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => Value::SharedArrayBuffer(data), Object::WeakMap(data) => Value::WeakMap(data), Object::WeakRef(data) => Value::WeakRef(data), @@ -466,6 +471,7 @@ impl TryFrom for Object { Value::Proxy(data) => Ok(Object::Proxy(data)), Value::RegExp(idx) => Ok(Object::RegExp(idx)), Value::Set(data) => Ok(Object::Set(data)), + #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(data) => Ok(Object::SharedArrayBuffer(data)), Value::WeakMap(data) => Ok(Object::WeakMap(data)), Value::WeakRef(data) => Ok(Object::WeakRef(data)), @@ -544,6 +550,7 @@ impl Hash for Object { Object::Proxy(data) => data.get_index().hash(state), Object::RegExp(data) => data.get_index().hash(state), Object::Set(data) => data.get_index().hash(state), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.get_index().hash(state), Object::WeakMap(data) => data.get_index().hash(state), Object::WeakRef(data) => data.get_index().hash(state), @@ -623,6 +630,7 @@ impl InternalSlots for Object { Object::Proxy(data) => data.internal_extensible(agent), Object::RegExp(data) => data.internal_extensible(agent), Object::Set(data) => data.internal_extensible(agent), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_extensible(agent), Object::WeakMap(data) => data.internal_extensible(agent), Object::WeakRef(data) => data.internal_extensible(agent), @@ -696,6 +704,7 @@ impl InternalSlots for Object { Object::Proxy(data) => data.internal_set_extensible(agent, value), Object::RegExp(data) => data.internal_set_extensible(agent, value), Object::Set(data) => data.internal_set_extensible(agent, value), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_set_extensible(agent, value), Object::WeakMap(data) => data.internal_set_extensible(agent, value), Object::WeakRef(data) => data.internal_set_extensible(agent, value), @@ -783,6 +792,7 @@ impl InternalSlots for Object { Object::Proxy(data) => data.internal_prototype(agent), Object::RegExp(data) => data.internal_prototype(agent), Object::Set(data) => data.internal_prototype(agent), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_prototype(agent), Object::WeakMap(data) => data.internal_prototype(agent), Object::WeakRef(data) => data.internal_prototype(agent), @@ -858,6 +868,7 @@ impl InternalSlots for Object { Object::Proxy(data) => data.internal_set_prototype(agent, prototype), Object::RegExp(data) => data.internal_set_prototype(agent, prototype), Object::Set(data) => data.internal_set_prototype(agent, prototype), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_set_prototype(agent, prototype), Object::WeakMap(data) => data.internal_set_prototype(agent, prototype), Object::WeakRef(data) => data.internal_set_prototype(agent, prototype), @@ -947,6 +958,7 @@ impl InternalMethods for Object { Object::Proxy(data) => data.internal_get_prototype_of(agent), Object::RegExp(data) => data.internal_get_prototype_of(agent), Object::Set(data) => data.internal_get_prototype_of(agent), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_get_prototype_of(agent), Object::WeakMap(data) => data.internal_get_prototype_of(agent), Object::WeakRef(data) => data.internal_get_prototype_of(agent), @@ -1040,6 +1052,7 @@ impl InternalMethods for Object { Object::Proxy(data) => data.internal_set_prototype_of(agent, prototype), Object::RegExp(data) => data.internal_set_prototype_of(agent, prototype), Object::Set(data) => data.internal_set_prototype_of(agent, prototype), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_set_prototype_of(agent, prototype), Object::WeakMap(data) => data.internal_set_prototype_of(agent, prototype), Object::WeakRef(data) => data.internal_set_prototype_of(agent, prototype), @@ -1127,6 +1140,7 @@ impl InternalMethods for Object { Object::Proxy(data) => data.internal_is_extensible(agent), Object::RegExp(data) => data.internal_is_extensible(agent), Object::Set(data) => data.internal_is_extensible(agent), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_is_extensible(agent), Object::WeakMap(data) => data.internal_is_extensible(agent), Object::WeakRef(data) => data.internal_is_extensible(agent), @@ -1208,6 +1222,7 @@ impl InternalMethods for Object { Object::Proxy(data) => data.internal_prevent_extensions(agent), Object::RegExp(data) => data.internal_prevent_extensions(agent), Object::Set(data) => data.internal_prevent_extensions(agent), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_prevent_extensions(agent), Object::WeakMap(data) => data.internal_prevent_extensions(agent), Object::WeakRef(data) => data.internal_prevent_extensions(agent), @@ -1305,6 +1320,7 @@ impl InternalMethods for Object { Object::Proxy(data) => data.internal_get_own_property(agent, property_key), Object::RegExp(data) => data.internal_get_own_property(agent, property_key), Object::Set(data) => data.internal_get_own_property(agent, property_key), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_get_own_property(agent, property_key), Object::WeakMap(data) => data.internal_get_own_property(agent, property_key), Object::WeakRef(data) => data.internal_get_own_property(agent, property_key), @@ -1435,6 +1451,7 @@ impl InternalMethods for Object { Object::Set(data) => { data.internal_define_own_property(agent, property_key, property_descriptor) } + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => { data.internal_define_own_property(agent, property_key, property_descriptor) } @@ -1547,6 +1564,7 @@ impl InternalMethods for Object { Object::Proxy(data) => data.internal_has_property(agent, property_key), Object::RegExp(data) => data.internal_has_property(agent, property_key), Object::Set(data) => data.internal_has_property(agent, property_key), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_has_property(agent, property_key), Object::WeakMap(data) => data.internal_has_property(agent, property_key), Object::WeakRef(data) => data.internal_has_property(agent, property_key), @@ -1643,6 +1661,7 @@ impl InternalMethods for Object { Object::Proxy(data) => data.internal_get(agent, property_key, receiver), Object::RegExp(data) => data.internal_get(agent, property_key, receiver), Object::Set(data) => data.internal_get(agent, property_key, receiver), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_get(agent, property_key, receiver), Object::WeakMap(data) => data.internal_get(agent, property_key, receiver), Object::WeakRef(data) => data.internal_get(agent, property_key, receiver), @@ -1748,6 +1767,7 @@ impl InternalMethods for Object { Object::Proxy(data) => data.internal_set(agent, property_key, value, receiver), Object::RegExp(data) => data.internal_set(agent, property_key, value, receiver), Object::Set(data) => data.internal_set(agent, property_key, value, receiver), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => { data.internal_set(agent, property_key, value, receiver) } @@ -1842,6 +1862,7 @@ impl InternalMethods for Object { Object::Proxy(data) => data.internal_delete(agent, property_key), Object::RegExp(data) => data.internal_delete(agent, property_key), Object::Set(data) => data.internal_delete(agent, property_key), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_delete(agent, property_key), Object::WeakMap(data) => data.internal_delete(agent, property_key), Object::WeakRef(data) => data.internal_delete(agent, property_key), @@ -1929,6 +1950,7 @@ impl InternalMethods for Object { Object::Proxy(data) => data.internal_own_property_keys(agent), Object::RegExp(data) => data.internal_own_property_keys(agent), Object::Set(data) => data.internal_own_property_keys(agent), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_own_property_keys(agent), Object::WeakMap(data) => data.internal_own_property_keys(agent), Object::WeakRef(data) => data.internal_own_property_keys(agent), @@ -2055,6 +2077,7 @@ impl HeapMarkAndSweep for Object { Object::Proxy(data) => data.mark_values(queues), Object::RegExp(data) => data.mark_values(queues), Object::Set(data) => data.mark_values(queues), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.mark_values(queues), Object::WeakMap(data) => data.mark_values(queues), Object::WeakRef(data) => data.mark_values(queues), @@ -2120,6 +2143,7 @@ impl HeapMarkAndSweep for Object { Object::Proxy(data) => data.sweep_values(compactions), Object::RegExp(data) => data.sweep_values(compactions), Object::Set(data) => data.sweep_values(compactions), + #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.sweep_values(compactions), Object::WeakMap(data) => data.sweep_values(compactions), Object::WeakRef(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 b888ea0cb..bf96245b6 100644 --- a/nova_vm/src/ecmascript/types/language/value.rs +++ b/nova_vm/src/ecmascript/types/language/value.rs @@ -11,6 +11,8 @@ use super::{ }; #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; +#[cfg(feature = "shared-array-buffer")] +use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer; #[cfg(feature = "array-buffer")] use crate::{ ecmascript::builtins::{data_view::DataView, ArrayBuffer}, @@ -42,7 +44,6 @@ use crate::{ proxy::Proxy, regexp::RegExp, set::Set, - shared_array_buffer::SharedArrayBuffer, weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, @@ -161,6 +162,7 @@ pub enum Value { Proxy(Proxy), RegExp(RegExp), Set(Set), + #[cfg(feature = "shared-array-buffer")] SharedArrayBuffer(SharedArrayBuffer), WeakMap(WeakMap), WeakRef(WeakRef), @@ -281,6 +283,7 @@ pub(crate) const MAP_DISCRIMINANT: u8 = value_discriminant(Value::Map(Map::_def( pub(crate) const PROMISE_DISCRIMINANT: u8 = value_discriminant(Value::Promise(Promise::_def())); pub(crate) const PROXY_DISCRIMINANT: u8 = value_discriminant(Value::Proxy(Proxy::_def())); pub(crate) const SET_DISCRIMINANT: u8 = value_discriminant(Value::Set(Set::_def())); +#[cfg(feature = "shared-array-buffer")] pub(crate) const SHARED_ARRAY_BUFFER_DISCRIMINANT: u8 = value_discriminant(Value::SharedArrayBuffer(SharedArrayBuffer::_def())); pub(crate) const WEAK_MAP_DISCRIMINANT: u8 = value_discriminant(Value::WeakMap(WeakMap::_def())); @@ -645,6 +648,7 @@ impl Value { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); @@ -861,6 +865,7 @@ impl Value { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); @@ -1087,6 +1092,7 @@ impl HeapMarkAndSweep for Value { Value::Proxy(data) => data.mark_values(queues), Value::Promise(data) => data.mark_values(queues), Value::Set(data) => data.mark_values(queues), + #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(data) => data.mark_values(queues), Value::WeakMap(data) => data.mark_values(queues), Value::WeakRef(data) => data.mark_values(queues), @@ -1165,6 +1171,7 @@ impl HeapMarkAndSweep for Value { Value::Proxy(data) => data.sweep_values(compactions), Value::Promise(data) => data.sweep_values(compactions), Value::Set(data) => data.sweep_values(compactions), + #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(data) => data.sweep_values(compactions), Value::WeakMap(data) => data.sweep_values(compactions), Value::WeakRef(data) => data.sweep_values(compactions), diff --git a/nova_vm/src/engine/bytecode/vm.rs b/nova_vm/src/engine/bytecode/vm.rs index 29b6018c8..2076cc692 100644 --- a/nova_vm/src/engine/bytecode/vm.rs +++ b/nova_vm/src/engine/bytecode/vm.rs @@ -2098,7 +2098,6 @@ fn typeof_operator(_: &mut Agent, val: Value) -> String { Value::Map(_) | Value::Promise(_) | Value::Set(_) | - Value::SharedArrayBuffer(_) | Value::WeakMap(_) | Value::WeakRef(_) | Value::WeakSet(_) | @@ -2111,6 +2110,8 @@ fn typeof_operator(_: &mut Agent, val: Value) -> String { Value::Generator(_) | Value::Module(_) | Value::EmbedderObject(_) => BUILTIN_STRING_MEMORY.object, + #[cfg(feature = "shared-array-buffer")] + Value::SharedArrayBuffer(_) => BUILTIN_STRING_MEMORY.object, #[cfg(feature = "array-buffer")] Value::ArrayBuffer(_) | Value::Int8Array(_) | diff --git a/nova_vm/src/heap.rs b/nova_vm/src/heap.rs index ae17882fc..26b6256ce 100644 --- a/nova_vm/src/heap.rs +++ b/nova_vm/src/heap.rs @@ -54,7 +54,6 @@ use crate::ecmascript::{ proxy::data::ProxyHeapData, regexp::RegExpHeapData, set::data::SetHeapData, - shared_array_buffer::data::SharedArrayBufferHeapData, weak_map::data::WeakMapHeapData, weak_ref::data::WeakRefHeapData, weak_set::data::WeakSetHeapData, @@ -68,6 +67,8 @@ use crate::ecmascript::{ #[cfg(feature = "date")] use crate::ecmascript::builtins::date::data::DateHeapData; +#[cfg(feature = "shared-array-buffer")] +use crate::ecmascript::builtins::shared_array_buffer::data::SharedArrayBufferHeapData; #[cfg(feature = "array-buffer")] use crate::ecmascript::builtins::{ data_view::data::DataViewHeapData, typed_array::data::TypedArrayHeapData, ArrayBufferHeapData, @@ -125,6 +126,7 @@ pub struct Heap { pub regexps: Vec>, pub sets: Vec>, pub set_iterators: Vec>, + #[cfg(feature = "shared-array-buffer")] pub shared_array_buffers: Vec>, pub symbols: Vec>, #[cfg(feature = "array-buffer")] @@ -219,6 +221,7 @@ impl Heap { scripts: Vec::with_capacity(1), sets: Vec::with_capacity(128), set_iterators: Vec::with_capacity(128), + #[cfg(feature = "shared-array-buffer")] shared_array_buffers: Vec::with_capacity(0), strings: Vec::with_capacity(1024), symbols: Vec::with_capacity(1024), diff --git a/nova_vm/src/heap/heap_bits.rs b/nova_vm/src/heap/heap_bits.rs index 5b3e8a4fb..c6f9e43de 100644 --- a/nova_vm/src/heap/heap_bits.rs +++ b/nova_vm/src/heap/heap_bits.rs @@ -12,6 +12,8 @@ use super::{ }; #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; +#[cfg(feature = "shared-array-buffer")] +use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer; #[cfg(feature = "array-buffer")] use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer}; use crate::ecmascript::{ @@ -40,7 +42,6 @@ use crate::ecmascript::{ proxy::Proxy, regexp::RegExp, set::Set, - shared_array_buffer::SharedArrayBuffer, weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, @@ -105,6 +106,7 @@ pub struct HeapBits { pub scripts: Box<[bool]>, pub sets: Box<[bool]>, pub set_iterators: Box<[bool]>, + #[cfg(feature = "shared-array-buffer")] pub shared_array_buffers: Box<[bool]>, pub strings: Box<[bool]>, pub symbols: Box<[bool]>, @@ -163,6 +165,7 @@ pub(crate) struct WorkQueues { pub scripts: Vec, pub sets: Vec, pub set_iterators: Vec, + #[cfg(feature = "shared-array-buffer")] pub shared_array_buffers: Vec, pub strings: Vec, pub symbols: Vec, @@ -221,6 +224,7 @@ impl HeapBits { let scripts = vec![false; heap.scripts.len()]; let sets = vec![false; heap.sets.len()]; let set_iterators = vec![false; heap.set_iterators.len()]; + #[cfg(feature = "shared-array-buffer")] 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()]; @@ -276,6 +280,7 @@ impl HeapBits { scripts: scripts.into_boxed_slice(), sets: sets.into_boxed_slice(), set_iterators: set_iterators.into_boxed_slice(), + #[cfg(feature = "shared-array-buffer")] shared_array_buffers: shared_array_buffers.into_boxed_slice(), strings: strings.into_boxed_slice(), symbols: symbols.into_boxed_slice(), @@ -339,6 +344,7 @@ impl WorkQueues { scripts: Vec::with_capacity(heap.scripts.len() / 4), sets: Vec::with_capacity(heap.sets.len() / 4), set_iterators: Vec::with_capacity(heap.set_iterators.len() / 4), + #[cfg(feature = "shared-array-buffer")] 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)), @@ -421,6 +427,7 @@ impl WorkQueues { scripts, sets, set_iterators, + #[cfg(feature = "shared-array-buffer")] shared_array_buffers, strings, symbols, @@ -439,6 +446,8 @@ impl WorkQueues { let array_buffers: &[bool; 0] = &[]; #[cfg(not(feature = "array-buffer"))] let typed_arrays: &[bool; 0] = &[]; + #[cfg(not(feature = "shared-array-buffer"))] + let shared_array_buffers: &[bool; 0] = &[]; array_buffers.is_empty() && arrays.is_empty() @@ -678,6 +687,7 @@ pub(crate) struct CompactionLists { pub scripts: CompactionList, pub sets: CompactionList, pub set_iterators: CompactionList, + #[cfg(feature = "shared-array-buffer")] pub shared_array_buffers: CompactionList, pub strings: CompactionList, pub symbols: CompactionList, @@ -749,6 +759,7 @@ impl CompactionLists { sets: CompactionList::from_mark_bits(&bits.sets), set_iterators: CompactionList::from_mark_bits(&bits.set_iterators), strings: CompactionList::from_mark_bits(&bits.strings), + #[cfg(feature = "shared-array-buffer")] shared_array_buffers: CompactionList::from_mark_bits(&bits.shared_array_buffers), symbols: CompactionList::from_mark_bits(&bits.symbols), #[cfg(feature = "array-buffer")] diff --git a/nova_vm/src/heap/heap_constants.rs b/nova_vm/src/heap/heap_constants.rs index a059b2a13..ce5aa640e 100644 --- a/nova_vm/src/heap/heap_constants.rs +++ b/nova_vm/src/heap/heap_constants.rs @@ -70,6 +70,7 @@ pub(crate) enum IntrinsicObjectIndexes { // Structured data #[cfg(feature = "array-buffer")] ArrayBufferPrototype, + #[cfg(feature = "shared-array-buffer")] SharedArrayBufferPrototype, #[cfg(feature = "array-buffer")] DataViewPrototype, @@ -191,6 +192,7 @@ pub(crate) enum IntrinsicConstructorIndexes { // Structured data #[cfg(feature = "array-buffer")] ArrayBuffer, + #[cfg(feature = "shared-array-buffer")] SharedArrayBuffer, #[cfg(feature = "array-buffer")] DataView, diff --git a/nova_vm/src/heap/heap_gc.rs b/nova_vm/src/heap/heap_gc.rs index 9a7e9a5e1..5a4d6a804 100644 --- a/nova_vm/src/heap/heap_gc.rs +++ b/nova_vm/src/heap/heap_gc.rs @@ -19,6 +19,8 @@ use super::{ }; #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; +#[cfg(feature = "shared-array-buffer")] +use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer; #[cfg(feature = "array-buffer")] use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer}; use crate::ecmascript::{ @@ -47,7 +49,6 @@ use crate::ecmascript::{ proxy::Proxy, regexp::RegExp, set::Set, - shared_array_buffer::SharedArrayBuffer, weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, @@ -143,6 +144,7 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { scripts, sets, set_iterators, + #[cfg(feature = "shared-array-buffer")] shared_array_buffers, strings, symbols, @@ -654,20 +656,23 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { set_iterators.get(index).mark_values(&mut queues); } }); - let mut shared_array_buffer_marks: Box<[SharedArrayBuffer]> = - queues.shared_array_buffers.drain(..).collect(); - shared_array_buffer_marks.sort(); - shared_array_buffer_marks.iter().for_each(|&idx| { - let index = idx.get_index(); - if let Some(marked) = bits.shared_array_buffers.get_mut(index) { - if *marked { - // Already marked, ignore - return; + #[cfg(feature = "shared-array-buffer")] + { + let mut shared_array_buffer_marks: Box<[SharedArrayBuffer]> = + queues.shared_array_buffers.drain(..).collect(); + shared_array_buffer_marks.sort(); + shared_array_buffer_marks.iter().for_each(|&idx| { + let index = idx.get_index(); + if let Some(marked) = bits.shared_array_buffers.get_mut(index) { + if *marked { + // Already marked, ignore + return; + } + *marked = true; + shared_array_buffers.get(index).mark_values(&mut queues); } - *marked = true; - shared_array_buffers.get(index).mark_values(&mut queues); - } - }); + }); + } let mut string_marks: Box<[HeapString]> = queues.strings.drain(..).collect(); string_marks.sort(); string_marks.iter().for_each(|&idx| { @@ -968,6 +973,7 @@ fn sweep(heap: &mut Heap, bits: &HeapBits, root_realms: &mut [Option; pub type RegExpIndex = BaseIndex; pub type SetIndex = BaseIndex; pub type SetIteratorIndex = BaseIndex; +#[cfg(feature = "shared-array-buffer")] pub type SharedArrayBufferIndex = BaseIndex; pub type StringIndex = BaseIndex; pub type SymbolIndex = BaseIndex;