Bug 1531035 - Assert that weak map keys are not null r=sfink
authorJon Coppeard <jcoppeard@mozilla.com>
Thu, 28 Feb 2019 16:38:49 +0000
changeset 519628 1edf55d690f2deed93a506589c4053a962f0758e
parent 519627 70b353cfbbf301b0175d6b36a957fd49479a5b2d
child 519629 664a5bdd8ab159d09bb75148a59ff5eaeafdabe8
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfink
bugs1531035
milestone67.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 1531035 - Assert that weak map keys are not null r=sfink
js/src/gc/WeakMap.h
js/src/vm/Debugger.h
--- a/js/src/gc/WeakMap.h
+++ b/js/src/gc/WeakMap.h
@@ -136,50 +136,73 @@ class WeakMapBase : public mozilla::Link
   // Whether this object has been marked during garbage collection and which
   // color it was marked.
   bool marked;
   gc::MarkColor markColor;
 };
 
 template <class Key, class Value>
 class WeakMap
-    : public HashMap<Key, Value, MovableCellHasher<Key>, ZoneAllocPolicy>,
+    : private HashMap<Key, Value, MovableCellHasher<Key>, ZoneAllocPolicy>,
       public WeakMapBase {
  public:
-  typedef HashMap<Key, Value, MovableCellHasher<Key>, ZoneAllocPolicy> Base;
-  typedef typename Base::Enum Enum;
-  typedef typename Base::Lookup Lookup;
-  typedef typename Base::Entry Entry;
-  typedef typename Base::Range Range;
-  typedef typename Base::Ptr Ptr;
-  typedef typename Base::AddPtr AddPtr;
+  using Base = HashMap<Key, Value, MovableCellHasher<Key>, ZoneAllocPolicy>;
+
+  using Lookup = typename Base::Lookup;
+  using Entry = typename Base::Entry;
+  using Range = typename Base::Range;
+  using Ptr = typename Base::Ptr;
+  using AddPtr = typename Base::AddPtr;
+
+  struct Enum : public Base::Enum {
+    explicit Enum(WeakMap& map) : Base::Enum(static_cast<Base&>(map)) {}
+  };
+
+  using Base::all;
+  using Base::has;
+  using Base::clear;
+  using Base::shallowSizeOfExcludingThis;
+
+  // Resolve ambiguity with LinkedListElement<>::remove.
+  using Base::remove;
 
   explicit WeakMap(JSContext* cx, JSObject* memOf = nullptr);
 
-  // Overwritten to add a read barrier to prevent an incorrectly gray value
-  // from escaping the weak map. See the UnmarkGrayTracer::onChild comment in
-  // gc/Marking.cpp.
+  // Add a read barrier to prevent an incorrectly gray value from escaping the
+  // weak map. See the UnmarkGrayTracer::onChild comment in gc/Marking.cpp.
   Ptr lookup(const Lookup& l) const {
     Ptr p = Base::lookup(l);
     if (p) {
       exposeGCThingToActiveJS(p->value());
     }
     return p;
   }
 
   AddPtr lookupForAdd(const Lookup& l) {
     AddPtr p = Base::lookupForAdd(l);
     if (p) {
       exposeGCThingToActiveJS(p->value());
     }
     return p;
   }
 
-  // Resolve ambiguity with LinkedListElement<>::remove.
-  using Base::remove;
+  template <typename KeyInput, typename ValueInput>
+  MOZ_MUST_USE bool put(KeyInput&& key, ValueInput&& value) {
+    MOZ_ASSERT(key);
+    return Base::put(std::forward<KeyInput>(key),
+                     std::forward<ValueInput>(value));
+  }
+
+  template <typename KeyInput, typename ValueInput>
+  MOZ_MUST_USE bool relookupOrAdd(AddPtr& ptr, KeyInput&& key,
+                                  ValueInput&& value) {
+    MOZ_ASSERT(key);
+    return Base::relookupOrAdd(ptr, std::forward<KeyInput>(key),
+                               std::forward<ValueInput>(value));
+  }
 
   void markEntry(GCMarker* marker, gc::Cell* markedCell,
                  JS::GCCellPtr origKey) override;
 
   void trace(JSTracer* trc) override;
 
  protected:
   static void addWeakEntry(GCMarker* marker, JS::GCCellPtr key,
--- a/js/src/vm/Debugger.h
+++ b/js/src/vm/Debugger.h
@@ -144,22 +144,22 @@ class DebuggerWeakMap
 
   explicit DebuggerWeakMap(JSContext* cx)
       : Base(cx), zoneCounts(cx->zone()), compartment(cx->compartment()) {}
 
  public:
   // Expose those parts of HashMap public interface that are used by Debugger
   // methods.
 
-  typedef typename Base::Entry Entry;
-  typedef typename Base::Ptr Ptr;
-  typedef typename Base::AddPtr AddPtr;
-  typedef typename Base::Range Range;
-  typedef typename Base::Enum Enum;
-  typedef typename Base::Lookup Lookup;
+  using Entry = typename Base::Entry;
+  using Ptr = typename Base::Ptr;
+  using AddPtr = typename Base::AddPtr;
+  using Range = typename Base::Range;
+  using Enum = typename Base::Enum;
+  using Lookup = typename Base::Lookup;
 
   // Expose WeakMap public interface.
 
   using Base::all;
   using Base::lookup;
   using Base::lookupForAdd;
   using Base::remove;
   using Base::trace;