haikuwebkit/LayoutTests/fast/js-promise-from-detached-if...

16 lines
411 B
HTML
Raw Permalink Normal View History

Promises returned by our DOM API have the caller's global instead of the callee's https://bugs.webkit.org/show_bug.cgi?id=218363 Reviewed by Darin Adler and Ryosuke Niwa. LayoutTests/imported/w3c: * web-platform-tests/fetch/range/sw.https.window.js: Re-import latest version of the test from upstream. Without those upstream changes, there would be a testharness error when running this test. * web-platform-tests/html/cross-origin-embedder-policy/coep-on-response-from-service-worker.https-expected.txt: * web-platform-tests/service-workers/service-worker/controller-with-no-fetch-event-handler.https-expected.txt: * web-platform-tests/service-workers/service-worker/fetch-event-redirect.https-expected.txt: * web-platform-tests/service-workers/service-worker/fetch-request-resources.https-expected.txt: * web-platform-tests/service-workers/service-worker/fetch-response-taint.https-expected.txt: * web-platform-tests/service-workers/service-worker/redirected-response.https-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-audiocontext-interface/promise-methods-after-discard-expected.txt: * web-platform-tests/webaudio/the-audio-api/the-offlineaudiocontext-interface/startrendering-after-discard-expected.txt: Rebaseline WPT tests that are now passing. Source/WebCore: Promises returned by our DOM APIs were using the caller's global instead of the callee's global. This behavior was inconsistent with Chrome and Firefox, and was causing failures in web-platform-tests. Because the global of the promise was wrong, the global of the values passed when settling the promise (e.g. the global of the exception used to reject a promise) was also wrong. This patch fixes this. After fixing the global of DOM promises, some tests started failing because they expect the promises coming from subframes to still get settled *after* their iframe has been removed from the document. Such promises get settled properly in Firefox and Chrome. They also used to settle properly in WebKit because we were incorrectly using the caller's global. The issue was that after an iframe gets detached, Document::stopActiveDOMObjects() would get called, which would stop the EventLoopTaskGroup associated with the document and clear all pending tasks from this group in the event loop. To address this, when a Document::stopActiveDOMObjects(), we now mark the Document's EventLoopTaskGroup as "ready to stop" instead of stopping it. Only once ALL groups in the EventLoop are ready to stop, do we actually stop all those groups. This is important because each document has its own group but all documents of similar origins share the same EventLoop. Tests: fast/js-promise-from-detached-iframe.html http/tests/eventloop/promise-from-cross-origin-detached-iframe.html webaudio/promise-global-object.html * bindings/js/JSDOMPromiseDeferred.h: (WebCore::DeferredPromise::shouldIgnoreRequestToFulfill const): (WebCore::callPromiseFunction): * dom/Document.cpp: (WebCore::Document::stopActiveDOMObjects): (WebCore::Document::eventLoop): * dom/EventLoop.cpp: (WebCore::EventLoop::registerGroup): (WebCore::EventLoop::unregisterGroup): (WebCore::EventLoop::stopAssociatedGroupsIfNecessary): * dom/EventLoop.h: (WebCore::EventLoopTaskGroup::EventLoopTaskGroup): (WebCore::EventLoopTaskGroup::~EventLoopTaskGroup): (WebCore::EventLoopTaskGroup::isReadyToStop const): (WebCore::EventLoopTaskGroup::markAsReadyToStop): (WebCore::EventLoopTaskGroup::stopAndDiscardAllTasks): * workers/WorkerOrWorkletGlobalScope.cpp: (WebCore::WorkerOrWorkletGlobalScope::prepareForDestruction): LayoutTests: * fast/js-promise-from-detached-iframe-expected.txt: Added. * fast/js-promise-from-detached-iframe.html: Added. Add layout test to verify that JS promises from iframes properly get settled after the the iframe gets removed from the doucment. I have verified that this test passes in both Firefox and Chrome. * http/tests/eventloop/promise-from-cross-origin-detached-iframe-expected.txt: Added. * http/tests/eventloop/promise-from-cross-origin-detached-iframe.html: Added. * http/tests/eventloop/resources/promise-from-cross-origin-detached-iframe-subframe.html: Added. Similar test as above but in a cross-origin iframe. Ryosuke recommended adding this test since event loops only shared between documents of similar origins. I have verified that this test passes in both Firefox and Chrome. * platform/mac/editing/input/reveal-caret-of-multiline-input-expected.txt: Rebaseline existing test that has slightly different output. * requestidlecallback/requestidlecallback-document-gc-expected.txt: * requestidlecallback/requestidlecallback-document-gc.html: Tweak test to check that enough documents are gc's at regular intervals, instead of expecting them to be collected in a 0-timer. * webaudio/promise-global-object-expected.txt: Added. * webaudio/promise-global-object.html: Added. Add test to verify that the global object of the promise is correct when the promise comes from calling a DOM API in an subframe. Previously, we would incorrectly use the caller's global instead of the callee's global. I have verified that this test passes in both Firefox and Chrome. Canonical link: https://commits.webkit.org/231086@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269227 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2020-10-31 16:11:57 +00:00
<!doctype html>
<script src="../resources/js-test.js"></script>
<body></body>
<script>
description("Tests that the promise from detached iframes do get resolved.");
jsTestIsAsync = true;
frame = document.createElement('iframe');
document.body.appendChild(frame);
frame.contentWindow.Promise.resolve("test").then(() => {
testPassed("Promise was resolved");
finishJSTest();
});
frame.remove();
</script>