Bug 1590492 - Rename ObjectValueMap to ObjectValueWeakMap to avoid confusion r=sfink
authorJon Coppeard <jcoppeard@mozilla.com>
Tue, 22 Oct 2019 18:03:20 +0000
changeset 498654 0d8eb90bc70c111944a4c33e483c33a7ed3d14b5
parent 498653 f7c323d26c22ec61e3ea74700aceb87df280e1b2
child 498655 6a00c4d68d5960f06906264614b9441d4a32b3ed
push id36723
push userapavel@mozilla.com
push dateWed, 23 Oct 2019 15:48:18 +0000
treeherdermozilla-central@782f341be605 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1590492
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1590492 - Rename ObjectValueMap to ObjectValueWeakMap to avoid confusion r=sfink Differential Revision: https://phabricator.services.mozilla.com/D50089
js/src/builtin/WeakMapObject-inl.h
js/src/builtin/WeakMapObject.cpp
js/src/builtin/WeakMapObject.h
js/src/builtin/WeakSetObject.cpp
js/src/gc/WeakMap.cpp
js/src/gc/WeakMap.h
--- a/js/src/builtin/WeakMapObject-inl.h
+++ b/js/src/builtin/WeakMapObject-inl.h
@@ -25,19 +25,19 @@ static bool TryPreserveReflector(JSConte
     }
   }
   return true;
 }
 
 static MOZ_ALWAYS_INLINE bool WeakCollectionPutEntryInternal(
     JSContext* cx, Handle<WeakCollectionObject*> obj, HandleObject key,
     HandleValue value) {
-  ObjectValueMap* map = obj->getMap();
+  ObjectValueWeakMap* map = obj->getMap();
   if (!map) {
-    auto newMap = cx->make_unique<ObjectValueMap>(cx, obj.get());
+    auto newMap = cx->make_unique<ObjectValueWeakMap>(cx, obj.get());
     if (!newMap) {
       return false;
     }
     map = newMap.release();
     InitObjectPrivate(obj, map, MemoryUse::WeakMapObject);
   }
 
   // Preserve wrapped native keys to prevent wrapper optimization.
--- a/js/src/builtin/WeakMapObject.cpp
+++ b/js/src/builtin/WeakMapObject.cpp
@@ -26,17 +26,17 @@ using namespace js;
     JSContext* cx, const CallArgs& args) {
   MOZ_ASSERT(is(args.thisv()));
 
   if (!args.get(0).isObject()) {
     args.rval().setBoolean(false);
     return true;
   }
 
-  if (ObjectValueMap* map =
+  if (ObjectValueWeakMap* map =
           args.thisv().toObject().as<WeakMapObject>().getMap()) {
     JSObject* key = &args[0].toObject();
     if (map->has(key)) {
       args.rval().setBoolean(true);
       return true;
     }
   }
 
@@ -55,20 +55,20 @@ bool WeakMapObject::has(JSContext* cx, u
     JSContext* cx, const CallArgs& args) {
   MOZ_ASSERT(WeakMapObject::is(args.thisv()));
 
   if (!args.get(0).isObject()) {
     args.rval().setUndefined();
     return true;
   }
 
-  if (ObjectValueMap* map =
+  if (ObjectValueWeakMap* map =
           args.thisv().toObject().as<WeakMapObject>().getMap()) {
     JSObject* key = &args[0].toObject();
-    if (ObjectValueMap::Ptr ptr = map->lookup(key)) {
+    if (ObjectValueWeakMap::Ptr ptr = map->lookup(key)) {
       args.rval().set(ptr->value());
       return true;
     }
   }
 
   args.rval().setUndefined();
   return true;
 }
@@ -84,20 +84,20 @@ bool WeakMapObject::get(JSContext* cx, u
     JSContext* cx, const CallArgs& args) {
   MOZ_ASSERT(WeakMapObject::is(args.thisv()));
 
   if (!args.get(0).isObject()) {
     args.rval().setBoolean(false);
     return true;
   }
 
-  if (ObjectValueMap* map =
+  if (ObjectValueWeakMap* map =
           args.thisv().toObject().as<WeakMapObject>().getMap()) {
     JSObject* key = &args[0].toObject();
-    if (ObjectValueMap::Ptr ptr = map->lookup(key)) {
+    if (ObjectValueWeakMap::Ptr ptr = map->lookup(key)) {
       map->remove(ptr);
       args.rval().setBoolean(true);
       return true;
     }
   }
 
   args.rval().setBoolean(false);
   return true;
@@ -137,20 +137,21 @@ bool WeakMapObject::set(JSContext* cx, u
 }
 
 bool WeakCollectionObject::nondeterministicGetKeys(
     JSContext* cx, Handle<WeakCollectionObject*> obj, MutableHandleObject ret) {
   RootedObject arr(cx, NewDenseEmptyArray(cx));
   if (!arr) {
     return false;
   }
-  if (ObjectValueMap* map = obj->getMap()) {
+  if (ObjectValueWeakMap* map = obj->getMap()) {
     // Prevent GC from mutating the weakmap while iterating.
     gc::AutoSuppressGC suppress(cx);
-    for (ObjectValueMap::Base::Range r = map->all(); !r.empty(); r.popFront()) {
+    for (ObjectValueWeakMap::Base::Range r = map->all(); !r.empty();
+         r.popFront()) {
       JS::ExposeObjectToActiveJS(r.front().key());
       RootedObject key(cx, r.front().key());
       if (!cx->compartment()->wrap(cx, &key)) {
         return false;
       }
       if (!NewbornArrayPush(cx, arr, ObjectValue(*key))) {
         return false;
       }
@@ -168,24 +169,24 @@ JS_FRIEND_API bool JS_NondeterministicGe
     ret.set(nullptr);
     return true;
   }
   return WeakCollectionObject::nondeterministicGetKeys(
       cx, obj.as<WeakCollectionObject>(), ret);
 }
 
 static void WeakCollection_trace(JSTracer* trc, JSObject* obj) {
-  if (ObjectValueMap* map = obj->as<WeakCollectionObject>().getMap()) {
+  if (ObjectValueWeakMap* map = obj->as<WeakCollectionObject>().getMap()) {
     map->trace(trc);
   }
 }
 
 static void WeakCollection_finalize(JSFreeOp* fop, JSObject* obj) {
   MOZ_ASSERT(fop->maybeOnHelperThread());
-  if (ObjectValueMap* map = obj->as<WeakCollectionObject>().getMap()) {
+  if (ObjectValueWeakMap* map = obj->as<WeakCollectionObject>().getMap()) {
     fop->delete_(obj, map, MemoryUse::WeakMapObject);
   }
 }
 
 JS_PUBLIC_API JSObject* JS::NewWeakMapObject(JSContext* cx) {
   return NewBuiltinClassInstance<WeakMapObject>(cx);
 }
 
@@ -194,21 +195,21 @@ JS_PUBLIC_API bool JS::IsWeakMapObject(J
 }
 
 JS_PUBLIC_API bool JS::GetWeakMapEntry(JSContext* cx, HandleObject mapObj,
                                        HandleObject key,
                                        MutableHandleValue rval) {
   CHECK_THREAD(cx);
   cx->check(key);
   rval.setUndefined();
-  ObjectValueMap* map = mapObj->as<WeakMapObject>().getMap();
+  ObjectValueWeakMap* map = mapObj->as<WeakMapObject>().getMap();
   if (!map) {
     return true;
   }
-  if (ObjectValueMap::Ptr ptr = map->lookup(key)) {
+  if (ObjectValueWeakMap::Ptr ptr = map->lookup(key)) {
     // Read barrier to prevent an incorrectly gray value from escaping the
     // weak map. See the comment before UnmarkGrayChildren in gc/Marking.cpp
     ExposeValueToActiveJS(ptr->value().get());
     rval.set(ptr->value());
   }
   return true;
 }
 
--- a/js/src/builtin/WeakMapObject.h
+++ b/js/src/builtin/WeakMapObject.h
@@ -12,22 +12,22 @@
 
 namespace js {
 
 class GlobalObject;
 
 // Abstract base class for WeakMapObject and WeakSetObject.
 class WeakCollectionObject : public NativeObject {
  public:
-  ObjectValueMap* getMap() {
-    return static_cast<ObjectValueMap*>(getPrivate());
+  ObjectValueWeakMap* getMap() {
+    return static_cast<ObjectValueWeakMap*>(getPrivate());
   }
 
   size_t sizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) {
-    ObjectValueMap* map = getMap();
+    ObjectValueWeakMap* map = getMap();
     return map ? map->sizeOfIncludingThis(aMallocSizeOf) : 0;
   }
 
   static MOZ_MUST_USE bool nondeterministicGetKeys(
       JSContext* cx, Handle<WeakCollectionObject*> obj,
       MutableHandleObject ret);
 
  protected:
--- a/js/src/builtin/WeakSetObject.cpp
+++ b/js/src/builtin/WeakSetObject.cpp
@@ -66,20 +66,20 @@ bool WeakSetObject::add(JSContext* cx, u
 
   // Step 4.
   if (!args.get(0).isObject()) {
     args.rval().setBoolean(false);
     return true;
   }
 
   // Steps 5-6.
-  if (ObjectValueMap* map =
+  if (ObjectValueWeakMap* map =
           args.thisv().toObject().as<WeakSetObject>().getMap()) {
     JSObject* value = &args[0].toObject();
-    if (ObjectValueMap::Ptr ptr = map->lookup(value)) {
+    if (ObjectValueWeakMap::Ptr ptr = map->lookup(value)) {
       map->remove(ptr);
       args.rval().setBoolean(true);
       return true;
     }
   }
 
   // Step 7.
   args.rval().setBoolean(false);
@@ -102,17 +102,17 @@ bool WeakSetObject::delete_(JSContext* c
 
   // Step 5.
   if (!args.get(0).isObject()) {
     args.rval().setBoolean(false);
     return true;
   }
 
   // Steps 4, 6.
-  if (ObjectValueMap* map =
+  if (ObjectValueWeakMap* map =
           args.thisv().toObject().as<WeakSetObject>().getMap()) {
     JSObject* value = &args[0].toObject();
     if (map->has(value)) {
       args.rval().setBoolean(true);
       return true;
     }
   }
 
--- a/js/src/gc/WeakMap.cpp
+++ b/js/src/gc/WeakMap.cpp
@@ -124,21 +124,22 @@ void WeakMapBase::restoreMarkedWeakMaps(
   for (WeakMapSet::Range r = markedWeakMaps.all(); !r.empty(); r.popFront()) {
     WeakMapBase* map = r.front();
     MOZ_ASSERT(map->zone()->isGCMarking());
     MOZ_ASSERT(!map->marked);
     map->marked = true;
   }
 }
 
-size_t ObjectValueMap::sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) {
+size_t ObjectValueWeakMap::sizeOfIncludingThis(
+    mozilla::MallocSizeOf mallocSizeOf) {
   return mallocSizeOf(this) + shallowSizeOfExcludingThis(mallocSizeOf);
 }
 
-bool ObjectValueMap::findSweepGroupEdges() {
+bool ObjectValueWeakMap::findSweepGroupEdges() {
   /*
    * For unmarked weakmap keys with delegates in a different zone, add a zone
    * edge to ensure that the delegate zone finishes marking before the key
    * zone.
    */
   JS::AutoSuppressGCAnalysis nogc;
   for (Range r = all(); !r.empty(); r.popFront()) {
     JSObject* key = r.front().key();
@@ -158,17 +159,17 @@ bool ObjectValueMap::findSweepGroupEdges
     }
   }
   return true;
 }
 
 ObjectWeakMap::ObjectWeakMap(JSContext* cx) : map(cx, nullptr) {}
 
 JSObject* ObjectWeakMap::lookup(const JSObject* obj) {
-  if (ObjectValueMap::Ptr p = map.lookup(const_cast<JSObject*>(obj))) {
+  if (ObjectValueWeakMap::Ptr p = map.lookup(const_cast<JSObject*>(obj))) {
     return &p->value().toObject();
   }
   return nullptr;
 }
 
 bool ObjectWeakMap::add(JSContext* cx, JSObject* obj, JSObject* target) {
   MOZ_ASSERT(obj && target);
 
@@ -186,14 +187,14 @@ void ObjectWeakMap::clear() { map.clear(
 void ObjectWeakMap::trace(JSTracer* trc) { map.trace(trc); }
 
 size_t ObjectWeakMap::sizeOfExcludingThis(mozilla::MallocSizeOf mallocSizeOf) {
   return map.shallowSizeOfExcludingThis(mallocSizeOf);
 }
 
 #ifdef JSGC_HASH_TABLE_CHECKS
 void ObjectWeakMap::checkAfterMovingGC() {
-  for (ObjectValueMap::Range r = map.all(); !r.empty(); r.popFront()) {
+  for (ObjectValueWeakMap::Range r = map.all(); !r.empty(); r.popFront()) {
     CheckGCThingAfterMovingGC(r.front().key().get());
     CheckGCThingAfterMovingGC(&r.front().value().toObject());
   }
 }
 #endif  // JSGC_HASH_TABLE_CHECKS
--- a/js/src/gc/WeakMap.h
+++ b/js/src/gc/WeakMap.h
@@ -242,17 +242,17 @@ class WeakMap
     JS::ExposeObjectToActiveJS(obj);
   }
 
   bool keyNeedsMark(GCMarker* marker, JSObject* key) const;
   bool keyNeedsMark(GCMarker* marker, JSScript* script) const;
   bool keyNeedsMark(GCMarker* marker, LazyScript* script) const;
 
   bool findSweepGroupEdges() override {
-    // This is overridden by ObjectValueMap and DebuggerWeakMap.
+    // This is overridden by ObjectValueWeakMap and DebuggerWeakMap.
     return true;
   }
 
   void sweep() override;
 
   void clearAndCompact() override {
     Base::clear();
     Base::compact();
@@ -267,28 +267,28 @@ class WeakMap
   void assertEntriesNotAboutToBeFinalized();
 #endif
 
 #ifdef JS_GC_ZEAL
   bool checkMarking() const override;
 #endif
 };
 
-class ObjectValueMap : public WeakMap<HeapPtr<JSObject*>, HeapPtr<Value>> {
+class ObjectValueWeakMap : public WeakMap<HeapPtr<JSObject*>, HeapPtr<Value>> {
  public:
-  ObjectValueMap(JSContext* cx, JSObject* obj) : WeakMap(cx, obj) {}
+  ObjectValueWeakMap(JSContext* cx, JSObject* obj) : WeakMap(cx, obj) {}
 
   bool findSweepGroupEdges() override;
 
   size_t sizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf);
 };
 
 // Generic weak map for mapping objects to other objects.
 class ObjectWeakMap {
-  ObjectValueMap map;
+  ObjectValueWeakMap map;
 
  public:
   explicit ObjectWeakMap(JSContext* cx);
 
   JS::Zone* zone() const { return map.zone(); }
 
   JSObject* lookup(const JSObject* obj);
   bool add(JSContext* cx, JSObject* obj, JSObject* target);
@@ -305,14 +305,14 @@ class ObjectWeakMap {
 #endif
 };
 
 } /* namespace js */
 
 namespace JS {
 
 template <>
-struct DeletePolicy<js::ObjectValueMap>
-    : public js::GCManagedDeletePolicy<js::ObjectValueMap> {};
+struct DeletePolicy<js::ObjectValueWeakMap>
+    : public js::GCManagedDeletePolicy<js::ObjectValueWeakMap> {};
 
 } /* namespace JS */
 
 #endif /* gc_WeakMap_h */