Ignore:
Timestamp:
Oct 9, 2020, 11:10:54 AM (5 years ago)
Author:
[email protected]
Message:

Finalizers shouldn't run if events can't fire
https://bugs.webkit.org/show_bug.cgi?id=214508

Reviewed by Ryosuke Niwa.

Source/JavaScriptCore:

This patch makes it so the DeferredWorkTimer won't run scheduled
tasks if those would not have run if they were scheduled in
WebCore. To do this there is now a concept of a
ScriptExecutionOwner. The ScriptExecutionOwner is almost always
the same as the global object of the pending task (referred to as
the ticket). The only exception to this is if the global object
is a JSDOMWindowBase, then the ScriptExecutionOwner is the
Document's JS wrapper. To tell the status of a
ScriptExecutionOwner, the DeferredWorkTimer calls a virtual
function on the global object of the ticket, for JSC-only this
just always returns Running. For WebCore, we ask the
ScriptExecutionContext associated with the ScriptExecutionOwner.

  • API/JSAPIGlobalObject.cpp:
  • API/JSAPIGlobalObject.mm:
  • jsc.cpp:
  • runtime/DeferredWorkTimer.cpp:

(JSC::DeferredWorkTimer::doWork):
(JSC::DeferredWorkTimer::addPendingWork):
(JSC::DeferredWorkTimer::hasDependancyInPendingWork):
(JSC::DeferredWorkTimer::didResumeScriptExecutionOwner):

  • runtime/DeferredWorkTimer.h:
  • runtime/JSFinalizationRegistry.cpp:

(JSC::JSFinalizationRegistry::create):
(JSC::JSFinalizationRegistry::finishCreation):

  • runtime/JSFinalizationRegistry.h:
  • runtime/JSGlobalObject.cpp:
  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::currentScriptExecutionOwner):
(JSC::JSGlobalObject::scriptExecutionStatus):

Source/WebCore:

This patch makes it so the DeferredWorkTimer won't run scheduled
tasks if those would not have run if they were scheduled in
WebCore. To do this there is now a concept of a
ScriptExecutionOwner. The ScriptExecutionOwner is almost always
the same as the global object of the pending task (referred to as
the ticket). The only exception to this is if the global object
is a JSDOMWindowBase, then the ScriptExecutionOwner is the
Document's JS wrapper. To tell the status of a
ScriptExecutionOwner, the DeferredWorkTimer calls a virtual
function on the global object of the ticket, for JSC-only this
just always returns Running. For WebCore, we ask the
ScriptExecutionContext associated with the ScriptExecutionOwner.

  • bindings/js/JSDOMWindowBase.cpp:

(WebCore::JSDOMWindowBase::currentScriptExecutionOwner):
(WebCore::JSDOMWindowBase::scriptExecutionStatus):

  • bindings/js/JSDOMWindowBase.h:
  • bindings/js/JSDOMWrapperCache.h:
  • bindings/js/JSRemoteDOMWindowBase.cpp:
  • bindings/js/JSWorkerGlobalScopeBase.cpp:

(WebCore::JSWorkerGlobalScopeBase::scriptExecutionStatus):

  • bindings/js/JSWorkerGlobalScopeBase.h:
  • bindings/js/JSWorkletGlobalScopeBase.cpp:

(WebCore::JSWorkletGlobalScopeBase::scriptExecutionStatus):

  • bindings/js/JSWorkletGlobalScopeBase.h:
  • dom/ScriptExecutionContext.cpp:

(WebCore::ScriptExecutionContext::contextIdentifier const):
(WebCore::ScriptExecutionContext::removeFromContextsMap):
(WebCore::ScriptExecutionContext::~ScriptExecutionContext):
(WebCore::ScriptExecutionContext::jscScriptExecutionStatus const):
(WebCore::ScriptExecutionContext::resumeActiveDOMObjects):
(WebCore::ScriptExecutionContext::postTaskTo):

  • dom/ScriptExecutionContext.h:

Source/WTF:

Add a DropLockScope to make it easier to drop a lock for a short
piece of code. Also, instead of deleting int Locker constructor
we should just delete the underlying type of the
NoLockingNecessary enum.

  • wtf/Locker.h:

(WTF::Locker::~Locker):
(WTF::Locker::unlockEarly):
(WTF::Locker::Locker):
(WTF::Locker::operator=):
(WTF::Locker::unlock):
(WTF::DropLockForScope::DropLockForScope):
(WTF::DropLockForScope::~DropLockForScope):

LayoutTests:

Add tests that check we don't run any tasks from JSC's event loop while contexts
are suspended/stopped. Also skip the WASM tests on Win because WASM doesn't work
there.

  • fast/frames/detached-frame-wasm-resolve-expected.txt: Added.
  • fast/frames/detached-frame-wasm-resolve.html: Added.
  • fast/history/page-cache-active-finalization-registry-callback-expected.txt: Added.
  • fast/history/page-cache-active-finalization-registry-callback.html: Added.
  • fast/history/page-cache-wasm-promise-resolve-expected.txt: Added.
  • fast/history/page-cache-wasm-promise-resolve.html: Added.
  • platform/win/TestExpectations:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r268247 r268271  
     12020-10-09  Keith Miller  <[email protected]>
     2
     3        Finalizers shouldn't run if events can't fire
     4        https://bugs.webkit.org/show_bug.cgi?id=214508
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        This patch makes it so the DeferredWorkTimer won't run scheduled
     9        tasks if those would not have run if they were scheduled in
     10        WebCore. To do this there is now a concept of a
     11        ScriptExecutionOwner. The ScriptExecutionOwner is almost always
     12        the same as the global object of the pending task (referred to as
     13        the ticket). The only exception to this is if the global object
     14        is a JSDOMWindowBase, then the ScriptExecutionOwner is the
     15        Document's JS wrapper. To tell the status of a
     16        ScriptExecutionOwner, the DeferredWorkTimer calls a virtual
     17        function on the global object of the ticket, for JSC-only this
     18        just always returns Running. For WebCore, we ask the
     19        ScriptExecutionContext associated with the ScriptExecutionOwner.
     20
     21        * API/JSAPIGlobalObject.cpp:
     22        * API/JSAPIGlobalObject.mm:
     23        * jsc.cpp:
     24        * runtime/DeferredWorkTimer.cpp:
     25        (JSC::DeferredWorkTimer::doWork):
     26        (JSC::DeferredWorkTimer::addPendingWork):
     27        (JSC::DeferredWorkTimer::hasDependancyInPendingWork):
     28        (JSC::DeferredWorkTimer::didResumeScriptExecutionOwner):
     29        * runtime/DeferredWorkTimer.h:
     30        * runtime/JSFinalizationRegistry.cpp:
     31        (JSC::JSFinalizationRegistry::create):
     32        (JSC::JSFinalizationRegistry::finishCreation):
     33        * runtime/JSFinalizationRegistry.h:
     34        * runtime/JSGlobalObject.cpp:
     35        * runtime/JSGlobalObject.h:
     36        (JSC::JSGlobalObject::currentScriptExecutionOwner):
     37        (JSC::JSGlobalObject::scriptExecutionStatus):
     38
    1392020-10-08  Yusuke Suzuki  <[email protected]>
    240
Note: See TracChangeset for help on using the changeset viewer.