From 2339177245ab1fd2dadb86aab8f1565fb36842e6 Mon Sep 17 00:00:00 2001 From: Dean Srebnik <49134864+load1n9@users.noreply.github.com> Date: Sun, 13 Oct 2024 19:03:01 -0400 Subject: [PATCH 1/4] feat: weak map as feature --- nova_vm/Cargo.toml | 3 +- nova_vm/src/ecmascript/builtins.rs | 1 + .../ecmascript/builtins/keyed_collections.rs | 1 + nova_vm/src/ecmascript/builtins/ordinary.rs | 5 +- nova_vm/src/ecmascript/execution/realm.rs | 24 +++++----- .../ecmascript/execution/realm/intrinsics.rs | 16 +++++-- .../src/ecmascript/types/language/object.rs | 32 +++++++++++-- .../src/ecmascript/types/language/value.rs | 9 +++- nova_vm/src/engine/bytecode/vm.rs | 3 +- nova_vm/src/heap.rs | 46 ++++++++++--------- nova_vm/src/heap/heap_bits.rs | 13 +++++- nova_vm/src/heap/heap_gc.rs | 33 +++++++------ nova_vm/src/heap/indexes.rs | 4 +- 13 files changed, 131 insertions(+), 59 deletions(-) diff --git a/nova_vm/Cargo.toml b/nova_vm/Cargo.toml index c2abba55b..0deb2a175 100644 --- a/nova_vm/Cargo.toml +++ b/nova_vm/Cargo.toml @@ -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] diff --git a/nova_vm/src/ecmascript/builtins.rs b/nova_vm/src/ecmascript/builtins.rs index 1042f8a0f..1ce6aa05e 100644 --- a/nova_vm/src/ecmascript/builtins.rs +++ b/nova_vm/src/ecmascript/builtins.rs @@ -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; diff --git a/nova_vm/src/ecmascript/builtins/keyed_collections.rs b/nova_vm/src/ecmascript/builtins/keyed_collections.rs index c1c82987a..51773442a 100644 --- a/nova_vm/src/ecmascript/builtins/keyed_collections.rs +++ b/nova_vm/src/ecmascript/builtins/keyed_collections.rs @@ -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; diff --git a/nova_vm/src/ecmascript/builtins/ordinary.rs b/nova_vm/src/ecmascript/builtins/ordinary.rs index 1a223535f..4b8607210 100644 --- a/nova_vm/src/ecmascript/builtins/ordinary.rs +++ b/nova_vm/src/ecmascript/builtins/ordinary.rs @@ -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, @@ -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, @@ -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(), @@ -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()), diff --git a/nova_vm/src/ecmascript/execution/realm.rs b/nova_vm/src/ecmascript/execution/realm.rs index 352bd814c..1f1b9ad8c 100644 --- a/nova_vm/src/ecmascript/execution/realm.rs +++ b/nova_vm/src/ecmascript/execution/realm.rs @@ -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(); diff --git a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs index 94211bc0e..6f6bab25f 100644 --- a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs +++ b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs @@ -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, @@ -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, }, @@ -218,6 +219,7 @@ pub enum ProtoIntrinsics { #[cfg(feature = "array-buffer")] Uint8Array, UriError, + #[cfg(feature = "weak-map")] WeakMap, WeakRef, WeakSet, @@ -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); @@ -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(), @@ -1518,6 +1523,7 @@ 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) @@ -1525,12 +1531,14 @@ impl Intrinsics { } /// %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) } @@ -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); diff --git a/nova_vm/src/ecmascript/types/language/object.rs b/nova_vm/src/ecmascript/types/language/object.rs index db8a1b97b..594dab094 100644 --- a/nova_vm/src/ecmascript/types/language/object.rs +++ b/nova_vm/src/ecmascript/types/language/object.rs @@ -15,6 +15,8 @@ use std::hash::Hash; use super::value::DATE_DISCRIMINANT; #[cfg(feature = "shared-array-buffer")] use super::value::SHARED_ARRAY_BUFFER_DISCRIMINANT; +#[cfg(feature = "weak-map")] +use super::value::WEAK_MAP_DISCRIMINANT; #[cfg(feature = "array-buffer")] use super::value::{ ARRAY_BUFFER_DISCRIMINANT, BIGINT_64_ARRAY_DISCRIMINANT, BIGUINT_64_ARRAY_DISCRIMINANT, @@ -35,16 +37,17 @@ use super::{ FINALIZATION_REGISTRY_DISCRIMINANT, GENERATOR_DISCRIMINANT, ITERATOR_DISCRIMINANT, MAP_DISCRIMINANT, MAP_ITERATOR_DISCRIMINANT, MODULE_DISCRIMINANT, OBJECT_DISCRIMINANT, PRIMITIVE_OBJECT_DISCRIMINANT, PROMISE_DISCRIMINANT, PROXY_DISCRIMINANT, - REGEXP_DISCRIMINANT, SET_DISCRIMINANT, SET_ITERATOR_DISCRIMINANT, WEAK_MAP_DISCRIMINANT, - WEAK_REF_DISCRIMINANT, WEAK_SET_DISCRIMINANT, + REGEXP_DISCRIMINANT, SET_DISCRIMINANT, SET_ITERATOR_DISCRIMINANT, WEAK_REF_DISCRIMINANT, + WEAK_SET_DISCRIMINANT, }, Function, IntoValue, Value, }; - #[cfg(feature = "date")] use crate::ecmascript::builtins::date::Date; #[cfg(feature = "shared-array-buffer")] use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer; +#[cfg(feature = "weak-map")] +use crate::ecmascript::builtins::weak_map::WeakMap; #[cfg(feature = "array-buffer")] use crate::{ ecmascript::builtins::{data_view::DataView, typed_array::TypedArray, ArrayBuffer}, @@ -73,7 +76,6 @@ use crate::{ proxy::Proxy, regexp::RegExp, set::Set, - weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, ArgumentsList, Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, @@ -129,6 +131,7 @@ pub enum Object { Set(Set) = SET_DISCRIMINANT, #[cfg(feature = "shared-array-buffer")] SharedArrayBuffer(SharedArrayBuffer) = SHARED_ARRAY_BUFFER_DISCRIMINANT, + #[cfg(feature = "weak-map")] WeakMap(WeakMap) = WEAK_MAP_DISCRIMINANT, WeakRef(WeakRef) = WEAK_REF_DISCRIMINANT, WeakSet(WeakSet) = WEAK_SET_DISCRIMINANT, @@ -200,6 +203,7 @@ impl IntoValue for Object { Object::Set(data) => Value::Set(data), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => Value::SharedArrayBuffer(data), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => Value::WeakMap(data), Object::WeakRef(data) => Value::WeakRef(data), Object::WeakSet(data) => Value::WeakSet(data), @@ -391,6 +395,7 @@ impl From for Value { Object::Set(data) => Value::Set(data), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => Value::SharedArrayBuffer(data), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => Value::WeakMap(data), Object::WeakRef(data) => Value::WeakRef(data), Object::WeakSet(data) => Value::WeakSet(data), @@ -473,6 +478,7 @@ impl TryFrom for Object { Value::Set(data) => Ok(Object::Set(data)), #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(data) => Ok(Object::SharedArrayBuffer(data)), + #[cfg(feature = "weak-map")] Value::WeakMap(data) => Ok(Object::WeakMap(data)), Value::WeakRef(data) => Ok(Object::WeakRef(data)), Value::WeakSet(data) => Ok(Object::WeakSet(data)), @@ -552,6 +558,7 @@ impl Hash for Object { Object::Set(data) => data.get_index().hash(state), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.get_index().hash(state), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.get_index().hash(state), Object::WeakRef(data) => data.get_index().hash(state), Object::WeakSet(data) => data.get_index().hash(state), @@ -632,6 +639,7 @@ impl InternalSlots for Object { Object::Set(data) => data.internal_extensible(agent), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_extensible(agent), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_extensible(agent), Object::WeakRef(data) => data.internal_extensible(agent), Object::WeakSet(data) => data.internal_extensible(agent), @@ -706,6 +714,7 @@ impl InternalSlots for Object { Object::Set(data) => data.internal_set_extensible(agent, value), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_set_extensible(agent, value), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_set_extensible(agent, value), Object::WeakRef(data) => data.internal_set_extensible(agent, value), Object::WeakSet(data) => data.internal_set_extensible(agent, value), @@ -794,6 +803,7 @@ impl InternalSlots for Object { Object::Set(data) => data.internal_prototype(agent), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_prototype(agent), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_prototype(agent), Object::WeakRef(data) => data.internal_prototype(agent), Object::WeakSet(data) => data.internal_prototype(agent), @@ -870,6 +880,7 @@ impl InternalSlots for Object { Object::Set(data) => data.internal_set_prototype(agent, prototype), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_set_prototype(agent, prototype), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_set_prototype(agent, prototype), Object::WeakRef(data) => data.internal_set_prototype(agent, prototype), Object::WeakSet(data) => data.internal_set_prototype(agent, prototype), @@ -960,6 +971,7 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_get_prototype_of(agent), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_get_prototype_of(agent), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_get_prototype_of(agent), Object::WeakRef(data) => data.internal_get_prototype_of(agent), Object::WeakSet(data) => data.internal_get_prototype_of(agent), @@ -1054,6 +1066,7 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_set_prototype_of(agent, prototype), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_set_prototype_of(agent, prototype), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_set_prototype_of(agent, prototype), Object::WeakRef(data) => data.internal_set_prototype_of(agent, prototype), Object::WeakSet(data) => data.internal_set_prototype_of(agent, prototype), @@ -1142,6 +1155,7 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_is_extensible(agent), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_is_extensible(agent), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_is_extensible(agent), Object::WeakRef(data) => data.internal_is_extensible(agent), Object::WeakSet(data) => data.internal_is_extensible(agent), @@ -1224,6 +1238,7 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_prevent_extensions(agent), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_prevent_extensions(agent), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_prevent_extensions(agent), Object::WeakRef(data) => data.internal_prevent_extensions(agent), Object::WeakSet(data) => data.internal_prevent_extensions(agent), @@ -1322,6 +1337,7 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_get_own_property(agent, property_key), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_get_own_property(agent, property_key), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_get_own_property(agent, property_key), Object::WeakRef(data) => data.internal_get_own_property(agent, property_key), Object::WeakSet(data) => data.internal_get_own_property(agent, property_key), @@ -1455,6 +1471,7 @@ impl InternalMethods for Object { Object::SharedArrayBuffer(data) => { data.internal_define_own_property(agent, property_key, property_descriptor) } + #[cfg(feature = "weak-map")] Object::WeakMap(data) => { data.internal_define_own_property(agent, property_key, property_descriptor) } @@ -1566,6 +1583,7 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_has_property(agent, property_key), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_has_property(agent, property_key), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_has_property(agent, property_key), Object::WeakRef(data) => data.internal_has_property(agent, property_key), Object::WeakSet(data) => data.internal_has_property(agent, property_key), @@ -1663,6 +1681,7 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_get(agent, property_key, receiver), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_get(agent, property_key, receiver), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_get(agent, property_key, receiver), Object::WeakRef(data) => data.internal_get(agent, property_key, receiver), Object::WeakSet(data) => data.internal_get(agent, property_key, receiver), @@ -1771,6 +1790,7 @@ impl InternalMethods for Object { Object::SharedArrayBuffer(data) => { data.internal_set(agent, property_key, value, receiver) } + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_set(agent, property_key, value, receiver), Object::WeakRef(data) => data.internal_set(agent, property_key, value, receiver), Object::WeakSet(data) => data.internal_set(agent, property_key, value, receiver), @@ -1864,6 +1884,7 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_delete(agent, property_key), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_delete(agent, property_key), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_delete(agent, property_key), Object::WeakRef(data) => data.internal_delete(agent, property_key), Object::WeakSet(data) => data.internal_delete(agent, property_key), @@ -1952,6 +1973,7 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_own_property_keys(agent), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_own_property_keys(agent), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.internal_own_property_keys(agent), Object::WeakRef(data) => data.internal_own_property_keys(agent), Object::WeakSet(data) => data.internal_own_property_keys(agent), @@ -2079,6 +2101,7 @@ impl HeapMarkAndSweep for Object { Object::Set(data) => data.mark_values(queues), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.mark_values(queues), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.mark_values(queues), Object::WeakRef(data) => data.mark_values(queues), Object::WeakSet(data) => data.mark_values(queues), @@ -2145,6 +2168,7 @@ impl HeapMarkAndSweep for Object { Object::Set(data) => data.sweep_values(compactions), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.sweep_values(compactions), + #[cfg(feature = "weak-map")] Object::WeakMap(data) => data.sweep_values(compactions), Object::WeakRef(data) => data.sweep_values(compactions), Object::WeakSet(data) => data.sweep_values(compactions), diff --git a/nova_vm/src/ecmascript/types/language/value.rs b/nova_vm/src/ecmascript/types/language/value.rs index bf96245b6..9d48f8b62 100644 --- a/nova_vm/src/ecmascript/types/language/value.rs +++ b/nova_vm/src/ecmascript/types/language/value.rs @@ -13,6 +13,8 @@ use super::{ use crate::ecmascript::builtins::date::Date; #[cfg(feature = "shared-array-buffer")] use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer; +#[cfg(feature = "weak-map")] +use crate::ecmascript::builtins::weak_map::WeakMap; #[cfg(feature = "array-buffer")] use crate::{ ecmascript::builtins::{data_view::DataView, ArrayBuffer}, @@ -44,7 +46,6 @@ use crate::{ proxy::Proxy, regexp::RegExp, set::Set, - weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, @@ -164,6 +165,7 @@ pub enum Value { Set(Set), #[cfg(feature = "shared-array-buffer")] SharedArrayBuffer(SharedArrayBuffer), + #[cfg(feature = "weak-map")] WeakMap(WeakMap), WeakRef(WeakRef), WeakSet(WeakSet), @@ -286,6 +288,7 @@ pub(crate) const SET_DISCRIMINANT: u8 = value_discriminant(Value::Set(Set::_def( #[cfg(feature = "shared-array-buffer")] pub(crate) const SHARED_ARRAY_BUFFER_DISCRIMINANT: u8 = value_discriminant(Value::SharedArrayBuffer(SharedArrayBuffer::_def())); +#[cfg(feature = "weak-map")] pub(crate) const WEAK_MAP_DISCRIMINANT: u8 = value_discriminant(Value::WeakMap(WeakMap::_def())); pub(crate) const WEAK_REF_DISCRIMINANT: u8 = value_discriminant(Value::WeakRef(WeakRef::_def())); pub(crate) const WEAK_SET_DISCRIMINANT: u8 = value_discriminant(Value::WeakSet(WeakSet::_def())); @@ -653,6 +656,7 @@ impl Value { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "weak-map")] Value::WeakMap(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); @@ -870,6 +874,7 @@ impl Value { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "weak-map")] Value::WeakMap(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); @@ -1094,6 +1099,7 @@ impl HeapMarkAndSweep for Value { Value::Set(data) => data.mark_values(queues), #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(data) => data.mark_values(queues), + #[cfg(feature = "weak-map")] Value::WeakMap(data) => data.mark_values(queues), Value::WeakRef(data) => data.mark_values(queues), Value::WeakSet(data) => data.mark_values(queues), @@ -1173,6 +1179,7 @@ impl HeapMarkAndSweep for Value { Value::Set(data) => data.sweep_values(compactions), #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(data) => data.sweep_values(compactions), + #[cfg(feature = "weak-map")] Value::WeakMap(data) => data.sweep_values(compactions), Value::WeakRef(data) => data.sweep_values(compactions), Value::WeakSet(data) => data.sweep_values(compactions), diff --git a/nova_vm/src/engine/bytecode/vm.rs b/nova_vm/src/engine/bytecode/vm.rs index b1812a905..ba6ab3e03 100644 --- a/nova_vm/src/engine/bytecode/vm.rs +++ b/nova_vm/src/engine/bytecode/vm.rs @@ -2176,7 +2176,6 @@ fn typeof_operator(_: &mut Agent, val: Value) -> String { Value::Map(_) | Value::Promise(_) | Value::Set(_) | - Value::WeakMap(_) | Value::WeakRef(_) | Value::WeakSet(_) | Value::AsyncFromSyncIterator | @@ -2188,6 +2187,8 @@ fn typeof_operator(_: &mut Agent, val: Value) -> String { Value::Generator(_) | Value::Module(_) | Value::EmbedderObject(_) => BUILTIN_STRING_MEMORY.object, + #[cfg(feature = "weak-map")] + Value::WeakMap(_) => BUILTIN_STRING_MEMORY.object, #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(_) => BUILTIN_STRING_MEMORY.object, #[cfg(feature = "array-buffer")] diff --git a/nova_vm/src/heap.rs b/nova_vm/src/heap.rs index 26b6256ce..360a3f8c0 100644 --- a/nova_vm/src/heap.rs +++ b/nova_vm/src/heap.rs @@ -29,6 +29,28 @@ use self::{ }, indexes::{NumberIndex, ObjectIndex, StringIndex}, }; +#[cfg(feature = "date")] +use crate::ecmascript::builtins::date::data::DateHeapData; +#[cfg(feature = "shared-array-buffer")] +use crate::ecmascript::builtins::shared_array_buffer::data::SharedArrayBufferHeapData; +#[cfg(feature = "weak-map")] +use crate::ecmascript::builtins::weak_map::data::WeakMapHeapData; +#[cfg(feature = "array-buffer")] +use crate::ecmascript::builtins::{ + data_view::data::DataViewHeapData, typed_array::data::TypedArrayHeapData, ArrayBufferHeapData, +}; +use crate::ecmascript::{ + builtins::ArrayHeapData, + execution::{Environments, Realm, RealmIdentifier}, + scripts_and_modules::{ + module::ModuleIdentifier, + script::{Script, ScriptIdentifier}, + }, + types::{ + BigIntHeapData, BoundFunctionHeapData, BuiltinFunctionHeapData, ECMAScriptFunctionHeapData, + NumberHeapData, Object, ObjectHeapData, String, StringHeapData, SymbolHeapData, Value, + }, +}; use crate::ecmascript::{ builtins::{ control_abstraction_objects::{ @@ -54,7 +76,6 @@ use crate::ecmascript::{ proxy::data::ProxyHeapData, regexp::RegExpHeapData, set::data::SetHeapData, - weak_map::data::WeakMapHeapData, weak_ref::data::WeakRefHeapData, weak_set::data::WeakSetHeapData, }, @@ -64,27 +85,6 @@ use crate::ecmascript::{ BUILTIN_STRINGS_LIST, }, }; - -#[cfg(feature = "date")] -use crate::ecmascript::builtins::date::data::DateHeapData; -#[cfg(feature = "shared-array-buffer")] -use crate::ecmascript::builtins::shared_array_buffer::data::SharedArrayBufferHeapData; -#[cfg(feature = "array-buffer")] -use crate::ecmascript::builtins::{ - data_view::data::DataViewHeapData, typed_array::data::TypedArrayHeapData, ArrayBufferHeapData, -}; -use crate::ecmascript::{ - builtins::ArrayHeapData, - execution::{Environments, Realm, RealmIdentifier}, - scripts_and_modules::{ - module::ModuleIdentifier, - script::{Script, ScriptIdentifier}, - }, - types::{ - BigIntHeapData, BoundFunctionHeapData, BuiltinFunctionHeapData, ECMAScriptFunctionHeapData, - NumberHeapData, Object, ObjectHeapData, String, StringHeapData, SymbolHeapData, Value, - }, -}; pub(crate) use heap_bits::{CompactionLists, HeapMarkAndSweep, WorkQueues}; #[derive(Debug)] @@ -131,6 +131,7 @@ pub struct Heap { pub symbols: Vec>, #[cfg(feature = "array-buffer")] pub typed_arrays: Vec>, + #[cfg(feature = "weak-map")] pub weak_maps: Vec>, pub weak_refs: Vec>, pub weak_sets: Vec>, @@ -227,6 +228,7 @@ impl Heap { symbols: Vec::with_capacity(1024), #[cfg(feature = "array-buffer")] typed_arrays: Vec::with_capacity(0), + #[cfg(feature = "weak-map")] weak_maps: Vec::with_capacity(0), weak_refs: Vec::with_capacity(0), weak_sets: Vec::with_capacity(0), diff --git a/nova_vm/src/heap/heap_bits.rs b/nova_vm/src/heap/heap_bits.rs index c6f9e43de..e620ed0b7 100644 --- a/nova_vm/src/heap/heap_bits.rs +++ b/nova_vm/src/heap/heap_bits.rs @@ -14,6 +14,8 @@ use super::{ use crate::ecmascript::builtins::date::Date; #[cfg(feature = "shared-array-buffer")] use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer; +#[cfg(feature = "weak-map")] +use crate::ecmascript::builtins::weak_map::WeakMap; #[cfg(feature = "array-buffer")] use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer}; use crate::ecmascript::{ @@ -42,7 +44,6 @@ use crate::ecmascript::{ proxy::Proxy, regexp::RegExp, set::Set, - weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, @@ -112,6 +113,7 @@ pub struct HeapBits { pub symbols: Box<[bool]>, #[cfg(feature = "array-buffer")] pub typed_arrays: Box<[bool]>, + #[cfg(feature = "weak-map")] pub weak_maps: Box<[bool]>, pub weak_refs: Box<[bool]>, pub weak_sets: Box<[bool]>, @@ -171,6 +173,7 @@ pub(crate) struct WorkQueues { pub symbols: Vec, #[cfg(feature = "array-buffer")] pub typed_arrays: Vec, + #[cfg(feature = "weak-map")] pub weak_maps: Vec, pub weak_refs: Vec, pub weak_sets: Vec, @@ -230,6 +233,7 @@ impl HeapBits { let symbols = vec![false; heap.symbols.len()]; #[cfg(feature = "array-buffer")] let typed_arrays = vec![false; heap.typed_arrays.len()]; + #[cfg(feature = "weak-map")] let weak_maps = vec![false; heap.weak_maps.len()]; let weak_refs = vec![false; heap.weak_refs.len()]; let weak_sets = vec![false; heap.weak_sets.len()]; @@ -286,6 +290,7 @@ impl HeapBits { symbols: symbols.into_boxed_slice(), #[cfg(feature = "array-buffer")] typed_arrays: typed_arrays.into_boxed_slice(), + #[cfg(feature = "weak-map")] weak_maps: weak_maps.into_boxed_slice(), weak_refs: weak_refs.into_boxed_slice(), weak_sets: weak_sets.into_boxed_slice(), @@ -350,6 +355,7 @@ impl WorkQueues { symbols: Vec::with_capacity((heap.symbols.len() / 4).max(13)), #[cfg(feature = "array-buffer")] typed_arrays: Vec::with_capacity(heap.typed_arrays.len() / 4), + #[cfg(feature = "weak-map")] weak_maps: Vec::with_capacity(heap.weak_maps.len() / 4), weak_refs: Vec::with_capacity(heap.weak_refs.len() / 4), weak_sets: Vec::with_capacity(heap.weak_sets.len() / 4), @@ -433,6 +439,7 @@ impl WorkQueues { symbols, #[cfg(feature = "array-buffer")] typed_arrays, + #[cfg(feature = "weak-map")] weak_maps, weak_refs, weak_sets, @@ -448,6 +455,8 @@ impl WorkQueues { let typed_arrays: &[bool; 0] = &[]; #[cfg(not(feature = "shared-array-buffer"))] let shared_array_buffers: &[bool; 0] = &[]; + #[cfg(not(feature = "weak-map"))] + let weak_maps: &[bool; 0] = &[]; array_buffers.is_empty() && arrays.is_empty() @@ -693,6 +702,7 @@ pub(crate) struct CompactionLists { pub symbols: CompactionList, #[cfg(feature = "array-buffer")] pub typed_arrays: CompactionList, + #[cfg(feature = "weak-map")] pub weak_maps: CompactionList, pub weak_refs: CompactionList, pub weak_sets: CompactionList, @@ -766,6 +776,7 @@ impl CompactionLists { data_views: CompactionList::from_mark_bits(&bits.data_views), finalization_registrys: CompactionList::from_mark_bits(&bits.finalization_registrys), proxys: CompactionList::from_mark_bits(&bits.proxys), + #[cfg(feature = "weak-map")] weak_maps: CompactionList::from_mark_bits(&bits.weak_maps), weak_refs: CompactionList::from_mark_bits(&bits.weak_refs), weak_sets: CompactionList::from_mark_bits(&bits.weak_sets), diff --git a/nova_vm/src/heap/heap_gc.rs b/nova_vm/src/heap/heap_gc.rs index 5a4d6a804..9d826001f 100644 --- a/nova_vm/src/heap/heap_gc.rs +++ b/nova_vm/src/heap/heap_gc.rs @@ -21,6 +21,8 @@ use super::{ use crate::ecmascript::builtins::date::Date; #[cfg(feature = "shared-array-buffer")] use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer; +#[cfg(feature = "weak-map")] +use crate::ecmascript::builtins::weak_map::WeakMap; #[cfg(feature = "array-buffer")] use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer}; use crate::ecmascript::{ @@ -49,7 +51,6 @@ use crate::ecmascript::{ proxy::Proxy, regexp::RegExp, set::Set, - weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet, Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, @@ -150,6 +151,7 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { symbols, #[cfg(feature = "array-buffer")] typed_arrays, + #[cfg(feature = "weak-map")] weak_maps, weak_refs, weak_sets, @@ -716,19 +718,22 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { } }); } - let mut weak_map_marks: Box<[WeakMap]> = queues.weak_maps.drain(..).collect(); - weak_map_marks.sort(); - weak_map_marks.iter().for_each(|&idx| { - let index = idx.get_index(); - if let Some(marked) = bits.weak_maps.get_mut(index) { - if *marked { - // Already marked, ignore - return; + #[cfg(feature = "weak-map")] + { + let mut weak_map_marks: Box<[WeakMap]> = queues.weak_maps.drain(..).collect(); + weak_map_marks.sort(); + weak_map_marks.iter().for_each(|&idx| { + let index = idx.get_index(); + if let Some(marked) = bits.weak_maps.get_mut(index) { + if *marked { + // Already marked, ignore + return; + } + *marked = true; + weak_maps.get(index).mark_values(&mut queues); } - *marked = true; - weak_maps.get(index).mark_values(&mut queues); - } - }); + }); + } let mut weak_ref_marks: Box<[WeakRef]> = queues.weak_refs.drain(..).collect(); weak_ref_marks.sort(); weak_ref_marks.iter().for_each(|&idx| { @@ -979,6 +984,7 @@ fn sweep(heap: &mut Heap, bits: &HeapBits, root_realms: &mut [Option; pub type SymbolIndex = BaseIndex; #[cfg(feature = "array-buffer")] pub type TypedArrayIndex = BaseIndex; +#[cfg(feature = "weak-map")] pub type WeakMapIndex = BaseIndex; pub type WeakRefIndex = BaseIndex; pub type WeakSetIndex = BaseIndex; From 797ebf52a98bb687d00b62304e45ed102ad88ebd Mon Sep 17 00:00:00 2001 From: Dean Srebnik <49134864+load1n9@users.noreply.github.com> Date: Mon, 14 Oct 2024 11:16:00 -0400 Subject: [PATCH 2/4] feat: move WeakSets and WeakRefs to the weak-refs feature --- nova_vm/Cargo.toml | 4 +- nova_vm/src/ecmascript/builtins.rs | 4 +- .../ecmascript/builtins/keyed_collections.rs | 3 +- .../ecmascript/builtins/managing_memory.rs | 1 + nova_vm/src/ecmascript/builtins/ordinary.rs | 17 +-- nova_vm/src/ecmascript/execution/realm.rs | 48 ++++----- .../ecmascript/execution/realm/intrinsics.rs | 65 +++++++---- .../src/ecmascript/types/language/object.rs | 101 ++++++++++++------ .../src/ecmascript/types/language/value.rs | 30 ++++-- nova_vm/src/engine/bytecode/vm.rs | 8 +- nova_vm/src/heap.rs | 17 +-- nova_vm/src/heap/heap_bits.rs | 45 +++++--- nova_vm/src/heap/heap_gc.rs | 71 ++++++------ nova_vm/src/heap/indexes.rs | 13 ++- 14 files changed, 269 insertions(+), 158 deletions(-) diff --git a/nova_vm/Cargo.toml b/nova_vm/Cargo.toml index 0deb2a175..b851accd5 100644 --- a/nova_vm/Cargo.toml +++ b/nova_vm/Cargo.toml @@ -23,13 +23,13 @@ sonic-rs = { workspace = true, optional = true } wtf8 = { workspace = true } [features] -default = ["math", "json", "date", "array-buffer", "shared-array-buffer", "weak-map"] +default = ["math", "json", "date", "array-buffer", "shared-array-buffer"] math = [] json = ["sonic-rs"] date = [] array-buffer = [] shared-array-buffer = [] -weak-map = [] +weak-refs = [] typescript = [] [build-dependencies] diff --git a/nova_vm/src/ecmascript/builtins.rs b/nova_vm/src/ecmascript/builtins.rs index 1ce6aa05e..09f4fef00 100644 --- a/nova_vm/src/ecmascript/builtins.rs +++ b/nova_vm/src/ecmascript/builtins.rs @@ -45,9 +45,11 @@ pub(crate) mod structured_data; pub(crate) mod text_processing; #[cfg(feature = "array-buffer")] pub(crate) mod typed_array; -#[cfg(feature = "weak-map")] +#[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::*; diff --git a/nova_vm/src/ecmascript/builtins/keyed_collections.rs b/nova_vm/src/ecmascript/builtins/keyed_collections.rs index 51773442a..85dacf765 100644 --- a/nova_vm/src/ecmascript/builtins/keyed_collections.rs +++ b/nova_vm/src/ecmascript/builtins/keyed_collections.rs @@ -4,6 +4,7 @@ pub(crate) mod map_objects; pub(crate) mod set_objects; -#[cfg(feature = "weak-map")] +#[cfg(feature = "weak-refs")] pub(crate) mod weak_map_objects; +#[cfg(feature = "weak-refs")] pub(crate) mod weak_set_objects; diff --git a/nova_vm/src/ecmascript/builtins/managing_memory.rs b/nova_vm/src/ecmascript/builtins/managing_memory.rs index 46f1a06b0..aa1d635a0 100644 --- a/nova_vm/src/ecmascript/builtins/managing_memory.rs +++ b/nova_vm/src/ecmascript/builtins/managing_memory.rs @@ -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; diff --git a/nova_vm/src/ecmascript/builtins/ordinary.rs b/nova_vm/src/ecmascript/builtins/ordinary.rs index 4b8607210..ee94f7a4f 100644 --- a/nova_vm/src/ecmascript/builtins/ordinary.rs +++ b/nova_vm/src/ecmascript/builtins/ordinary.rs @@ -28,8 +28,6 @@ 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, @@ -44,14 +42,17 @@ use super::{ promise::data::PromiseHeapData, regexp::RegExpHeapData, set::data::SetHeapData, - 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 for Agent { type Output = ObjectHeapData; @@ -972,9 +973,11 @@ pub(crate) fn ordinary_object_create_with_intrinsics( .heap .create(TypedArrayHeapData::default()) .into_object(), - #[cfg(feature = "weak-map")] + #[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(), }; @@ -1112,9 +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-map")] + #[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 { diff --git a/nova_vm/src/ecmascript/execution/realm.rs b/nova_vm/src/ecmascript/execution/realm.rs index 1f1b9ad8c..1f7f4a8d8 100644 --- a/nova_vm/src/ecmascript/execution/realm.rs +++ b/nova_vm/src/ecmascript/execution/realm.rs @@ -941,7 +941,7 @@ pub(crate) fn set_default_global_bindings( define_property_or_throw(agent, global, name, desc)?; // 19.3.38 WeakMap ( . . . ) - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] { let name = PropertyKey::from(BUILTIN_STRING_MEMORY.WeakMap); let value = agent.get_realm(realm_id).intrinsics().weak_map(); @@ -953,30 +953,30 @@ pub(crate) fn set_default_global_bindings( ..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.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 diff --git a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs index 6f6bab25f..e4fc3bca0 100644 --- a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs +++ b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs @@ -3,9 +3,18 @@ // 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 = "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::{ @@ -80,18 +89,10 @@ use crate::{ set_iterator_objects::set_iterator_prototype::SetIteratorPrototype, set_prototype::SetPrototype, }, - 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}, @@ -219,9 +220,11 @@ pub enum ProtoIntrinsics { #[cfg(feature = "array-buffer")] Uint8Array, UriError, - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] WeakMap, + #[cfg(feature = "weak-refs")] WeakRef, + #[cfg(feature = "weak-refs")] WeakSet, } @@ -306,11 +309,13 @@ impl Intrinsics { SetPrototype::create_intrinsic(agent, realm); SetConstructor::create_intrinsic(agent, realm); SetIteratorPrototype::create_intrinsic(agent, realm); - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] WeakMapPrototype::create_intrinsic(agent, realm); - #[cfg(feature = "weak-map")] + #[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); @@ -327,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); @@ -414,9 +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-map")] + #[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(), } } @@ -1523,7 +1532,7 @@ impl Intrinsics { } /// %WeakMap.prototype% - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] pub(crate) fn weak_map_prototype(&self) -> OrdinaryObject { IntrinsicObjectIndexes::WeakMapPrototype .get_object_index(self.object_index_base) @@ -1531,19 +1540,20 @@ impl Intrinsics { } /// %WeakMap% - #[cfg(feature = "weak-map")] + #[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-map")] + #[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) @@ -1551,17 +1561,20 @@ impl Intrinsics { } /// %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) @@ -1569,12 +1582,14 @@ impl Intrinsics { } /// %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) } @@ -1743,13 +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-map")] + #[cfg(feature = "weak-refs")] self.weak_map_prototype().mark_values(queues); - #[cfg(feature = "weak-map")] + #[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); } diff --git a/nova_vm/src/ecmascript/types/language/object.rs b/nova_vm/src/ecmascript/types/language/object.rs index 594dab094..f1fb02af8 100644 --- a/nova_vm/src/ecmascript/types/language/object.rs +++ b/nova_vm/src/ecmascript/types/language/object.rs @@ -15,8 +15,6 @@ use std::hash::Hash; use super::value::DATE_DISCRIMINANT; #[cfg(feature = "shared-array-buffer")] use super::value::SHARED_ARRAY_BUFFER_DISCRIMINANT; -#[cfg(feature = "weak-map")] -use super::value::WEAK_MAP_DISCRIMINANT; #[cfg(feature = "array-buffer")] use super::value::{ ARRAY_BUFFER_DISCRIMINANT, BIGINT_64_ARRAY_DISCRIMINANT, BIGUINT_64_ARRAY_DISCRIMINANT, @@ -25,6 +23,8 @@ use super::value::{ UINT_16_ARRAY_DISCRIMINANT, UINT_32_ARRAY_DISCRIMINANT, UINT_8_ARRAY_DISCRIMINANT, UINT_8_CLAMPED_ARRAY_DISCRIMINANT, }; +#[cfg(feature = "weak-refs")] +use super::value::{WEAK_MAP_DISCRIMINANT, WEAK_REF_DISCRIMINANT, WEAK_SET_DISCRIMINANT}; use super::{ value::{ ARGUMENTS_DISCRIMINANT, ARRAY_DISCRIMINANT, ARRAY_ITERATOR_DISCRIMINANT, @@ -37,8 +37,7 @@ use super::{ FINALIZATION_REGISTRY_DISCRIMINANT, GENERATOR_DISCRIMINANT, ITERATOR_DISCRIMINANT, MAP_DISCRIMINANT, MAP_ITERATOR_DISCRIMINANT, MODULE_DISCRIMINANT, OBJECT_DISCRIMINANT, PRIMITIVE_OBJECT_DISCRIMINANT, PROMISE_DISCRIMINANT, PROXY_DISCRIMINANT, - REGEXP_DISCRIMINANT, SET_DISCRIMINANT, SET_ITERATOR_DISCRIMINANT, WEAK_REF_DISCRIMINANT, - WEAK_SET_DISCRIMINANT, + REGEXP_DISCRIMINANT, SET_DISCRIMINANT, SET_ITERATOR_DISCRIMINANT, }, Function, IntoValue, Value, }; @@ -46,8 +45,8 @@ use super::{ use crate::ecmascript::builtins::date::Date; #[cfg(feature = "shared-array-buffer")] use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer; -#[cfg(feature = "weak-map")] -use crate::ecmascript::builtins::weak_map::WeakMap; +#[cfg(feature = "weak-refs")] +use crate::ecmascript::builtins::{weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet}; #[cfg(feature = "array-buffer")] use crate::{ ecmascript::builtins::{data_view::DataView, typed_array::TypedArray, ArrayBuffer}, @@ -76,8 +75,6 @@ use crate::{ proxy::Proxy, regexp::RegExp, set::Set, - weak_ref::WeakRef, - weak_set::WeakSet, ArgumentsList, Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, }, execution::{Agent, JsResult}, @@ -131,9 +128,11 @@ pub enum Object { Set(Set) = SET_DISCRIMINANT, #[cfg(feature = "shared-array-buffer")] SharedArrayBuffer(SharedArrayBuffer) = SHARED_ARRAY_BUFFER_DISCRIMINANT, - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] WeakMap(WeakMap) = WEAK_MAP_DISCRIMINANT, + #[cfg(feature = "weak-refs")] WeakRef(WeakRef) = WEAK_REF_DISCRIMINANT, + #[cfg(feature = "weak-refs")] WeakSet(WeakSet) = WEAK_SET_DISCRIMINANT, #[cfg(feature = "array-buffer")] Int8Array(TypedArrayIndex) = INT_8_ARRAY_DISCRIMINANT, @@ -203,9 +202,11 @@ impl IntoValue for Object { Object::Set(data) => Value::Set(data), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => Value::SharedArrayBuffer(data), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => Value::WeakMap(data), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => Value::WeakRef(data), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => Value::WeakSet(data), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => Value::Int8Array(data), @@ -395,9 +396,11 @@ impl From for Value { Object::Set(data) => Value::Set(data), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => Value::SharedArrayBuffer(data), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => Value::WeakMap(data), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => Value::WeakRef(data), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => Value::WeakSet(data), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => Value::Int8Array(data), @@ -478,9 +481,11 @@ impl TryFrom for Object { Value::Set(data) => Ok(Object::Set(data)), #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(data) => Ok(Object::SharedArrayBuffer(data)), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Value::WeakMap(data) => Ok(Object::WeakMap(data)), + #[cfg(feature = "weak-refs")] Value::WeakRef(data) => Ok(Object::WeakRef(data)), + #[cfg(feature = "weak-refs")] Value::WeakSet(data) => Ok(Object::WeakSet(data)), #[cfg(feature = "array-buffer")] Value::Int8Array(data) => Ok(Object::Int8Array(data)), @@ -558,9 +563,11 @@ impl Hash for Object { Object::Set(data) => data.get_index().hash(state), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.get_index().hash(state), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.get_index().hash(state), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.get_index().hash(state), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.get_index().hash(state), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => data.into_index().hash(state), @@ -639,9 +646,11 @@ impl InternalSlots for Object { Object::Set(data) => data.internal_extensible(agent), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_extensible(agent), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_extensible(agent), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_extensible(agent), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_extensible(agent), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => TypedArray::Int8Array(data).internal_extensible(agent), @@ -714,9 +723,11 @@ impl InternalSlots for Object { Object::Set(data) => data.internal_set_extensible(agent, value), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_set_extensible(agent, value), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_set_extensible(agent, value), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_set_extensible(agent, value), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_set_extensible(agent, value), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { @@ -803,9 +814,11 @@ impl InternalSlots for Object { Object::Set(data) => data.internal_prototype(agent), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_prototype(agent), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_prototype(agent), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_prototype(agent), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_prototype(agent), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => TypedArray::Int8Array(data).internal_prototype(agent), @@ -880,9 +893,11 @@ impl InternalSlots for Object { Object::Set(data) => data.internal_set_prototype(agent, prototype), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_set_prototype(agent, prototype), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_set_prototype(agent, prototype), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_set_prototype(agent, prototype), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_set_prototype(agent, prototype), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { @@ -971,9 +986,11 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_get_prototype_of(agent), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_get_prototype_of(agent), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_get_prototype_of(agent), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_get_prototype_of(agent), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_get_prototype_of(agent), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => TypedArray::Int8Array(data).internal_get_prototype_of(agent), @@ -1066,9 +1083,11 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_set_prototype_of(agent, prototype), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_set_prototype_of(agent, prototype), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_set_prototype_of(agent, prototype), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_set_prototype_of(agent, prototype), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_set_prototype_of(agent, prototype), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { @@ -1155,9 +1174,11 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_is_extensible(agent), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_is_extensible(agent), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_is_extensible(agent), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_is_extensible(agent), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_is_extensible(agent), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => TypedArray::Int8Array(data).internal_is_extensible(agent), @@ -1238,9 +1259,11 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_prevent_extensions(agent), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_prevent_extensions(agent), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_prevent_extensions(agent), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_prevent_extensions(agent), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_prevent_extensions(agent), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { @@ -1337,9 +1360,11 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_get_own_property(agent, property_key), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_get_own_property(agent, property_key), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_get_own_property(agent, property_key), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_get_own_property(agent, property_key), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_get_own_property(agent, property_key), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { @@ -1471,13 +1496,15 @@ impl InternalMethods for Object { Object::SharedArrayBuffer(data) => { data.internal_define_own_property(agent, property_key, property_descriptor) } - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => { data.internal_define_own_property(agent, property_key, property_descriptor) } + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => { data.internal_define_own_property(agent, property_key, property_descriptor) } + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => { data.internal_define_own_property(agent, property_key, property_descriptor) } @@ -1583,9 +1610,11 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_has_property(agent, property_key), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_has_property(agent, property_key), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_has_property(agent, property_key), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_has_property(agent, property_key), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_has_property(agent, property_key), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { @@ -1681,9 +1710,11 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_get(agent, property_key, receiver), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_get(agent, property_key, receiver), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_get(agent, property_key, receiver), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_get(agent, property_key, receiver), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_get(agent, property_key, receiver), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { @@ -1790,9 +1821,11 @@ impl InternalMethods for Object { Object::SharedArrayBuffer(data) => { data.internal_set(agent, property_key, value, receiver) } - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_set(agent, property_key, value, receiver), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_set(agent, property_key, value, receiver), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_set(agent, property_key, value, receiver), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { @@ -1884,9 +1917,11 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_delete(agent, property_key), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_delete(agent, property_key), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_delete(agent, property_key), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_delete(agent, property_key), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_delete(agent, property_key), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { @@ -1973,9 +2008,11 @@ impl InternalMethods for Object { Object::Set(data) => data.internal_own_property_keys(agent), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.internal_own_property_keys(agent), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.internal_own_property_keys(agent), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.internal_own_property_keys(agent), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.internal_own_property_keys(agent), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => { @@ -2101,9 +2138,11 @@ impl HeapMarkAndSweep for Object { Object::Set(data) => data.mark_values(queues), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.mark_values(queues), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.mark_values(queues), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.mark_values(queues), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.mark_values(queues), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => data.mark_values(queues), @@ -2168,9 +2207,11 @@ impl HeapMarkAndSweep for Object { Object::Set(data) => data.sweep_values(compactions), #[cfg(feature = "shared-array-buffer")] Object::SharedArrayBuffer(data) => data.sweep_values(compactions), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Object::WeakMap(data) => data.sweep_values(compactions), + #[cfg(feature = "weak-refs")] Object::WeakRef(data) => data.sweep_values(compactions), + #[cfg(feature = "weak-refs")] Object::WeakSet(data) => data.sweep_values(compactions), #[cfg(feature = "array-buffer")] Object::Int8Array(data) => data.sweep_values(compactions), diff --git a/nova_vm/src/ecmascript/types/language/value.rs b/nova_vm/src/ecmascript/types/language/value.rs index 9d48f8b62..51006e55f 100644 --- a/nova_vm/src/ecmascript/types/language/value.rs +++ b/nova_vm/src/ecmascript/types/language/value.rs @@ -13,8 +13,8 @@ use super::{ use crate::ecmascript::builtins::date::Date; #[cfg(feature = "shared-array-buffer")] use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer; -#[cfg(feature = "weak-map")] -use crate::ecmascript::builtins::weak_map::WeakMap; +#[cfg(feature = "weak-refs")] +use crate::ecmascript::builtins::{weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet}; #[cfg(feature = "array-buffer")] use crate::{ ecmascript::builtins::{data_view::DataView, ArrayBuffer}, @@ -46,8 +46,6 @@ use crate::{ proxy::Proxy, regexp::RegExp, set::Set, - weak_ref::WeakRef, - weak_set::WeakSet, Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, }, execution::{Agent, JsResult}, @@ -165,9 +163,11 @@ pub enum Value { Set(Set), #[cfg(feature = "shared-array-buffer")] SharedArrayBuffer(SharedArrayBuffer), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] WeakMap(WeakMap), + #[cfg(feature = "weak-refs")] WeakRef(WeakRef), + #[cfg(feature = "weak-refs")] WeakSet(WeakSet), // TypedArrays @@ -288,9 +288,11 @@ pub(crate) const SET_DISCRIMINANT: u8 = value_discriminant(Value::Set(Set::_def( #[cfg(feature = "shared-array-buffer")] pub(crate) const SHARED_ARRAY_BUFFER_DISCRIMINANT: u8 = value_discriminant(Value::SharedArrayBuffer(SharedArrayBuffer::_def())); -#[cfg(feature = "weak-map")] +#[cfg(feature = "weak-refs")] pub(crate) const WEAK_MAP_DISCRIMINANT: u8 = value_discriminant(Value::WeakMap(WeakMap::_def())); +#[cfg(feature = "weak-refs")] pub(crate) const WEAK_REF_DISCRIMINANT: u8 = value_discriminant(Value::WeakRef(WeakRef::_def())); +#[cfg(feature = "weak-refs")] pub(crate) const WEAK_SET_DISCRIMINANT: u8 = value_discriminant(Value::WeakSet(WeakSet::_def())); #[cfg(feature = "array-buffer")] pub(crate) const INT_8_ARRAY_DISCRIMINANT: u8 = @@ -656,15 +658,17 @@ impl Value { discriminant.hash(hasher); data.get_index().hash(hasher); } - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Value::WeakMap(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "weak-refs")] Value::WeakRef(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "weak-refs")] Value::WeakSet(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); @@ -874,15 +878,17 @@ impl Value { discriminant.hash(hasher); data.get_index().hash(hasher); } - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Value::WeakMap(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "weak-refs")] Value::WeakRef(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); } + #[cfg(feature = "weak-refs")] Value::WeakSet(data) => { discriminant.hash(hasher); data.get_index().hash(hasher); @@ -1099,9 +1105,11 @@ impl HeapMarkAndSweep for Value { Value::Set(data) => data.mark_values(queues), #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(data) => data.mark_values(queues), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Value::WeakMap(data) => data.mark_values(queues), + #[cfg(feature = "weak-refs")] Value::WeakRef(data) => data.mark_values(queues), + #[cfg(feature = "weak-refs")] Value::WeakSet(data) => data.mark_values(queues), #[cfg(feature = "array-buffer")] Value::Int8Array(data) => data.mark_values(queues), @@ -1179,9 +1187,11 @@ impl HeapMarkAndSweep for Value { Value::Set(data) => data.sweep_values(compactions), #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(data) => data.sweep_values(compactions), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] Value::WeakMap(data) => data.sweep_values(compactions), + #[cfg(feature = "weak-refs")] Value::WeakRef(data) => data.sweep_values(compactions), + #[cfg(feature = "weak-refs")] Value::WeakSet(data) => data.sweep_values(compactions), #[cfg(feature = "array-buffer")] Value::Int8Array(data) => data.sweep_values(compactions), diff --git a/nova_vm/src/engine/bytecode/vm.rs b/nova_vm/src/engine/bytecode/vm.rs index ba6ab3e03..86c8ab4d4 100644 --- a/nova_vm/src/engine/bytecode/vm.rs +++ b/nova_vm/src/engine/bytecode/vm.rs @@ -2176,8 +2176,6 @@ fn typeof_operator(_: &mut Agent, val: Value) -> String { Value::Map(_) | Value::Promise(_) | Value::Set(_) | - Value::WeakRef(_) | - Value::WeakSet(_) | Value::AsyncFromSyncIterator | Value::AsyncIterator | Value::Iterator | @@ -2187,8 +2185,10 @@ fn typeof_operator(_: &mut Agent, val: Value) -> String { Value::Generator(_) | Value::Module(_) | Value::EmbedderObject(_) => BUILTIN_STRING_MEMORY.object, - #[cfg(feature = "weak-map")] - Value::WeakMap(_) => BUILTIN_STRING_MEMORY.object, + #[cfg(feature = "weak-refs")] + Value::WeakMap(_) | + Value::WeakRef(_) | + Value::WeakSet(_) => BUILTIN_STRING_MEMORY.object, #[cfg(feature = "shared-array-buffer")] Value::SharedArrayBuffer(_) => BUILTIN_STRING_MEMORY.object, #[cfg(feature = "array-buffer")] diff --git a/nova_vm/src/heap.rs b/nova_vm/src/heap.rs index 360a3f8c0..46eee04c1 100644 --- a/nova_vm/src/heap.rs +++ b/nova_vm/src/heap.rs @@ -33,12 +33,15 @@ use self::{ use crate::ecmascript::builtins::date::data::DateHeapData; #[cfg(feature = "shared-array-buffer")] use crate::ecmascript::builtins::shared_array_buffer::data::SharedArrayBufferHeapData; -#[cfg(feature = "weak-map")] -use crate::ecmascript::builtins::weak_map::data::WeakMapHeapData; #[cfg(feature = "array-buffer")] use crate::ecmascript::builtins::{ data_view::data::DataViewHeapData, typed_array::data::TypedArrayHeapData, ArrayBufferHeapData, }; +#[cfg(feature = "weak-refs")] +use crate::ecmascript::builtins::{ + weak_map::data::WeakMapHeapData, weak_ref::data::WeakRefHeapData, + weak_set::data::WeakSetHeapData, +}; use crate::ecmascript::{ builtins::ArrayHeapData, execution::{Environments, Realm, RealmIdentifier}, @@ -76,8 +79,6 @@ use crate::ecmascript::{ proxy::data::ProxyHeapData, regexp::RegExpHeapData, set::data::SetHeapData, - weak_ref::data::WeakRefHeapData, - weak_set::data::WeakSetHeapData, }, scripts_and_modules::source_code::SourceCodeHeapData, types::{ @@ -131,9 +132,11 @@ pub struct Heap { pub symbols: Vec>, #[cfg(feature = "array-buffer")] pub typed_arrays: Vec>, - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] pub weak_maps: Vec>, + #[cfg(feature = "weak-refs")] pub weak_refs: Vec>, + #[cfg(feature = "weak-refs")] pub weak_sets: Vec>, pub modules: Vec>, pub scripts: Vec>, @@ -228,9 +231,11 @@ impl Heap { symbols: Vec::with_capacity(1024), #[cfg(feature = "array-buffer")] typed_arrays: Vec::with_capacity(0), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] weak_maps: Vec::with_capacity(0), + #[cfg(feature = "weak-refs")] weak_refs: Vec::with_capacity(0), + #[cfg(feature = "weak-refs")] weak_sets: Vec::with_capacity(0), }; diff --git a/nova_vm/src/heap/heap_bits.rs b/nova_vm/src/heap/heap_bits.rs index e620ed0b7..ede7a15be 100644 --- a/nova_vm/src/heap/heap_bits.rs +++ b/nova_vm/src/heap/heap_bits.rs @@ -14,10 +14,10 @@ use super::{ use crate::ecmascript::builtins::date::Date; #[cfg(feature = "shared-array-buffer")] use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer; -#[cfg(feature = "weak-map")] -use crate::ecmascript::builtins::weak_map::WeakMap; #[cfg(feature = "array-buffer")] use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer}; +#[cfg(feature = "weak-refs")] +use crate::ecmascript::builtins::{weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet}; use crate::ecmascript::{ builtins::{ bound_function::BoundFunction, @@ -44,8 +44,6 @@ use crate::ecmascript::{ proxy::Proxy, regexp::RegExp, set::Set, - weak_ref::WeakRef, - weak_set::WeakSet, Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, }, execution::{ @@ -113,9 +111,11 @@ pub struct HeapBits { pub symbols: Box<[bool]>, #[cfg(feature = "array-buffer")] pub typed_arrays: Box<[bool]>, - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] pub weak_maps: Box<[bool]>, + #[cfg(feature = "weak-refs")] pub weak_refs: Box<[bool]>, + #[cfg(feature = "weak-refs")] pub weak_sets: Box<[bool]>, } @@ -173,9 +173,11 @@ pub(crate) struct WorkQueues { pub symbols: Vec, #[cfg(feature = "array-buffer")] pub typed_arrays: Vec, - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] pub weak_maps: Vec, + #[cfg(feature = "weak-refs")] pub weak_refs: Vec, + #[cfg(feature = "weak-refs")] pub weak_sets: Vec, } @@ -233,9 +235,11 @@ impl HeapBits { let symbols = vec![false; heap.symbols.len()]; #[cfg(feature = "array-buffer")] let typed_arrays = vec![false; heap.typed_arrays.len()]; - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] let weak_maps = vec![false; heap.weak_maps.len()]; + #[cfg(feature = "weak-refs")] let weak_refs = vec![false; heap.weak_refs.len()]; + #[cfg(feature = "weak-refs")] let weak_sets = vec![false; heap.weak_sets.len()]; Self { #[cfg(feature = "array-buffer")] @@ -290,9 +294,11 @@ impl HeapBits { symbols: symbols.into_boxed_slice(), #[cfg(feature = "array-buffer")] typed_arrays: typed_arrays.into_boxed_slice(), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] weak_maps: weak_maps.into_boxed_slice(), + #[cfg(feature = "weak-refs")] weak_refs: weak_refs.into_boxed_slice(), + #[cfg(feature = "weak-refs")] weak_sets: weak_sets.into_boxed_slice(), } } @@ -355,9 +361,11 @@ impl WorkQueues { symbols: Vec::with_capacity((heap.symbols.len() / 4).max(13)), #[cfg(feature = "array-buffer")] typed_arrays: Vec::with_capacity(heap.typed_arrays.len() / 4), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] weak_maps: Vec::with_capacity(heap.weak_maps.len() / 4), + #[cfg(feature = "weak-refs")] weak_refs: Vec::with_capacity(heap.weak_refs.len() / 4), + #[cfg(feature = "weak-refs")] weak_sets: Vec::with_capacity(heap.weak_sets.len() / 4), } } @@ -439,9 +447,11 @@ impl WorkQueues { symbols, #[cfg(feature = "array-buffer")] typed_arrays, - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] weak_maps, + #[cfg(feature = "weak-refs")] weak_refs, + #[cfg(feature = "weak-refs")] weak_sets, } = self; @@ -455,8 +465,13 @@ impl WorkQueues { let typed_arrays: &[bool; 0] = &[]; #[cfg(not(feature = "shared-array-buffer"))] let shared_array_buffers: &[bool; 0] = &[]; - #[cfg(not(feature = "weak-map"))] + #[cfg(not(feature = "weak-refs"))] let weak_maps: &[bool; 0] = &[]; + #[cfg(not(feature = "weak-refs"))] + let weak_refs: &[bool; 0] = &[]; + #[cfg(not(feature = "weak-refs"))] + let weak_sets: &[bool; 0] = &[]; + array_buffers.is_empty() && arrays.is_empty() @@ -702,9 +717,11 @@ pub(crate) struct CompactionLists { pub symbols: CompactionList, #[cfg(feature = "array-buffer")] pub typed_arrays: CompactionList, - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] pub weak_maps: CompactionList, + #[cfg(feature = "weak-refs")] pub weak_refs: CompactionList, + #[cfg(feature = "weak-refs")] pub weak_sets: CompactionList, } @@ -776,9 +793,11 @@ impl CompactionLists { data_views: CompactionList::from_mark_bits(&bits.data_views), finalization_registrys: CompactionList::from_mark_bits(&bits.finalization_registrys), proxys: CompactionList::from_mark_bits(&bits.proxys), - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] weak_maps: CompactionList::from_mark_bits(&bits.weak_maps), + #[cfg(feature = "weak-refs")] weak_refs: CompactionList::from_mark_bits(&bits.weak_refs), + #[cfg(feature = "weak-refs")] weak_sets: CompactionList::from_mark_bits(&bits.weak_sets), #[cfg(feature = "array-buffer")] typed_arrays: CompactionList::from_mark_bits(&bits.typed_arrays), diff --git a/nova_vm/src/heap/heap_gc.rs b/nova_vm/src/heap/heap_gc.rs index 9d826001f..31cd035b4 100644 --- a/nova_vm/src/heap/heap_gc.rs +++ b/nova_vm/src/heap/heap_gc.rs @@ -21,10 +21,10 @@ use super::{ use crate::ecmascript::builtins::date::Date; #[cfg(feature = "shared-array-buffer")] use crate::ecmascript::builtins::shared_array_buffer::SharedArrayBuffer; -#[cfg(feature = "weak-map")] -use crate::ecmascript::builtins::weak_map::WeakMap; #[cfg(feature = "array-buffer")] use crate::ecmascript::builtins::{data_view::DataView, ArrayBuffer}; +#[cfg(feature = "weak-refs")] +use crate::ecmascript::builtins::{weak_map::WeakMap, weak_ref::WeakRef, weak_set::WeakSet}; use crate::ecmascript::{ builtins::{ bound_function::BoundFunction, @@ -51,8 +51,6 @@ use crate::ecmascript::{ proxy::Proxy, regexp::RegExp, set::Set, - weak_ref::WeakRef, - weak_set::WeakSet, Array, BuiltinConstructorFunction, BuiltinFunction, ECMAScriptFunction, }, execution::{ @@ -151,9 +149,11 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { symbols, #[cfg(feature = "array-buffer")] typed_arrays, - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] weak_maps, + #[cfg(feature = "weak-refs")] weak_refs, + #[cfg(feature = "weak-refs")] weak_sets, } = heap; let Environments { @@ -718,7 +718,7 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { } }); } - #[cfg(feature = "weak-map")] + #[cfg(feature = "weak-refs")] { let mut weak_map_marks: Box<[WeakMap]> = queues.weak_maps.drain(..).collect(); weak_map_marks.sort(); @@ -733,33 +733,34 @@ pub fn heap_gc(heap: &mut Heap, root_realms: &mut [Option]) { weak_maps.get(index).mark_values(&mut queues); } }); - } - let mut weak_ref_marks: Box<[WeakRef]> = queues.weak_refs.drain(..).collect(); - weak_ref_marks.sort(); - weak_ref_marks.iter().for_each(|&idx| { - let index = idx.get_index(); - if let Some(marked) = bits.weak_refs.get_mut(index) { - if *marked { - // Already marked, ignore - return; + let mut weak_ref_marks: Box<[WeakRef]> = queues.weak_refs.drain(..).collect(); + weak_ref_marks.sort(); + weak_ref_marks.iter().for_each(|&idx| { + let index = idx.get_index(); + if let Some(marked) = bits.weak_refs.get_mut(index) { + if *marked { + // Already marked, ignore + return; + } + *marked = true; + weak_refs.get(index).mark_values(&mut queues); } - *marked = true; - weak_refs.get(index).mark_values(&mut queues); - } - }); - let mut weak_set_marks: Box<[WeakSet]> = queues.weak_sets.drain(..).collect(); - weak_set_marks.sort(); - weak_set_marks.iter().for_each(|&idx| { - let index = idx.get_index(); - if let Some(marked) = bits.weak_sets.get_mut(index) { - if *marked { - // Already marked, ignore - return; + }); + let mut weak_set_marks: Box<[WeakSet]> = queues.weak_sets.drain(..).collect(); + weak_set_marks.sort(); + weak_set_marks.iter().for_each(|&idx| { + let index = idx.get_index(); + if let Some(marked) = bits.weak_sets.get_mut(index) { + if *marked { + // Already marked, ignore + return; + } + *marked = true; + weak_sets.get(index).mark_values(&mut queues); } - *marked = true; - weak_sets.get(index).mark_values(&mut queues); - } - }); + }); + } + let mut e_2_4_marks: Box<[(ElementIndex, u32)]> = queues.e_2_4.drain(..).collect(); e_2_4_marks.sort(); e_2_4_marks.iter().for_each(|&(idx, len)| { @@ -984,9 +985,11 @@ fn sweep(heap: &mut Heap, bits: &HeapBits, root_realms: &mut [Option; pub type SymbolIndex = BaseIndex; #[cfg(feature = "array-buffer")] pub type TypedArrayIndex = BaseIndex; -#[cfg(feature = "weak-map")] +#[cfg(feature = "weak-refs")] pub type WeakMapIndex = BaseIndex; +#[cfg(feature = "weak-refs")] pub type WeakRefIndex = BaseIndex; +#[cfg(feature = "weak-refs")] pub type WeakSetIndex = BaseIndex; // Implement Default for ElementIndex: This is done to support Default From 9c157b7bdff1e25cb7c3e93e2d6b78acb8f23aaf Mon Sep 17 00:00:00 2001 From: Dean Srebnik <49134864+load1n9@users.noreply.github.com> Date: Mon, 14 Oct 2024 11:16:30 -0400 Subject: [PATCH 3/4] fix: add weak-refs feature by default --- nova_vm/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nova_vm/Cargo.toml b/nova_vm/Cargo.toml index b851accd5..103c74895 100644 --- a/nova_vm/Cargo.toml +++ b/nova_vm/Cargo.toml @@ -23,7 +23,7 @@ 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 = [] From 26b074a316aa4abed221fb33f64a192911d9149d Mon Sep 17 00:00:00 2001 From: Dean Srebnik <49134864+load1n9@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:59:52 -0400 Subject: [PATCH 4/4] chore: fmt --- nova_vm/src/ecmascript/builtins/ordinary.rs | 8 ++++---- nova_vm/src/ecmascript/execution/realm/intrinsics.rs | 12 ++++++------ nova_vm/src/heap/heap_bits.rs | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/nova_vm/src/ecmascript/builtins/ordinary.rs b/nova_vm/src/ecmascript/builtins/ordinary.rs index ee94f7a4f..66dd63dc3 100644 --- a/nova_vm/src/ecmascript/builtins/ordinary.rs +++ b/nova_vm/src/ecmascript/builtins/ordinary.rs @@ -975,9 +975,9 @@ pub(crate) fn ordinary_object_create_with_intrinsics( .into_object(), #[cfg(feature = "weak-refs")] ProtoIntrinsics::WeakMap => agent.heap.create(WeakMapHeapData::default()).into_object(), - #[cfg(feature = "weak-refs")] + #[cfg(feature = "weak-refs")] ProtoIntrinsics::WeakRef => agent.heap.create(WeakRefHeapData::default()).into_object(), - #[cfg(feature = "weak-refs")] + #[cfg(feature = "weak-refs")] ProtoIntrinsics::WeakSet => agent.heap.create(WeakSetHeapData::default()).into_object(), }; @@ -1117,9 +1117,9 @@ pub(crate) fn get_prototype_from_constructor( ProtoIntrinsics::UriError => Some(intrinsics.uri_error().into_function()), #[cfg(feature = "weak-refs")] ProtoIntrinsics::WeakMap => Some(intrinsics.weak_map().into_function()), - #[cfg(feature = "weak-refs")] + #[cfg(feature = "weak-refs")] ProtoIntrinsics::WeakRef => Some(intrinsics.weak_ref().into_function()), - #[cfg(feature = "weak-refs")] + #[cfg(feature = "weak-refs")] ProtoIntrinsics::WeakSet => Some(intrinsics.weak_set().into_function()), }; if Some(constructor) == intrinsic_constructor { diff --git a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs index e4fc3bca0..ecd2e83bd 100644 --- a/nova_vm/src/ecmascript/execution/realm/intrinsics.rs +++ b/nova_vm/src/ecmascript/execution/realm/intrinsics.rs @@ -1758,17 +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")] + #[cfg(feature = "weak-refs")] self.weak_map_prototype().mark_values(queues); - #[cfg(feature = "weak-refs")] + #[cfg(feature = "weak-refs")] self.weak_map().mark_values(queues); - #[cfg(feature = "weak-refs")] + #[cfg(feature = "weak-refs")] self.weak_ref_prototype().mark_values(queues); - #[cfg(feature = "weak-refs")] + #[cfg(feature = "weak-refs")] self.weak_ref().mark_values(queues); - #[cfg(feature = "weak-refs")] + #[cfg(feature = "weak-refs")] self.weak_set_prototype().mark_values(queues); - #[cfg(feature = "weak-refs")] + #[cfg(feature = "weak-refs")] self.weak_set().mark_values(queues); } diff --git a/nova_vm/src/heap/heap_bits.rs b/nova_vm/src/heap/heap_bits.rs index ede7a15be..bc1243a5a 100644 --- a/nova_vm/src/heap/heap_bits.rs +++ b/nova_vm/src/heap/heap_bits.rs @@ -472,7 +472,6 @@ impl WorkQueues { #[cfg(not(feature = "weak-refs"))] let weak_sets: &[bool; 0] = &[]; - array_buffers.is_empty() && arrays.is_empty() && array_iterators.is_empty()