diff --git a/nova_vm/Cargo.toml b/nova_vm/Cargo.toml index d2433b3dd..582fbebb2 100644 --- a/nova_vm/Cargo.toml +++ b/nova_vm/Cargo.toml @@ -24,13 +24,14 @@ unicode-normalization = { workspace = true } wtf8 = { workspace = true } [features] -default = ["math", "json", "date", "array-buffer", "shared-array-buffer", "weak-refs"] +default = ["math", "json", "date", "array-buffer", "shared-array-buffer", "weak-refs", "atomics"] math = [] json = ["sonic-rs"] date = [] array-buffer = [] shared-array-buffer = [] weak-refs = [] +atomics = ["array-buffer", "shared-array-buffer"] typescript = [] [build-dependencies] diff --git a/nova_vm/src/ecmascript/builtins/structured_data.rs b/nova_vm/src/ecmascript/builtins/structured_data.rs index 7f09afe82..031e9408d 100644 --- a/nova_vm/src/ecmascript/builtins/structured_data.rs +++ b/nova_vm/src/ecmascript/builtins/structured_data.rs @@ -4,6 +4,7 @@ #[cfg(feature = "array-buffer")] pub(crate) mod array_buffer_objects; +#[cfg(feature = "atomics")] pub(crate) mod atomics_object; #[cfg(feature = "array-buffer")] 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 1f7f4a8d8..5fef330bf 100644 --- a/nova_vm/src/ecmascript/execution/realm.rs +++ b/nova_vm/src/ecmascript/execution/realm.rs @@ -982,17 +982,19 @@ pub(crate) fn set_default_global_bindings( // 19.4 Other Properties of the Global Object { // 19.4.1 Atomics - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Atomics); - let value = agent.get_realm(realm_id).intrinsics().atomics(); - 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 = "atomics")] + { + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Atomics); + let value = agent.get_realm(realm_id).intrinsics().atomics(); + 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.4.2 JSON #[cfg(feature = "json")] { diff --git a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs index ecd2e83bd..39b3cf52a 100644 --- a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs +++ b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs @@ -22,6 +22,8 @@ use crate::ecmascript::builtins::numbers_and_dates::date_objects::{ }; #[cfg(feature = "math")] use crate::ecmascript::builtins::numbers_and_dates::math_object::MathObject; +#[cfg(feature = "atomics")] +use crate::ecmascript::builtins::structured_data::atomics_object::AtomicsObject; #[cfg(feature = "json")] use crate::ecmascript::builtins::structured_data::json_object::JSONObject; #[cfg(feature = "shared-array-buffer")] @@ -96,7 +98,6 @@ use crate::{ }, primitive_objects::PrimitiveObject, reflection::{proxy_constructor::ProxyConstructor, reflect_object::ReflectObject}, - structured_data::atomics_object::AtomicsObject, text_processing::{ regexp_objects::{ regexp_constructor::RegExpConstructor, regexp_prototype::RegExpPrototype, @@ -149,7 +150,6 @@ use crate::{ IntrinsicObjectIndexes, IntrinsicPrimitiveObjectIndexes, WorkQueues, }, }; - #[derive(Debug, Clone)] pub(crate) struct Intrinsics { pub(crate) object_index_base: ObjectIndex, @@ -329,6 +329,7 @@ impl Intrinsics { DataViewPrototype::create_intrinsic(agent, realm); #[cfg(feature = "array-buffer")] DataViewConstructor::create_intrinsic(agent, realm); + #[cfg(feature = "atomics")] AtomicsObject::create_intrinsic(agent, realm); #[cfg(feature = "json")] JSONObject::create_intrinsic(agent, realm); @@ -612,6 +613,7 @@ impl Intrinsics { } /// %Atomics% + #[cfg(feature = "atomics")] pub(crate) fn atomics(&self) -> OrdinaryObject { IntrinsicObjectIndexes::AtomicsObject .get_object_index(self.object_index_base) @@ -1618,6 +1620,7 @@ impl HeapMarkAndSweep for Intrinsics { self.async_generator_function().mark_values(queues); self.async_generator_prototype().mark_values(queues); self.async_iterator_prototype().mark_values(queues); + #[cfg(feature = "atomics")] self.atomics().mark_values(queues); self.big_int_prototype().mark_values(queues); self.big_int().mark_values(queues); diff --git a/nova_vm/src/heap/heap_constants.rs b/nova_vm/src/heap/heap_constants.rs index ce5aa640e..f93e6fd95 100644 --- a/nova_vm/src/heap/heap_constants.rs +++ b/nova_vm/src/heap/heap_constants.rs @@ -74,6 +74,7 @@ pub(crate) enum IntrinsicObjectIndexes { SharedArrayBufferPrototype, #[cfg(feature = "array-buffer")] DataViewPrototype, + #[cfg(feature = "atomics")] AtomicsObject, JSONObject,