Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nova_vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ sonic-rs = { workspace = true }
wtf8 = { workspace = true }

[features]
default = ["math"]
math = []

typescript = []

[build-dependencies]
Expand Down
1 change: 1 addition & 0 deletions nova_vm/src/ecmascript/builtins/numbers_and_dates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

pub mod bigint_objects;
pub mod date_objects;
#[cfg(feature = "math")]
pub mod math_object;
pub mod number_objects;
24 changes: 13 additions & 11 deletions nova_vm/src/ecmascript/execution/realm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion nova_vm/src/ecmascript/execution/realm/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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)]
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -976,6 +979,7 @@ impl Intrinsics {
.into()
}

#[cfg(feature = "math")]
/// %Math%
pub(crate) fn math(&self) -> OrdinaryObject {
IntrinsicObjectIndexes::MathObject
Expand Down Expand Up @@ -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);
Expand Down