Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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-map"]
math = []
json = ["sonic-rs"]
date = []
array-buffer = []
shared-array-buffer = []
weak-map = []
typescript = []

[build-dependencies]
Expand Down
1 change: 1 addition & 0 deletions nova_vm/src/ecmascript/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub(crate) mod structured_data;
pub(crate) mod text_processing;
#[cfg(feature = "array-buffer")]
pub(crate) mod typed_array;
#[cfg(feature = "weak-map")]
pub(crate) mod weak_map;
pub(crate) mod weak_ref;
pub(crate) mod weak_set;
Expand Down
1 change: 1 addition & 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,6 @@

pub(crate) mod map_objects;
pub(crate) mod set_objects;
#[cfg(feature = "weak-map")]
pub(crate) mod weak_map_objects;
pub(crate) mod weak_set_objects;
5 changes: 4 additions & 1 deletion nova_vm/src/ecmascript/builtins/ordinary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use crate::{
use super::date::data::DateHeapData;
#[cfg(feature = "shared-array-buffer")]
use super::shared_array_buffer::data::SharedArrayBufferHeapData;
#[cfg(feature = "weak-map")]
use super::weak_map::data::WeakMapHeapData;
use super::{
control_abstraction_objects::generator_objects::GeneratorHeapData,
error::ErrorHeapData,
Expand All @@ -42,7 +44,6 @@ use super::{
promise::data::PromiseHeapData,
regexp::RegExpHeapData,
set::data::SetHeapData,
weak_map::data::WeakMapHeapData,
weak_ref::data::WeakRefHeapData,
weak_set::data::WeakSetHeapData,
ArrayHeapData,
Expand Down Expand Up @@ -971,6 +972,7 @@ pub(crate) fn ordinary_object_create_with_intrinsics(
.heap
.create(TypedArrayHeapData::default())
.into_object(),
#[cfg(feature = "weak-map")]
ProtoIntrinsics::WeakMap => agent.heap.create(WeakMapHeapData::default()).into_object(),
ProtoIntrinsics::WeakRef => agent.heap.create(WeakRefHeapData::default()).into_object(),
ProtoIntrinsics::WeakSet => agent.heap.create(WeakSetHeapData::default()).into_object(),
Expand Down Expand Up @@ -1110,6 +1112,7 @@ 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-map")]
ProtoIntrinsics::WeakMap => Some(intrinsics.weak_map().into_function()),
ProtoIntrinsics::WeakRef => Some(intrinsics.weak_ref().into_function()),
ProtoIntrinsics::WeakSet => Some(intrinsics.weak_set().into_function()),
Expand Down
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 @@ -941,17 +941,19 @@ 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)?;

#[cfg(feature = "weak-map")]
{
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();
Expand Down
16 changes: 13 additions & 3 deletions nova_vm/src/ecmascript/execution/realm/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

use super::RealmIdentifier;
#[cfg(feature = "weak-map")]
use crate::ecmascript::builtins::keyed_collections::weak_map_objects::{
weak_map_constructor::WeakMapConstructor, weak_map_prototype::WeakMapPrototype,
};
#[cfg(feature = "date")]
use crate::ecmascript::builtins::numbers_and_dates::date_objects::{
date_constructor::DateConstructor, date_prototype::DatePrototype,
Expand Down Expand Up @@ -76,9 +80,6 @@ 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,
},
Expand Down Expand Up @@ -218,6 +219,7 @@ pub enum ProtoIntrinsics {
#[cfg(feature = "array-buffer")]
Uint8Array,
UriError,
#[cfg(feature = "weak-map")]
WeakMap,
WeakRef,
WeakSet,
Expand Down Expand Up @@ -304,7 +306,9 @@ impl Intrinsics {
SetPrototype::create_intrinsic(agent, realm);
SetConstructor::create_intrinsic(agent, realm);
SetIteratorPrototype::create_intrinsic(agent, realm);
#[cfg(feature = "weak-map")]
WeakMapPrototype::create_intrinsic(agent, realm);
#[cfg(feature = "weak-map")]
WeakMapConstructor::create_intrinsic(agent, realm);
WeakSetPrototype::create_intrinsic(agent, realm);
WeakSetConstructor::create_intrinsic(agent, realm);
Expand Down Expand Up @@ -410,6 +414,7 @@ impl Intrinsics {
ProtoIntrinsics::Uint32Array => self.uint32_array_prototype().into(),
#[cfg(feature = "array-buffer")]
ProtoIntrinsics::Uint8Array => self.uint8_array_prototype().into(),
#[cfg(feature = "weak-map")]
ProtoIntrinsics::WeakMap => self.weak_map_prototype().into(),
ProtoIntrinsics::WeakRef => self.weak_ref_prototype().into(),
ProtoIntrinsics::WeakSet => self.weak_set_prototype().into(),
Expand Down Expand Up @@ -1518,19 +1523,22 @@ impl Intrinsics {
}

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

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

#[cfg(feature = "weak-map")]
pub(crate) fn weak_map_base_object(&self) -> ObjectIndex {
IntrinsicConstructorIndexes::WeakMap.get_object_index(self.object_index_base)
}
Expand Down Expand Up @@ -1735,7 +1743,9 @@ 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-map")]
self.weak_map_prototype().mark_values(queues);
#[cfg(feature = "weak-map")]
self.weak_map().mark_values(queues);
self.weak_ref_prototype().mark_values(queues);
self.weak_ref().mark_values(queues);
Expand Down
Loading