Skip to content

Commit

Permalink
Reject with AbortSignal's reason when the signal is already aborted
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=258187

Reviewed by Ryosuke Niwa.

Previously, WebKit always reject fetch with AbortError when the signal
is already aborted. However, based on the spec, when the abort reason
is given, we should reject the promise with the given reason.

* LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/general.any-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/general.any.serviceworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/general.any.sharedworker-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/fetch/api/abort/general.any.worker-expected.txt:
* Source/WebCore/Modules/fetch/WindowOrWorkerGlobalScopeFetch.cpp:
(WebCore::doFetch):

Canonical link: https://commits.webkit.org/267033@main
  • Loading branch information
CYBAI authored and annevk committed Aug 18, 2023
1 parent 989de9d commit 718ac9d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

PASS Aborting rejects with AbortError
FAIL Aborting rejects with abort reason promise_rejects_exactly: fetch() should reject with abort reason function "function() { throw e }" threw object "AbortError: Request signal is aborted" but we expected it to throw object "error1: error1"
PASS Aborting rejects with abort reason
PASS Aborting rejects with AbortError - no-cors
PASS TypeError from request constructor takes priority - RequestInit's window is not null
PASS TypeError from request constructor takes priority - Input URL is not valid
Expand All @@ -20,7 +20,7 @@ PASS TypeError from request constructor takes priority - Bad cache init paramete
PASS TypeError from request constructor takes priority - Bad redirect init parameter value
PASS Request objects have a signal property
PASS Signal on request object
FAIL Signal on request object should also have abort reason promise_rejects_exactly: fetch() should reject with abort reason function "function() { throw e }" threw object "AbortError: Request signal is aborted" but we expected it to throw object "error1: error1"
PASS Signal on request object should also have abort reason
PASS Signal on request object created from request object
PASS Signal on request object created from request object, with signal on second request
PASS Signal on request object created from request object, with signal on second request overriding another
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

PASS Aborting rejects with AbortError
FAIL Aborting rejects with abort reason promise_rejects_exactly: fetch() should reject with abort reason function "function() { throw e }" threw object "AbortError: Request signal is aborted" but we expected it to throw object "error1: error1"
PASS Aborting rejects with abort reason
PASS Aborting rejects with AbortError - no-cors
PASS TypeError from request constructor takes priority - RequestInit's window is not null
PASS TypeError from request constructor takes priority - Input URL is not valid
Expand All @@ -20,7 +20,7 @@ PASS TypeError from request constructor takes priority - Bad cache init paramete
PASS TypeError from request constructor takes priority - Bad redirect init parameter value
PASS Request objects have a signal property
PASS Signal on request object
FAIL Signal on request object should also have abort reason promise_rejects_exactly: fetch() should reject with abort reason function "function() { throw e }" threw object "AbortError: Request signal is aborted" but we expected it to throw object "error1: error1"
PASS Signal on request object should also have abort reason
PASS Signal on request object created from request object
PASS Signal on request object created from request object, with signal on second request
PASS Signal on request object created from request object, with signal on second request overriding another
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

PASS Aborting rejects with AbortError
FAIL Aborting rejects with abort reason promise_rejects_exactly: fetch() should reject with abort reason function "function() { throw e }" threw object "AbortError: Request signal is aborted" but we expected it to throw object "error1: error1"
PASS Aborting rejects with abort reason
PASS Aborting rejects with AbortError - no-cors
PASS TypeError from request constructor takes priority - RequestInit's window is not null
PASS TypeError from request constructor takes priority - Input URL is not valid
Expand All @@ -20,7 +20,7 @@ PASS TypeError from request constructor takes priority - Bad cache init paramete
PASS TypeError from request constructor takes priority - Bad redirect init parameter value
PASS Request objects have a signal property
PASS Signal on request object
FAIL Signal on request object should also have abort reason promise_rejects_exactly: fetch() should reject with abort reason function "function() { throw e }" threw object "AbortError: Request signal is aborted" but we expected it to throw object "error1: error1"
PASS Signal on request object should also have abort reason
PASS Signal on request object created from request object
PASS Signal on request object created from request object, with signal on second request
PASS Signal on request object created from request object, with signal on second request overriding another
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

PASS Aborting rejects with AbortError
FAIL Aborting rejects with abort reason promise_rejects_exactly: fetch() should reject with abort reason function "function() { throw e }" threw object "AbortError: Request signal is aborted" but we expected it to throw object "error1: error1"
PASS Aborting rejects with abort reason
PASS Aborting rejects with AbortError - no-cors
PASS TypeError from request constructor takes priority - RequestInit's window is not null
PASS TypeError from request constructor takes priority - Input URL is not valid
Expand All @@ -20,7 +20,7 @@ PASS TypeError from request constructor takes priority - Bad cache init paramete
PASS TypeError from request constructor takes priority - Bad redirect init parameter value
PASS Request objects have a signal property
PASS Signal on request object
FAIL Signal on request object should also have abort reason promise_rejects_exactly: fetch() should reject with abort reason function "function() { throw e }" threw object "AbortError: Request signal is aborted" but we expected it to throw object "error1: error1"
PASS Signal on request object should also have abort reason
PASS Signal on request object created from request object
PASS Signal on request object created from request object, with signal on second request
PASS Signal on request object created from request object, with signal on second request overriding another
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ static void doFetch(ScriptExecutionContext& scope, FetchRequest::Info&& input, F

auto request = requestOrException.releaseReturnValue();
if (request->signal().aborted()) {
promise.reject(Exception { AbortError, "Request signal is aborted"_s });
auto reason = request->signal().reason().getValue();
if (reason.isUndefined())
promise.reject(Exception { AbortError, "Request signal is aborted"_s });
else
promise.rejectType<IDLAny>(reason);

return;
}

Expand Down

0 comments on commit 718ac9d

Please sign in to comment.