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: 2 additions & 1 deletion nova_vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ sonic-rs = { workspace = true, optional = true }
wtf8 = { workspace = true }

[features]
default = ["math", "json", "date", "array-buffer", "shared-array-buffer"]
default = ["math", "json", "date", "array-buffer", "shared-array-buffer", "weak-refs"]
math = []
json = ["sonic-rs"]
date = []
array-buffer = []
shared-array-buffer = []
weak-refs = []
typescript = []

[build-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions nova_vm/src/ecmascript/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ pub(crate) mod structured_data;
pub(crate) mod text_processing;
#[cfg(feature = "array-buffer")]
pub(crate) mod typed_array;
#[cfg(feature = "weak-refs")]
pub(crate) mod weak_map;
#[cfg(feature = "weak-refs")]
pub(crate) mod weak_ref;
#[cfg(feature = "weak-refs")]
pub(crate) mod weak_set;

pub(crate) use arguments::*;
Expand Down
2 changes: 2 additions & 0 deletions nova_vm/src/ecmascript/builtins/keyed_collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

pub(crate) mod map_objects;
pub(crate) mod set_objects;
#[cfg(feature = "weak-refs")]
pub(crate) mod weak_map_objects;
#[cfg(feature = "weak-refs")]
pub(crate) mod weak_set_objects;
1 change: 1 addition & 0 deletions nova_vm/src/ecmascript/builtins/managing_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

pub(crate) mod finalization_registry_objects;
#[cfg(feature = "weak-refs")]
pub(crate) mod weak_ref_objects;
14 changes: 11 additions & 3 deletions nova_vm/src/ecmascript/builtins/ordinary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ use super::{
promise::data::PromiseHeapData,
regexp::RegExpHeapData,
set::data::SetHeapData,
weak_map::data::WeakMapHeapData,
weak_ref::data::WeakRefHeapData,
weak_set::data::WeakSetHeapData,
ArrayHeapData,
};
#[cfg(feature = "array-buffer")]
use super::{
data_view::data::DataViewHeapData, typed_array::data::TypedArrayHeapData, ArrayBufferHeapData,
};
#[cfg(feature = "weak-refs")]
use super::{
weak_map::data::WeakMapHeapData, weak_ref::data::WeakRefHeapData,
weak_set::data::WeakSetHeapData,
};

impl Index<OrdinaryObject> for Agent {
type Output = ObjectHeapData;
Expand Down Expand Up @@ -971,8 +973,11 @@ pub(crate) fn ordinary_object_create_with_intrinsics(
.heap
.create(TypedArrayHeapData::default())
.into_object(),
#[cfg(feature = "weak-refs")]
ProtoIntrinsics::WeakMap => agent.heap.create(WeakMapHeapData::default()).into_object(),
#[cfg(feature = "weak-refs")]
ProtoIntrinsics::WeakRef => agent.heap.create(WeakRefHeapData::default()).into_object(),
#[cfg(feature = "weak-refs")]
ProtoIntrinsics::WeakSet => agent.heap.create(WeakSetHeapData::default()).into_object(),
};

Expand Down Expand Up @@ -1110,8 +1115,11 @@ pub(crate) fn get_prototype_from_constructor(
#[cfg(feature = "array-buffer")]
ProtoIntrinsics::Uint8Array => Some(intrinsics.uint8_array().into_function()),
ProtoIntrinsics::UriError => Some(intrinsics.uri_error().into_function()),
#[cfg(feature = "weak-refs")]
ProtoIntrinsics::WeakMap => Some(intrinsics.weak_map().into_function()),
#[cfg(feature = "weak-refs")]
ProtoIntrinsics::WeakRef => Some(intrinsics.weak_ref().into_function()),
#[cfg(feature = "weak-refs")]
ProtoIntrinsics::WeakSet => Some(intrinsics.weak_set().into_function()),
};
if Some(constructor) == intrinsic_constructor {
Expand Down
68 changes: 35 additions & 33 deletions nova_vm/src/ecmascript/execution/realm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,40 +941,42 @@ pub(crate) fn set_default_global_bindings(
define_property_or_throw(agent, global, name, desc)?;

// 19.3.38 WeakMap ( . . . )
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.WeakMap);
let value = agent.get_realm(realm_id).intrinsics().weak_map();
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.3.39 WeakRef ( . . . )
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.WeakRef);
let value = agent.get_realm(realm_id).intrinsics().weak_ref();
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 = "weak-refs")]
{
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.WeakMap);
let value = agent.get_realm(realm_id).intrinsics().weak_map();
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.3.39 WeakRef ( . . . )
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.WeakRef);
let value = agent.get_realm(realm_id).intrinsics().weak_ref();
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.3.40 WeakSet ( . . . )
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.WeakSet);
let value = agent.get_realm(realm_id).intrinsics().weak_set();
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.3.40 WeakSet ( . . . )
let name = PropertyKey::from(BUILTIN_STRING_MEMORY.WeakSet);
let value = agent.get_realm(realm_id).intrinsics().weak_set();
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 Other Properties of the Global Object
Expand Down
57 changes: 43 additions & 14 deletions nova_vm/src/ecmascript/execution/realm/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use super::RealmIdentifier;
#[cfg(feature = "weak-refs")]
use crate::ecmascript::builtins::keyed_collections::{
weak_map_objects::{
weak_map_constructor::WeakMapConstructor, weak_map_prototype::WeakMapPrototype,
},
weak_set_objects::{
weak_set_constructor::WeakSetConstructor, weak_set_prototype::WeakSetPrototype,
},
};
#[cfg(feature = "weak-refs")]
use crate::ecmascript::builtins::managing_memory::weak_ref_objects::{
weak_ref_constructor::WeakRefConstructor, weak_ref_prototype::WeakRefPrototype,
};
#[cfg(feature = "date")]
use crate::ecmascript::builtins::numbers_and_dates::date_objects::{
date_constructor::DateConstructor, date_prototype::DatePrototype,
Expand Down Expand Up @@ -76,21 +89,10 @@ use crate::{
set_iterator_objects::set_iterator_prototype::SetIteratorPrototype,
set_prototype::SetPrototype,
},
weak_map_objects::{
weak_map_constructor::WeakMapConstructor, weak_map_prototype::WeakMapPrototype,
},
weak_set_objects::{
weak_set_constructor::WeakSetConstructor, weak_set_prototype::WeakSetPrototype,
},
},
managing_memory::{
finalization_registry_objects::{
finalization_registry_constructor::FinalizationRegistryConstructor,
finalization_registry_prototype::FinalizationRegistryPrototype,
},
weak_ref_objects::{
weak_ref_constructor::WeakRefConstructor, weak_ref_prototype::WeakRefPrototype,
},
managing_memory::finalization_registry_objects::{
finalization_registry_constructor::FinalizationRegistryConstructor,
finalization_registry_prototype::FinalizationRegistryPrototype,
},
primitive_objects::PrimitiveObject,
reflection::{proxy_constructor::ProxyConstructor, reflect_object::ReflectObject},
Expand Down Expand Up @@ -218,8 +220,11 @@ pub enum ProtoIntrinsics {
#[cfg(feature = "array-buffer")]
Uint8Array,
UriError,
#[cfg(feature = "weak-refs")]
WeakMap,
#[cfg(feature = "weak-refs")]
WeakRef,
#[cfg(feature = "weak-refs")]
WeakSet,
}

Expand Down Expand Up @@ -304,9 +309,13 @@ impl Intrinsics {
SetPrototype::create_intrinsic(agent, realm);
SetConstructor::create_intrinsic(agent, realm);
SetIteratorPrototype::create_intrinsic(agent, realm);
#[cfg(feature = "weak-refs")]
WeakMapPrototype::create_intrinsic(agent, realm);
#[cfg(feature = "weak-refs")]
WeakMapConstructor::create_intrinsic(agent, realm);
#[cfg(feature = "weak-refs")]
WeakSetPrototype::create_intrinsic(agent, realm);
#[cfg(feature = "weak-refs")]
WeakSetConstructor::create_intrinsic(agent, realm);
#[cfg(feature = "array-buffer")]
ArrayBufferPrototype::create_intrinsic(agent, realm);
Expand All @@ -323,7 +332,9 @@ impl Intrinsics {
AtomicsObject::create_intrinsic(agent, realm);
#[cfg(feature = "json")]
JSONObject::create_intrinsic(agent, realm);
#[cfg(feature = "weak-refs")]
WeakRefPrototype::create_intrinsic(agent, realm);
#[cfg(feature = "weak-refs")]
WeakRefConstructor::create_intrinsic(agent, realm);
FinalizationRegistryPrototype::create_intrinsic(agent, realm);
FinalizationRegistryConstructor::create_intrinsic(agent, realm);
Expand Down Expand Up @@ -410,8 +421,11 @@ impl Intrinsics {
ProtoIntrinsics::Uint32Array => self.uint32_array_prototype().into(),
#[cfg(feature = "array-buffer")]
ProtoIntrinsics::Uint8Array => self.uint8_array_prototype().into(),
#[cfg(feature = "weak-refs")]
ProtoIntrinsics::WeakMap => self.weak_map_prototype().into(),
#[cfg(feature = "weak-refs")]
ProtoIntrinsics::WeakRef => self.weak_ref_prototype().into(),
#[cfg(feature = "weak-refs")]
ProtoIntrinsics::WeakSet => self.weak_set_prototype().into(),
}
}
Expand Down Expand Up @@ -1518,55 +1532,64 @@ impl Intrinsics {
}

/// %WeakMap.prototype%
#[cfg(feature = "weak-refs")]
pub(crate) fn weak_map_prototype(&self) -> OrdinaryObject {
IntrinsicObjectIndexes::WeakMapPrototype
.get_object_index(self.object_index_base)
.into()
}

/// %WeakMap%
#[cfg(feature = "weak-refs")]
pub(crate) fn weak_map(&self) -> BuiltinFunction {
IntrinsicConstructorIndexes::WeakMap
.get_builtin_function_index(self.builtin_function_index_base)
.into()
}

#[cfg(feature = "weak-refs")]
pub(crate) fn weak_map_base_object(&self) -> ObjectIndex {
IntrinsicConstructorIndexes::WeakMap.get_object_index(self.object_index_base)
}

/// %WeakRef.prototype%
#[cfg(feature = "weak-refs")]
pub(crate) fn weak_ref_prototype(&self) -> OrdinaryObject {
IntrinsicObjectIndexes::WeakRefPrototype
.get_object_index(self.object_index_base)
.into()
}

/// %WeakRef%
#[cfg(feature = "weak-refs")]
pub(crate) fn weak_ref(&self) -> BuiltinFunction {
IntrinsicConstructorIndexes::WeakRef
.get_builtin_function_index(self.builtin_function_index_base)
.into()
}

#[cfg(feature = "weak-refs")]
pub(crate) fn weak_ref_base_object(&self) -> ObjectIndex {
IntrinsicConstructorIndexes::WeakRef.get_object_index(self.object_index_base)
}

/// %WeakSet.prototype%
#[cfg(feature = "weak-refs")]
pub(crate) fn weak_set_prototype(&self) -> OrdinaryObject {
IntrinsicObjectIndexes::WeakSetPrototype
.get_object_index(self.object_index_base)
.into()
}

/// %WeakSet%
#[cfg(feature = "weak-refs")]
pub(crate) fn weak_set(&self) -> BuiltinFunction {
IntrinsicConstructorIndexes::WeakSet
.get_builtin_function_index(self.builtin_function_index_base)
.into()
}

#[cfg(feature = "weak-refs")]
pub(crate) fn weak_set_base_object(&self) -> ObjectIndex {
IntrinsicConstructorIndexes::WeakSet.get_object_index(self.object_index_base)
}
Expand Down Expand Up @@ -1735,11 +1758,17 @@ impl HeapMarkAndSweep for Intrinsics {
self.unescape().mark_values(queues);
self.uri_error_prototype().mark_values(queues);
self.uri_error().mark_values(queues);
#[cfg(feature = "weak-refs")]
self.weak_map_prototype().mark_values(queues);
#[cfg(feature = "weak-refs")]
self.weak_map().mark_values(queues);
#[cfg(feature = "weak-refs")]
self.weak_ref_prototype().mark_values(queues);
#[cfg(feature = "weak-refs")]
self.weak_ref().mark_values(queues);
#[cfg(feature = "weak-refs")]
self.weak_set_prototype().mark_values(queues);
#[cfg(feature = "weak-refs")]
self.weak_set().mark_values(queues);
}

Expand Down
Loading