Only add prototypes to the PrototypeMap if they're not already present
[WebKit-https.git] / Source / JavaScriptCore / runtime / PrototypeMapInlines.h
index 1d269d0..4dcd7c9 100644 (file)
@@ -44,7 +44,11 @@ ALWAYS_INLINE TriState PrototypeMap::isPrototype(JSObject* object) const
 
 ALWAYS_INLINE void PrototypeMap::addPrototype(JSObject* object)
 {
-    m_prototypes.set(object, object);
+    auto addResult = m_prototypes.add(object, Weak<JSObject>());
+    if (addResult.isNewEntry)
+        addResult.iterator->value = Weak<JSObject>(object);
+    else
+        ASSERT(addResult.iterator->value.get() == object);
 
     // Note that this method makes the somewhat odd decision to not check if this
     // object currently has indexed accessors. We could do that check here, and if