Changeset 128159 in webkit


Ignore:
Timestamp:
Sep 11, 2012 2:35:13 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Removed V8IsolatedContext
https://bugs.webkit.org/show_bug.cgi?id=95735

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

Remove V8IsolatedContext and merge functionality into V8DOMWindowShell.
This brings the V8 isolated world model into closer alignment with
that of JSC.

No new tests. No change in functionality.

  • UseV8.cmake:
  • WebCore.gypi:
  • bindings/scripts/CodeGeneratorV8.pm:

(GenerateImplementation):

  • bindings/scripts/test/V8/V8Float64Array.cpp:
  • bindings/scripts/test/V8/V8TestActiveDOMObject.cpp:
  • bindings/scripts/test/V8/V8TestCustomNamedGetter.cpp:
  • bindings/scripts/test/V8/V8TestEventConstructor.cpp:
  • bindings/scripts/test/V8/V8TestEventTarget.cpp:
  • bindings/scripts/test/V8/V8TestException.cpp:
  • bindings/scripts/test/V8/V8TestInterface.cpp:
  • bindings/scripts/test/V8/V8TestMediaQueryListListener.cpp:
  • bindings/scripts/test/V8/V8TestNamedConstructor.cpp:
  • bindings/scripts/test/V8/V8TestNode.cpp:
  • bindings/scripts/test/V8/V8TestObj.cpp:
  • bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp:
  • bindings/v8/DOMData.cpp:

(WebCore::DOMData::getCurrentStore):

  • bindings/v8/DOMWrapperWorld.cpp:

(WebCore::DOMWrapperWorld::ensureIsolatedWorld):

  • bindings/v8/DOMWrapperWorld.h:

(DOMWrapperWorld):

  • bindings/v8/ScriptController.cpp:

(WebCore::ScriptController::ScriptController):
(WebCore::ScriptController::resetIsolatedWorlds):
(WebCore::ScriptController::ensureIsolatedWorldContext):
(WebCore::ScriptController::existingWindowShellInternal):
(WebCore):
(WebCore::ScriptController::windowShell):
(WebCore::ScriptController::evaluateInIsolatedWorld):
(WebCore::ScriptController::setIsolatedWorldSecurityOrigin):
(WebCore::ScriptController::currentWorldContext):
(WebCore::ScriptController::evaluateInWorld):
(WebCore::ScriptController::collectIsolatedContexts):

  • bindings/v8/ScriptController.h:

(WebCore):
(ScriptController):
(WebCore::ScriptController::existingWindowShell):

  • bindings/v8/SharedPersistent.h:

(WebCore):
(WebCore::SharedPersistent::create):
(WebCore::SharedPersistent::get):
(WebCore::SharedPersistent::SharedPersistent):
(SharedPersistent):

  • bindings/v8/V8Binding.cpp:

(WebCore::perContextDataForCurrentWorld):

  • bindings/v8/V8DOMWindowShell.cpp:

(WebCore::setIsolatedWorldField):
(WebCore::V8DOMWindowShell::enteredIsolatedWorldContext):
(WebCore):
(WebCore::setInjectedScriptContextDebugId):
(WebCore::V8DOMWindowShell::create):
(WebCore::V8DOMWindowShell::V8DOMWindowShell):
(WebCore::V8DOMWindowShell::destroyIsolatedShell):
(WebCore::isolatedContextWeakCallback):
(WebCore::V8DOMWindowShell::disposeContext):
(WebCore::V8DOMWindowShell::initializeIfNeeded):
(WebCore::V8DOMWindowShell::createContext):
(WebCore::V8DOMWindowShell::installDOMWindow):
(WebCore::V8DOMWindowShell::updateDocumentWrapper):
(WebCore::V8DOMWindowShell::updateDocumentProperty):
(WebCore::V8DOMWindowShell::clearDocumentProperty):
(WebCore::V8DOMWindowShell::setSecurityToken):
(WebCore::V8DOMWindowShell::updateDocument):
(WebCore::V8DOMWindowShell::namedItemAdded):
(WebCore::V8DOMWindowShell::namedItemRemoved):
(WebCore::V8DOMWindowShell::updateSecurityOrigin):
(WebCore::V8DOMWindowShell::setIsolatedWorldSecurityOrigin):

  • bindings/v8/V8DOMWindowShell.h:

(V8DOMWindowShell):
(WebCore::V8DOMWindowShell::world):
(WebCore::V8DOMWindowShell::isolatedWorldSecurityOrigin):
(WebCore::V8DOMWindowShell::getEntered):

  • bindings/v8/V8DOMWrapper.h:

(WebCore::V8DOMWrapper::getCachedWrapper):

  • bindings/v8/V8IsolatedContext.cpp: Removed.
  • bindings/v8/V8IsolatedContext.h: Removed.
  • bindings/v8/V8LazyEventListener.cpp:
  • bindings/v8/WorldContextHandle.cpp:

(WebCore::WorldContextHandle::WorldContextHandle):
(WebCore::WorldContextHandle::adjustedContext):

  • bindings/v8/custom/V8DocumentCustom.cpp:

(WebCore::toV8):

  • bindings/v8/custom/V8HTMLDocumentCustom.cpp:

(WebCore::toV8):

  • bindings/v8/custom/V8SVGDocumentCustom.cpp:

(WebCore::toV8):

  • bindings/v8/custom/V8XMLHttpRequestConstructor.cpp:

(WebCore::V8XMLHttpRequest::constructorCallback):

Location:
trunk/Source/WebCore
Files:
2 deleted
32 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r128156 r128159  
     12012-09-11  Dan Carney  <dcarney@google.com>
     2
     3        Removed V8IsolatedContext
     4        https://bugs.webkit.org/show_bug.cgi?id=95735
     5
     6        Reviewed by Adam Barth.
     7
     8        Remove V8IsolatedContext and merge functionality into V8DOMWindowShell.
     9        This brings the V8 isolated world model into closer alignment with
     10        that of JSC.
     11
     12        No new tests.  No change in functionality.
     13
     14        * UseV8.cmake:
     15        * WebCore.gypi:
     16        * bindings/scripts/CodeGeneratorV8.pm:
     17        (GenerateImplementation):
     18        * bindings/scripts/test/V8/V8Float64Array.cpp:
     19        * bindings/scripts/test/V8/V8TestActiveDOMObject.cpp:
     20        * bindings/scripts/test/V8/V8TestCustomNamedGetter.cpp:
     21        * bindings/scripts/test/V8/V8TestEventConstructor.cpp:
     22        * bindings/scripts/test/V8/V8TestEventTarget.cpp:
     23        * bindings/scripts/test/V8/V8TestException.cpp:
     24        * bindings/scripts/test/V8/V8TestInterface.cpp:
     25        * bindings/scripts/test/V8/V8TestMediaQueryListListener.cpp:
     26        * bindings/scripts/test/V8/V8TestNamedConstructor.cpp:
     27        * bindings/scripts/test/V8/V8TestNode.cpp:
     28        * bindings/scripts/test/V8/V8TestObj.cpp:
     29        * bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp:
     30        * bindings/v8/DOMData.cpp:
     31        (WebCore::DOMData::getCurrentStore):
     32        * bindings/v8/DOMWrapperWorld.cpp:
     33        (WebCore::DOMWrapperWorld::ensureIsolatedWorld):
     34        * bindings/v8/DOMWrapperWorld.h:
     35        (DOMWrapperWorld):
     36        * bindings/v8/ScriptController.cpp:
     37        (WebCore::ScriptController::ScriptController):
     38        (WebCore::ScriptController::resetIsolatedWorlds):
     39        (WebCore::ScriptController::ensureIsolatedWorldContext):
     40        (WebCore::ScriptController::existingWindowShellInternal):
     41        (WebCore):
     42        (WebCore::ScriptController::windowShell):
     43        (WebCore::ScriptController::evaluateInIsolatedWorld):
     44        (WebCore::ScriptController::setIsolatedWorldSecurityOrigin):
     45        (WebCore::ScriptController::currentWorldContext):
     46        (WebCore::ScriptController::evaluateInWorld):
     47        (WebCore::ScriptController::collectIsolatedContexts):
     48        * bindings/v8/ScriptController.h:
     49        (WebCore):
     50        (ScriptController):
     51        (WebCore::ScriptController::existingWindowShell):
     52        * bindings/v8/SharedPersistent.h:
     53        (WebCore):
     54        (WebCore::SharedPersistent::create):
     55        (WebCore::SharedPersistent::get):
     56        (WebCore::SharedPersistent::SharedPersistent):
     57        (SharedPersistent):
     58        * bindings/v8/V8Binding.cpp:
     59        (WebCore::perContextDataForCurrentWorld):
     60        * bindings/v8/V8DOMWindowShell.cpp:
     61        (WebCore::setIsolatedWorldField):
     62        (WebCore::V8DOMWindowShell::enteredIsolatedWorldContext):
     63        (WebCore):
     64        (WebCore::setInjectedScriptContextDebugId):
     65        (WebCore::V8DOMWindowShell::create):
     66        (WebCore::V8DOMWindowShell::V8DOMWindowShell):
     67        (WebCore::V8DOMWindowShell::destroyIsolatedShell):
     68        (WebCore::isolatedContextWeakCallback):
     69        (WebCore::V8DOMWindowShell::disposeContext):
     70        (WebCore::V8DOMWindowShell::initializeIfNeeded):
     71        (WebCore::V8DOMWindowShell::createContext):
     72        (WebCore::V8DOMWindowShell::installDOMWindow):
     73        (WebCore::V8DOMWindowShell::updateDocumentWrapper):
     74        (WebCore::V8DOMWindowShell::updateDocumentProperty):
     75        (WebCore::V8DOMWindowShell::clearDocumentProperty):
     76        (WebCore::V8DOMWindowShell::setSecurityToken):
     77        (WebCore::V8DOMWindowShell::updateDocument):
     78        (WebCore::V8DOMWindowShell::namedItemAdded):
     79        (WebCore::V8DOMWindowShell::namedItemRemoved):
     80        (WebCore::V8DOMWindowShell::updateSecurityOrigin):
     81        (WebCore::V8DOMWindowShell::setIsolatedWorldSecurityOrigin):
     82        * bindings/v8/V8DOMWindowShell.h:
     83        (V8DOMWindowShell):
     84        (WebCore::V8DOMWindowShell::world):
     85        (WebCore::V8DOMWindowShell::isolatedWorldSecurityOrigin):
     86        (WebCore::V8DOMWindowShell::getEntered):
     87        * bindings/v8/V8DOMWrapper.h:
     88        (WebCore::V8DOMWrapper::getCachedWrapper):
     89        * bindings/v8/V8IsolatedContext.cpp: Removed.
     90        * bindings/v8/V8IsolatedContext.h: Removed.
     91        * bindings/v8/V8LazyEventListener.cpp:
     92        * bindings/v8/WorldContextHandle.cpp:
     93        (WebCore::WorldContextHandle::WorldContextHandle):
     94        (WebCore::WorldContextHandle::adjustedContext):
     95        * bindings/v8/custom/V8DocumentCustom.cpp:
     96        (WebCore::toV8):
     97        * bindings/v8/custom/V8HTMLDocumentCustom.cpp:
     98        (WebCore::toV8):
     99        * bindings/v8/custom/V8SVGDocumentCustom.cpp:
     100        (WebCore::toV8):
     101        * bindings/v8/custom/V8XMLHttpRequestConstructor.cpp:
     102        (WebCore::V8XMLHttpRequest::constructorCallback):
     103
    11042012-09-11  Keishi Hattori  <keishi@webkit.org>
    2105
  • trunk/Source/WebCore/UseV8.cmake

    r127249 r128159  
    5858    bindings/v8/V8GCForContextDispose.cpp
    5959    bindings/v8/V8HiddenPropertyName.cpp
    60     bindings/v8/V8IsolatedContext.cpp
    6160    bindings/v8/V8LazyEventListener.cpp
    6261    bindings/v8/V8NodeFilterCondition.cpp
  • trunk/Source/WebCore/WebCore.gypi

    r128153 r128159  
    23022302            'bindings/v8/V8HiddenPropertyName.cpp',
    23032303            'bindings/v8/V8HiddenPropertyName.h',
    2304             'bindings/v8/V8IsolatedContext.cpp',
    2305             'bindings/v8/V8IsolatedContext.h',
    23062304            'bindings/v8/V8LazyEventListener.cpp',
    23072305            'bindings/v8/V8LazyEventListener.h',
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r128139 r128159  
    25202520    AddToImplIncludes("V8Binding.h");
    25212521    AddToImplIncludes("V8DOMWrapper.h");
    2522     AddToImplIncludes("V8IsolatedContext.h");
    25232522
    25242523    AddIncludesForType($interfaceName);
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8Float64Array.cpp

    r127972 r128159  
    3333#include "V8Float32Array.h"
    3434#include "V8Int32Array.h"
    35 #include "V8IsolatedContext.h"
    3635#include <wtf/Float32Array.h>
    3736#include <wtf/Float64Array.h>
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestActiveDOMObject.cpp

    r127972 r128159  
    2929#include "V8Binding.h"
    3030#include "V8DOMWrapper.h"
    31 #include "V8IsolatedContext.h"
    3231#include "V8Node.h"
    3332#include <wtf/UnusedParam.h>
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestCustomNamedGetter.cpp

    r127972 r128159  
    2929#include "V8Binding.h"
    3030#include "V8DOMWrapper.h"
    31 #include "V8IsolatedContext.h"
    3231#include <wtf/UnusedParam.h>
    3332
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestEventConstructor.cpp

    r127972 r128159  
    2929#include "V8Binding.h"
    3030#include "V8DOMWrapper.h"
    31 #include "V8IsolatedContext.h"
    3231#include <wtf/UnusedParam.h>
    3332
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestEventTarget.cpp

    r127972 r128159  
    3131#include "V8DOMWrapper.h"
    3232#include "V8Event.h"
    33 #include "V8IsolatedContext.h"
    3433#include "V8Node.h"
    3534#include <wtf/UnusedParam.h>
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestException.cpp

    r127972 r128159  
    2828#include "V8Binding.h"
    2929#include "V8DOMWrapper.h"
    30 #include "V8IsolatedContext.h"
    3130#include <wtf/UnusedParam.h>
    3231
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestInterface.cpp

    r128139 r128159  
    3232#include "V8Binding.h"
    3333#include "V8DOMWrapper.h"
    34 #include "V8IsolatedContext.h"
    3534#include "V8Node.h"
    3635#include "V8TestObj.h"
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestMediaQueryListListener.cpp

    r127972 r128159  
    3030#include "V8Binding.h"
    3131#include "V8DOMWrapper.h"
    32 #include "V8IsolatedContext.h"
    3332#include <wtf/UnusedParam.h>
    3433
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestNamedConstructor.cpp

    r128094 r128159  
    2929#include "V8Binding.h"
    3030#include "V8DOMWrapper.h"
    31 #include "V8IsolatedContext.h"
    3231#include <wtf/UnusedParam.h>
    3332
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestNode.cpp

    r127972 r128159  
    2828#include "V8Binding.h"
    2929#include "V8DOMWrapper.h"
    30 #include "V8IsolatedContext.h"
    3130#include "V8Node.h"
    3231#include <wtf/UnusedParam.h>
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp

    r128139 r128159  
    4444#include "V8Document.h"
    4545#include "V8Float32Array.h"
    46 #include "V8IsolatedContext.h"
    4746#include "V8SVGDocument.h"
    4847#include "V8SVGPoint.h"
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestSerializedScriptValueInterface.cpp

    r127972 r128159  
    3333#include "V8Binding.h"
    3434#include "V8DOMWrapper.h"
    35 #include "V8IsolatedContext.h"
    3635#include "V8MessagePort.h"
    3736#include <wtf/ArrayBuffer.h>
  • trunk/Source/WebCore/bindings/v8/DOMData.cpp

    r125216 r128159  
    3232#include "DOMData.h"
    3333#include "V8Binding.h"
    34 #include "V8IsolatedContext.h"
     34#include "V8DOMWindowShell.h"
    3535#include "WebGLContextAttributes.h"
    3636#include "WebGLUniformLocation.h"
     
    4444    if (UNLIKELY(data->domDataStore() != 0))
    4545        return *data->domDataStore();
    46     V8IsolatedContext* context = V8IsolatedContext::getEntered();
     46    V8DOMWindowShell* context = V8DOMWindowShell::getEntered();
    4747    if (UNLIKELY(context != 0))
    4848        return *context->world()->domDataStore();
  • trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.cpp

    r126926 r128159  
    9191static int temporaryWorldId = DOMWrapperWorld::uninitializedWorldId-1;
    9292
    93 PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::getOrCreateIsolatedWorld(int worldId, int extensionGroup)
     93PassRefPtr<DOMWrapperWorld> DOMWrapperWorld::ensureIsolatedWorld(int worldId, int extensionGroup)
    9494{
    9595    ASSERT(worldId != mainWorldId);
    96     ASSERT(worldId != uninitializedWorldId);
    9796
    9897    WorldMap& map = isolatedWorldMap();
    99     if (!worldId)
     98    if (worldId == uninitializedWorldId)
    10099        worldId = temporaryWorldId--;
    101100    else {
  • trunk/Source/WebCore/bindings/v8/DOMWrapperWorld.h

    r126566 r128159  
    4242class DOMWrapperWorld : public WTF::RefCountedBase {
    4343public:
    44     static const int mainWorldId = -1;
    45     static const int mainWorldExtensionGroup = -1;
    46     static const int uninitializedWorldId = -2;
    47     static const int uninitializedExtensionGroup = -2;
     44    static const int mainWorldId = 0;
     45    static const int mainWorldExtensionGroup = 0;
     46    static const int uninitializedWorldId = -1;
     47    static const int uninitializedExtensionGroup = -1;
    4848    // If 0 is passed as worldId, the world will be assigned a temporary id instead.
    49     static PassRefPtr<DOMWrapperWorld> getOrCreateIsolatedWorld(int worldId, int extensionGroup);
     49    static PassRefPtr<DOMWrapperWorld> ensureIsolatedWorld(int worldId, int extensionGroup);
    5050    static bool isolatedWorldsExist() { return isolatedWorldCount; }
    5151    // FIXME: this is a workaround for a problem in WebViewImpl.
  • trunk/Source/WebCore/bindings/v8/ScriptController.cpp

    r128123 r128159  
    6363#include "V8HiddenPropertyName.h"
    6464#include "V8HTMLEmbedElement.h"
    65 #include "V8IsolatedContext.h"
    6665#include "V8NPObject.h"
    6766#include "V8RecursionScope.h"
     
    101100    : m_frame(frame)
    102101    , m_sourceURL(0)
    103     , m_windowShell(V8DOMWindowShell::create(frame))
     102    , m_windowShell(V8DOMWindowShell::create(frame, mainThreadNormalWorld()))
    104103    , m_paused(false)
    105104#if ENABLE(NETSCAPE_PLUGIN_API)
     
    148147    for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin();
    149148         iter != m_isolatedWorlds.end(); ++iter) {
    150         iter->second->destroy();
     149        iter->second->destroyIsolatedShell();
    151150    }
    152151    m_isolatedWorlds.clear();
     
    315314}
    316315
    317 void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources, Vector<ScriptValue>* results)
    318 {
    319     evaluateInIsolatedWorld(worldID, sources, 0, results);
    320 }
    321 
    322 void ScriptController::evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results)
    323 {
     316V8DOMWindowShell* ScriptController::ensureIsolatedWorldContext(int worldId, int extensionGroup)
     317{
     318    ASSERT(worldId != DOMWrapperWorld::mainWorldId);
     319
     320    // Check the map for non-temporary worlds.
     321    if (worldId != DOMWrapperWorld::uninitializedWorldId) {
     322        IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldId);
     323        if (iter != m_isolatedWorlds.end()) {
     324            ASSERT(iter->second->world()->worldId() == worldId);
     325            ASSERT(iter->second->world()->extensionGroup() == extensionGroup);
     326            return iter->second;
     327        }
     328    }
     329
     330    RefPtr<DOMWrapperWorld> world = DOMWrapperWorld::ensureIsolatedWorld(worldId, extensionGroup);
     331    OwnPtr<V8DOMWindowShell> isolatedWorldShell = V8DOMWindowShell::create(m_frame, world);
     332    m_isolatedWorlds.set(world->worldId(), isolatedWorldShell.get());
     333    return isolatedWorldShell.leakPtr();
     334}
     335
     336V8DOMWindowShell* ScriptController::existingWindowShellInternal(DOMWrapperWorld* world)
     337{
     338    ASSERT(world);
     339
     340    if (LIKELY(world->isMainWorld()))
     341        return m_windowShell.get();
     342
     343    IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(world->worldId());
     344    return iter == m_isolatedWorlds.end() ? 0 : iter->second;
     345}
     346
     347V8DOMWindowShell* ScriptController::windowShell(DOMWrapperWorld* world)
     348{
     349    V8DOMWindowShell* shell = existingWindowShellInternal(world);
     350    if (LIKELY(!!shell))
     351        return shell;
     352
     353    OwnPtr<V8DOMWindowShell> isolatedWorldShell = V8DOMWindowShell::create(m_frame, world);
     354    m_isolatedWorlds.set(world->worldId(), isolatedWorldShell.get());
     355    return isolatedWorldShell.leakPtr();
     356}
     357
     358void ScriptController::evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results)
     359{
     360    // Except in the test runner, worldID should be non 0 as it conflicts with the mainWorldId.
     361    // FIXME: Change the test runner to perform this swap and make this an ASSERT.
     362    if (UNLIKELY(!worldID))
     363        worldID = DOMWrapperWorld::uninitializedWorldId;
     364
    324365    v8::HandleScope handleScope;
    325 
    326     // FIXME: This will need to get reorganized once we have a windowShell for the isolated world.
    327     if (!windowShell()->initializeIfNeeded())
    328         return;
    329 
    330366    v8::Local<v8::Array> v8Results;
    331367    {
    332368        v8::HandleScope evaluateHandleScope;
    333         V8IsolatedContext* isolatedContext = 0;
    334         if (worldID > 0) {
    335             IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldID);
    336             if (iter != m_isolatedWorlds.end())
    337                 isolatedContext = iter->second;
    338             else {
    339                 isolatedContext = new V8IsolatedContext(m_frame, DOMWrapperWorld::getOrCreateIsolatedWorld(worldID, extensionGroup));
    340                 if (isolatedContext->context().IsEmpty()) {
    341                     delete isolatedContext;
    342                     return;
    343                 }
    344 
    345                 // FIXME: We should change this to using window shells to match JSC.
    346                 m_isolatedWorlds.set(worldID, isolatedContext);
    347             }
    348 
     369        V8DOMWindowShell* isolatedWorldShell = ensureIsolatedWorldContext(worldID, extensionGroup);
     370
     371        if (worldID != DOMWrapperWorld::uninitializedWorldId) {
    349372            IsolatedWorldSecurityOriginMap::iterator securityOriginIter = m_isolatedWorldSecurityOrigins.find(worldID);
    350373            if (securityOriginIter != m_isolatedWorldSecurityOrigins.end())
    351                 isolatedContext->setSecurityOrigin(securityOriginIter->second);
    352         } else {
    353             isolatedContext = new V8IsolatedContext(m_frame, DOMWrapperWorld::getOrCreateIsolatedWorld(worldID, extensionGroup));
    354             if (isolatedContext->context().IsEmpty()) {
    355                 delete isolatedContext;
    356                 return;
    357             }
     374                isolatedWorldShell->setIsolatedWorldSecurityOrigin(securityOriginIter->second);
    358375        }
    359376
    360         v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolatedContext->context());
     377        isolatedWorldShell->initializeIfNeeded();
     378        if (isolatedWorldShell->context().IsEmpty())
     379            return;
     380
     381        v8::Local<v8::Context> context = v8::Local<v8::Context>::New(isolatedWorldShell->context());
    361382        v8::Context::Scope contextScope(context);
    362383        v8::Local<v8::Array> resultArray = v8::Array::New(sources.size());
     
    369390        }
    370391
    371         if (!worldID)
    372             isolatedContext->destroy();
     392        // Mark temporary shell for weak destruction.
     393        if (worldID == DOMWrapperWorld::uninitializedWorldId) {
     394            int actualWorldId = isolatedWorldShell->world()->worldId();
     395            m_isolatedWorlds.remove(actualWorldId);
     396            isolatedWorldShell->destroyIsolatedShell();
     397        }
    373398
    374399        v8Results = evaluateHandleScope.Close(resultArray);
     
    387412    IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldID);
    388413    if (iter != m_isolatedWorlds.end())
    389         iter->second->setSecurityOrigin(securityOrigin);
     414        iter->second->setIsolatedWorldSecurityOrigin(securityOrigin);
    390415}
    391416
     
    404429v8::Local<v8::Context> ScriptController::currentWorldContext()
    405430{
    406     if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered()) {
    407         RefPtr<SharedPersistent<v8::Context> > context = isolatedContext->sharedContext();
    408         if (m_frame != toFrameIfNotDetached(context->get()))
     431    if (V8DOMWindowShell* isolatedShell = V8DOMWindowShell::getEntered()) {
     432        v8::Persistent<v8::Context> context = isolatedShell->context();
     433        if (context.IsEmpty() || m_frame != toFrameIfNotDetached(context))
    409434            return v8::Local<v8::Context>();
    410         return v8::Local<v8::Context>::New(context->get());
     435        return v8::Local<v8::Context>::New(context);
    411436    }
    412437    windowShell()->initializeIfNeeded();
     
    533558                                       DOMWrapperWorld* world)
    534559{
     560    if (world == mainThreadNormalWorld()) {
     561        evaluate(source);
     562        return;
     563    }
    535564    Vector<ScriptSourceCode> sources;
    536565    sources.append(source);
    537     // FIXME: Get an ID from the world param.
    538     evaluateInIsolatedWorld(0, sources, 0);
     566    evaluateInIsolatedWorld(world->worldId(), sources, world->extensionGroup(), 0);
    539567}
    540568
     
    637665    v8::HandleScope handleScope;
    638666    for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isolatedWorlds.end(); ++it) {
    639         V8IsolatedContext* isolatedContext = it->second;
    640         if (!isolatedContext->securityOrigin())
     667        V8DOMWindowShell* isolatedWorldShell = it->second;
     668        if (!isolatedWorldShell->isolatedWorldSecurityOrigin())
    641669            continue;
    642         v8::Handle<v8::Context> v8Context = isolatedContext->context();
     670        v8::Handle<v8::Context> v8Context = isolatedWorldShell->context();
    643671        if (v8Context.IsEmpty())
    644672            continue;
    645673        ScriptState* scriptState = ScriptState::forContext(v8::Local<v8::Context>::New(v8Context));
    646         result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, isolatedContext->securityOrigin()));
     674        result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, isolatedWorldShell->isolatedWorldSecurityOrigin()));
    647675    }
    648676}
  • trunk/Source/WebCore/bindings/v8/ScriptController.h

    r128123 r128159  
    5858class SecurityOrigin;
    5959class V8DOMWindowShell;
    60 class V8IsolatedContext;
    6160class Widget;
    62 
    63 // Note: although the pointer is raw, the instance is kept alive by a strong
    64 // reference to the v8 context it contains, which is not made weak until we
    65 // call world->destroy().
    66 //
    67 // FIXME: We want to eventually be holding window shells instead of the
    68 // IsolatedContext directly.
    69 // https://bugs.webkit.org/show_bug.cgi?id=94875
    70 typedef HashMap<int, V8IsolatedContext*> IsolatedWorldMap;
    71 
    72 typedef HashMap<int, RefPtr<SecurityOrigin> > IsolatedWorldSecurityOriginMap;
    7361
    7462typedef WTF::Vector<v8::Extension*> V8Extensions;
     
    7967    ~ScriptController();
    8068
    81     // FIXME: This should eventually take DOMWrapperWorld argument.
    82     // https://bugs.webkit.org/show_bug.cgi?id=94875
    8369    V8DOMWindowShell* windowShell() const { return m_windowShell.get(); }
     70    V8DOMWindowShell* windowShell(DOMWrapperWorld*);
     71    // FIXME: Replace existingWindowShell with existingWindowShellInternal see comment in V8DOMWindowShell::initializeIfNeeded.
     72    ScriptController* existingWindowShell(DOMWrapperWorld*) { return this; }
     73    V8DOMWindowShell* existingWindowShellInternal(DOMWrapperWorld*);
    8474
    8575    ScriptValue executeScript(const ScriptSourceCode&);
     
    10595    // The caller must hold an execution context.
    10696    ScriptValue evaluate(const ScriptSourceCode&);
    107 
    108     // Evaluate JavaScript in a new isolated world. The script gets its own
    109     // global scope, its own prototypes for intrinsic JavaScript objects (String,
    110     // Array, and so-on), and its own wrappers for all DOM nodes and DOM
    111     // constructors.
    112     void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources, Vector<ScriptValue>* results);
    11397
    11498    // Executes JavaScript in an isolated world. The script gets its own global scope,
     
    119103    // Otherwise, a new world is created.
    120104    //
    121     // If the worldID is 0, a new world is always created.
     105    // If the worldID is 0 or DOMWrapperWorld::uninitializedWorldId, a new world is always created.
    122106    //
    123107    // FIXME: Get rid of extensionGroup here.
    124     void evaluateInIsolatedWorld(unsigned worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results);
     108    void evaluateInIsolatedWorld(int worldID, const Vector<ScriptSourceCode>& sources, int extensionGroup, Vector<ScriptValue>* results);
    125109
    126110    // Associates an isolated world (see above for description) with a security
     
    128112    // to come from that origin, not the frame's.
    129113    void setIsolatedWorldSecurityOrigin(int worldID, PassRefPtr<SecurityOrigin>);
    130 
    131     // Masquerade 'this' as the windowShell.
    132     // This is a bit of a hack, but provides reasonable compatibility
    133     // with what JSC does as well.
    134     ScriptController* windowShell(DOMWrapperWorld*) { return this; }
    135     ScriptController* existingWindowShell(DOMWrapperWorld*) { return this; }
    136114
    137115    // Creates a property of the global object of a frame.
     
    209187
    210188private:
     189    // Note: although the pointer is raw, the instance is kept alive by a strong
     190    // reference to the v8 context it contains, which is not made weak until we
     191    // call world->destroyIsolatedShell().
     192    typedef HashMap<int, V8DOMWindowShell*> IsolatedWorldMap;
     193    typedef HashMap<int, RefPtr<SecurityOrigin> > IsolatedWorldSecurityOriginMap;
     194
    211195    void resetIsolatedWorlds();
    212196
     
    214198    const String* m_sourceURL;
    215199
    216     // For the moment, we have one of these. Soon we will have one per DOMWrapperWorld.
     200    V8DOMWindowShell* ensureIsolatedWorldContext(int worldId, int extensionGroup);
    217201    OwnPtr<V8DOMWindowShell> m_windowShell;
    218202
     
    221205    // evaluateInIsolatedWorld().
    222206    IsolatedWorldMap m_isolatedWorlds;
    223 
    224207    IsolatedWorldSecurityOriginMap m_isolatedWorldSecurityOrigins;
    225208
  • trunk/Source/WebCore/bindings/v8/SharedPersistent.h

    r95901 r128159  
    3232#define SharedPersistent_h
    3333
     34#include "ScopedPersistent.h"
    3435#include <v8.h>
    3536#include <wtf/PassRefPtr.h>
     
    3839namespace WebCore {
    3940
    40     // A shareable reference to a v8 persistent handle.  Using a shared
    41     // persistent any number of objects can share a reference to a v8
    42     // object and when it should no longer be accessible the object's
    43     // owner can clear it.
     41    // FIXME: Remove this class.
    4442    template <typename T>
    4543    class SharedPersistent : public RefCounted<SharedPersistent<T> > {
    4644    public:
    47         void set(v8::Persistent<T> value)
    48         {
    49             m_value = value;
    50         }
    51         v8::Persistent<T> get()
    52         {
    53             return m_value;
    54         }
    55         void disposeHandle()
    56         {
    57             if (!m_value.IsEmpty()) {
    58               m_value.Dispose();
    59               m_value.Clear();
    60             }
    61         }
    62         static PassRefPtr<SharedPersistent<T> > create(v8::Persistent<T> value)
     45        static PassRefPtr<SharedPersistent<T> > create(v8::Handle<T> value)
    6346        {
    6447            return adoptRef(new SharedPersistent<T>(value));
    6548        }
    66         static PassRefPtr<SharedPersistent<T> > create()
     49        inline v8::Persistent<T> get()
    6750        {
    68             return create(v8::Persistent<T>());
     51            return m_value.get();
    6952        }
    7053    private:
    71         explicit SharedPersistent(v8::Persistent<T> value) : m_value(value) { }
    72         v8::Persistent<T> m_value;
     54        explicit SharedPersistent(v8::Handle<T> value) : m_value(value) { }
     55        ScopedPersistent<T> m_value;
    7356    };
    7457
  • trunk/Source/WebCore/bindings/v8/V8Binding.cpp

    r127972 r128159  
    311311V8PerContextData* perContextDataForCurrentWorld(Frame* frame)
    312312{
    313     V8IsolatedContext* isolatedContext;
    314     if (UNLIKELY(!!(isolatedContext = V8IsolatedContext::getEntered())))
    315         return isolatedContext->perContextData();
     313    V8DOMWindowShell* isolatedShell;
     314    if (UNLIKELY(!!(isolatedShell = V8DOMWindowShell::getEntered())))
     315        return isolatedShell->perContextData();
    316316    return frame->script()->windowShell()->perContextData();
    317317}
  • trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp

    r127977 r128159  
    3838#include "Frame.h"
    3939#include "FrameLoaderClient.h"
     40#include "InspectorInstrumentation.h"
    4041#include "MemoryUsageSupport.h"
    4142#include "Page.h"
     
    171172}
    172173
    173 PassOwnPtr<V8DOMWindowShell> V8DOMWindowShell::create(Frame* frame)
    174 {
    175     return adoptPtr(new V8DOMWindowShell(frame));
    176 }
    177 
    178 V8DOMWindowShell::V8DOMWindowShell(Frame* frame)
     174static void setIsolatedWorldField(V8DOMWindowShell* shell, v8::Local<v8::Context> context)
     175{
     176    toInnerGlobalObject(context)->SetPointerInInternalField(V8DOMWindow::enteredIsolatedWorldIndex, shell);
     177}
     178
     179V8DOMWindowShell* V8DOMWindowShell::enteredIsolatedWorldContext()
     180{
     181    return static_cast<V8DOMWindowShell*>(toInnerGlobalObject(v8::Context::GetEntered())->GetPointerFromInternalField(V8DOMWindow::enteredIsolatedWorldIndex));
     182}
     183
     184static void setInjectedScriptContextDebugId(v8::Handle<v8::Context> targetContext, int debugId)
     185{
     186    char buffer[32];
     187    if (debugId == -1)
     188        snprintf(buffer, sizeof(buffer), "injected");
     189    else
     190        snprintf(buffer, sizeof(buffer), "injected,%d", debugId);
     191    targetContext->SetData(v8::String::New(buffer));
     192}
     193
     194PassOwnPtr<V8DOMWindowShell> V8DOMWindowShell::create(Frame* frame, PassRefPtr<DOMWrapperWorld> world)
     195{
     196    return adoptPtr(new V8DOMWindowShell(frame, world));
     197}
     198
     199V8DOMWindowShell::V8DOMWindowShell(Frame* frame, PassRefPtr<DOMWrapperWorld> world)
    179200    : m_frame(frame)
     201    , m_world(world)
    180202{
    181203}
     
    187209}
    188210
    189 void V8DOMWindowShell::disposeContext()
    190 {
     211void V8DOMWindowShell::destroyIsolatedShell()
     212{
     213    disposeContext(true);
     214}
     215
     216static void isolatedContextWeakCallback(v8::Persistent<v8::Value> object, void* parameter)
     217{
     218    // Handle will be disposed in delete.
     219    delete static_cast<V8DOMWindowShell*>(parameter);
     220}
     221
     222void V8DOMWindowShell::disposeContext(bool weak)
     223{
     224    ASSERT(!m_context.get().IsWeak());
    191225    m_perContextData.clear();
    192226
    193     if (!m_context.isEmpty()) {
    194         m_frame->loader()->client()->willReleaseScriptContext(m_context.get(), 0);
     227    if (m_context.isEmpty())
     228        return;
     229
     230    m_frame->loader()->client()->willReleaseScriptContext(m_context.get(), m_world->worldId());
     231
     232    if (!weak)
    195233        m_context.clear();
    196 
    197         // It's likely that disposing the context has created a lot of
    198         // garbage. Notify V8 about this so it'll have a chance of cleaning
    199         // it up when idle.
    200         bool isMainFrame = m_frame->page() && (m_frame->page()->mainFrame() == m_frame);
     234    else {
     235        ASSERT(!m_world->isMainWorld());
     236        destroyGlobal();
     237        m_frame = 0;
     238        m_context.get().MakeWeak(this, isolatedContextWeakCallback);
     239    }
     240
     241    // It's likely that disposing the context has created a lot of
     242    // garbage. Notify V8 about this so it'll have a chance of cleaning
     243    // it up when idle.
     244    if (m_world->isMainWorld()) {
     245        bool isMainFrame = m_frame->page() && (m_frame->page()->mainFrame() == m_frame);
    201246        V8GCForContextDispose::instance().notifyContextDisposed(isMainFrame);
    202247    }
     
    285330    initializeV8IfNeeded();
    286331
    287     m_context.adopt(createNewContext(m_global.get(), 0, 0));
     332    createContext();
    288333    if (m_context.isEmpty())
    289334        return false;
     335
     336    bool isMainWorld = m_world->isMainWorld();
    290337
    291338    v8::Local<v8::Context> context = v8::Local<v8::Context>::New(m_context.get());
     
    300347    }
    301348
     349    // Flag context as isolated.
     350    if (!isMainWorld) {
     351        V8DOMWindowShell* mainWindow = m_frame->script()->windowShell();
     352        mainWindow->initializeIfNeeded();
     353        if (!mainWindow->context().IsEmpty())
     354            setInjectedScriptContextDebugId(m_context.get(), m_frame->script()->contextDebugId(mainWindow->context()));
     355        setIsolatedWorldField(this, context);
     356    }
     357
    302358    m_perContextData = V8PerContextData::create(m_context.get());
    303359    if (!m_perContextData->init()) {
     
    306362    }
    307363
    308     if (!installDOMWindow(context, m_frame->document()->domWindow())) {
     364    if (!installDOMWindow()) {
    309365        disposeContext();
    310366        return false;
    311367    }
    312368
    313     updateDocument();
    314 
    315     setSecurityToken();
    316 
    317     if (m_frame->document())
    318         context->AllowCodeGenerationFromStrings(m_frame->document()->contentSecurityPolicy()->allowEval(0, ContentSecurityPolicy::SuppressReport));
    319 
    320     m_frame->loader()->client()->didCreateScriptContext(m_context.get(), 0, 0);
    321 
    322     // FIXME: This is wrong. We should actually do this for the proper world once
    323     // we do isolated worlds the WebCore way.
    324     m_frame->loader()->dispatchDidClearWindowObjectInWorld(0);
     369    if (isMainWorld) {
     370        updateDocument();
     371        setSecurityToken();
     372        if (m_frame->document())
     373            context->AllowCodeGenerationFromStrings(m_frame->document()->contentSecurityPolicy()->allowEval(0, ContentSecurityPolicy::SuppressReport));
     374    } else {
     375        // Using the default security token means that the canAccess is always
     376        // called, which is slow.
     377        // FIXME: Use tokens where possible. This will mean keeping track of all
     378        //        created contexts so that they can all be updated when the
     379        //        document domain
     380        //        changes.
     381        m_context->UseDefaultSecurityToken();
     382    }
     383    m_frame->loader()->client()->didCreateScriptContext(m_context.get(), m_world->extensionGroup(), m_world->worldId());
     384
     385    if (isMainWorld) {
     386        // FIXME: This call is probably in the wrong spot, but causes a test timeout for http/tests/misc/window-open-then-write.html when removed.
     387        // Additionally, ScriptController::existingWindowShell cannot be correctly implemented until this call is gone.
     388        m_frame->loader()->dispatchDidClearWindowObjectInWorld(0);
     389    }
    325390
    326391    return true;
    327392}
    328393
    329 v8::Persistent<v8::Context> V8DOMWindowShell::createNewContext(v8::Handle<v8::Object> global, int extensionGroup, int worldId)
    330 {
    331     v8::Persistent<v8::Context> result;
    332 
     394void V8DOMWindowShell::createContext()
     395{
    333396    // The activeDocumentLoader pointer could be 0 during frame shutdown.
    334397    // FIXME: Can we remove this check?
    335398    if (!m_frame->loader()->activeDocumentLoader())
    336         return result;
     399        return;
    337400
    338401    // Create a new environment using an empty template for the shadow
     
    340403    v8::Persistent<v8::ObjectTemplate> globalTemplate = V8DOMWindow::GetShadowObjectTemplate();
    341404    if (globalTemplate.IsEmpty())
    342         return result;
     405        return;
    343406
    344407    // Used to avoid sleep calls in unload handlers.
     
    355418    OwnArrayPtr<const char*> extensionNames = adoptArrayPtr(new const char*[extensions.size()]);
    356419    int index = 0;
     420    int extensionGroup = m_world->extensionGroup();
     421    int worldId = m_world->worldId();
    357422    for (size_t i = 0; i < extensions.size(); ++i) {
    358423        // Ensure our date extension is always allowed.
     
    364429    }
    365430    v8::ExtensionConfiguration extensionConfiguration(index, extensionNames.get());
    366     result = v8::Context::New(&extensionConfiguration, globalTemplate, global);
    367 
    368     return result;
    369 }
    370 
    371 bool V8DOMWindowShell::installDOMWindow(v8::Handle<v8::Context> context, DOMWindow* window)
    372 {
     431
     432    m_context.adopt(v8::Context::New(&extensionConfiguration, globalTemplate, m_global.get()));
     433}
     434
     435bool V8DOMWindowShell::installDOMWindow()
     436{
     437    DOMWindow* window = m_frame->document()->domWindow();
    373438    v8::Local<v8::Object> windowWrapper = V8ObjectConstructor::newInstance(V8DOMWrapper::constructorForType(&V8DOMWindow::info, window));
    374439    if (windowWrapper.IsEmpty())
     
    394459    //       JavaScript object.
    395460    //
    396     v8::Handle<v8::Object> innerGlobalObject = toInnerGlobalObject(context);
     461    v8::Handle<v8::Object> innerGlobalObject = toInnerGlobalObject(m_context.get());
    397462    V8DOMWrapper::setDOMWrapper(innerGlobalObject, &V8DOMWindow::info, window);
    398463    innerGlobalObject->SetPrototype(windowWrapper);
     
    402467void V8DOMWindowShell::updateDocumentWrapper(v8::Handle<v8::Object> wrapper)
    403468{
     469    ASSERT(m_world->isMainWorld());
    404470    m_document.set(wrapper);
    405471}
     
    407473void V8DOMWindowShell::updateDocumentProperty()
    408474{
     475    if (!m_world->isMainWorld())
     476        return;
     477
    409478    v8::HandleScope handleScope;
    410479    // FIXME: Should we use a new Local handle here?
     
    435504{
    436505    ASSERT(!m_context.isEmpty());
     506    if (!m_world->isMainWorld())
     507        return;
    437508    m_context->Global()->ForceDelete(v8::String::New("document"));
    438509}
     
    440511void V8DOMWindowShell::setSecurityToken()
    441512{
     513    ASSERT(m_world->isMainWorld());
     514
    442515    Document* document = m_frame->document();
    443516
     
    470543void V8DOMWindowShell::updateDocument()
    471544{
     545    ASSERT(m_world->isMainWorld());
    472546    if (m_global.isEmpty())
    473547        return;
     
    495569void V8DOMWindowShell::namedItemAdded(HTMLDocument* document, const AtomicString& name)
    496570{
     571    ASSERT(m_world->isMainWorld());
     572
    497573    if (!initializeIfNeeded())
    498574        return;
     
    508584void V8DOMWindowShell::namedItemRemoved(HTMLDocument* document, const AtomicString& name)
    509585{
     586    ASSERT(m_world->isMainWorld());
     587
    510588    if (document->hasNamedItem(name.impl()) || document->hasExtraNamedItem(name.impl()))
    511589        return;
     
    524602void V8DOMWindowShell::updateSecurityOrigin()
    525603{
     604    ASSERT(m_world->isMainWorld());
    526605    if (m_context.isEmpty())
    527606        return;
     
    530609}
    531610
     611void V8DOMWindowShell::setIsolatedWorldSecurityOrigin(PassRefPtr<SecurityOrigin> securityOrigin)
     612{
     613    ASSERT(!m_world->isMainWorld());
     614    // FIXME: Should this be here?
     615    if (!m_isolatedWorldShellSecurityOrigin && !context().IsEmpty() && InspectorInstrumentation::hasFrontends()) {
     616        v8::HandleScope handleScope;
     617        ScriptState* scriptState = ScriptState::forContext(v8::Local<v8::Context>::New(context()));
     618        InspectorInstrumentation::didCreateIsolatedContext(m_frame, scriptState, securityOrigin.get());
     619    }
     620    m_isolatedWorldShellSecurityOrigin = securityOrigin;
     621}
     622
    532623} // WebCore
  • trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h

    r127977 r128159  
    3232#define V8DOMWindowShell_h
    3333
     34#include "DOMWrapperWorld.h"
    3435#include "ScopedPersistent.h"
     36#include "SecurityOrigin.h"
    3537#include "V8PerContextData.h"
    3638#include "WrapperTypeInfo.h"
     
    5254class V8DOMWindowShell {
    5355public:
    54     static PassOwnPtr<V8DOMWindowShell> create(Frame*);
     56    static PassOwnPtr<V8DOMWindowShell> create(Frame*, PassRefPtr<DOMWrapperWorld>);
    5557
    5658    v8::Persistent<v8::Context> context() const { return m_context.get(); }
     
    6971
    7072    v8::Persistent<v8::Context> createNewContext(v8::Handle<v8::Object> global, int extensionGroup, int worldId);
    71     static bool installDOMWindow(v8::Handle<v8::Context> context, DOMWindow*);
    7273
    7374    bool initializeIfNeeded();
     
    8182    V8PerContextData* perContextData() { return m_perContextData.get(); }
    8283
     84    DOMWrapperWorld* world() { return m_world.get(); }
     85
     86    void setIsolatedWorldSecurityOrigin(PassRefPtr<SecurityOrigin>);
     87    SecurityOrigin* isolatedWorldSecurityOrigin() const
     88    {
     89        ASSERT(!m_world->isMainWorld());
     90        return m_isolatedWorldShellSecurityOrigin.get();
     91    };
     92
     93    // Returns the isolated world associated with
     94    // v8::Context::GetEntered(). Because worlds are isolated, the entire
     95    // JavaScript call stack should be from the same isolated world.
     96    // Returns 0 if the entered context is from the main world.
     97    //
     98    // FIXME: Consider edge cases with DOM mutation events that might
     99    // violate this invariant.
     100    //
     101    // FIXME: This is poorly named after the deletion of isolated contexts.
     102    static V8DOMWindowShell* getEntered()
     103    {
     104        if (!DOMWrapperWorld::isolatedWorldsExist())
     105            return 0;
     106        if (!v8::Context::InContext())
     107            return 0;
     108        return enteredIsolatedWorldContext();
     109    }
     110
     111    void destroyIsolatedShell();
    83112private:
    84     explicit V8DOMWindowShell(Frame*);
     113    V8DOMWindowShell(Frame*, PassRefPtr<DOMWrapperWorld>);
    85114
    86     void disposeContext();
     115    void disposeContext(bool weak = false);
    87116
    88117    void setSecurityToken();
     
    95124    void clearDocumentProperty();
    96125
     126    void createContext();
     127    bool installDOMWindow();
     128
     129    static V8DOMWindowShell* enteredIsolatedWorldContext();
     130
    97131    Frame* m_frame;
     132    RefPtr<DOMWrapperWorld> m_world;
    98133
    99134    OwnPtr<V8PerContextData> m_perContextData;
     
    102137    ScopedPersistent<v8::Object> m_global;
    103138    ScopedPersistent<v8::Object> m_document;
     139
     140    // FIXME: Either remove this or the map in ScriptController.
     141    RefPtr<SecurityOrigin> m_isolatedWorldShellSecurityOrigin;
    104142};
    105143
  • trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h

    r128102 r128159  
    3838#include "V8CustomXPathNSResolver.h"
    3939#include "V8DOMMap.h"
    40 #include "V8IsolatedContext.h"
     40#include "V8DOMWindowShell.h"
    4141#include "V8Utilities.h"
    4242#include "WrapperTypeInfo.h"
     
    124124            }
    125125
    126             V8IsolatedContext* context = V8IsolatedContext::getEntered();
     126            V8DOMWindowShell* context = V8DOMWindowShell::getEntered();
    127127            if (LIKELY(!context)) {
    128128                v8::Persistent<v8::Object>* wrapper = node->wrapper();
  • trunk/Source/WebCore/bindings/v8/V8LazyEventListener.cpp

    r128126 r128159  
    3838#include "HTMLFormElement.h"
    3939#include "Node.h"
     40#include "ScriptSourceCode.h"
    4041#include "V8Binding.h"
    4142#include "V8DOMWrapper.h"
  • trunk/Source/WebCore/bindings/v8/WorldContextHandle.cpp

    r126083 r128159  
    3333
    3434#include "ScriptController.h"
    35 #include "V8IsolatedContext.h"
     35#include "V8DOMWindowShell.h"
    3636
    3737namespace WebCore {
     
    4343        return;
    4444
    45     if (V8IsolatedContext* context = V8IsolatedContext::getEntered())
    46         m_context = context->sharedContext();
     45    V8DOMWindowShell* shell = V8DOMWindowShell::getEntered();
     46    if (LIKELY(!shell)) {
     47        m_worldToUse = UseMainWorld;
     48        return;
     49    }
     50
     51    ASSERT(!shell->context().IsEmpty());
     52    m_context = SharedPersistent<v8::Context>::create(shell->context());
    4753}
    4854
    4955v8::Local<v8::Context> WorldContextHandle::adjustedContext(ScriptController* script) const
    5056{
    51     if (m_worldToUse == UseMainWorld || !m_context || m_context->get().IsEmpty())
     57    if (m_worldToUse == UseMainWorld)
    5258        return script->mainWorldContext();
    5359
     60    ASSERT(!m_context->get().IsEmpty());
    5461    return v8::Local<v8::Context>::New(m_context->get());
    5562}
  • trunk/Source/WebCore/bindings/v8/custom/V8DocumentCustom.cpp

    r127946 r128159  
    4545#include "V8CustomXPathNSResolver.h"
    4646#include "V8DOMImplementation.h"
     47#include "V8DOMWindowShell.h"
    4748#include "V8DOMWrapper.h"
    4849#include "V8HTMLDocument.h"
    49 #include "V8IsolatedContext.h"
    5050#include "V8Node.h"
    5151#include "V8Touch.h"
     
    131131    if (wrapper.IsEmpty())
    132132        return wrapper;
    133     if (!V8IsolatedContext::getEntered()) {
     133    if (!V8DOMWindowShell::getEntered()) {
    134134        if (Frame* frame = impl->frame())
    135135            frame->script()->windowShell()->updateDocumentWrapper(wrapper);
  • trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp

    r128095 r128159  
    4141#include "V8Binding.h"
    4242#include "V8DOMWindow.h"
     43#include "V8DOMWindowShell.h"
    4344#include "V8HTMLAllCollection.h"
    4445#include "V8HTMLCollection.h"
    45 #include "V8IsolatedContext.h"
    4646#include "V8Node.h"
    4747#include "V8RecursionScope.h"
     
    184184    if (wrapper.IsEmpty())
    185185        return wrapper;
    186     if (!V8IsolatedContext::getEntered()) {
     186    if (!V8DOMWindowShell::getEntered()) {
    187187        if (Frame* frame = impl->frame())
    188188            frame->script()->windowShell()->updateDocumentWrapper(wrapper);
  • trunk/Source/WebCore/bindings/v8/custom/V8SVGDocumentCustom.cpp

    r127946 r128159  
    3535
    3636#include "Frame.h"
    37 #include "V8IsolatedContext.h"
     37#include "V8DOMWindowShell.h"
    3838
    3939namespace WebCore {
     
    4646    if (wrapper.IsEmpty())
    4747        return wrapper;
    48     if (!V8IsolatedContext::getEntered()) {
     48    if (!V8DOMWindowShell::getEntered()) {
    4949        if (Frame* frame = impl->frame())
    5050            frame->script()->windowShell()->updateDocumentWrapper(wrapper);
  • trunk/Source/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp

    r128139 r128159  
    3636#include "SecurityOrigin.h"
    3737#include "V8Binding.h"
    38 #include "V8IsolatedContext.h"
     38#include "V8DOMWindowShell.h"
    3939#include "V8Utilities.h"
    4040#include "WorkerContext.h"
     
    5656
    5757    RefPtr<SecurityOrigin> securityOrigin;
    58     if (V8IsolatedContext* isolatedContext = V8IsolatedContext::getEntered())
    59         securityOrigin = isolatedContext->securityOrigin();
     58    if (V8DOMWindowShell* isolatedWorldShell = V8DOMWindowShell::getEntered())
     59        securityOrigin = isolatedWorldShell->isolatedWorldSecurityOrigin();
    6060
    6161    RefPtr<XMLHttpRequest> xmlHttpRequest = XMLHttpRequest::create(context, securityOrigin);
Note: See TracChangeset for help on using the changeset viewer.