Title: [287532] trunk
Revision
287532
Author
[email protected]
Date
2022-01-03 00:17:59 -0800 (Mon, 03 Jan 2022)

Log Message

FetchRequest.clone does not need to be called with the current context
https://bugs.webkit.org/show_bug.cgi?id=234515

Reviewed by Darin Adler.

Source/WebCore:

Make FetchRequest, FetchResponse and FetchBodyOwner take a ScriptExecutionContext* instead of a ScriptExecutionContext&.
This allows cloning FetchRequest and FetchResponse with the context of the original request or response.

Update call site, as well as for AbortSignal.

For FetchResponse, we did a change to throw in case of cloning FetchResponse on a stopped context.
It appeared that Firefox is not doing that, and Chrome is only doing that in some specific cases.
For that reason, it is better to go back to our previous behavior of not throwing.

To ease testing, we add an internals API to check whether a request/response is linked to a closed context.

Covered by updated tests.

* Modules/cache/DOMCache.cpp:
* Modules/fetch/FetchBodyOwner.cpp:
* Modules/fetch/FetchBodyOwner.h:
* Modules/fetch/FetchRequest.cpp:
* Modules/fetch/FetchRequest.h:
* Modules/fetch/FetchRequest.idl:
* Modules/fetch/FetchResponse.cpp:
* Modules/fetch/FetchResponse.h:
* dom/AbortController.cpp:
* dom/AbortSignal.cpp:
* dom/AbortSignal.h:
* testing/Internals.cpp:
* testing/Internals.h:
* testing/Internals.idl:
* testing/ServiceWorkerInternals.cpp:

LayoutTests:

* http/wpt/fetch/clone-realm-expected.txt:
* http/wpt/fetch/clone-realm.html:
* http/wpt/fetch/resources/clone-realm-iframe.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (287531 => 287532)


--- trunk/LayoutTests/ChangeLog	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/LayoutTests/ChangeLog	2022-01-03 08:17:59 UTC (rev 287532)
@@ -1,3 +1,14 @@
+2022-01-03  Youenn Fablet  <[email protected]>
+
+        FetchRequest.clone does not need to be called with the current context
+        https://bugs.webkit.org/show_bug.cgi?id=234515
+
+        Reviewed by Darin Adler.
+
+        * http/wpt/fetch/clone-realm-expected.txt:
+        * http/wpt/fetch/clone-realm.html:
+        * http/wpt/fetch/resources/clone-realm-iframe.html: Added.
+
 2022-01-02  Diego Pino Garcia  <[email protected]>
 
         [GTK] Unreviewed test gardening, update baseline for imported/w3c/web-platform-tests/html/infrastructure/safe-passing-of-structured-data/transfer-errors.window.html

Modified: trunk/LayoutTests/http/wpt/fetch/clone-realm-expected.txt (287531 => 287532)


--- trunk/LayoutTests/http/wpt/fetch/clone-realm-expected.txt	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/LayoutTests/http/wpt/fetch/clone-realm-expected.txt	2022-01-03 08:17:59 UTC (rev 287532)
@@ -1,3 +1,4 @@
 
-PASS Cloning a response fails when its frame is detached
+PASS Cloning a response succeeds even if its body is stream based
+PASS Cloning request/response when its frame is detached
 

Modified: trunk/LayoutTests/http/wpt/fetch/clone-realm.html (287531 => 287532)


--- trunk/LayoutTests/http/wpt/fetch/clone-realm.html	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/LayoutTests/http/wpt/fetch/clone-realm.html	2022-01-03 08:17:59 UTC (rev 287532)
@@ -15,18 +15,36 @@
       document.body.appendChild(frame);
     });
 }
+
 promise_test(async (t) => {
     const frame = await with_iframe('/');
     const response = await frame.contentWindow.fetch('/');
     await response.clone().text();
     frame.remove();
-    try {
-        response.clone();
-        assert_not_reached();
-    } catch (e) {
-        assert_equals(e.name, 'InvalidStateError');
+    response.clone();
+}, "Cloning a response succeeds even if its body is stream based");
+
+promise_test(async (t) => {
+    let frame = await with_iframe('/WebKit/fetch/resources/clone-realm-iframe.html');
+
+    if (window.internals) {
+        assert_false(internals.isFetchObjectContextStopped(testResponse), "response before");
+        assert_false(internals.isFetchObjectContextStopped(testRequest), "request before");
     }
-}, "Cloning a response fails when its frame is detached");
+
+    frame.remove();
+
+    const clonedResponse = testResponse.clone();
+    const clonedRequest = testRequest.clone();
+
+    if (window.internals) {
+        assert_true(internals.isFetchObjectContextStopped(testResponse), "response after");
+        assert_true(internals.isFetchObjectContextStopped(clonedResponse), "clonedResponse");
+        assert_true(internals.isFetchObjectContextStopped(testRequest), "request after");
+        assert_true(internals.isFetchObjectContextStopped(clonedRequest), "clonedRequest");
+    }
+}, "Cloning request/response when its frame is detached");
+
 </script>
     </body>
 </html>

Added: trunk/LayoutTests/http/wpt/fetch/resources/clone-realm-iframe.html (0 => 287532)


--- trunk/LayoutTests/http/wpt/fetch/resources/clone-realm-iframe.html	                        (rev 0)
+++ trunk/LayoutTests/http/wpt/fetch/resources/clone-realm-iframe.html	2022-01-03 08:17:59 UTC (rev 287532)
@@ -0,0 +1,9 @@
+<!doctype html>
+<html>
+    <body>
+<script>
+window.parent.testRequest = new Request('/');
+window.parent.testResponse = new Response('text');
+</script>
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (287531 => 287532)


--- trunk/Source/WebCore/ChangeLog	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/ChangeLog	2022-01-03 08:17:59 UTC (rev 287532)
@@ -1,3 +1,39 @@
+2022-01-03  Youenn Fablet  <[email protected]>
+
+        FetchRequest.clone does not need to be called with the current context
+        https://bugs.webkit.org/show_bug.cgi?id=234515
+
+        Reviewed by Darin Adler.
+
+        Make FetchRequest, FetchResponse and FetchBodyOwner take a ScriptExecutionContext* instead of a ScriptExecutionContext&.
+        This allows cloning FetchRequest and FetchResponse with the context of the original request or response.
+
+        Update call site, as well as for AbortSignal.
+
+        For FetchResponse, we did a change to throw in case of cloning FetchResponse on a stopped context.
+        It appeared that Firefox is not doing that, and Chrome is only doing that in some specific cases.
+        For that reason, it is better to go back to our previous behavior of not throwing.
+
+        To ease testing, we add an internals API to check whether a request/response is linked to a closed context.
+
+        Covered by updated tests.
+
+        * Modules/cache/DOMCache.cpp:
+        * Modules/fetch/FetchBodyOwner.cpp:
+        * Modules/fetch/FetchBodyOwner.h:
+        * Modules/fetch/FetchRequest.cpp:
+        * Modules/fetch/FetchRequest.h:
+        * Modules/fetch/FetchRequest.idl:
+        * Modules/fetch/FetchResponse.cpp:
+        * Modules/fetch/FetchResponse.h:
+        * dom/AbortController.cpp:
+        * dom/AbortSignal.cpp:
+        * dom/AbortSignal.h:
+        * testing/Internals.cpp:
+        * testing/Internals.h:
+        * testing/Internals.idl:
+        * testing/ServiceWorkerInternals.cpp:
+
 2022-01-02  Manuel Rego Casasnovas  <[email protected]>
 
         Access key should work on focusable element.

Modified: trunk/Source/WebCore/Modules/cache/DOMCache.cpp (287531 => 287532)


--- trunk/Source/WebCore/Modules/cache/DOMCache.cpp	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/Modules/cache/DOMCache.cpp	2022-01-03 08:17:59 UTC (rev 287532)
@@ -83,7 +83,7 @@
 {
     auto resourceResponse = record.response;
     resourceResponse.setSource(ResourceResponse::Source::DOMCache);
-    auto response = FetchResponse::create(context, std::nullopt, record.responseHeadersGuard, WTFMove(resourceResponse));
+    auto response = FetchResponse::create(&context, std::nullopt, record.responseHeadersGuard, WTFMove(resourceResponse));
     response->setBodyData(copyResponseBody(record.responseBody), record.responseBodySize);
     return response;
 }

Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp (287531 => 287532)


--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp	2022-01-03 08:17:59 UTC (rev 287532)
@@ -41,8 +41,8 @@
 
 namespace WebCore {
 
-FetchBodyOwner::FetchBodyOwner(ScriptExecutionContext& context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers)
-    : ActiveDOMObject(&context)
+FetchBodyOwner::FetchBodyOwner(ScriptExecutionContext* context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers)
+    : ActiveDOMObject(context)
     , m_body(WTFMove(body))
     , m_headers(WTFMove(headers))
 {

Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h (287531 => 287532)


--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h	2022-01-03 08:17:59 UTC (rev 287532)
@@ -72,7 +72,7 @@
     const String& contentType() const { return m_contentType; }
 
 protected:
-    FetchBodyOwner(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&);
+    FetchBodyOwner(ScriptExecutionContext*, std::optional<FetchBody>&&, Ref<FetchHeaders>&&);
 
     const FetchBody& body() const { return *m_body; }
     FetchBody& body() { return *m_body; }

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp (287531 => 287532)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2022-01-03 08:17:59 UTC (rev 287532)
@@ -274,7 +274,7 @@
 
 ExceptionOr<Ref<FetchRequest>> FetchRequest::create(ScriptExecutionContext& context, Info&& input, Init&& init)
 {
-    auto request = adoptRef(*new FetchRequest(context, std::nullopt, FetchHeaders::create(FetchHeaders::Guard::Request), { }, { }, { }));
+    auto request = adoptRef(*new FetchRequest(&context, std::nullopt, FetchHeaders::create(FetchHeaders::Guard::Request), { }, { }, { }));
     request->suspendIfNeeded();
 
     if (std::holds_alternative<String>(input)) {
@@ -292,7 +292,7 @@
 
 Ref<FetchRequest> FetchRequest::create(ScriptExecutionContext& context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, ResourceRequest&& request, FetchOptions&& options, String&& referrer)
 {
-    auto result = adoptRef(*new FetchRequest(context, WTFMove(body), WTFMove(headers), WTFMove(request), WTFMove(options), WTFMove(referrer)));
+    auto result = adoptRef(*new FetchRequest(&context, WTFMove(body), WTFMove(headers), WTFMove(request), WTFMove(options), WTFMove(referrer)));
     result->suspendIfNeeded();
     return result;
 }
@@ -326,12 +326,12 @@
     return request;
 }
 
-ExceptionOr<Ref<FetchRequest>> FetchRequest::clone(ScriptExecutionContext& context)
+ExceptionOr<Ref<FetchRequest>> FetchRequest::clone()
 {
     if (isDisturbedOrLocked())
         return Exception { TypeError, "Body is disturbed or locked"_s };
 
-    auto clone = adoptRef(*new FetchRequest(context, std::nullopt, FetchHeaders::create(m_headers.get()), ResourceRequest { m_request }, FetchOptions { m_options }, String { m_referrer }));
+    auto clone = adoptRef(*new FetchRequest(scriptExecutionContext(), std::nullopt, FetchHeaders::create(m_headers.get()), ResourceRequest { m_request }, FetchOptions { m_options }, String { m_referrer }));
     clone->suspendIfNeeded();
     clone->cloneBody(*this);
     clone->setNavigationPreloadIdentifier(m_navigationPreloadIdentifier);

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.h (287531 => 287532)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.h	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.h	2022-01-03 08:17:59 UTC (rev 287532)
@@ -73,7 +73,7 @@
 
     const String& integrity() const { return m_options.integrity; }
 
-    ExceptionOr<Ref<FetchRequest>> clone(ScriptExecutionContext&);
+    ExceptionOr<Ref<FetchRequest>> clone();
 
     const FetchOptions& fetchOptions() const { return m_options; }
     const ResourceRequest& internalRequest() const { return m_request; }
@@ -85,7 +85,7 @@
     void setNavigationPreloadIdentifier(FetchIdentifier identifier) { m_navigationPreloadIdentifier = identifier; }
 
 private:
-    FetchRequest(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceRequest&&, FetchOptions&&, String&& referrer);
+    FetchRequest(ScriptExecutionContext*, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceRequest&&, FetchOptions&&, String&& referrer);
 
     ExceptionOr<void> initializeOptions(const Init&);
     ExceptionOr<void> initializeWith(FetchRequest&, Init&&);
@@ -103,7 +103,7 @@
     FetchIdentifier m_navigationPreloadIdentifier;
 };
 
-inline FetchRequest::FetchRequest(ScriptExecutionContext& context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, ResourceRequest&& request, FetchOptions&& options, String&& referrer)
+inline FetchRequest::FetchRequest(ScriptExecutionContext* context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, ResourceRequest&& request, FetchOptions&& options, String&& referrer)
     : FetchBodyOwner(context, WTFMove(body), WTFMove(headers))
     , m_request(WTFMove(request))
     , m_options(WTFMove(options))

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.idl (287531 => 287532)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.idl	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.idl	2022-01-03 08:17:59 UTC (rev 287532)
@@ -32,6 +32,7 @@
 
 [
     ActiveDOMObject,
+    ExportMacro=WEBCORE_EXPORT,
     Exposed=(Window,Worker),
     GenerateIsReachable=Impl,
     InterfaceName=Request,
@@ -57,7 +58,7 @@
     // readonly attribute boolean isHistoryNavigation;
     readonly attribute AbortSignal signal;
 
-    [CallWith=ScriptExecutionContext, NewObject] FetchRequest clone();
+    [NewObject] FetchRequest clone();
 };
 
 FetchRequest includes FetchBody;

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (287531 => 287532)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp	2022-01-03 08:17:59 UTC (rev 287532)
@@ -48,7 +48,7 @@
     return status == 101 || status == 204 || status == 205 || status == 304;
 }
 
-Ref<FetchResponse> FetchResponse::create(ScriptExecutionContext& context, std::optional<FetchBody>&& body, FetchHeaders::Guard guard, ResourceResponse&& response)
+Ref<FetchResponse> FetchResponse::create(ScriptExecutionContext* context, std::optional<FetchBody>&& body, FetchHeaders::Guard guard, ResourceResponse&& response)
 {
     bool isSynthetic = response.type() == ResourceResponse::Type::Default || response.type() == ResourceResponse::Type::Error;
     bool isOpaque = response.tainting() == ResourceResponse::Tainting::Opaque;
@@ -127,7 +127,7 @@
     // FIXME: Implement.
     
     // 12. Return r.
-    auto r = adoptRef(*new FetchResponse(context, WTFMove(extractedBody), WTFMove(headers), { }));
+    auto r = adoptRef(*new FetchResponse(&context, WTFMove(extractedBody), WTFMove(headers), { }));
     r->suspendIfNeeded();
 
     r->m_contentType = contentType;
@@ -143,7 +143,7 @@
 
 Ref<FetchResponse> FetchResponse::error(ScriptExecutionContext& context)
 {
-    auto response = adoptRef(*new FetchResponse(context, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
+    auto response = adoptRef(*new FetchResponse(&context, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
     response->suspendIfNeeded();
     response->m_internalResponse.setType(Type::Error);
     return response;
@@ -159,7 +159,7 @@
         return Exception { TypeError, "Redirection URL contains credentials"_s };
     if (!ResourceResponse::isRedirectionStatusCode(status))
         return Exception { RangeError, makeString("Status code ", status, "is not a redirection status code") };
-    auto redirectResponse = adoptRef(*new FetchResponse(context, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
+    auto redirectResponse = adoptRef(*new FetchResponse(&context, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
     redirectResponse->suspendIfNeeded();
     redirectResponse->m_internalResponse.setHTTPStatusCode(status);
     redirectResponse->m_internalResponse.setHTTPHeaderField(HTTPHeaderName::Location, requestURL.string());
@@ -167,7 +167,7 @@
     return redirectResponse;
 }
 
-FetchResponse::FetchResponse(ScriptExecutionContext& context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
+FetchResponse::FetchResponse(ScriptExecutionContext* context, std::optional<FetchBody>&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
     : FetchBodyOwner(context, WTFMove(body), WTFMove(headers))
     , m_internalResponse(WTFMove(response))
 {
@@ -175,18 +175,14 @@
 
 ExceptionOr<Ref<FetchResponse>> FetchResponse::clone()
 {
-    if (isContextStopped())
-        return Exception { InvalidStateError, "Context is stopped"_s };
-
     if (isDisturbedOrLocked())
         return Exception { TypeError, "Body is disturbed or locked"_s };
 
-    ASSERT(scriptExecutionContext());
-    auto& context = *scriptExecutionContext();
-
     // If loading, let's create a stream so that data is teed on both clones.
     if (isLoading() && !m_readableStreamSource) {
-        auto* globalObject = context.globalObject();
+        auto* context = scriptExecutionContext();
+
+        auto* globalObject = context ? context->globalObject() : nullptr;
         if (!globalObject)
             return Exception { InvalidStateError, "Context is stopped"_s };
 
@@ -199,7 +195,7 @@
     if (m_internalResponse.type() == ResourceResponse::Type::Default)
         m_internalResponse.setHTTPHeaderFields(HTTPHeaderMap { headers().internalHeaders() });
 
-    auto clone = FetchResponse::create(context, std::nullopt, headers().guard(), ResourceResponse { m_internalResponse });
+    auto clone = FetchResponse::create(scriptExecutionContext(), std::nullopt, headers().guard(), ResourceResponse { m_internalResponse });
     clone->cloneBody(*this);
     clone->m_opaqueLoadIdentifier = m_opaqueLoadIdentifier;
     clone->m_bodySizeWithPadding = m_bodySizeWithPadding;
@@ -254,7 +250,7 @@
 
     InspectorInstrumentation::willFetch(context, request.url().string());
 
-    auto response = adoptRef(*new FetchResponse(context, FetchBody { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
+    auto response = adoptRef(*new FetchResponse(&context, FetchBody { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
     response->suspendIfNeeded();
 
     response->body().consumer().setAsLoading();

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.h (287531 => 287532)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.h	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.h	2022-01-03 08:17:59 UTC (rev 287532)
@@ -57,7 +57,7 @@
         std::optional<FetchHeaders::Init> headers;
     };
 
-    WEBCORE_EXPORT static Ref<FetchResponse> create(ScriptExecutionContext&, std::optional<FetchBody>&&, FetchHeaders::Guard, ResourceResponse&&);
+    WEBCORE_EXPORT static Ref<FetchResponse> create(ScriptExecutionContext*, std::optional<FetchBody>&&, FetchHeaders::Guard, ResourceResponse&&);
 
     static ExceptionOr<Ref<FetchResponse>> create(ScriptExecutionContext&, std::optional<FetchBody::Init>&&, Init&&);
     static Ref<FetchResponse> error(ScriptExecutionContext&);
@@ -112,7 +112,7 @@
     bool hasWasmMIMEType() const;
 
 private:
-    FetchResponse(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceResponse&&);
+    FetchResponse(ScriptExecutionContext*, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceResponse&&);
 
     void stop() final;
     const char* activeDOMObjectName() const final;

Modified: trunk/Source/WebCore/dom/AbortController.cpp (287531 => 287532)


--- trunk/Source/WebCore/dom/AbortController.cpp	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/dom/AbortController.cpp	2022-01-03 08:17:59 UTC (rev 287532)
@@ -41,7 +41,7 @@
 }
 
 AbortController::AbortController(ScriptExecutionContext& context)
-    : m_signal(AbortSignal::create(context))
+    : m_signal(AbortSignal::create(&context))
 {
 }
 

Modified: trunk/Source/WebCore/dom/AbortSignal.cpp (287531 => 287532)


--- trunk/Source/WebCore/dom/AbortSignal.cpp	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/dom/AbortSignal.cpp	2022-01-03 08:17:59 UTC (rev 287532)
@@ -39,7 +39,7 @@
 
 WTF_MAKE_ISO_ALLOCATED_IMPL(AbortSignal);
 
-Ref<AbortSignal> AbortSignal::create(ScriptExecutionContext& context)
+Ref<AbortSignal> AbortSignal::create(ScriptExecutionContext* context)
 {
     return adoptRef(*new AbortSignal(context));
 }
@@ -50,11 +50,11 @@
     ASSERT(reason);
     if (reason.isUndefined())
         reason = toJS(&globalObject, &globalObject, DOMException::create(AbortError));
-    return adoptRef(*new AbortSignal(context, Aborted::Yes, reason));
+    return adoptRef(*new AbortSignal(&context, Aborted::Yes, reason));
 }
 
-AbortSignal::AbortSignal(ScriptExecutionContext& context, Aborted aborted, JSC::JSValue reason)
-    : ContextDestructionObserver(&context)
+AbortSignal::AbortSignal(ScriptExecutionContext* context, Aborted aborted, JSC::JSValue reason)
+    : ContextDestructionObserver(context)
     , m_aborted(aborted == Aborted::Yes)
     , m_reason(reason)
 {

Modified: trunk/Source/WebCore/dom/AbortSignal.h (287531 => 287532)


--- trunk/Source/WebCore/dom/AbortSignal.h	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/dom/AbortSignal.h	2022-01-03 08:17:59 UTC (rev 287532)
@@ -42,7 +42,7 @@
 class AbortSignal final : public RefCounted<AbortSignal>, public EventTargetWithInlineData, private ContextDestructionObserver {
     WTF_MAKE_ISO_ALLOCATED_EXPORT(AbortSignal, WEBCORE_EXPORT);
 public:
-    static Ref<AbortSignal> create(ScriptExecutionContext&);
+    static Ref<AbortSignal> create(ScriptExecutionContext*);
 
     static Ref<AbortSignal> abort(JSDOMGlobalObject&, ScriptExecutionContext&, JSC::JSValue reason);
 
@@ -66,7 +66,7 @@
 
 private:
     enum class Aborted : bool { No, Yes };
-    explicit AbortSignal(ScriptExecutionContext&, Aborted = Aborted::No, JSC::JSValue reason = JSC::jsUndefined());
+    explicit AbortSignal(ScriptExecutionContext*, Aborted = Aborted::No, JSC::JSValue reason = JSC::jsUndefined());
 
     // EventTarget.
     EventTargetInterface eventTargetInterface() const final { return AbortSignalEventTargetInterfaceType; }

Modified: trunk/Source/WebCore/testing/Internals.cpp (287531 => 287532)


--- trunk/Source/WebCore/testing/Internals.cpp	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/testing/Internals.cpp	2022-01-03 08:17:59 UTC (rev 287532)
@@ -78,6 +78,7 @@
 #include "EventNames.h"
 #include "ExtendableEvent.h"
 #include "ExtensionStyleSheets.h"
+#include "FetchRequest.h"
 #include "FetchResponse.h"
 #include "File.h"
 #include "FloatQuad.h"
@@ -918,6 +919,15 @@
     frame()->loader().setStrictRawResourceValidationPolicyDisabledForTesting(disabled);
 }
 
+bool Internals::isFetchObjectContextStopped(const FetchObject& object)
+{
+    return switchOn(object, [](const RefPtr<FetchRequest>& request) {
+        return request->isContextStopped();
+    }, [](auto& response) {
+        return response->isContextStopped();
+    });
+}
+
 void Internals::clearMemoryCache()
 {
     MemoryCache::singleton().evictResources();

Modified: trunk/Source/WebCore/testing/Internals.h (287531 => 287532)


--- trunk/Source/WebCore/testing/Internals.h	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/testing/Internals.h	2022-01-03 08:17:59 UTC (rev 287532)
@@ -68,6 +68,7 @@
 class Element;
 class EventListener;
 class ExtendableEvent;
+class FetchRequest;
 class FetchResponse;
 class File;
 class Frame;
@@ -190,6 +191,9 @@
     void setOverrideResourceLoadPriority(ResourceLoadPriority);
     void setStrictRawResourceValidationPolicyDisabled(bool);
 
+    using FetchObject = std::variant<RefPtr<FetchRequest>, RefPtr<FetchResponse>>;
+    bool isFetchObjectContextStopped(const FetchObject&);
+
     void clearMemoryCache();
     void pruneMemoryCacheToSize(unsigned size);
     void destroyDecodedDataForAllImages();

Modified: trunk/Source/WebCore/testing/Internals.idl (287531 => 287532)


--- trunk/Source/WebCore/testing/Internals.idl	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/testing/Internals.idl	2022-01-03 08:17:59 UTC (rev 287532)
@@ -305,6 +305,8 @@
     required DOMPointReadOnly bottomLeft;
 };
 
+typedef (FetchRequest or FetchResponse) FetchObject;
+
 [
     ExportMacro=WEBCORE_TESTSUPPORT_EXPORT,
     LegacyNoInterfaceObject,
@@ -337,6 +339,8 @@
     undefined setOverrideResourceLoadPriority(ResourceLoadPriority priority);
     undefined setStrictRawResourceValidationPolicyDisabled(boolean disabled);
 
+    boolean isFetchObjectContextStopped(FetchObject object);
+
     undefined clearBackForwardCache();
     unsigned long backForwardCacheSize();
     undefined preventDocumentFromEnteringBackForwardCache();

Modified: trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp (287531 => 287532)


--- trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp	2022-01-03 07:39:38 UTC (rev 287531)
+++ trunk/Source/WebCore/testing/ServiceWorkerInternals.cpp	2022-01-03 08:17:59 UTC (rev 287532)
@@ -129,7 +129,7 @@
     ResourceResponse response;
     response.setType(ResourceResponse::Type::Cors);
     response.setTainting(ResourceResponse::Tainting::Opaque);
-    auto fetchResponse = FetchResponse::create(context, FetchBody::fromFormData(context, formData), FetchHeaders::Guard::Response, WTFMove(response));
+    auto fetchResponse = FetchResponse::create(&context, FetchBody::fromFormData(context, formData), FetchHeaders::Guard::Response, WTFMove(response));
     fetchResponse->initializeOpaqueLoadIdentifierForTesting();
     return fetchResponse;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to