Skip to content

Commit 018a5c1

Browse files
authored
feat: ability to disable math (#429)
1 parent 62d5679 commit 018a5c1

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

nova_vm/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ sonic-rs = { workspace = true }
2323
wtf8 = { workspace = true }
2424

2525
[features]
26+
default = ["math"]
27+
math = []
28+
2629
typescript = []
2730

2831
[build-dependencies]

nova_vm/src/ecmascript/builtins/numbers_and_dates.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44

55
pub mod bigint_objects;
66
pub mod date_objects;
7+
#[cfg(feature = "math")]
78
pub mod math_object;
89
pub mod number_objects;

nova_vm/src/ecmascript/execution/realm.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -989,17 +989,19 @@ pub(crate) fn set_default_global_bindings(
989989
define_property_or_throw(agent, global, name, desc)?;
990990

991991
// 19.4.3 Math
992-
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Math);
993-
let value = agent.get_realm(realm_id).intrinsics().math();
994-
let desc = PropertyDescriptor {
995-
value: Some(value.into_value()),
996-
writable: Some(true),
997-
enumerable: Some(false),
998-
configurable: Some(true),
999-
..Default::default()
1000-
};
1001-
define_property_or_throw(agent, global, name, desc)?;
1002-
992+
#[cfg(feature = "math")]
993+
{
994+
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Math);
995+
let value = agent.get_realm(realm_id).intrinsics().math();
996+
let desc = PropertyDescriptor {
997+
value: Some(value.into_value()),
998+
writable: Some(true),
999+
enumerable: Some(false),
1000+
configurable: Some(true),
1001+
..Default::default()
1002+
};
1003+
define_property_or_throw(agent, global, name, desc)?;
1004+
}
10031005
// 19.4.4 Reflect
10041006
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.Reflect);
10051007
let value = agent.get_realm(realm_id).intrinsics().reflect();

nova_vm/src/ecmascript/execution/realm/intrinsics.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ use crate::{
128128
bigint_constructor::BigIntConstructor, bigint_prototype::BigIntPrototype,
129129
},
130130
date_objects::{date_constructor::DateConstructor, date_prototype::DatePrototype},
131-
math_object::MathObject,
132131
number_objects::{
133132
number_constructor::NumberConstructor, number_prototype::NumberPrototype,
134133
},
@@ -143,6 +142,9 @@ use crate::{
143142
},
144143
};
145144

145+
#[cfg(feature = "math")]
146+
use crate::ecmascript::builtins::numbers_and_dates::math_object::MathObject;
147+
146148
use super::RealmIdentifier;
147149

148150
#[derive(Debug, Clone)]
@@ -258,6 +260,7 @@ impl Intrinsics {
258260
NumberConstructor::create_intrinsic(agent, realm);
259261
BigIntPrototype::create_intrinsic(agent, realm);
260262
BigIntConstructor::create_intrinsic(agent, realm);
263+
#[cfg(feature = "math")]
261264
MathObject::create_intrinsic(agent, realm);
262265
DatePrototype::create_intrinsic(agent, realm);
263266
DateConstructor::create_intrinsic(agent, realm);
@@ -976,6 +979,7 @@ impl Intrinsics {
976979
.into()
977980
}
978981

982+
#[cfg(feature = "math")]
979983
/// %Math%
980984
pub(crate) fn math(&self) -> OrdinaryObject {
981985
IntrinsicObjectIndexes::MathObject
@@ -1547,6 +1551,7 @@ impl HeapMarkAndSweep for Intrinsics {
15471551
self.map_prototype().mark_values(queues);
15481552
self.map().mark_values(queues);
15491553
self.map_iterator_prototype().mark_values(queues);
1554+
#[cfg(feature = "math")]
15501555
self.math().mark_values(queues);
15511556
self.number_prototype().mark_values(queues);
15521557
self.number().mark_values(queues);

0 commit comments

Comments
 (0)