summaryrefslogtreecommitdiffstats
path: root/WebCore/bindings/v8/V8DOMMap.h
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/bindings/v8/V8DOMMap.h')
-rw-r--r--WebCore/bindings/v8/V8DOMMap.h61
1 files changed, 59 insertions, 2 deletions
diff --git a/WebCore/bindings/v8/V8DOMMap.h b/WebCore/bindings/v8/V8DOMMap.h
index 909fbcd..41dc2e04 100644
--- a/WebCore/bindings/v8/V8DOMMap.h
+++ b/WebCore/bindings/v8/V8DOMMap.h
@@ -31,8 +31,7 @@
#ifndef V8DOMMap_h
#define V8DOMMap_h
-#include "dom_wrapper_map.h"
-
+#include <wtf/HashMap.h>
#include <v8.h>
namespace WebCore {
@@ -41,6 +40,61 @@ namespace WebCore {
class SVGElementInstance;
#endif
+ // A table of wrappers with weak pointers.
+ // This table allows us to avoid track wrapped objects for debugging
+ // and for ensuring that we don't double wrap the same object.
+ template<class KeyType, class ValueType> class WeakReferenceMap {
+ public:
+ WeakReferenceMap(v8::WeakReferenceCallback callback) : m_weakReferenceCallback(callback) { }
+ #ifndef NDEBUG
+ virtual ~WeakReferenceMap()
+ {
+ if (m_map.size() > 0)
+ fprintf(stderr, "Leak %d JS wrappers.\n", m_map.size());
+ }
+ #endif
+
+ // Get the JS wrapper object of an object.
+ virtual v8::Persistent<ValueType> get(KeyType* obj)
+ {
+ ValueType* wrapper = m_map.get(obj);
+ return wrapper ? v8::Persistent<ValueType>(wrapper) : v8::Persistent<ValueType>();
+ }
+
+ virtual void set(KeyType* obj, v8::Persistent<ValueType> wrapper)
+ {
+ ASSERT(!m_map.contains(obj));
+ wrapper.MakeWeak(obj, m_weakReferenceCallback);
+ m_map.set(obj, *wrapper);
+ }
+
+ virtual void forget(KeyType* obj)
+ {
+ ASSERT(obj);
+ ValueType* wrapper = m_map.take(obj);
+ if (!wrapper)
+ return;
+
+ v8::Persistent<ValueType> handle(wrapper);
+ handle.Dispose();
+ handle.Clear();
+ }
+
+ bool contains(KeyType* obj) { return m_map.contains(obj); }
+
+ HashMap<KeyType*, ValueType*>& impl() { return m_map; }
+
+ protected:
+ HashMap<KeyType*, ValueType*> m_map;
+ v8::WeakReferenceCallback m_weakReferenceCallback;
+ };
+
+
+ template <class KeyType> class DOMWrapperMap : public WeakReferenceMap<KeyType, v8::Object> {
+ public:
+ DOMWrapperMap(v8::WeakReferenceCallback callback) : WeakReferenceMap<KeyType, v8::Object>(callback) { }
+ };
+
// Callback when JS wrapper of active DOM object is dead.
void weakActiveDOMObjectCallback(v8::Persistent<v8::Value> v8Object, void* domObject);
@@ -53,6 +107,9 @@ namespace WebCore {
// A map from a DOM object to its JS wrapper for DOM objects which can have pending activity.
DOMWrapperMap<void>& getActiveDOMObjectMap();
+ // This should be called to remove all DOM objects associated with the current thread when it is tearing down.
+ void removeAllDOMObjectsInCurrentThread();
+
#if ENABLE(SVG)
// A map for SVGElementInstances to its JS wrapper.
DOMWrapperMap<SVGElementInstance>& getDOMSVGElementInstanceMap();