From a89b2ebb8e192c5e8cea21079bda2ee2c0c7dddd Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 25 May 2012 15:09:11 +0200 Subject: Imported WebKit commit eb5c1b8fe4d4b1b90b5137433fc58a91da0e6878 (http://svn.webkit.org/repository/webkit/trunk@118516) --- Source/JavaScriptCore/heap/Weak.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'Source/JavaScriptCore/heap/Weak.h') 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 #include "PassWeak.h" #include "WeakSetInlines.h" +#include +#include namespace JSC { @@ -150,6 +151,32 @@ template inline WeakImpl* Weak::hashTableDeletedValue() return reinterpret_cast(-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 inline void weakAdd(HashMap >& map, const T& key, PassWeak value) +{ + ASSERT(!map.get(key)); + map.set(key, value); // The table may still have a zombie for value. +} + +template inline void weakRemove(HashMap >& map, const T& key, typename Weak::GetType value) +{ + typename HashMap >::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 inline void weakClear(Weak& weak, typename Weak::GetType value) +{ + ASSERT_UNUSED(value, value); + ASSERT(weak.was(value)); + ASSERT(!weak); + weak.clear(); +} + } // namespace JSC namespace WTF { -- cgit v1.2.1