tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit e00ee9c5dc6fbeeed3f230a8077227f2dae251ec
parent b48243d060f0e0bd84e66d795ddcec182214b3dc
Author: Alexandru Marc <amarc@mozilla.com>
Date:   Mon, 27 Oct 2025 12:26:16 +0200

Revert "Bug 1993183 - Part 4: Use CellAllocPolicy for JS WeakMap objects r=sfink" for causing bug 1995159

This reverts commit fdebe325b1d13e571fb210622c28862cb46be6b7.

Revert "Bug 1993183 - Part 3: Update retained size for CellAllocPolicy during sweeping as well as finalizing r=sfink"

This reverts commit f8b3beb4090fa8ae59f5ec9a91087ef09f52f355.

Revert "Bug 1993183 - Part 2: Add WeakMap alloc policy template parameter r=sfink"

This reverts commit 4f9e513a488d238d7c090e3ecbd09e51b54631c2.

Revert "Bug 1993183 - Part 1: Remove weakmap type aliases r=sfink"

This reverts commit beee3e9ab8ff427d25aafb6cfa55bc23a4590ef0.

Diffstat:
Mjs/src/builtin/WeakMapObject-inl.h | 4++--
Mjs/src/builtin/WeakMapObject.cpp | 65+++++++++++++++++++++++++++++++++--------------------------------
Mjs/src/builtin/WeakMapObject.h | 8+++-----
Mjs/src/builtin/WeakSetObject.cpp | 10++++++----
Mjs/src/debugger/DebugScript.h | 3+--
Mjs/src/debugger/Debugger.h | 4++--
Mjs/src/gc/GCContext.h | 1-
Mjs/src/gc/WeakMap-inl.h | 63++++++++++++++++++++++++++++++---------------------------------
Mjs/src/gc/WeakMap.cpp | 2+-
Mjs/src/gc/WeakMap.h | 14++++++++++----
Mjs/src/gc/WeakMapPtr.cpp | 2+-
Mjs/src/gc/Zone.cpp | 2+-
Mjs/src/jsapi-tests/testGCGrayMarking.cpp | 6++----
Mjs/src/jsfriendapi.cpp | 3+--
Mjs/src/vm/EnvironmentObject.h | 3+--
Mjs/src/vm/Realm.cpp | 4++--
Mjs/src/vm/Realm.h | 8++------
17 files changed, 98 insertions(+), 104 deletions(-)

diff --git a/js/src/builtin/WeakMapObject-inl.h b/js/src/builtin/WeakMapObject-inl.h @@ -32,11 +32,11 @@ static MOZ_ALWAYS_INLINE bool EnsureObjectHasWeakMap( if (obj->getMap()) { return true; } - auto newMap = cx->make_unique<WeakCollectionObject::Map>(cx, obj); + auto newMap = cx->make_unique<ValueValueWeakMap>(cx, obj); if (!newMap) { return false; } - WeakCollectionObject::Map* map = newMap.release(); + ValueValueWeakMap* map = newMap.release(); InitReservedSlot(obj, WeakCollectionObject::DataSlot, map, MemoryUse::WeakMapObject); return true; diff --git a/js/src/builtin/WeakMapObject.cpp b/js/src/builtin/WeakMapObject.cpp @@ -37,7 +37,8 @@ using namespace js; return true; } - if (Map* map = args.thisv().toObject().as<WeakMapObject>().getMap()) { + if (ValueValueWeakMap* map = + args.thisv().toObject().as<WeakMapObject>().getMap()) { Value key = args[0]; if (map->has(key)) { args.rval().setBoolean(true); @@ -59,7 +60,7 @@ bool WeakMapObject::has(JSContext* cx, unsigned argc, Value* vp) { // static bool WeakMapObject::hasObject(WeakMapObject* weakMap, JSObject* obj) { AutoUnsafeCallWithABI unsafe; - Map* map = weakMap->getMap(); + ValueValueWeakMap* map = weakMap->getMap(); return map && map->has(ObjectValue(*obj)); } @@ -72,9 +73,10 @@ bool WeakMapObject::hasObject(WeakMapObject* weakMap, JSObject* obj) { return true; } - if (Map* map = args.thisv().toObject().as<WeakMapObject>().getMap()) { + if (ValueValueWeakMap* map = + args.thisv().toObject().as<WeakMapObject>().getMap()) { Value key = args[0]; - if (Map::Ptr ptr = map->lookup(key)) { + if (ValueValueWeakMap::Ptr ptr = map->lookup(key)) { args.rval().set(ptr->value()); return true; } @@ -95,8 +97,8 @@ bool WeakMapObject::get(JSContext* cx, unsigned argc, Value* vp) { void WeakMapObject::getObject(WeakMapObject* weakMap, JSObject* obj, Value* result) { AutoUnsafeCallWithABI unsafe; - if (Map* map = weakMap->getMap()) { - if (Map::Ptr ptr = map->lookup(ObjectValue(*obj))) { + if (ValueValueWeakMap* map = weakMap->getMap()) { + if (ValueValueWeakMap::Ptr ptr = map->lookup(ObjectValue(*obj))) { *result = ptr->value(); return; } @@ -113,12 +115,13 @@ void WeakMapObject::getObject(WeakMapObject* weakMap, JSObject* obj, return true; } - if (Map* map = args.thisv().toObject().as<WeakMapObject>().getMap()) { + if (ValueValueWeakMap* map = + args.thisv().toObject().as<WeakMapObject>().getMap()) { Value key = args[0]; // The lookup here is only used for the removal, so we can skip the read // barrier. This is not very important for performance, but makes it easier // to test nonbarriered removal from internal weakmaps (eg Debugger maps.) - if (Map::Ptr ptr = map->lookupUnbarriered(key)) { + if (ValueValueWeakMap::Ptr ptr = map->lookupUnbarriered(key)) { map->remove(ptr); args.rval().setBoolean(true); return true; @@ -184,8 +187,8 @@ static bool GetOrAddWeakMapEntry(JSContext* cx, Handle<WeakMapObject*> mapObj, return false; } - WeakCollectionObject::Map* map = mapObj->getMap(); - auto addPtr = map->lookupForAdd(key); + ValueValueWeakMap* map = mapObj->getMap(); + ValueValueWeakMap::AddPtr addPtr = map->lookupForAdd(key); if (!addPtr) { if (!PreserveReflectorAndAssertValidEntry(cx, mapObj, key, value)) { return false; @@ -216,12 +219,12 @@ bool WeakMapObject::getOrInsert(JSContext* cx, unsigned argc, Value* vp) { size_t WeakCollectionObject::sizeOfExcludingThis( mozilla::MallocSizeOf aMallocSizeOf) { - Map* map = getMap(); + ValueValueWeakMap* map = getMap(); return map ? map->sizeOfIncludingThis(aMallocSizeOf) : 0; } size_t WeakCollectionObject::nondeterministicGetSize() { - Map* map = getMap(); + ValueValueWeakMap* map = getMap(); if (!map) { return 0; } @@ -235,10 +238,10 @@ bool WeakCollectionObject::nondeterministicGetKeys( if (!arr) { return false; } - if (Map* map = obj->getMap()) { + if (ValueValueWeakMap* map = obj->getMap()) { // Prevent GC from mutating the weakmap while iterating. gc::AutoSuppressGC suppress(cx); - for (Map::Range r = map->all(); !r.empty(); r.popFront()) { + for (ValueValueWeakMap::Range r = map->all(); !r.empty(); r.popFront()) { const auto& key = r.front().key(); MOZ_ASSERT(key.isObject() || key.isSymbol()); JS::ExposeValueToActiveJS(key); @@ -267,16 +270,14 @@ JS_PUBLIC_API bool JS_NondeterministicGetWeakMapKeys(JSContext* cx, cx, obj.as<WeakCollectionObject>(), ret); } -/* static */ -void WeakCollectionObject::trace(JSTracer* trc, JSObject* obj) { - if (Map* map = obj->as<WeakCollectionObject>().getMap()) { +static void WeakCollection_trace(JSTracer* trc, JSObject* obj) { + if (ValueValueWeakMap* map = obj->as<WeakCollectionObject>().getMap()) { map->trace(trc); } } -/* static */ -void WeakCollectionObject::finalize(JS::GCContext* gcx, JSObject* obj) { - if (Map* map = obj->as<WeakCollectionObject>().getMap()) { +static void WeakCollection_finalize(JS::GCContext* gcx, JSObject* obj) { + if (ValueValueWeakMap* map = obj->as<WeakCollectionObject>().getMap()) { gcx->delete_(obj, map, MemoryUse::WeakMapObject); } } @@ -300,12 +301,12 @@ JS_PUBLIC_API bool JS::GetWeakMapEntry(JSContext* cx, HandleObject mapObj, return true; } - WeakMapObject::Map* map = mapObj->as<WeakMapObject>().getMap(); + ValueValueWeakMap* map = mapObj->as<WeakMapObject>().getMap(); if (!map) { return true; } - if (auto ptr = map->lookup(key)) { + if (ValueValueWeakMap::Ptr ptr = map->lookup(key)) { rval.set(ptr->value()); } return true; @@ -409,16 +410,16 @@ bool WeakMapObject::construct(JSContext* cx, unsigned argc, Value* vp) { } const JSClassOps WeakCollectionObject::classOps_ = { - nullptr, // addProperty - nullptr, // delProperty - nullptr, // enumerate - nullptr, // newEnumerate - nullptr, // resolve - nullptr, // mayResolve - &finalize, // finalize - nullptr, // call - nullptr, // construct - &trace, // trace + nullptr, // addProperty + nullptr, // delProperty + nullptr, // enumerate + nullptr, // newEnumerate + nullptr, // resolve + nullptr, // mayResolve + WeakCollection_finalize, // finalize + nullptr, // call + nullptr, // construct + WeakCollection_trace, // trace }; const ClassSpec WeakMapObject::classSpec_ = { diff --git a/js/src/builtin/WeakMapObject.h b/js/src/builtin/WeakMapObject.h @@ -17,8 +17,9 @@ class WeakCollectionObject : public NativeObject { public: enum { DataSlot, SlotCount }; - using Map = WeakMap<Value, Value, CellAllocPolicy>; - Map* getMap() { return maybePtrFromReservedSlot<Map>(DataSlot); } + ValueValueWeakMap* getMap() { + return maybePtrFromReservedSlot<ValueValueWeakMap>(DataSlot); + } size_t sizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf); @@ -29,9 +30,6 @@ class WeakCollectionObject : public NativeObject { protected: static const JSClassOps classOps_; - - static void trace(JSTracer* trc, JSObject* obj); - static void finalize(JS::GCContext* gcx, JSObject* obj); }; class WeakMapObject : public WeakCollectionObject { diff --git a/js/src/builtin/WeakSetObject.cpp b/js/src/builtin/WeakSetObject.cpp @@ -75,9 +75,10 @@ bool WeakSetObject::add(JSContext* cx, unsigned argc, Value* vp) { } // Steps 5-6. - if (Map* map = args.thisv().toObject().as<WeakSetObject>().getMap()) { + if (ValueValueWeakMap* map = + args.thisv().toObject().as<WeakSetObject>().getMap()) { Value value = args[0]; - if (Map::Ptr ptr = map->lookup(value)) { + if (ValueValueWeakMap::Ptr ptr = map->lookup(value)) { map->remove(ptr); args.rval().setBoolean(true); return true; @@ -110,7 +111,8 @@ bool WeakSetObject::delete_(JSContext* cx, unsigned argc, Value* vp) { } // Steps 4, 6. - if (Map* map = args.thisv().toObject().as<WeakSetObject>().getMap()) { + if (ValueValueWeakMap* map = + args.thisv().toObject().as<WeakSetObject>().getMap()) { Value value = args[0]; if (map->has(value)) { args.rval().setBoolean(true); @@ -134,7 +136,7 @@ bool WeakSetObject::has(JSContext* cx, unsigned argc, Value* vp) { // static bool WeakSetObject::hasObject(WeakSetObject* weakSet, JSObject* obj) { AutoUnsafeCallWithABI unsafe; - Map* map = weakSet->getMap(); + ValueValueWeakMap* map = weakSet->getMap(); return map && map->has(ObjectValue(*obj)); } diff --git a/js/src/debugger/DebugScript.h b/js/src/debugger/DebugScript.h @@ -150,8 +150,7 @@ class DebugScriptObject : public NativeObject { }; // A weak map from JSScripts to DebugScriptObjects. -class DebugScriptMap - : public WeakMap<JSScript*, DebugScriptObject*, ZoneAllocPolicy> { +class DebugScriptMap : public WeakMap<JSScript*, DebugScriptObject*> { public: explicit DebugScriptMap(JSContext* cx) : WeakMap(cx) {} }; diff --git a/js/src/debugger/Debugger.h b/js/src/debugger/Debugger.h @@ -336,7 +336,7 @@ extern void CheckDebuggeeThing(JSObject* obj, bool invisibleOk); * beacomes a debuggee again later, new Frame objects are created.) */ template <class Referent, class Wrapper, bool InvisibleKeysOk = false> -class DebuggerWeakMap : private WeakMap<Referent*, Wrapper*, ZoneAllocPolicy> { +class DebuggerWeakMap : private WeakMap<Referent*, Wrapper*> { private: using Key = Referent*; using Value = Wrapper*; @@ -344,7 +344,7 @@ class DebuggerWeakMap : private WeakMap<Referent*, Wrapper*, ZoneAllocPolicy> { JS::Compartment* compartment; public: - using Base = WeakMap<Key, Value, ZoneAllocPolicy>; + using Base = WeakMap<Key, Value>; using ReferentType = Referent; using WrapperType = Wrapper; diff --git a/js/src/gc/GCContext.h b/js/src/gc/GCContext.h @@ -106,7 +106,6 @@ class GCContext { js::gc::GCUse gcUse() const { return gcUse_; } bool isCollecting() const { return gcUse() != js::gc::GCUse::None; } - bool isSweeping() const { return gcUse_ == js::gc::GCUse::Sweeping; } bool isFinalizing() const { return gcUse_ == js::gc::GCUse::Finalizing; } #ifdef DEBUG diff --git a/js/src/gc/WeakMap-inl.h b/js/src/gc/WeakMap-inl.h @@ -92,8 +92,8 @@ static inline JSObject* GetDelegate(const T& key) { // were in different zones, then we could have a case where the map zone is not // collecting but the value zone is, and incorrectly free a value that is // reachable solely through weakmaps. -template <class K, class V, class AP> -void WeakMap<K, V, AP>::assertMapIsSameZoneWithValue(const BarrieredValue& v) { +template <class K, class V> +void WeakMap<K, V>::assertMapIsSameZoneWithValue(const BarrieredValue& v) { #ifdef DEBUG gc::Cell* cell = gc::ToMarkable(v); if (cell) { @@ -103,12 +103,12 @@ void WeakMap<K, V, AP>::assertMapIsSameZoneWithValue(const BarrieredValue& v) { #endif } -template <class K, class V, class AP> -WeakMap<K, V, AP>::WeakMap(JSContext* cx, JSObject* memOf) +template <class K, class V> +WeakMap<K, V>::WeakMap(JSContext* cx, JSObject* memOf) : WeakMap(cx->zone(), memOf) {} -template <class K, class V, class AP> -WeakMap<K, V, AP>::WeakMap(JS::Zone* zone, JSObject* memOf) +template <class K, class V> +WeakMap<K, V>::WeakMap(JS::Zone* zone, JSObject* memOf) : WeakMapBase(memOf, zone), map_(zone) { static_assert(std::is_same_v<typename RemoveBarrier<K>::Type, K>); static_assert(std::is_same_v<typename RemoveBarrier<V>::Type, V>); @@ -129,8 +129,8 @@ WeakMap<K, V, AP>::WeakMap(JS::Zone* zone, JSObject* memOf) } } -template <class K, class V, class AP> -WeakMap<K, V, AP>::~WeakMap() { +template <class K, class V> +WeakMap<K, V>::~WeakMap() { #ifdef DEBUG // Weak maps store their data in an unbarriered map (|map_|) meaning that no // barriers are run on destruction. This is safe because: @@ -162,10 +162,10 @@ WeakMap<K, V, AP>::~WeakMap() { // Optionally adds edges to the ephemeron edges table for any keys (or // delegates) where future changes to their mark color would require marking the // value (or the key). -template <class K, class V, class AP> -bool WeakMap<K, V, AP>::markEntry(GCMarker* marker, gc::CellColor mapColor, - BarrieredKey& key, BarrieredValue& value, - bool populateWeakKeysTable) { +template <class K, class V> +bool WeakMap<K, V>::markEntry(GCMarker* marker, gc::CellColor mapColor, + BarrieredKey& key, BarrieredValue& value, + bool populateWeakKeysTable) { #ifdef DEBUG MOZ_ASSERT(IsMarked(mapColor)); if (marker->isParallelMarking()) { @@ -253,8 +253,8 @@ bool WeakMap<K, V, AP>::markEntry(GCMarker* marker, gc::CellColor mapColor, return marked; } -template <class K, class V, class AP> -void WeakMap<K, V, AP>::trace(JSTracer* trc) { +template <class K, class V> +void WeakMap<K, V>::trace(JSTracer* trc) { MOZ_ASSERT(isInList()); TraceNullableEdge(trc, &memberOf, "WeakMap owner"); @@ -286,8 +286,8 @@ void WeakMap<K, V, AP>::trace(JSTracer* trc) { } } -template <class K, class V, class AP> -bool WeakMap<K, V, AP>::markEntries(GCMarker* marker) { +template <class K, class V> +bool WeakMap<K, V>::markEntries(GCMarker* marker) { // This method is called whenever the map's mark color changes. Mark values // (and keys with delegates) as required for the new color and populate the // ephemeron edges if we're in incremental marking mode. @@ -321,10 +321,8 @@ bool WeakMap<K, V, AP>::markEntries(GCMarker* marker) { return markedAny; } -template <class K, class V, class AP> -void WeakMap<K, V, AP>::traceWeakEdges(JSTracer* trc) { - MOZ_ASSERT(zone()->isGCSweeping()); - +template <class K, class V> +void WeakMap<K, V>::traceWeakEdges(JSTracer* trc) { // Scan the map, removing all entries whose keys remain unmarked. Rebuild // cached key state at the same time. mayHaveSymbolKeys = false; @@ -345,8 +343,8 @@ void WeakMap<K, V, AP>::traceWeakEdges(JSTracer* trc) { } // memberOf can be nullptr, which means that the map is not part of a JSObject. -template <class K, class V, class AP> -void WeakMap<K, V, AP>::traceMappings(WeakMapTracer* tracer) { +template <class K, class V> +void WeakMap<K, V>::traceMappings(WeakMapTracer* tracer) { for (Range r = all(); !r.empty(); r.popFront()) { gc::Cell* key = gc::ToMarkable(r.front().key()); gc::Cell* value = gc::ToMarkable(r.front().value()); @@ -357,8 +355,8 @@ void WeakMap<K, V, AP>::traceMappings(WeakMapTracer* tracer) { } } -template <class K, class V, class AP> -bool WeakMap<K, V, AP>::findSweepGroupEdges(Zone* atomsZone) { +template <class K, class V> +bool WeakMap<K, V>::findSweepGroupEdges(Zone* atomsZone) { // For weakmap keys with delegates in a different zone, add a zone edge to // ensure that the delegate zone finishes marking before the key zone. @@ -406,15 +404,14 @@ bool WeakMap<K, V, AP>::findSweepGroupEdges(Zone* atomsZone) { return true; } -template <class K, class V, class AP> -size_t WeakMap<K, V, AP>::sizeOfIncludingThis( - mozilla::MallocSizeOf mallocSizeOf) { +template <class K, class V> +size_t WeakMap<K, V>::sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) { return mallocSizeOf(this) + shallowSizeOfExcludingThis(mallocSizeOf); } #if DEBUG -template <class K, class V, class AP> -void WeakMap<K, V, AP>::assertEntriesNotAboutToBeFinalized() { +template <class K, class V> +void WeakMap<K, V>::assertEntriesNotAboutToBeFinalized() { for (Range r = all(); !r.empty(); r.popFront()) { K k = r.front().key(); MOZ_ASSERT(!gc::IsAboutToBeFinalizedUnbarriered(k)); @@ -429,8 +426,8 @@ void WeakMap<K, V, AP>::assertEntriesNotAboutToBeFinalized() { #endif #ifdef JS_GC_ZEAL -template <class K, class V, class AP> -bool WeakMap<K, V, AP>::checkMarking() const { +template <class K, class V> +bool WeakMap<K, V>::checkMarking() const { bool ok = true; for (Range r = all(); !r.empty(); r.popFront()) { gc::Cell* key = gc::ToMarkable(r.front().key()); @@ -445,8 +442,8 @@ bool WeakMap<K, V, AP>::checkMarking() const { #endif #ifdef JSGC_HASH_TABLE_CHECKS -template <class K, class V, class AP> -void WeakMap<K, V, AP>::checkAfterMovingGC() const { +template <class K, class V> +void WeakMap<K, V>::checkAfterMovingGC() const { for (Range r = all(); !r.empty(); r.popFront()) { gc::Cell* key = gc::ToMarkable(r.front().key()); gc::Cell* value = gc::ToMarkable(r.front().value()); diff --git a/js/src/gc/WeakMap.cpp b/js/src/gc/WeakMap.cpp @@ -188,5 +188,5 @@ void WeakMapBase::restoreMarkedWeakMaps(WeakMapColors& markedWeakMaps) { } namespace js { -template class WeakMap<JSObject*, JSObject*, ZoneAllocPolicy>; +template class WeakMap<JSObject*, JSObject*>; } // namespace js diff --git a/js/src/gc/WeakMap.h b/js/src/gc/WeakMap.h @@ -203,15 +203,15 @@ class WeakMapBase : public mozilla::LinkedListElement<WeakMapBase> { template <typename Key> struct WeakMapKeyHasher : public StableCellHasher<HeapPtr<Key>> {}; -template <class Key, class Value, class AllocPolicy> +template <class Key, class Value> class WeakMap : public WeakMapBase { using BarrieredKey = HeapPtr<Key>; using BarrieredValue = HeapPtr<Value>; - using Map = - HashMap<HeapPtr<Key>, HeapPtr<Value>, WeakMapKeyHasher<Key>, AllocPolicy>; + using Map = HashMap<HeapPtr<Key>, HeapPtr<Value>, WeakMapKeyHasher<Key>, + ZoneAllocPolicy>; using UnbarrieredMap = - HashMap<Key, Value, StableCellHasher<Key>, AllocPolicy>; + HashMap<Key, Value, StableCellHasher<Key>, ZoneAllocPolicy>; UnbarrieredMap map_; // Barriers are added by |map()| accessor. @@ -385,6 +385,12 @@ class WeakMap : public WeakMapBase { void traceMappings(WeakMapTracer* tracer) override; }; +using ObjectValueWeakMap = WeakMap<JSObject*, Value>; +using ValueValueWeakMap = WeakMap<Value, Value>; + +// Generic weak map for mapping objects to other objects. +using ObjectWeakMap = WeakMap<JSObject*, JSObject*>; + // Get the hash from the Symbol. HashNumber GetSymbolHash(JS::Symbol* sym); diff --git a/js/src/gc/WeakMapPtr.cpp b/js/src/gc/WeakMapPtr.cpp @@ -34,7 +34,7 @@ template <typename K, typename V> struct Utils { using KeyType = K; using ValueType = V; - using Type = WeakMap<KeyType, ValueType, ZoneAllocPolicy>; + using Type = WeakMap<KeyType, ValueType>; using PtrType = Type*; static PtrType cast(void* ptr) { return static_cast<PtrType>(ptr); } }; diff --git a/js/src/gc/Zone.cpp b/js/src/gc/Zone.cpp @@ -144,7 +144,7 @@ void js::TrackedAllocPolicy<kind>::decMemory(size_t nbytes) { // Only subtract freed cell memory from retained size for cell associations // during sweeping. JS::GCContext* gcx = TlsGCContext.get(); - updateRetainedSize = gcx->isSweeping() || gcx->isFinalizing(); + updateRetainedSize = gcx->isFinalizing(); } zone_->decNonGCMemory(this, nbytes, MemoryUse::TrackedAllocPolicy, diff --git a/js/src/jsapi-tests/testGCGrayMarking.cpp b/js/src/jsapi-tests/testGCGrayMarking.cpp @@ -26,10 +26,8 @@ static constexpr CellColor MarkedCellColors[] = {CellColor::Gray, namespace js { -struct GCManagedObjectWeakMap - : public WeakMap<JSObject*, JSObject*, ZoneAllocPolicy> { - using Base = WeakMap<JSObject*, JSObject*, ZoneAllocPolicy>; - using Base::Base; +struct GCManagedObjectWeakMap : public ObjectWeakMap { + using ObjectWeakMap::ObjectWeakMap; }; } // namespace js diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp @@ -741,8 +741,7 @@ JS_PUBLIC_API void js::SetAllocationMetadataBuilder( } JS_PUBLIC_API JSObject* js::GetAllocationMetadata(JSObject* obj) { - ObjectRealm::ObjectMetadataTable* map = - ObjectRealm::get(obj).objectMetadataTable.get(); + ObjectWeakMap* map = ObjectRealm::get(obj).objectMetadataTable.get(); if (map) { auto ptr = map->lookup(obj); if (ptr) { diff --git a/js/src/vm/EnvironmentObject.h b/js/src/vm/EnvironmentObject.h @@ -1470,8 +1470,7 @@ class DebugEnvironments { Zone* zone_; /* The map from (non-debug) environments to debug environments. */ - using ProxiedEnvironmentsMap = WeakMap<JSObject*, JSObject*, ZoneAllocPolicy>; - ProxiedEnvironmentsMap proxiedEnvs; + ObjectWeakMap proxiedEnvs; /* * The map from live frames which have optimized-away environments to the diff --git a/js/src/vm/Realm.cpp b/js/src/vm/Realm.cpp @@ -148,7 +148,7 @@ ObjectRealm::getOrCreateNonSyntacticLexicalEnvironment(JSContext* cx, MOZ_ASSERT(&ObjectRealm::get(enclosing) == this); if (!nonSyntacticLexicalEnvironments_) { - auto map = cx->make_unique<NonSyntacticLexialEnvironmentsMap>(cx); + auto map = cx->make_unique<ObjectWeakMap>(cx); if (!map) { return nullptr; } @@ -419,7 +419,7 @@ void Realm::setNewObjectMetadata(JSContext* cx, HandleObject obj) { cx->check(metadata); if (!objects_.objectMetadataTable) { - auto table = cx->make_unique<ObjectRealm::ObjectMetadataTable>(cx); + auto table = cx->make_unique<ObjectWeakMap>(cx); if (!table) { oomUnsafe.crash("setNewObjectMetadata"); } diff --git a/js/src/vm/Realm.h b/js/src/vm/Realm.h @@ -240,10 +240,7 @@ class ObjectRealm { // All non-syntactic lexical environments in the realm. These are kept in a // map because when loading scripts into a non-syntactic environment, we // need to use the same lexical environment to persist lexical bindings. - using NonSyntacticLexialEnvironmentsMap = - WeakMap<JSObject*, JSObject*, ZoneAllocPolicy>; - js::UniquePtr<NonSyntacticLexialEnvironmentsMap> - nonSyntacticLexicalEnvironments_; + js::UniquePtr<js::ObjectWeakMap> nonSyntacticLexicalEnvironments_; ObjectRealm(const ObjectRealm&) = delete; void operator=(const ObjectRealm&) = delete; @@ -254,8 +251,7 @@ class ObjectRealm { // Keep track of the metadata objects which can be associated with each JS // object. Both keys and values are in this realm. - using ObjectMetadataTable = WeakMap<JSObject*, JSObject*, ZoneAllocPolicy>; - js::UniquePtr<ObjectMetadataTable> objectMetadataTable; + js::UniquePtr<js::ObjectWeakMap> objectMetadataTable; using IteratorCache = js::HashSet<js::PropertyIteratorObject*, js::IteratorHashPolicy,