Changeset 129984 in webkit


Ignore:
Timestamp:
Sep 29, 2012, 1:29:34 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Unreviewed, rolling out r129965.
http://trac.webkit.org/changeset/129965
https://bugs.webkit.org/show_bug.cgi?id=97970

Causes ASSERTs in workers (Requested by abarth on #webkit).

Patch by Sheriff Bot <webkit.review.bot@gmail.com> on 2012-09-29

  • bindings/v8/DOMData.cpp:

(WebCore::DOMData::getCurrentStore):

  • bindings/v8/ScopedPersistent.h:
  • bindings/v8/ScriptController.cpp:

(WebCore::ScriptController::resetIsolatedWorlds):
(WebCore::ScriptController::evaluateInIsolatedWorld):
(WebCore::ScriptController::currentWorldContext):

  • bindings/v8/V8Binding.cpp:

(WebCore::perContextDataForCurrentWorld):

  • bindings/v8/V8DOMWindowShell.cpp:

(WebCore::setIsolatedWorldField):
(WebCore::V8DOMWindowShell::enteredIsolatedWorldContext):
(WebCore::V8DOMWindowShell::destroyIsolatedShell):
(WebCore):
(WebCore::isolatedContextWeakCallback):
(WebCore::V8DOMWindowShell::disposeContext):
(WebCore::V8DOMWindowShell::initializeIfNeeded):
(WebCore::V8DOMWindowShell::setIsolatedWorldSecurityOrigin):

  • bindings/v8/V8DOMWindowShell.h:

(V8DOMWindowShell):
(WebCore::V8DOMWindowShell::getEntered):

  • bindings/v8/V8DOMWrapper.h:

(WebCore::V8DOMWrapper::getCachedWrapper):

  • bindings/v8/WorldContextHandle.cpp:

(WebCore::WorldContextHandle::WorldContextHandle):

  • 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:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r129983 r129984  
     12012-09-29  Sheriff Bot  <webkit.review.bot@gmail.com>
     2
     3        Unreviewed, rolling out r129965.
     4        http://trac.webkit.org/changeset/129965
     5        https://bugs.webkit.org/show_bug.cgi?id=97970
     6
     7        Causes ASSERTs in workers (Requested by abarth on #webkit).
     8
     9        * bindings/v8/DOMData.cpp:
     10        (WebCore::DOMData::getCurrentStore):
     11        * bindings/v8/ScopedPersistent.h:
     12        * bindings/v8/ScriptController.cpp:
     13        (WebCore::ScriptController::resetIsolatedWorlds):
     14        (WebCore::ScriptController::evaluateInIsolatedWorld):
     15        (WebCore::ScriptController::currentWorldContext):
     16        * bindings/v8/V8Binding.cpp:
     17        (WebCore::perContextDataForCurrentWorld):
     18        * bindings/v8/V8DOMWindowShell.cpp:
     19        (WebCore::setIsolatedWorldField):
     20        (WebCore::V8DOMWindowShell::enteredIsolatedWorldContext):
     21        (WebCore::V8DOMWindowShell::destroyIsolatedShell):
     22        (WebCore):
     23        (WebCore::isolatedContextWeakCallback):
     24        (WebCore::V8DOMWindowShell::disposeContext):
     25        (WebCore::V8DOMWindowShell::initializeIfNeeded):
     26        (WebCore::V8DOMWindowShell::setIsolatedWorldSecurityOrigin):
     27        * bindings/v8/V8DOMWindowShell.h:
     28        (V8DOMWindowShell):
     29        (WebCore::V8DOMWindowShell::getEntered):
     30        * bindings/v8/V8DOMWrapper.h:
     31        (WebCore::V8DOMWrapper::getCachedWrapper):
     32        * bindings/v8/WorldContextHandle.cpp:
     33        (WebCore::WorldContextHandle::WorldContextHandle):
     34        * bindings/v8/custom/V8DocumentCustom.cpp:
     35        (WebCore::toV8):
     36        * bindings/v8/custom/V8HTMLDocumentCustom.cpp:
     37        (WebCore::toV8):
     38        * bindings/v8/custom/V8SVGDocumentCustom.cpp:
     39        (WebCore::toV8):
     40        * bindings/v8/custom/V8XMLHttpRequestConstructor.cpp:
     41        (WebCore::V8XMLHttpRequest::constructorCallback):
     42
    1432012-09-29  Emil A Eklund  <eae@chromium.org>
    244
  • trunk/Source/WebCore/bindings/v8/DOMData.cpp

    r129965 r129984  
    4444    if (UNLIKELY(data->domDataStore() != 0))
    4545        return *data->domDataStore();
    46     V8DOMWindowShell::IsolatedContextData* isolatedData = V8DOMWindowShell::enteredIsolatedContextData();
    47     if (UNLIKELY(!!isolatedData))
    48         return *isolatedData->world()->domDataStore();
     46    V8DOMWindowShell* context = V8DOMWindowShell::getEntered();
     47    if (UNLIKELY(context != 0))
     48        return *context->world()->domDataStore();
    4949    return defaultStore;
    5050}
  • trunk/Source/WebCore/bindings/v8/ScopedPersistent.h

    r129965 r129984  
    7979    }
    8080
    81     v8::Persistent<T> leakHandle()
    82     {
    83         v8::Persistent<T> handle = m_handle;
    84         m_handle.Clear();
    85         return handle;
    86     }
    87 
    8881private:
    8982    v8::Persistent<T> m_handle;
  • trunk/Source/WebCore/bindings/v8/ScriptController.cpp

    r129965 r129984  
    147147    for (IsolatedWorldMap::iterator iter = m_isolatedWorlds.begin();
    148148         iter != m_isolatedWorlds.end(); ++iter) {
    149         iter->second->clearIsolatedShell();
    150         delete iter->second;
     149        iter->second->destroyIsolatedShell();
    151150    }
    152151    m_isolatedWorlds.clear();
     
    392391        }
    393392
    394         // Destroy temporary world.
     393        // Mark temporary shell for weak destruction.
    395394        if (worldID == DOMWrapperWorld::uninitializedWorldId) {
    396395            int actualWorldId = isolatedWorldShell->world()->worldId();
    397396            m_isolatedWorlds.remove(actualWorldId);
    398             isolatedWorldShell->clearIsolatedShell();
    399             delete isolatedWorldShell;
     397            isolatedWorldShell->destroyIsolatedShell();
    400398        }
    401399
     
    432430v8::Local<v8::Context> ScriptController::currentWorldContext()
    433431{
    434     V8DOMWindowShell::IsolatedContextData* isolatedContextData = V8DOMWindowShell::enteredIsolatedContextData();
    435     if (UNLIKELY(!!isolatedContextData)) {
    436         V8DOMWindowShell* isolatedShell = existingWindowShellInternal(isolatedContextData->world());
    437         // A temporary isolated world has been deleted, so use the current context.
    438         if (UNLIKELY(!isolatedShell)) {
    439             v8::Handle<v8::Context> context = v8::Context::GetEntered();
    440             if (m_frame != toFrameIfNotDetached(context))
    441                 return v8::Local<v8::Context>();
    442             return v8::Local<v8::Context>::New(context);
    443         }
    444         // The shell exists, but potentially it has a new context, so use it.
    445         if (isolatedShell->context().IsEmpty() || m_frame != toFrameIfNotDetached(isolatedShell->context()))
     432    if (V8DOMWindowShell* isolatedShell = V8DOMWindowShell::getEntered()) {
     433        v8::Persistent<v8::Context> context = isolatedShell->context();
     434        if (context.IsEmpty() || m_frame != toFrameIfNotDetached(context))
    446435            return v8::Local<v8::Context>();
    447         return v8::Local<v8::Context>::New(isolatedShell->context());
     436        return v8::Local<v8::Context>::New(context);
    448437    }
    449438    windowShell()->initializeIfNeeded();
  • trunk/Source/WebCore/bindings/v8/V8Binding.cpp

    r129965 r129984  
    312312V8PerContextData* perContextDataForCurrentWorld(Frame* frame)
    313313{
    314     V8DOMWindowShell::IsolatedContextData* isolatedShellData = 0;
    315     if (UNLIKELY(!!(isolatedShellData = V8DOMWindowShell::enteredIsolatedContextData())))
    316         return isolatedShellData->perContextData();
     314    V8DOMWindowShell* isolatedShell;
     315    if (UNLIKELY(!!(isolatedShell = V8DOMWindowShell::getEntered())))
     316        return isolatedShell->perContextData();
    317317    return frame->script()->windowShell()->perContextData();
    318318}
  • trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.cpp

    r129965 r129984  
    171171}
    172172
    173 static void setIsolatedWorldField(V8DOMWindowShell::IsolatedContextData* data, v8::Handle<v8::Context> context)
    174 {
    175     toInnerGlobalObject(context)->SetPointerInInternalField(V8DOMWindow::enteredIsolatedWorldIndex, data);
    176 }
    177 
    178 V8DOMWindowShell::IsolatedContextData* V8DOMWindowShell::toIsolatedContextData(v8::Handle<v8::Object> innerGlobal)
    179 {
    180     ASSERT(innerGlobal->InternalFieldCount() >= V8DOMWindow::enteredIsolatedWorldIndex);
    181     return static_cast<IsolatedContextData*>(innerGlobal->GetPointerFromInternalField(V8DOMWindow::enteredIsolatedWorldIndex));
     173static void setIsolatedWorldField(V8DOMWindowShell* shell, v8::Local<v8::Context> context)
     174{
     175    toInnerGlobalObject(context)->SetPointerInInternalField(V8DOMWindow::enteredIsolatedWorldIndex, shell);
     176}
     177
     178V8DOMWindowShell* V8DOMWindowShell::enteredIsolatedWorldContext()
     179{
     180    return static_cast<V8DOMWindowShell*>(toInnerGlobalObject(v8::Context::GetEntered())->GetPointerFromInternalField(V8DOMWindow::enteredIsolatedWorldIndex));
    182181}
    183182
     
    209208}
    210209
     210void V8DOMWindowShell::destroyIsolatedShell()
     211{
     212    disposeContext(true);
     213}
     214
    211215static void isolatedContextWeakCallback(v8::Persistent<v8::Value> object, void* parameter)
    212216{
    213     object.Dispose();
    214     delete static_cast<V8DOMWindowShell::IsolatedContextData*>(parameter);
    215 }
    216 
    217 void V8DOMWindowShell::disposeContext()
    218 {
     217    // Handle will be disposed in delete.
     218    delete static_cast<V8DOMWindowShell*>(parameter);
     219}
     220
     221void V8DOMWindowShell::disposeContext(bool weak)
     222{
     223    ASSERT(!m_context.get().IsWeak());
    219224    m_perContextData.clear();
    220225
     
    224229    m_frame->loader()->client()->willReleaseScriptContext(m_context.get(), m_world->worldId());
    225230
    226     if (m_isolatedContextData) {
     231    if (!weak)
     232        m_context.clear();
     233    else {
    227234        ASSERT(!m_world->isMainWorld());
    228         // Here we must intentionally leak the per context data pointer as it gets deleted in isolatedContextWeakCallback.
    229         m_context.leakHandle().MakeWeak(m_isolatedContextData.leakPtr(), isolatedContextWeakCallback);
    230         // The global handle keeps a reference to the context, so it must be removed.
    231         m_global.clear();
    232     } else
    233         m_context.clear();
     235        destroyGlobal();
     236        m_frame = 0;
     237        m_context.get().MakeWeak(this, isolatedContextWeakCallback);
     238    }
    234239
    235240    // It's likely that disposing the context has created a lot of
     
    245250{
    246251    m_global.clear();
    247 }
    248 
    249 void V8DOMWindowShell::clearIsolatedShell()
    250 {
    251     disposeContext();
    252252}
    253253
     
    346346    }
    347347
    348     m_perContextData = V8PerContextData::create(m_context.get());
    349     if (!m_perContextData->init()) {
    350         disposeContext();
    351         return false;
    352     }
    353 
    354348    // Flag context as isolated.
    355349    if (!isMainWorld) {
     
    358352        if (!mainWindow->context().IsEmpty())
    359353            setInjectedScriptContextDebugId(m_context.get(), m_frame->script()->contextDebugId(mainWindow->context()));
    360         m_isolatedContextData = IsolatedContextData::create(m_world, m_perContextData.release(), m_isolatedWorldShellSecurityOrigin);
    361         setIsolatedWorldField(m_isolatedContextData.get(), context);
     354        setIsolatedWorldField(this, context);
     355    }
     356
     357    m_perContextData = V8PerContextData::create(m_context.get());
     358    if (!m_perContextData->init()) {
     359        disposeContext();
     360        return false;
    362361    }
    363362
     
    619618    }
    620619    m_isolatedWorldShellSecurityOrigin = securityOrigin;
    621     if (m_isolatedContextData)
    622         m_isolatedContextData->setSecurityOrigin(m_isolatedWorldShellSecurityOrigin);
    623620}
    624621
  • trunk/Source/WebCore/bindings/v8/V8DOMWindowShell.h

    r129965 r129984  
    5454class V8DOMWindowShell {
    5555public:
    56 
    57     // This class holds all the data that is accessible from a context for an isolated shell.
    58     // It survives until the context is deleted.
    59     class IsolatedContextData {
    60         WTF_MAKE_NONCOPYABLE(IsolatedContextData);
    61     public:
    62         static PassOwnPtr<IsolatedContextData> create(PassRefPtr<DOMWrapperWorld> world, PassOwnPtr<V8PerContextData> perContextData, PassRefPtr<SecurityOrigin> securityOrigin)
    63         {
    64             return adoptPtr(new IsolatedContextData(world, perContextData, securityOrigin));
    65         }
    66         DOMWrapperWorld* world() { return m_world.get(); }
    67         V8PerContextData* perContextData() { return m_perContextData.get(); }
    68         void setSecurityOrigin(PassRefPtr<SecurityOrigin> origin) { m_securityOrigin = origin; }
    69         SecurityOrigin* securityOrigin() { return m_securityOrigin.get(); }
    70 
    71     private:
    72         IsolatedContextData(PassRefPtr<DOMWrapperWorld> world, PassOwnPtr<V8PerContextData> perContextData, PassRefPtr<SecurityOrigin> securityOrigin)
    73             : m_world(world)
    74             , m_perContextData(perContextData)
    75             , m_securityOrigin(securityOrigin)
    76         {
    77         }
    78 
    79         RefPtr<DOMWrapperWorld> m_world;
    80         OwnPtr<V8PerContextData> m_perContextData;
    81         RefPtr<SecurityOrigin> m_securityOrigin;
    82     };
    83 
    8456    static PassOwnPtr<V8DOMWindowShell> create(Frame*, PassRefPtr<DOMWrapperWorld>);
    8557
     
    10577    void clearForNavigation();
    10678    void clearForClose();
    107     void clearIsolatedShell();
    10879
    10980    void destroyGlobal();
     
    12091    };
    12192
    122     inline static IsolatedContextData* enteredIsolatedContextData()
     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()
    123103    {
    124         if (LIKELY(!DOMWrapperWorld::isolatedWorldsExist()))
     104        if (!DOMWrapperWorld::isolatedWorldsExist())
    125105            return 0;
    126106        if (!v8::Context::InContext())
    127107            return 0;
    128         v8::Handle<v8::Object> innerGlobal = v8::Handle<v8::Object>::Cast(v8::Context::GetEntered()->Global()->GetPrototype());
    129         IsolatedContextData* isolatedContextData = toIsolatedContextData(innerGlobal);
    130         if (LIKELY(!isolatedContextData))
    131             return 0;
    132         return isolatedContextData;
     108        return enteredIsolatedWorldContext();
    133109    }
    134110
    135     static IsolatedContextData* toIsolatedContextData(v8::Handle<v8::Object> innerGlobal);
    136 
     111    void destroyIsolatedShell();
    137112private:
    138113    V8DOMWindowShell(Frame*, PassRefPtr<DOMWrapperWorld>);
    139114
    140     void disposeContext();
     115    void disposeContext(bool weak = false);
    141116
    142117    void setSecurityToken();
     
    152127    bool installDOMWindow();
    153128
     129    static V8DOMWindowShell* enteredIsolatedWorldContext();
     130
    154131    Frame* m_frame;
    155132    RefPtr<DOMWrapperWorld> m_world;
    156133
    157134    OwnPtr<V8PerContextData> m_perContextData;
    158     OwnPtr<IsolatedContextData> m_isolatedContextData;
    159135
    160136    ScopedPersistent<v8::Context> m_context;
  • trunk/Source/WebCore/bindings/v8/V8DOMWrapper.h

    r129965 r129984  
    119119            }
    120120
    121             V8DOMWindowShell::IsolatedContextData* isolatedData = V8DOMWindowShell::enteredIsolatedContextData();
    122             if (LIKELY(!isolatedData)) {
     121            V8DOMWindowShell* context = V8DOMWindowShell::getEntered();
     122            if (LIKELY(!context)) {
    123123                v8::Persistent<v8::Object>* wrapper = node->wrapper();
    124124                if (!wrapper)
     
    126126                return *wrapper;
    127127            }
    128             DOMDataStore* store = isolatedData->world()->domDataStore();
     128            DOMDataStore* store = context->world()->domDataStore();
    129129            DOMNodeMapping& domNodeMap = node->isActiveNode() ? store->activeDomNodeMap() : store->domNodeMap();
    130130            return domNodeMap.get(node);
  • trunk/Source/WebCore/bindings/v8/WorldContextHandle.cpp

    r129965 r129984  
    4545        return;
    4646
    47     if (!v8::Context::InContext()) {
     47#if ENABLE(WORKERS)
     48    // FIXME We are duplicating a lot of effort here checking the context for the worker and for the isolated world.
     49    if (v8::Context::InContext()) {
     50        v8::Handle<v8::Context> context = v8::Context::GetCurrent();
     51        if (!context.IsEmpty()) {
     52            if (UNLIKELY(!V8DOMWrapper::isWrapperOfType(toInnerGlobalObject(context), &V8DOMWindow::info))) {
     53                m_worldToUse = UseWorkerWorld;
     54                return;
     55            }
     56        }
     57    }
     58#endif
     59
     60    V8DOMWindowShell* shell = V8DOMWindowShell::getEntered();
     61    if (LIKELY(!shell)) {
    4862        m_worldToUse = UseMainWorld;
    4963        return;
    5064    }
    5165
    52     v8::Handle<v8::Context> context = v8::Context::GetCurrent();
    53     ASSERT(!context.IsEmpty());
    54     v8::Handle<v8::Object> innerGlobal = toInnerGlobalObject(context);
    55 #if ENABLE(WORKERS)
    56     if (UNLIKELY(!V8DOMWrapper::isWrapperOfType(innerGlobal, &V8DOMWindow::info))) {
    57         m_worldToUse = UseWorkerWorld;
    58         return;
    59     }
    60 #endif
    61 
    62     V8DOMWindowShell::IsolatedContextData* data = V8DOMWindowShell::toIsolatedContextData(innerGlobal);
    63     if (LIKELY(!data)) {
    64         m_worldToUse = UseMainWorld;
    65         return;
    66     }
    67 
    68     m_context = SharedPersistent<v8::Context>::create(context);
     66    ASSERT(!shell->context().IsEmpty());
     67    m_context = SharedPersistent<v8::Context>::create(shell->context());
    6968}
    7069
  • trunk/Source/WebCore/bindings/v8/custom/V8DocumentCustom.cpp

    r129971 r129984  
    109109    if (wrapper.IsEmpty())
    110110        return wrapper;
    111     if (!V8DOMWindowShell::enteredIsolatedContextData()) {
     111    if (!V8DOMWindowShell::getEntered()) {
    112112        if (Frame* frame = impl->frame())
    113113            frame->script()->windowShell()->updateDocumentWrapper(wrapper);
  • trunk/Source/WebCore/bindings/v8/custom/V8HTMLDocumentCustom.cpp

    r129971 r129984  
    184184    if (wrapper.IsEmpty())
    185185        return wrapper;
    186     if (!V8DOMWindowShell::enteredIsolatedContextData()) {
     186    if (!V8DOMWindowShell::getEntered()) {
    187187        if (Frame* frame = impl->frame())
    188188            frame->script()->windowShell()->updateDocumentWrapper(wrapper);
  • trunk/Source/WebCore/bindings/v8/custom/V8SVGDocumentCustom.cpp

    r129971 r129984  
    4646    if (wrapper.IsEmpty())
    4747        return wrapper;
    48     if (!V8DOMWindowShell::enteredIsolatedContextData()) {
     48    if (!V8DOMWindowShell::getEntered()) {
    4949        if (Frame* frame = impl->frame())
    5050            frame->script()->windowShell()->updateDocumentWrapper(wrapper);
  • trunk/Source/WebCore/bindings/v8/custom/V8XMLHttpRequestConstructor.cpp

    r129965 r129984  
    5656
    5757    RefPtr<SecurityOrigin> securityOrigin;
    58     if (V8DOMWindowShell::IsolatedContextData* isolatedContextData = V8DOMWindowShell::enteredIsolatedContextData())
    59         securityOrigin = isolatedContextData->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.