Title: [135293] trunk/Source/WebCore
Revision
135293
Author
commit-qu...@webkit.org
Date
2012-11-20 10:26:32 -0800 (Tue, 20 Nov 2012)

Log Message

Remove V8DOMWindowShell::getEntered
https://bugs.webkit.org/show_bug.cgi?id=96637

Patch by Dan Carney <dcar...@google.com> on 2012-11-20
Reviewed by Adam Barth.

V8DOMWindowShell::getEntered was refactored so that the window shell
no longer has to be kept alive by a v8 context. Instead, only
the DOMWrapperWorld will be kept alive.

No new tests. No change in functionality.

* bindings/v8/DOMDataStore.cpp:
(WebCore::DOMDataStore::current):
* bindings/v8/DOMWrapperWorld.cpp:
(WebCore::isolatedWorldWeakCallback):
(WebCore):
(WebCore::DOMWrapperWorld::makeContextWeak):
(WebCore::DOMWrapperWorld::setIsolatedWorldField):
* bindings/v8/DOMWrapperWorld.h:
(DOMWrapperWorld):
(WebCore::DOMWrapperWorld::isolated):
* bindings/v8/ScriptController.cpp:
(WebCore::ScriptController::existingWindowShell):
(WebCore::ScriptController::windowShell):
(WebCore::ScriptController::evaluateInIsolatedWorld):
(WebCore::ScriptController::currentWorldContext):
(WebCore::ScriptController::collectIsolatedContexts):
* bindings/v8/ScriptController.h:
(ScriptController):
* bindings/v8/V8Binding.h:
(WebCore::worldForEnteredContextIfIsolated):
* bindings/v8/V8DOMWindowShell.cpp:
(WebCore::V8DOMWindowShell::destroyIsolatedShell):
(WebCore::V8DOMWindowShell::disposeContext):
(WebCore::V8DOMWindowShell::initializeIfNeeded):
* bindings/v8/V8DOMWindowShell.h:
(V8DOMWindowShell):
* bindings/v8/V8PerContextData.h:
* bindings/v8/WorldContextHandle.cpp:
(WebCore::WorldContextHandle::WorldContextHandle):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (135292 => 135293)


--- trunk/Source/WebCore/ChangeLog	2012-11-20 18:24:05 UTC (rev 135292)
+++ trunk/Source/WebCore/ChangeLog	2012-11-20 18:26:32 UTC (rev 135293)
@@ -1,3 +1,46 @@
+2012-11-20  Dan Carney  <dcar...@google.com>
+
+        Remove V8DOMWindowShell::getEntered
+        https://bugs.webkit.org/show_bug.cgi?id=96637
+
+        Reviewed by Adam Barth.
+
+        V8DOMWindowShell::getEntered was refactored so that the window shell
+        no longer has to be kept alive by a v8 context. Instead, only
+        the DOMWrapperWorld will be kept alive.
+
+        No new tests. No change in functionality.
+
+        * bindings/v8/DOMDataStore.cpp:
+        (WebCore::DOMDataStore::current):
+        * bindings/v8/DOMWrapperWorld.cpp:
+        (WebCore::isolatedWorldWeakCallback):
+        (WebCore):
+        (WebCore::DOMWrapperWorld::makeContextWeak):
+        (WebCore::DOMWrapperWorld::setIsolatedWorldField):
+        * bindings/v8/DOMWrapperWorld.h:
+        (DOMWrapperWorld):
+        (WebCore::DOMWrapperWorld::isolated):
+        * bindings/v8/ScriptController.cpp:
+        (WebCore::ScriptController::existingWindowShell):
+        (WebCore::ScriptController::windowShell):
+        (WebCore::ScriptController::evaluateInIsolatedWorld):
+        (WebCore::ScriptController::currentWorldContext):
+        (WebCore::ScriptController::collectIsolatedContexts):
+        * bindings/v8/ScriptController.h:
+        (ScriptController):
+        * bindings/v8/V8Binding.h:
+        (WebCore::worldForEnteredContextIfIsolated):
+        * bindings/v8/V8DOMWindowShell.cpp:
+        (WebCore::V8DOMWindowShell::destroyIsolatedShell):
+        (WebCore::V8DOMWindowShell::disposeContext):
+        (WebCore::V8DOMWindowShell::initializeIfNeeded):
+        * bindings/v8/V8DOMWindowShell.h:
+        (V8DOMWindowShell):
+        * bindings/v8/V8PerContextData.h:
+        * bindings/v8/WorldContextHandle.cpp:
+        (WebCore::WorldContextHandle::WorldContextHandle):
+
 2012-11-20  Mike West  <mk...@chromium.org>
 
         Remove '#include "ScriptCallStackFactory.h"' include when unnecessary.

Modified: trunk/Source/WebCore/bindings/v8/DOMDataStore.cpp (135292 => 135293)


--- trunk/Source/WebCore/bindings/v8/DOMDataStore.cpp	2012-11-20 18:24:05 UTC (rev 135292)
+++ trunk/Source/WebCore/bindings/v8/DOMDataStore.cpp	2012-11-20 18:26:32 UTC (rev 135293)
@@ -57,9 +57,9 @@
     V8PerIsolateData* data = "" ? V8PerIsolateData::from(isolate) : V8PerIsolateData::current();
     if (UNLIKELY(!!data->domDataStore()))
         return data->domDataStore();
-    V8DOMWindowShell* shell = V8DOMWindowShell::isolated(v8::Context::GetEntered());
-    if (UNLIKELY(!!shell))
-        return shell->world()->isolatedWorldDOMDataStore();
+    DOMWrapperWorld* isolatedWorld = DOMWrapperWorld::isolated(v8::Context::GetEntered());
+    if (UNLIKELY(!!isolatedWorld))
+        return isolatedWorld->isolatedWorldDOMDataStore();
     return &mainWorldDOMDataStore;
 }
 

Modified: trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.cpp (135292 => 135293)


--- trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.cpp	2012-11-20 18:24:05 UTC (rev 135292)
+++ trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.cpp	2012-11-20 18:26:32 UTC (rev 135293)
@@ -64,6 +64,27 @@
     return cachedNormalWorld.get();
 }
 
+static void isolatedWorldWeakCallback(v8::Persistent<v8::Value> object, void* parameter)
+{
+    object.Dispose();
+    object.Clear();
+    static_cast<DOMWrapperWorld*>(parameter)->deref();
+}
+
+void DOMWrapperWorld::makeContextWeak(v8::Handle<v8::Context> context)
+{
+    ASSERT(isIsolatedWorld());
+    ASSERT(isolated(context) == this);
+    v8::Persistent<v8::Context>::New(context).MakeWeak(this, isolatedWorldWeakCallback);
+    // Matching deref is in weak callback.
+    this->ref();
+}
+
+void DOMWrapperWorld::setIsolatedWorldField(v8::Handle<v8::Context> context)
+{
+    context->SetAlignedPointerInEmbedderData(v8ContextIsolatedWorld, isMainWorld() ? 0 : this);
+}
+
 typedef HashMap<int, DOMWrapperWorld*> WorldMap;
 static WorldMap& isolatedWorldMap()
 {

Modified: trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.h (135292 => 135293)


--- trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.h	2012-11-20 18:24:05 UTC (rev 135292)
+++ trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.h	2012-11-20 18:26:32 UTC (rev 135293)
@@ -32,6 +32,8 @@
 #define DOMWrapperWorld_h
 
 #include "SecurityOrigin.h"
+#include "V8PerContextData.h"
+#include <v8.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
@@ -53,6 +55,14 @@
     static bool isolatedWorldsExist() { return isolatedWorldCount; }
     static bool isIsolatedWorldId(int worldId) { return worldId != mainWorldId && worldId != uninitializedWorldId; }
     static void getAllWorlds(Vector<RefPtr<DOMWrapperWorld> >& worlds);
+
+    void makeContextWeak(v8::Handle<v8::Context>);
+    void setIsolatedWorldField(v8::Handle<v8::Context>);
+    static DOMWrapperWorld* isolated(v8::Handle<v8::Context> context)
+    {
+        return static_cast<DOMWrapperWorld*>(context->GetAlignedPointerFromEmbedderData(v8ContextIsolatedWorld));
+    }
+
     // Associates an isolated world (see above for description) with a security
     // origin. XMLHttpRequest instances used in that world will be considered
     // to come from that origin, not the frame's.

Modified: trunk/Source/WebCore/bindings/v8/ScriptController.cpp (135292 => 135293)


--- trunk/Source/WebCore/bindings/v8/ScriptController.cpp	2012-11-20 18:24:05 UTC (rev 135292)
+++ trunk/Source/WebCore/bindings/v8/ScriptController.cpp	2012-11-20 18:26:32 UTC (rev 135293)
@@ -347,7 +347,7 @@
     IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId());
     if (iter == m_isolatedWorlds.end())
         return 0;
-    return iter->value->isContextInitialized() ? iter->value : 0;
+    return iter->value->isContextInitialized() ? iter->value.get() : 0;
 }
 
 V8DOMWindowShell* ScriptController::windowShell(DOMWrapperWorld* world)
@@ -360,11 +360,11 @@
     else {
         IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId());
         if (iter != m_isolatedWorlds.end())
-            shell = iter->value;
+            shell = iter->value.get();
         else {
             OwnPtr<V8DOMWindowShell> isolatedWorldShell = V8DOMWindowShell::create(m_frame, world);
             shell = isolatedWorldShell.get();
-            m_isolatedWorlds.set(world->worldId(), isolatedWorldShell.leakPtr());
+            m_isolatedWorlds.set(world->worldId(), isolatedWorldShell.release());
         }
     }
     if (!shell->isContextInitialized() && shell->initializeIfNeeded()) {
@@ -407,9 +407,8 @@
 
         // Mark temporary shell for weak destruction.
         if (worldID == DOMWrapperWorld::uninitializedWorldId) {
-            int actualWorldId = isolatedWorldShell->world()->worldId();
-            m_isolatedWorlds.remove(actualWorldId);
             isolatedWorldShell->destroyIsolatedShell();
+            m_isolatedWorlds.remove(world->worldId());
         }
 
         v8Results = evaluateHandleScope.Close(resultArray);
@@ -444,7 +443,7 @@
 {
     if (v8::Context::InContext()) {
         v8::Handle<v8::Context> context = v8::Context::GetEntered();
-        if (V8DOMWindowShell::isolated(context)) {
+        if (DOMWrapperWorld::isolated(context)) {
             if (m_frame == toFrameIfNotDetached(context))
                 return v8::Local<v8::Context>::New(context);
             return v8::Local<v8::Context>();
@@ -673,7 +672,7 @@
 {
     v8::HandleScope handleScope;
     for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isolatedWorlds.end(); ++it) {
-        V8DOMWindowShell* isolatedWorldShell = it->value;
+        V8DOMWindowShell* isolatedWorldShell = it->value.get();
         SecurityOrigin* origin = isolatedWorldShell->world()->isolatedWorldSecurityOrigin();
         if (!origin)
             continue;

Modified: trunk/Source/WebCore/bindings/v8/ScriptController.h (135292 => 135293)


--- trunk/Source/WebCore/bindings/v8/ScriptController.h	2012-11-20 18:24:05 UTC (rev 135292)
+++ trunk/Source/WebCore/bindings/v8/ScriptController.h	2012-11-20 18:26:32 UTC (rev 135293)
@@ -193,10 +193,7 @@
     static int contextDebugId(v8::Handle<v8::Context>);
 
 private:
-    // Note: although the pointer is raw, the instance is kept alive by a strong
-    // reference to the v8 context it contains, which is not made weak until we
-    // call world->destroyIsolatedShell().
-    typedef HashMap<int, V8DOMWindowShell*> IsolatedWorldMap;
+    typedef HashMap<int, OwnPtr<V8DOMWindowShell> > IsolatedWorldMap;
 
     void reset();
 
@@ -204,10 +201,6 @@
     const String* m_sourceURL;
 
     OwnPtr<V8DOMWindowShell> m_windowShell;
-
-    // The isolated worlds we are tracking for this frame. We hold them alive
-    // here so that they can be used again by future calls to
-    // evaluateInIsolatedWorld().
     IsolatedWorldMap m_isolatedWorlds;
 
     bool m_paused;

Modified: trunk/Source/WebCore/bindings/v8/V8Binding.h (135292 => 135293)


--- trunk/Source/WebCore/bindings/v8/V8Binding.h	2012-11-20 18:24:05 UTC (rev 135292)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.h	2012-11-20 18:26:32 UTC (rev 135293)
@@ -32,10 +32,10 @@
 #define V8Binding_h
 
 #include "BindingSecurity.h"
+#include "DOMWrapperWorld.h"
 #include "Document.h"
 #include "V8BindingMacros.h"
 #include "V8DOMConfiguration.h"
-#include "V8DOMWindowShell.h"
 #include "V8DOMWrapper.h"
 #include "V8HiddenPropertyName.h"
 #include "V8ObjectConstructor.h"
@@ -383,10 +383,7 @@
     {
         if (!v8::Context::InContext())
             return 0;
-        V8DOMWindowShell* shell = V8DOMWindowShell::isolated(v8::Context::GetEntered());
-        if (!shell)
-            return 0;
-        return shell->world();
+        return DOMWrapperWorld::isolated(v8::Context::GetEntered());
     }
 
     // If the current context causes out of memory, _javascript_ setting

Modified: trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp (135292 => 135293)


--- trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp	2012-11-20 18:24:05 UTC (rev 135292)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp	2012-11-20 18:26:32 UTC (rev 135293)
@@ -192,18 +192,11 @@
 
 void V8DOMWindowShell::destroyIsolatedShell()
 {
-    disposeContext(true);
+    disposeContext();
 }
 
-static void isolatedContextWeakCallback(v8::Persistent<v8::Value> object, void* parameter)
+void V8DOMWindowShell::disposeContext()
 {
-    // Handle will be disposed in delete.
-    delete static_cast<V8DOMWindowShell*>(parameter);
-}
-
-void V8DOMWindowShell::disposeContext(bool weak)
-{
-    ASSERT(!m_context.get().IsWeak());
     m_perContextData.clear();
 
     if (m_context.isEmpty())
@@ -211,22 +204,18 @@
 
     m_frame->loader()->client()->willReleaseScriptContext(m_context.get(), m_world->worldId());
 
-    if (!weak)
-        m_context.clear();
-    else {
-        ASSERT(!m_world->isMainWorld());
+    if (m_world->isIsolatedWorld()) {
         destroyGlobal();
-        m_frame = 0;
-        m_context.get().MakeWeak(this, isolatedContextWeakCallback);
+        m_world->makeContextWeak(m_context.get());
     }
 
+    m_context.clear();
+
     // It's likely that disposing the context has created a lot of
     // garbage. Notify V8 about this so it'll have a chance of cleaning
     // it up when idle.
-    if (m_world->isMainWorld()) {
-        bool isMainFrame = m_frame->page() && (m_frame->page()->mainFrame() == m_frame);
-        V8GCForContextDispose::instance().notifyContextDisposed(isMainFrame);
-    }
+    bool isMainFrame = m_frame->page() && (m_frame->page()->mainFrame() == m_frame);
+    V8GCForContextDispose::instance().notifyContextDisposed(isMainFrame);
 }
 
 void V8DOMWindowShell::destroyGlobal()
@@ -320,6 +309,8 @@
     v8::Local<v8::Context> context = v8::Local<v8::Context>::New(m_context.get());
     v8::Context::Scope contextScope(context);
 
+    m_world->setIsolatedWorldField(m_context.get());
+
     if (m_global.isEmpty()) {
         m_global.set(context->Global());
         if (m_global.isEmpty()) {
@@ -328,13 +319,10 @@
         }
     }
 
-    if (isMainWorld)
-        context->SetAlignedPointerInEmbedderData(v8ContextIsolatedWindowShell, 0);
-    else {
+    if (!isMainWorld) {
         V8DOMWindowShell* mainWindow = m_frame->script()->existingWindowShell(mainThreadNormalWorld());
         if (mainWindow && !mainWindow->context().IsEmpty())
             setInjectedScriptContextDebugId(m_context.get(), m_frame->script()->contextDebugId(mainWindow->context()));
-        context->SetAlignedPointerInEmbedderData(v8ContextIsolatedWindowShell, this);
     }
 
     m_perContextData = V8PerContextData::create(m_context.get());

Modified: trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h (135292 => 135293)


--- trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h	2012-11-20 18:24:05 UTC (rev 135292)
+++ trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h	2012-11-20 18:26:32 UTC (rev 135293)
@@ -80,11 +80,6 @@
 
     void destroyGlobal();
 
-    static V8DOMWindowShell* isolated(v8::Handle<v8::Context> context)
-    {
-        return static_cast<V8DOMWindowShell*>(context->GetAlignedPointerFromEmbedderData(v8ContextIsolatedWindowShell));
-    }
-
     V8PerContextData* perContextData() { return m_perContextData.get(); }
     DOMWrapperWorld* world() { return m_world.get(); }
 
@@ -93,7 +88,7 @@
 private:
     V8DOMWindowShell(Frame*, PassRefPtr<DOMWrapperWorld>);
 
-    void disposeContext(bool weak = false);
+    void disposeContext();
 
     void setSecurityToken();
 

Modified: trunk/Source/WebCore/bindings/v8/V8PerContextData.h (135292 => 135293)


--- trunk/Source/WebCore/bindings/v8/V8PerContextData.h	2012-11-20 18:24:05 UTC (rev 135292)
+++ trunk/Source/WebCore/bindings/v8/V8PerContextData.h	2012-11-20 18:26:32 UTC (rev 135293)
@@ -47,7 +47,7 @@
 enum V8ContextEmbedderDataField {
     v8ContextDebugIdIndex,
     v8ContextPerContextDataIndex,
-    v8ContextIsolatedWindowShell,
+    v8ContextIsolatedWorld,
     // Rather than adding more embedder data fields to v8::Context,
     // consider adding the data to V8PerContextData instead.
 };

Modified: trunk/Source/WebCore/bindings/v8/WorldContextHandle.cpp (135292 => 135293)


--- trunk/Source/WebCore/bindings/v8/WorldContextHandle.cpp	2012-11-20 18:24:05 UTC (rev 135292)
+++ trunk/Source/WebCore/bindings/v8/WorldContextHandle.cpp	2012-11-20 18:26:32 UTC (rev 135293)
@@ -34,7 +34,6 @@
 #include "ScriptController.h"
 #include "V8Binding.h"
 #include "V8DOMWindow.h"
-#include "V8DOMWindowShell.h"
 
 namespace WebCore {
 
@@ -52,7 +51,7 @@
             return;
         }
 #endif
-        if (V8DOMWindowShell::isolated(context)) {
+        if (DOMWrapperWorld::isolated(context)) {
             m_context = SharedPersistent<v8::Context>::create(context);
             return;
         }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to