[V8] Merge getCachedWrapper(Node*) into DOMDataStore
authorabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Nov 2012 02:39:32 +0000 (02:39 +0000)
committerabarth@webkit.org <abarth@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Nov 2012 02:39:32 +0000 (02:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=102158

Reviewed by Eric Seidel.

This patch is an incremental step towards fully merging the Node code
path with the general code path. After this patch, at least Nodes flow
through the same class.

* Modules/indexeddb/IDBTransactionCoordinator.h:
* bindings/scripts/CodeGeneratorV8.pm:
(GenerateHeader):
(GenerateToV8Converters):
* bindings/v8/DOMDataStore.h:
(WebCore::DOMDataStore::getNode):
(DOMDataStore):
(WebCore::DOMDataStore::getWrapperFromObject):
* bindings/v8/DOMWrapperWorld.cpp:
(WebCore::DOMWrapperWorld::DOMWrapperWorld):
(WebCore):
* bindings/v8/DOMWrapperWorld.h:
(WebCore):
(DOMWrapperWorld):
* bindings/v8/V8DOMWrapper.h:
(V8DOMWrapper):

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/indexeddb/IDBTransactionCoordinator.h
Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
Source/WebCore/bindings/scripts/test/V8/V8TestNode.cpp
Source/WebCore/bindings/scripts/test/V8/V8TestNode.h
Source/WebCore/bindings/v8/DOMDataStore.h
Source/WebCore/bindings/v8/DOMWrapperWorld.cpp
Source/WebCore/bindings/v8/DOMWrapperWorld.h
Source/WebCore/bindings/v8/V8DOMWrapper.h

index 90fc281..2464272 100644 (file)
@@ -1,3 +1,31 @@
+2012-11-19  Adam Barth  <abarth@webkit.org>
+
+        [V8] Merge getCachedWrapper(Node*) into DOMDataStore
+        https://bugs.webkit.org/show_bug.cgi?id=102158
+
+        Reviewed by Eric Seidel.
+
+        This patch is an incremental step towards fully merging the Node code
+        path with the general code path. After this patch, at least Nodes flow
+        through the same class.
+
+        * Modules/indexeddb/IDBTransactionCoordinator.h:
+        * bindings/scripts/CodeGeneratorV8.pm:
+        (GenerateHeader):
+        (GenerateToV8Converters):
+        * bindings/v8/DOMDataStore.h:
+        (WebCore::DOMDataStore::getNode):
+        (DOMDataStore):
+        (WebCore::DOMDataStore::getWrapperFromObject):
+        * bindings/v8/DOMWrapperWorld.cpp:
+        (WebCore::DOMWrapperWorld::DOMWrapperWorld):
+        (WebCore):
+        * bindings/v8/DOMWrapperWorld.h:
+        (WebCore):
+        (DOMWrapperWorld):
+        * bindings/v8/V8DOMWrapper.h:
+        (V8DOMWrapper):
+
 2012-11-19  Kentaro Hara  <haraken@chromium.org>
 
         In the IDL parser, we should rename $dataNode to $interface
index e7b9fca..8299853 100644 (file)
@@ -29,6 +29,7 @@
 #if ENABLE(INDEXED_DATABASE)
 
 #include "IDBTransactionBackendInterface.h"
+#include <wtf/HashMap.h>
 #include <wtf/ListHashSet.h>
 #include <wtf/RefPtr.h>
 
index 6b76a1a..f069d56 100644 (file)
@@ -534,7 +534,7 @@ inline v8::Handle<v8::Value> toV8Fast(${nativeType}* impl, const v8::AccessorInf
 END
     } else {
 
-        my $getCachedWrapper = $codeGenerator->IsSubType($dataNode, "Node") ? "V8DOMWrapper::getCachedWrapper(impl)" : "DOMDataStore::current(isolate)->get(impl)";
+        my $getCachedWrapper = $codeGenerator->IsSubType($dataNode, "Node") ? "DOMDataStore::getNode(impl, isolate)" : "DOMDataStore::current(isolate)->get(impl)";
         my $createWrapperCall = $customWrap ? "${v8InterfaceName}::wrap" : "${v8InterfaceName}::createWrapper";
 
         if ($customWrap) {
@@ -587,7 +587,7 @@ inline v8::Handle<v8::Value> toV8Fast(${nativeType}* impl, const v8::AccessorInf
     // in an isolated world. The fastest way we know how to do that is to check
     // whether the holder's inline wrapper is the same wrapper we see in the
     // v8::AccessorInfo.
-    v8::Handle<v8::Object> wrapper = (holder->wrapper() == info.Holder()) ? impl->wrapper() : V8DOMWrapper::getCachedWrapper(impl);
+    v8::Handle<v8::Object> wrapper = (holder->wrapper() == info.Holder()) ? impl->wrapper() : DOMDataStore::getNode(impl, info.GetIsolate());
     if (!wrapper.IsEmpty())
         return wrapper;
     return wrap(impl, info.Holder(), info.GetIsolate());
@@ -3433,7 +3433,7 @@ sub GenerateToV8Converters
 
     my $createWrapperArgumentType = GetPassRefPtrType($nativeType);
     my $baseType = BaseInterfaceName($dataNode);
-    my $getCachedWrapper = $codeGenerator->IsSubType($dataNode, "Node") ? "V8DOMWrapper::getCachedWrapper(impl.get())" : "DOMDataStore::current(isolate)->get(impl.get())";
+    my $getCachedWrapper = $codeGenerator->IsSubType($dataNode, "Node") ? "DOMDataStore::getNode(impl.get(), isolate)" : "DOMDataStore::current(isolate)->get(impl.get())";
 
     push(@implContent, <<END);
 
@@ -3455,7 +3455,7 @@ END
     if (Frame* frame = impl->frame()) {
         if (frame->script()->initializeMainWorld()) {
             // initializeMainWorld may have created a wrapper for the object, retry from the start.
-            v8::Handle<v8::Object> wrapper = V8DOMWrapper::getCachedWrapper(impl.get());
+            v8::Handle<v8::Object> wrapper = DOMDataStore::getNode(impl.get(), isolate);
             if (!wrapper.IsEmpty())
                 return wrapper;
         }
index e1152fa..f9c57aa 100644 (file)
@@ -110,7 +110,7 @@ bool V8TestNode::HasInstance(v8::Handle<v8::Value> value)
 v8::Handle<v8::Object> V8TestNode::createWrapper(PassRefPtr<TestNode> impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate)
 {
     ASSERT(impl.get());
-    ASSERT(V8DOMWrapper::getCachedWrapper(impl.get()).IsEmpty());
+    ASSERT(DOMDataStore::getNode(impl.get(), isolate).IsEmpty());
     ASSERT(static_cast<void*>(static_cast<Node*>(impl.get())) == static_cast<void*>(impl.get()));
 
     v8::Handle<v8::Object> wrapper = V8DOMWrapper::instantiateV8Object(creationContext, &info, impl.get());
index ae710fc..9acb1e4 100644 (file)
@@ -56,7 +56,7 @@ private:
 inline v8::Handle<v8::Object> wrap(TestNode* impl, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate = 0)
 {
     ASSERT(impl);
-    ASSERT(V8DOMWrapper::getCachedWrapper(impl).IsEmpty());
+    ASSERT(DOMDataStore::getNode(impl, isolate).IsEmpty());
     return V8TestNode::createWrapper(impl, creationContext, isolate);
 }
 
@@ -64,7 +64,7 @@ inline v8::Handle<v8::Object> toV8Object(TestNode* impl, v8::Handle<v8::Object>
 {
     if (UNLIKELY(!impl))
         return v8::Handle<v8::Object>();
-    v8::Handle<v8::Object> wrapper = V8DOMWrapper::getCachedWrapper(impl);
+    v8::Handle<v8::Object> wrapper = DOMDataStore::getNode(impl, isolate);
     if (!wrapper.IsEmpty())
         return wrapper;
     return wrap(impl, creationContext, isolate);
@@ -74,7 +74,7 @@ inline v8::Handle<v8::Value> toV8(TestNode* impl, v8::Handle<v8::Object> creatio
 {
     if (UNLIKELY(!impl))
         return v8NullWithCheck(isolate);
-    v8::Handle<v8::Value> wrapper = V8DOMWrapper::getCachedWrapper(impl);
+    v8::Handle<v8::Value> wrapper = DOMDataStore::getNode(impl, isolate);
     if (!wrapper.IsEmpty())
         return wrapper;
     return wrap(impl, creationContext, isolate);
@@ -88,7 +88,7 @@ inline v8::Handle<v8::Value> toV8Fast(TestNode* impl, const v8::AccessorInfo& in
     // in an isolated world. The fastest way we know how to do that is to check
     // whether the holder's inline wrapper is the same wrapper we see in the
     // v8::AccessorInfo.
-    v8::Handle<v8::Object> wrapper = (holder->wrapper() == info.Holder()) ? impl->wrapper() : V8DOMWrapper::getCachedWrapper(impl);
+    v8::Handle<v8::Object> wrapper = (holder->wrapper() == info.Holder()) ? impl->wrapper() : DOMDataStore::getNode(impl, info.GetIsolate());
     if (!wrapper.IsEmpty())
         return wrapper;
     return wrap(impl, info.Holder(), info.GetIsolate());
index 3920c78..5e3d367 100644 (file)
@@ -32,6 +32,7 @@
 #define DOMDataStore_h
 
 #include "DOMWrapperMap.h"
+#include "DOMWrapperWorld.h"
 #include "Node.h"
 #include "V8GCController.h"
 #include <v8.h>
@@ -60,6 +61,13 @@ public:
 
     static DOMDataStore* current(v8::Isolate*);
 
+    static v8::Handle<v8::Object> getNode(Node* object, v8::Isolate* isolate)
+    {
+        if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist()))
+            return getWrapperFromObject(object);
+        return current(isolate)->get(object);
+    }
+
     template<typename T>
     inline v8::Handle<v8::Object> get(T* object)
     {
@@ -82,13 +90,13 @@ private:
     bool wrapperIsStoredInObject(void*) const { return false; }
     bool wrapperIsStoredInObject(ScriptWrappable*) const { return m_type == MainWorld; }
 
-    v8::Handle<v8::Object> getWrapperFromObject(void*) const
+    static v8::Handle<v8::Object> getWrapperFromObject(void*)
     {
         ASSERT_NOT_REACHED();
         return v8::Handle<v8::Object>();
     }
 
-    v8::Handle<v8::Object> getWrapperFromObject(ScriptWrappable* object) const
+    static v8::Handle<v8::Object> getWrapperFromObject(ScriptWrappable* object)
     {
         ASSERT(m_type == MainWorld);
         return object->wrapper();
index 93dd82e..d3a0952 100644 (file)
@@ -31,6 +31,7 @@
 #include "config.h"
 #include "DOMWrapperWorld.h"
 
+#include "DOMDataStore.h"
 #include <wtf/MainThread.h>
 #include <wtf/StdLibExtras.h>
 
@@ -48,6 +49,14 @@ PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::createMainWorld()
     return adoptRef(new DOMWrapperWorld(mainWorldId, mainWorldExtensionGroup));
 }
 
+DOMWrapperWorld::DOMWrapperWorld(int worldId, int extensionGroup)
+    : m_worldId(worldId)
+    , m_extensionGroup(extensionGroup)
+{
+    if (isIsolatedWorld())
+        m_domDataStore = adoptPtr(new DOMDataStore(DOMDataStore::IsolatedWorld));
+}
+
 DOMWrapperWorld* mainThreadNormalWorld()
 {
     ASSERT(isMainThread());
index aed4f4f..2900886 100644 (file)
@@ -31,7 +31,6 @@
 #ifndef DOMWrapperWorld_h
 #define DOMWrapperWorld_h
 
-#include "DOMDataStore.h"
 #include "SecurityOrigin.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
@@ -40,6 +39,8 @@
 
 namespace WebCore {
 
+class DOMDataStore;
+
 // This class represent a collection of DOM wrappers for a specific world.
 class DOMWrapperWorld : public WTF::RefCountedBase {
 public:
@@ -95,13 +96,7 @@ private:
     static PassRefPtr<DOMWrapperWorld> createMainWorld();
     static void deallocate(DOMWrapperWorld*);
 
-    DOMWrapperWorld(int worldId, int extensionGroup)
-        : m_worldId(worldId)
-        , m_extensionGroup(extensionGroup)
-    {
-        if (isIsolatedWorld())
-            m_domDataStore = adoptPtr(new DOMDataStore(DOMDataStore::IsolatedWorld));
-    }
+    DOMWrapperWorld(int worldId, int extensionGroup);
 
     const int m_worldId;
     const int m_extensionGroup;
index 6f43e72..1f8062d 100644 (file)
@@ -112,20 +112,6 @@ namespace WebCore {
 
         static v8::Local<v8::Object> instantiateV8Object(v8::Handle<v8::Object> creationContext, WrapperTypeInfo*, void*);
 
-        static v8::Handle<v8::Object> getCachedWrapper(Node* node)
-        {
-            ASSERT(isMainThread());
-            if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist()) || !v8::Context::InContext())
-                return node->wrapper();
-
-            v8::Handle<v8::Context> context = v8::Context::GetEntered();
-            V8DOMWindowShell* shell = V8DOMWindowShell::isolated(context);
-            if (LIKELY(!shell))
-                return node->wrapper();
-
-            return shell->world()->isolatedWorldDOMDataStore()->get(node);
-        }
-
     private:
         static void setWrapperClass(void*, v8::Persistent<v8::Object> wrapper)
         {