summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/heap/Weak.h
diff options
context:
space:
mode:
Diffstat (limited to 'Source/JavaScriptCore/heap/Weak.h')
-rw-r--r--Source/JavaScriptCore/heap/Weak.h29
1 files changed, 28 insertions, 1 deletions
diff --git a/Source/JavaScriptCore/heap/Weak.h b/Source/JavaScriptCore/heap/Weak.h
index 0938249b8..e5e0a97ec 100644
--- a/Source/JavaScriptCore/heap/Weak.h
+++ b/Source/JavaScriptCore/heap/Weak.h
@@ -26,9 +26,10 @@
#ifndef Weak_h
#define Weak_h
-#include <wtf/Assertions.h>
#include "PassWeak.h"
#include "WeakSetInlines.h"
+#include <wtf/Assertions.h>
+#include <wtf/HashMap.h>
namespace JSC {
@@ -150,6 +151,32 @@ template<typename T> inline WeakImpl* Weak<T>::hashTableDeletedValue()
return reinterpret_cast<WeakImpl*>(-1);
}
+// This function helps avoid modifying a weak table while holding an iterator into it. (Object allocation
+// can run a finalizer that modifies the table. We avoid that by requiring a pre-constructed object as our value.)
+template<typename T, typename U> inline void weakAdd(HashMap<T, Weak<U> >& map, const T& key, PassWeak<U> value)
+{
+ ASSERT(!map.get(key));
+ map.set(key, value); // The table may still have a zombie for value.
+}
+
+template<typename T, typename U> inline void weakRemove(HashMap<T, Weak<U> >& map, const T& key, typename Weak<U>::GetType value)
+{
+ typename HashMap<T, Weak<U> >::iterator it = map.find(key);
+ ASSERT_UNUSED(value, value);
+ ASSERT(it != map.end());
+ ASSERT(it->second.was(value));
+ ASSERT(!it->second);
+ map.remove(it);
+}
+
+template<typename T> inline void weakClear(Weak<T>& weak, typename Weak<T>::GetType value)
+{
+ ASSERT_UNUSED(value, value);
+ ASSERT(weak.was(value));
+ ASSERT(!weak);
+ weak.clear();
+}
+
} // namespace JSC
namespace WTF {