diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-25 15:09:11 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-05-25 15:09:11 +0200 |
commit | a89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd (patch) | |
tree | b7abd9f49ae1d4d2e426a5883bfccd42b8e2ee12 /Source/JavaScriptCore/heap/Weak.h | |
parent | 8d473cf9743f1d30a16a27114e93bd5af5648d23 (diff) | |
download | qtwebkit-a89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd.tar.gz |
Imported WebKit commit eb5c1b8fe4d4b1b90b5137433fc58a91da0e6878 (http://svn.webkit.org/repository/webkit/trunk@118516)
Diffstat (limited to 'Source/JavaScriptCore/heap/Weak.h')
-rw-r--r-- | Source/JavaScriptCore/heap/Weak.h | 29 |
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 { |