[V8] Generalize NodeWrapperMap to be able to handle other sorts of keys
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Nov 2012 00:24:06 +0000 (00:24 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Nov 2012 00:24:06 +0000 (00:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=100973

Reviewed by Kentaro Hara.

This is the first step towards using intrusive DOM wrapper maps more
widely in WebCore (see
http://lists.webkit.org/pipermail/webkit-dev/2012-November/022686.html
for more context).

* bindings/v8/DOMDataStore.cpp:
(WebCore::DOMDataStore::DOMDataStore):
* bindings/v8/IntrusiveDOMWrapperMap.h:
(WebCore):
(WebCore::IntrusiveDOMWrapperMap::weakCallback):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@133244 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/bindings/v8/DOMDataStore.cpp
Source/WebCore/bindings/v8/IntrusiveDOMWrapperMap.h

index 900f4e4..f935872 100644 (file)
@@ -1,3 +1,21 @@
+2012-11-01  Adam Barth  <abarth@webkit.org>
+
+        [V8] Generalize NodeWrapperMap to be able to handle other sorts of keys
+        https://bugs.webkit.org/show_bug.cgi?id=100973
+
+        Reviewed by Kentaro Hara.
+
+        This is the first step towards using intrusive DOM wrapper maps more
+        widely in WebCore (see
+        http://lists.webkit.org/pipermail/webkit-dev/2012-November/022686.html
+        for more context).
+
+        * bindings/v8/DOMDataStore.cpp:
+        (WebCore::DOMDataStore::DOMDataStore):
+        * bindings/v8/IntrusiveDOMWrapperMap.h:
+        (WebCore):
+        (WebCore::IntrusiveDOMWrapperMap::weakCallback):
+
 2012-11-01  Alexandru Chiculita  <achicu@adobe.com>
 
         [CSS Shaders] CustomFilterOperation should be converted to ValidatedCustomFilterOperation before using it
index a2259b0..b4f9daf 100644 (file)
@@ -43,7 +43,7 @@ DOMDataStore::DOMDataStore(Type type)
     : m_type(type)
 {
     if (type == MainWorld)
-        m_domNodeMap = adoptPtr(new DOMNodeWrapperMap);
+        m_domNodeMap = adoptPtr(new IntrusiveDOMWrapperMap<Node>);
     else {
         ASSERT(type == IsolatedWorld || type == Worker);
         // FIXME: In principle, we shouldn't need to create this
index 20289b3..396ff3e 100644 (file)
 
 namespace WebCore {
 
-class DOMNodeWrapperMap : public DOMWrapperMap<Node> {
+template<class KeyType>
+class IntrusiveDOMWrapperMap : public DOMWrapperMap<KeyType> {
 public:
-    virtual v8::Persistent<v8::Object> get(Node* node) OVERRIDE
+    virtual v8::Persistent<v8::Object> get(KeyType* key) OVERRIDE
     {
-        return node->wrapper();
+        return key->wrapper();
     }
 
-    virtual void set(Node* node, v8::Persistent<v8::Object> wrapper) OVERRIDE
+    virtual void set(KeyType* key, v8::Persistent<v8::Object> wrapper) OVERRIDE
     {
-        ASSERT(node && node->wrapper().IsEmpty());
-        ASSERT(wrapper.WrapperClassId() == v8DOMNodeClassId);
-        node->setWrapper(wrapper);
-        wrapper.MakeWeak(node, weakCallback);
+        ASSERT(key && key->wrapper().IsEmpty());
+        key->setWrapper(wrapper);
+        wrapper.MakeWeak(key, weakCallback);
     }
 
     virtual void clear() OVERRIDE
@@ -63,13 +63,13 @@ public:
 private:
     static void weakCallback(v8::Persistent<v8::Value> value, void* context)
     {
-        Node* node = static_cast<Node*>(context);
+        KeyType* key = static_cast<KeyType*>(context);
         ASSERT(value->IsObject());
-        ASSERT(node->wrapper() == v8::Persistent<v8::Object>::Cast(value));
+        ASSERT(key->wrapper() == v8::Persistent<v8::Object>::Cast(value));
 
-        node->clearWrapper();
+        key->clearWrapper();
         value.Dispose();
-        node->deref();
+        key->deref();
     }
 };