diff --git a/nova_vm/Cargo.toml b/nova_vm/Cargo.toml index 5b86394ea..18a493bcf 100644 --- a/nova_vm/Cargo.toml +++ b/nova_vm/Cargo.toml @@ -23,6 +23,9 @@ sonic-rs = { workspace = true } wtf8 = { workspace = true } [features] +default = ["math"] +math = [] + typescript = [] [build-dependencies] diff --git a/nova_vm/src/ecmascript/builtins/numbers_and_dates.rs b/nova_vm/src/ecmascript/builtins/numbers_and_dates.rs index 20c6cf1c2..1a8d0c288 100644 --- a/nova_vm/src/ecmascript/builtins/numbers_and_dates.rs +++ b/nova_vm/src/ecmascript/builtins/numbers_and_dates.rs @@ -4,5 +4,6 @@ pub mod bigint_objects; pub mod date_objects; +#[cfg(feature = "math")] pub mod math_object; pub mod number_objects; diff --git a/nova_vm/src/ecmascript/execution/realm.rs b/nova_vm/src/ecmascript/execution/realm.rs index 6dfdf27cd..3da76e673 100644 --- a/nova_vm/src/ecmascript/execution/realm.rs +++ b/nova_vm/src/ecmascript/execution/realm.rs @@ -989,17 +989,19 @@ pub(crate) fn set_default_global_bindings( define_property_or_throw(agent, global, name, desc)?; // 19.4.3 Math - let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Math); - let value = agent.get_realm(realm_id).intrinsics().math(); - 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 = "math")] + { + let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Math); + let value = agent.get_realm(realm_id).intrinsics().math(); + 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.4 Reflect let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Reflect); let value = agent.get_realm(realm_id).intrinsics().reflect(); diff --git a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs index c5d302ebe..e9cf3c079 100644 --- a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs +++ b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs @@ -128,7 +128,6 @@ use crate::{ bigint_constructor::BigIntConstructor, bigint_prototype::BigIntPrototype, }, date_objects::{date_constructor::DateConstructor, date_prototype::DatePrototype}, - math_object::MathObject, number_objects::{ number_constructor::NumberConstructor, number_prototype::NumberPrototype, }, @@ -143,6 +142,9 @@ use crate::{ }, }; +#[cfg(feature = "math")] +use crate::ecmascript::builtins::numbers_and_dates::math_object::MathObject; + use super::RealmIdentifier; #[derive(Debug, Clone)] @@ -258,6 +260,7 @@ impl Intrinsics { NumberConstructor::create_intrinsic(agent, realm); BigIntPrototype::create_intrinsic(agent, realm); BigIntConstructor::create_intrinsic(agent, realm); + #[cfg(feature = "math")] MathObject::create_intrinsic(agent, realm); DatePrototype::create_intrinsic(agent, realm); DateConstructor::create_intrinsic(agent, realm); @@ -976,6 +979,7 @@ impl Intrinsics { .into() } + #[cfg(feature = "math")] /// %Math% pub(crate) fn math(&self) -> OrdinaryObject { IntrinsicObjectIndexes::MathObject @@ -1547,6 +1551,7 @@ impl HeapMarkAndSweep for Intrinsics { self.map_prototype().mark_values(queues); self.map().mark_values(queues); self.map_iterator_prototype().mark_values(queues); + #[cfg(feature = "math")] self.math().mark_values(queues); self.number_prototype().mark_values(queues); self.number().mark_values(queues);