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::~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: