Skip to content

Commit e278a86

Browse files
authored
feat: json as a feature (#430)
1 parent 018a5c1 commit e278a86

File tree

4 files changed

+23
-15
lines changed

4 files changed

+23
-15
lines changed

nova_vm/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ oxc_syntax = { workspace = true }
1919
rand = { workspace = true }
2020
ryu-js = { workspace = true }
2121
small_string = { path = "../small_string" }
22-
sonic-rs = { workspace = true }
22+
sonic-rs = { workspace = true, optional = true}
2323
wtf8 = { workspace = true }
2424

2525
[features]
26-
default = ["math"]
26+
default = ["math", "json"]
2727
math = []
28+
json = ["sonic-rs"]
2829

2930
typescript = []
3031

nova_vm/src/ecmascript/builtins/structured_data.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
pub(crate) mod array_buffer_objects;
66
pub(crate) mod atomics_object;
77
pub(crate) mod data_view_objects;
8+
#[cfg(feature = "json")]
89
pub(crate) mod json_object;
910
pub(crate) mod shared_array_buffer_objects;

nova_vm/src/ecmascript/execution/realm.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -977,16 +977,19 @@ pub(crate) fn set_default_global_bindings(
977977
define_property_or_throw(agent, global, name, desc)?;
978978

979979
// 19.4.2 JSON
980-
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.JSON);
981-
let value = agent.get_realm(realm_id).intrinsics().json();
982-
let desc = PropertyDescriptor {
983-
value: Some(value.into_value()),
984-
writable: Some(true),
985-
enumerable: Some(false),
986-
configurable: Some(true),
987-
..Default::default()
988-
};
989-
define_property_or_throw(agent, global, name, desc)?;
980+
#[cfg(feature = "json")]
981+
{
982+
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.JSON);
983+
let value = agent.get_realm(realm_id).intrinsics().json();
984+
let desc = PropertyDescriptor {
985+
value: Some(value.into_value()),
986+
writable: Some(true),
987+
enumerable: Some(false),
988+
configurable: Some(true),
989+
..Default::default()
990+
};
991+
define_property_or_throw(agent, global, name, desc)?;
992+
}
990993

991994
// 19.4.3 Math
992995
#[cfg(feature = "math")]

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ use crate::{
8282
data_view_constructor::DataViewConstructor,
8383
data_view_prototype::DataViewPrototype,
8484
},
85-
json_object::JSONObject,
8685
shared_array_buffer_objects::{
8786
shared_array_buffer_constructor::SharedArrayBufferConstructor,
8887
shared_array_buffer_prototype::SharedArrayBufferPrototype,
@@ -142,10 +141,11 @@ use crate::{
142141
},
143142
};
144143

144+
use super::RealmIdentifier;
145145
#[cfg(feature = "math")]
146146
use crate::ecmascript::builtins::numbers_and_dates::math_object::MathObject;
147-
148-
use super::RealmIdentifier;
147+
#[cfg(feature = "json")]
148+
use crate::ecmascript::builtins::structured_data::json_object::JSONObject;
149149

150150
#[derive(Debug, Clone)]
151151
pub(crate) struct Intrinsics {
@@ -294,6 +294,7 @@ impl Intrinsics {
294294
DataViewPrototype::create_intrinsic(agent, realm);
295295
DataViewConstructor::create_intrinsic(agent, realm);
296296
AtomicsObject::create_intrinsic(agent, realm);
297+
#[cfg(feature = "json")]
297298
JSONObject::create_intrinsic(agent, realm);
298299
WeakRefPrototype::create_intrinsic(agent, realm);
299300
WeakRefConstructor::create_intrinsic(agent, realm);
@@ -940,6 +941,7 @@ impl Intrinsics {
940941
.into()
941942
}
942943

944+
#[cfg(feature = "json")]
943945
/// %JSON%
944946
pub(crate) fn json(&self) -> OrdinaryObject {
945947
IntrinsicObjectIndexes::JSONObject
@@ -1546,6 +1548,7 @@ impl HeapMarkAndSweep for Intrinsics {
15461548
self.is_finite().mark_values(queues);
15471549
self.is_nan().mark_values(queues);
15481550
self.iterator_prototype().mark_values(queues);
1551+
#[cfg(feature = "json")]
15491552
self.json().mark_values(queues);
15501553
self.map_prototype_entries().mark_values(queues);
15511554
self.map_prototype().mark_values(queues);

0 commit comments

Comments
 (0)