[V8] Refactor away IsolatedWorld
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Aug 2012 09:40:44 +0000 (09:40 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 24 Aug 2012 09:40:44 +0000 (09:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=93971

Patch by Dan Carney <dcarney@google.com> on 2012-08-24
Reviewed by Kentaro Hara.

Source/WebCore:

Remove IsolatedWorld class as it was 1:1 with DOMWrapperWorld.
This paves the way towards a JSC-like use of DOMWrapperWorld.

No new tests. No change in functionality.

* UseV8.cmake:
* WebCore.gypi:
* bindings/v8/DOMWrapperWorld.cpp:
(WebCore):
(WebCore::DOMWrapperWorld::createUninitializedWorld):
(WebCore::DOMWrapperWorld::createMainWorld):
(WebCore::mainThreadNormalWorld):
(WebCore::isolatedWorldMap):
(WebCore::DOMWrapperWorld::deallocate):
(WebCore::DOMWrapperWorld::getOrCreateIsolatedWorld):
* bindings/v8/DOMWrapperWorld.h:
(DOMWrapperWorld):
(WebCore::DOMWrapperWorld::isolatedWorldsExist):
(WebCore::DOMWrapperWorld::isMainWorld):
(WebCore::DOMWrapperWorld::worldId):
(WebCore::DOMWrapperWorld::extensionGroup):
(WebCore::DOMWrapperWorld::domDataStore):
(WebCore::DOMWrapperWorld::deref):
(WebCore::DOMWrapperWorld::DOMWrapperWorld):
* bindings/v8/IsolatedWorld.cpp: Removed.
* bindings/v8/IsolatedWorld.h: Removed.
* bindings/v8/ScriptController.cpp:
(WebCore::ScriptController::evaluateInIsolatedWorld):
* bindings/v8/V8DOMMap.cpp:
(WebCore::DOMDataStoreHandle::DOMDataStoreHandle):
(WebCore::DOMDataStoreHandle::~DOMDataStoreHandle):
* bindings/v8/V8DOMMap.h:
(DOMDataStoreHandle):
* bindings/v8/V8DOMWrapper.h:
(WebCore::V8DOMWrapper::getCachedWrapper):
* bindings/v8/V8IsolatedContext.cpp:
(WebCore::V8IsolatedContext::V8IsolatedContext):
(WebCore::V8IsolatedContext::destroy):
* bindings/v8/V8IsolatedContext.h:
(V8IsolatedContext):
(WebCore::V8IsolatedContext::getEntered):
(WebCore::V8IsolatedContext::world):
* bindings/v8/V8PerIsolateData.h:
(WebCore::V8PerIsolateData::registerDOMDataStore):
(WebCore::V8PerIsolateData::unregisterDOMDataStore):

Source/WebKit/chromium:

Remove IsolatedWorld class as it was 1:1 with DOMWrapperWorld.

* src/WebViewImpl.cpp:
(WebKit::WebView::addUserScript):
(WebKit::WebView::addUserStyleSheet):

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

16 files changed:
Source/WebCore/ChangeLog
Source/WebCore/UseV8.cmake
Source/WebCore/WebCore.gypi
Source/WebCore/bindings/v8/DOMWrapperWorld.cpp
Source/WebCore/bindings/v8/DOMWrapperWorld.h
Source/WebCore/bindings/v8/IsolatedWorld.cpp [deleted file]
Source/WebCore/bindings/v8/IsolatedWorld.h [deleted file]
Source/WebCore/bindings/v8/ScriptController.cpp
Source/WebCore/bindings/v8/V8DOMMap.cpp
Source/WebCore/bindings/v8/V8DOMMap.h
Source/WebCore/bindings/v8/V8DOMWrapper.h
Source/WebCore/bindings/v8/V8IsolatedContext.cpp
Source/WebCore/bindings/v8/V8IsolatedContext.h
Source/WebCore/bindings/v8/V8PerIsolateData.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebViewImpl.cpp

index be2cd23..3f78741 100644 (file)
@@ -1,3 +1,56 @@
+2012-08-24  Dan Carney  <dcarney@google.com>
+
+        [V8] Refactor away IsolatedWorld
+        https://bugs.webkit.org/show_bug.cgi?id=93971
+
+        Reviewed by Kentaro Hara.
+
+        Remove IsolatedWorld class as it was 1:1 with DOMWrapperWorld.
+        This paves the way towards a JSC-like use of DOMWrapperWorld.
+
+        No new tests. No change in functionality.
+
+        * UseV8.cmake:
+        * WebCore.gypi:
+        * bindings/v8/DOMWrapperWorld.cpp:
+        (WebCore):
+        (WebCore::DOMWrapperWorld::createUninitializedWorld):
+        (WebCore::DOMWrapperWorld::createMainWorld):
+        (WebCore::mainThreadNormalWorld):
+        (WebCore::isolatedWorldMap):
+        (WebCore::DOMWrapperWorld::deallocate):
+        (WebCore::DOMWrapperWorld::getOrCreateIsolatedWorld):
+        * bindings/v8/DOMWrapperWorld.h:
+        (DOMWrapperWorld):
+        (WebCore::DOMWrapperWorld::isolatedWorldsExist):
+        (WebCore::DOMWrapperWorld::isMainWorld):
+        (WebCore::DOMWrapperWorld::worldId):
+        (WebCore::DOMWrapperWorld::extensionGroup):
+        (WebCore::DOMWrapperWorld::domDataStore):
+        (WebCore::DOMWrapperWorld::deref):
+        (WebCore::DOMWrapperWorld::DOMWrapperWorld):
+        * bindings/v8/IsolatedWorld.cpp: Removed.
+        * bindings/v8/IsolatedWorld.h: Removed.
+        * bindings/v8/ScriptController.cpp:
+        (WebCore::ScriptController::evaluateInIsolatedWorld):
+        * bindings/v8/V8DOMMap.cpp:
+        (WebCore::DOMDataStoreHandle::DOMDataStoreHandle):
+        (WebCore::DOMDataStoreHandle::~DOMDataStoreHandle):
+        * bindings/v8/V8DOMMap.h:
+        (DOMDataStoreHandle):
+        * bindings/v8/V8DOMWrapper.h:
+        (WebCore::V8DOMWrapper::getCachedWrapper):
+        * bindings/v8/V8IsolatedContext.cpp:
+        (WebCore::V8IsolatedContext::V8IsolatedContext):
+        (WebCore::V8IsolatedContext::destroy):
+        * bindings/v8/V8IsolatedContext.h:
+        (V8IsolatedContext):
+        (WebCore::V8IsolatedContext::getEntered):
+        (WebCore::V8IsolatedContext::world):
+        * bindings/v8/V8PerIsolateData.h:
+        (WebCore::V8PerIsolateData::registerDOMDataStore):
+        (WebCore::V8PerIsolateData::unregisterDOMDataStore):
+
 2012-08-24  Adam Barth  <abarth@webkit.org>
 
         [V8] Improve the developer ergonomics of ScopedPersistent
index 45eee60..9252415 100755 (executable)
@@ -25,7 +25,6 @@ LIST(APPEND WebCore_SOURCES
     bindings/v8/DateExtension.cpp
     bindings/v8/IDBBindingUtilities.cpp
     bindings/v8/IDBCustomBindings.cpp
-    bindings/v8/IsolatedWorld.cpp
     bindings/v8/Dictionary.cpp
     bindings/v8/PageScriptDebugServer.cpp
     bindings/v8/RetainedDOMInfo.cpp
index 3ad3b2e..57ac230 100644 (file)
             'bindings/v8/IDBBindingUtilities.h',
             'bindings/v8/IDBCustomBindings.cpp',
             'bindings/v8/IntrusiveDOMWrapperMap.h',
-            'bindings/v8/IsolatedWorld.cpp',
-            'bindings/v8/IsolatedWorld.h',
             'bindings/v8/JavaScriptCallFrame.cpp',
             'bindings/v8/JavaScriptCallFrame.h',
             'bindings/v8/NPObjectWrapper.cpp',
index 6a9c6db..31a0286 100644 (file)
 
 namespace WebCore {
 
-DOMWrapperWorld::DOMWrapperWorld()
+int DOMWrapperWorld::isolatedWorldCount = 0;
+
+PassRefPtr<DOMWrapperWorld>  DOMWrapperWorld::createUninitializedWorld()
+{
+    return adoptRef(new DOMWrapperWorld(uninitializedWorldId, uninitializedExtensionGroup));
+}
+
+PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::createMainWorld()
 {
-    // This class is pretty boring, huh?
+    return adoptRef(new DOMWrapperWorld(mainWorldId, mainWorldExtensionGroup));
 }
 
 DOMWrapperWorld* mainThreadNormalWorld()
 {
     ASSERT(isMainThread());
-    DEFINE_STATIC_LOCAL(RefPtr<DOMWrapperWorld>, cachedNormalWorld, (DOMWrapperWorld::create()));
+    DEFINE_STATIC_LOCAL(RefPtr<DOMWrapperWorld>, cachedNormalWorld, (DOMWrapperWorld::createMainWorld()));
     return cachedNormalWorld.get();
 }
 
+// FIXME: This should probably go to PerIsolateData.
+typedef HashMap<int, DOMWrapperWorld*> WorldMap;
+static WorldMap& isolatedWorldMap()
+{
+    DEFINE_STATIC_LOCAL(WorldMap, map, ());
+    return map;
+}
+
+void DOMWrapperWorld::deallocate(DOMWrapperWorld* world)
+{
+    int worldId = world->worldId();
+
+    // Ensure we never deallocate mainThreadNormalWorld
+    if (worldId == mainWorldId)
+        return;
+
+    delete world;
+
+    if (worldId == uninitializedWorldId)
+        return;
+
+    WorldMap& map = isolatedWorldMap();
+    WorldMap::iterator i = map.find(worldId);
+    if (i == map.end()) {
+        ASSERT_NOT_REACHED();
+        return;
+    }
+    ASSERT(i->second == world);
+
+    map.remove(i);
+    isolatedWorldCount--;
+}
+
+static int temporaryWorldId = DOMWrapperWorld::uninitializedWorldId-1;
+
+PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::getOrCreateIsolatedWorld(int worldId, int extensionGroup)
+{
+    ASSERT(worldId != mainWorldId);
+    ASSERT(worldId != uninitializedWorldId);
+
+    WorldMap& map = isolatedWorldMap();
+    if (!worldId)
+        worldId = temporaryWorldId--;
+    else {
+        WorldMap::iterator i = map.find(worldId);
+        if (i != map.end()) {
+            ASSERT(i->second->worldId() == worldId);
+            ASSERT(i->second->extensionGroup() == extensionGroup);
+            return i->second;
+        }
+    }
+
+    RefPtr<DOMWrapperWorld> world = adoptRef(new DOMWrapperWorld(worldId, extensionGroup));
+    map.add(worldId, world.get());
+    isolatedWorldCount++;
+    return world.release();
+}
+
 } // namespace WebCore
index 2a9df30..01125b7 100644 (file)
@@ -31,6 +31,7 @@
 #ifndef DOMWrapperWorld_h
 #define DOMWrapperWorld_h
 
+#include "DOMDataStore.h"
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 namespace WebCore {
 
 // This class represent a collection of DOM wrappers for a specific world.
-// The base class is pretty boring because the wrappers are actually stored
-// statically in V8DOMMap and garbage collected by V8 itself.
-class DOMWrapperWorld : public RefCounted<DOMWrapperWorld> {
+class DOMWrapperWorld : public WTF::RefCountedBase {
 public:
-    static PassRefPtr<DOMWrapperWorld> create() { return adoptRef(new DOMWrapperWorld()); }
-    virtual ~DOMWrapperWorld() {}
+    static const int mainWorldId = -1;
+    static const int mainWorldExtensionGroup = -1;
+    static const int uninitializedWorldId = -2;
+    static const int uninitializedExtensionGroup = -2;
+    // If 0 is passed as worldId, the world will be assigned a temporary id instead.
+    static PassRefPtr<DOMWrapperWorld> getOrCreateIsolatedWorld(int worldId, int extensionGroup);
+    static bool isolatedWorldsExist() { return isolatedWorldCount; }
+    // FIXME: this is a workaround for a problem in WebViewImpl.
+    // Do not use this anywhere else!!
+    static PassRefPtr<DOMWrapperWorld> createUninitializedWorld();
 
-protected:
-    DOMWrapperWorld();
+    bool isMainWorld() { return m_worldId == mainWorldId; }
+    int worldId() const { return m_worldId; }
+    int extensionGroup() const { return m_extensionGroup; }
+    DOMDataStore* domDataStore() const
+    {
+        ASSERT(m_worldId != uninitializedWorldId);
+        return m_domDataStore.getStore();
+    }
+    void deref()
+    {
+        if (derefBase())
+            deallocate(this);
+    }
+
+private:
+    static int isolatedWorldCount;
+    static PassRefPtr<DOMWrapperWorld> createMainWorld();
+    static void deallocate(DOMWrapperWorld*);
+    DOMWrapperWorld(int worldId, int extensionGroup)
+        : m_worldId(worldId)
+        , m_extensionGroup(extensionGroup)
+        , m_domDataStore(worldId != uninitializedWorldId)
+    {
+    }
+
+    const int m_worldId;
+    const int m_extensionGroup;
+    // The backing store for the isolated world's DOM wrappers. This class
+    // doesn't have visibility into the wrappers. This handle simply helps
+    // manage their lifetime.
+    DOMDataStoreHandle m_domDataStore;
+
+    friend DOMWrapperWorld* mainThreadNormalWorld();
 };
 
 DOMWrapperWorld* mainThreadNormalWorld();
diff --git a/Source/WebCore/bindings/v8/IsolatedWorld.cpp b/Source/WebCore/bindings/v8/IsolatedWorld.cpp
deleted file mode 100644 (file)
index 3686461..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2009 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "IsolatedWorld.h"
-
-namespace WebCore {
-
-int IsolatedWorld::isolatedWorldCount = 0;
-
-IsolatedWorld::IsolatedWorld(int id)
-{
-    ++isolatedWorldCount;
-    m_id = id;
-}
-
-IsolatedWorld::~IsolatedWorld()
-{
-    --isolatedWorldCount;
-}
-
-} // namespace WebCore
diff --git a/Source/WebCore/bindings/v8/IsolatedWorld.h b/Source/WebCore/bindings/v8/IsolatedWorld.h
deleted file mode 100644 (file)
index 53e3476..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2009 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *     * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *     * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef IsolatedWorld_h
-#define IsolatedWorld_h
-
-#include "DOMWrapperWorld.h"
-#include "V8DOMMap.h"
-
-namespace WebCore {
-
-// An DOMWrapperWorld other than the thread's normal world.
-class IsolatedWorld : public DOMWrapperWorld {
-public:
-    static PassRefPtr<IsolatedWorld> create(int id) { return adoptRef(new IsolatedWorld(id)); }
-    static int count() { return isolatedWorldCount; }
-
-    int id() const { return m_id; }
-    DOMDataStore* domDataStore() const { return m_domDataStore.getStore(); }
-
-protected:
-    explicit IsolatedWorld(int id);
-    ~IsolatedWorld();
-
-private:
-    int m_id;
-
-    // The backing store for the isolated world's DOM wrappers.  This class
-    // doesn't have visibility into the wrappers.  This handle simply helps
-    // manage their lifetime.
-    DOMDataStoreHandle m_domDataStore;
-
-    static int isolatedWorldCount;
-};
-
-} // namespace WebCore
-
-#endif // IsolatedWorld_h
index 4672570..47e01a0 100644 (file)
@@ -346,7 +346,7 @@ void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<Sc
             if (iter != m_isolatedWorlds.end())
                 isolatedContext = iter->second;
             else {
-                isolatedContext = new V8IsolatedContext(m_frame, extensionGroup, worldID);
+                isolatedContext = new V8IsolatedContext(m_frame, DOMWrapperWorld::getOrCreateIsolatedWorld(worldID, extensionGroup));
                 if (isolatedContext->context().IsEmpty()) {
                     delete isolatedContext;
                     return;
@@ -360,7 +360,7 @@ void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<Sc
             if (securityOriginIter != m_isolatedWorldSecurityOrigins.end())
                 isolatedContext->setSecurityOrigin(securityOriginIter->second);
         } else {
-            isolatedContext = new V8IsolatedContext(m_frame, extensionGroup, worldID);
+            isolatedContext = new V8IsolatedContext(m_frame, DOMWrapperWorld::getOrCreateIsolatedWorld(worldID, extensionGroup));
             if (isolatedContext->context().IsEmpty()) {
                 delete isolatedContext;
                 return;
index dd18d63..50925a8 100644 (file)
 
 namespace WebCore {
 
-DOMDataStoreHandle::DOMDataStoreHandle()
-    : m_store(adoptPtr(new ScopedDOMDataStore()))
+DOMDataStoreHandle::DOMDataStoreHandle(bool initialize)
+    : m_store(adoptPtr(!initialize ? 0 : new ScopedDOMDataStore()))
 {
-    V8PerIsolateData::current()->registerDOMDataStore(m_store.get());
+    if (m_store)
+        V8PerIsolateData::current()->registerDOMDataStore(m_store.get());
 }
 
 DOMDataStoreHandle::~DOMDataStoreHandle()
 {
-    V8PerIsolateData::current()->unregisterDOMDataStore(m_store.get());
+    if (m_store)
+        V8PerIsolateData::current()->unregisterDOMDataStore(m_store.get());
 }
 
 DOMNodeMapping& getDOMNodeMap(v8::Isolate* isolate)
index bf0e603..cc76ffa 100644 (file)
@@ -152,7 +152,7 @@ namespace WebCore {
     // A utility class to manage the lifetime of set of DOM wrappers.
     class DOMDataStoreHandle {
     public:
-        DOMDataStoreHandle();
+        DOMDataStoreHandle(bool initialize);
         ~DOMDataStoreHandle();
 
         DOMDataStore* getStore() const { return m_store.get(); }
index 25c14d6..4e564a3 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "DOMDataStore.h"
 #include "Event.h"
-#include "IsolatedWorld.h"
 #include "Node.h"
 #include "NodeFilter.h"
 #include "PlatformString.h"
@@ -125,7 +124,7 @@ namespace WebCore {
         static v8::Handle<v8::Object> getCachedWrapper(Node* node)
         {
             ASSERT(isMainThread());
-            if (LIKELY(!IsolatedWorld::count())) {
+            if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist())) {
                 v8::Persistent<v8::Object>* wrapper = node->wrapper();
                 if (LIKELY(!!wrapper))
                     return *wrapper;
index bd50894..98f8ec9 100644 (file)
@@ -64,8 +64,8 @@ static void setInjectedScriptContextDebugId(v8::Handle<v8::Context> targetContex
     targetContext->SetData(v8::String::New(buffer));
 }
 
-V8IsolatedContext::V8IsolatedContext(Frame* frame, int extensionGroup, int worldId)
-    : m_world(IsolatedWorld::create(worldId)),
+V8IsolatedContext::V8IsolatedContext(Frame* frame, PassRefPtr<DOMWrapperWorld> world)
+    : m_world(world),
       m_frame(frame)
 {
     v8::HandleScope scope;
@@ -74,7 +74,7 @@ V8IsolatedContext::V8IsolatedContext(Frame* frame, int extensionGroup, int world
         return;
 
     // FIXME: We should be creating a new V8DOMWindowShell here instead of riping out the context.
-    m_context = SharedPersistent<v8::Context>::create(frame->script()->windowShell()->createNewContext(v8::Handle<v8::Object>(), extensionGroup, m_world->id()));
+    m_context = SharedPersistent<v8::Context>::create(frame->script()->windowShell()->createNewContext(v8::Handle<v8::Object>(), m_world->extensionGroup(), m_world->worldId()));
     if (m_context->get().IsEmpty())
         return;
 
@@ -99,13 +99,13 @@ V8IsolatedContext::V8IsolatedContext(Frame* frame, int extensionGroup, int world
     //        changes.
     m_context->get()->UseDefaultSecurityToken();
 
-    m_frame->loader()->client()->didCreateScriptContext(context(), extensionGroup, m_world->id());
+    m_frame->loader()->client()->didCreateScriptContext(context(), m_world->extensionGroup(), m_world->worldId());
 }
 
 void V8IsolatedContext::destroy()
 {
     m_perContextData.clear();
-    m_frame->loader()->client()->willReleaseScriptContext(context(), m_world->id());
+    m_frame->loader()->client()->willReleaseScriptContext(context(), m_world->worldId());
     m_context->get().MakeWeak(this, &contextWeakReferenceCallback);
     m_frame = 0;
 }
index b191287..9d1c280 100644 (file)
@@ -31,7 +31,7 @@
 #ifndef V8IsolatedContext_h
 #define V8IsolatedContext_h
 
-#include "IsolatedWorld.h"
+#include "DOMWrapperWorld.h"
 #include "ScriptSourceCode.h" // for WebCore::ScriptSourceCode
 #include "SharedPersistent.h"
 #include "V8Utilities.h"
@@ -59,7 +59,7 @@ class V8IsolatedContext {
 public:
     // Creates an isolated world. To destroy it, call destroy().
     // This will delete the isolated world when the context it owns is GC'd.
-    V8IsolatedContext(Frame*, int extensionGroup, int worldId);
+    V8IsolatedContext(Frame*, PassRefPtr<DOMWrapperWorld>);
     ~V8IsolatedContext();
 
     // Call this to destroy the isolated world. It will be deleted sometime
@@ -82,7 +82,7 @@ public:
         // V8 team to add a real property to v8::Context for isolated worlds.
         // Until then, we optimize the common case of not having any isolated
         // worlds at all.
-        if (!IsolatedWorld::count())
+        if (!DOMWrapperWorld::isolatedWorldsExist())
             return 0;
         if (!v8::Context::InContext())
             return 0;
@@ -92,7 +92,7 @@ public:
     v8::Handle<v8::Context> context() { return m_context->get(); }
     PassRefPtr<SharedPersistent<v8::Context> > sharedContext() { return m_context; }
 
-    IsolatedWorld* world() const { return m_world.get(); }
+    DOMWrapperWorld* world() const { return m_world.get(); }
 
     SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); }
     void setSecurityOrigin(PassRefPtr<SecurityOrigin>);
@@ -115,7 +115,7 @@ private:
     // long as |m_context| has not been garbage collected.
     RefPtr<SharedPersistent<v8::Context> > m_context;
 
-    RefPtr<IsolatedWorld> m_world;
+    RefPtr<DOMWrapperWorld> m_world;
 
     RefPtr<SecurityOrigin> m_securityOrigin;
 
index ceb2ee8..6bc51d2 100644 (file)
@@ -95,12 +95,13 @@ public:
 
     void registerDOMDataStore(DOMDataStore* domDataStore) 
     {
+        ASSERT(m_domDataList.find(domDataStore) == notFound);
         m_domDataList.append(domDataStore);
     }
 
     void unregisterDOMDataStore(DOMDataStore* domDataStore)
     {
-        ASSERT(m_domDataList.find(domDataStore));
+        ASSERT(m_domDataList.find(domDataStore) != notFound);
         m_domDataList.remove(m_domDataList.find(domDataStore));
     }
 
index 2e08a17..f92e9a7 100644 (file)
@@ -1,3 +1,16 @@
+2012-08-24  Dan Carney  <dcarney@google.com>
+
+        [V8] Refactor away IsolatedWorld
+        https://bugs.webkit.org/show_bug.cgi?id=93971
+
+        Reviewed by Kentaro Hara.
+
+        Remove IsolatedWorld class as it was 1:1 with DOMWrapperWorld.
+
+        * src/WebViewImpl.cpp:
+        (WebKit::WebView::addUserScript):
+        (WebKit::WebView::addUserStyleSheet):
+
 2012-08-23  Antoine Labour  <piman@chromium.org>
 
         [chromium] Fix lost context when textures are evicted
index c6f9f7e..8121e36 100644 (file)
@@ -3390,7 +3390,7 @@ void WebView::addUserScript(const WebString& sourceCode,
         patterns->append(patternsIn[i]);
 
     PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
-    RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::create());
+    RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::createUninitializedWorld());
     pageGroup->addUserScriptToWorld(world.get(), sourceCode, WebURL(), patterns.release(), nullptr,
                                     static_cast<UserScriptInjectionTime>(injectAt),
                                     static_cast<UserContentInjectedFrames>(injectIn));
@@ -3406,7 +3406,7 @@ void WebView::addUserStyleSheet(const WebString& sourceCode,
         patterns->append(patternsIn[i]);
 
     PageGroup* pageGroup = PageGroup::pageGroup(pageGroupName);
-    RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::create());
+    RefPtr<DOMWrapperWorld> world(DOMWrapperWorld::createUninitializedWorld());
 
     // FIXME: Current callers always want the level to be "author". It probably makes sense to let
     // callers specify this though, since in other cases the caller will probably want "user" level.