-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
window.stop() should fire abort events on XMLHttpRequest asynchronously #14406
Conversation
EWS run on previous version of this PR (hash 8801765) |
8801765
to
646a595
Compare
EWS run on previous version of this PR (hash 646a595) |
646a595
to
304b06f
Compare
EWS run on previous version of this PR (hash 304b06f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me.
Please land the WPT PR first though.
@@ -1149,6 +1149,7 @@ void LocalDOMWindow::stop() | |||
if (!frame) | |||
return; | |||
|
|||
SetForScope isStopped { m_isStopping, true }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isStopping?
Also, shouldn't we need to write it as m_isStopping, true, false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isStopping
indeed, will fix.
With regards to your other comment, I don't think so. My version is a little safer in case of re-entrancy because it will restore whatever value m_isStopping
had before (which is likely false but not necessarily in case we re-enter this function).
@@ -682,7 +681,7 @@ void XMLHttpRequest::abort() | |||
{ | |||
Ref<XMLHttpRequest> protectedThis(*this); | |||
|
|||
m_wasAbortedByClient = true; | |||
m_wasAbortedByClient = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The web page is calling abort() so it seems m_wasAbortedByClient
should be true.
If we change the meaning of m_wasAbortedByClient
, we should change its name.
In this case, maybe we can remove it altogether.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, not sure what happened here. I'll restore.
if (auto* window = document->domWindow()) | ||
m_wasAbortedByClient |= window->isStopping(); | ||
} | ||
|
||
// The XHR specification says we should only fire an abort event if the cancelation was requested by the client. | ||
if (m_wasAbortedByClient && error.isCancellation()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this patch, m_wasAbortedByClient is always false, except in this method, and it is the only place we check it. Can we use a local variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While itβs non-obvious, I studied the code and verified that @youennf is right about this. No other code is looking at m_wasAbortedByClient
, and it will always be false entering this function, so we donβt need m_wasAbortedByClient
any more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is set to true in abort().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But abort
then unconditionally calls immediateAbort
. That sets m_error
unconditionally. So we will return early in that case and after the early return we are guaranteed that m_wasAbortedByClient
is false. So I am sure we can get the same behavior without a data member.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see. Thanks for clarifying. I'll look into it now.
@@ -889,18 +889,28 @@ String XMLHttpRequest::statusText() const | |||
return m_response.httpStatusText(); | |||
} | |||
|
|||
void XMLHttpRequest::didFail(const ResourceError& error) | |||
void XMLHttpRequest::handleCancellation(const ResourceError&) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why having a const ResourceError&
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will drop.
Upstream PR: web-platform-tests/wpt#40325 |
304b06f
to
04acea0
Compare
EWS run on previous version of this PR (hash 04acea0) |
if (auto* window = document->domWindow()) | ||
m_wasAbortedByClient |= window->isStopping(); | ||
} | ||
|
||
// The XHR specification says we should only fire an abort event if the cancelation was requested by the client. | ||
if (m_wasAbortedByClient && error.isCancellation()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While itβs non-obvious, I studied the code and verified that @youennf is right about this. No other code is looking at m_wasAbortedByClient
, and it will always be false entering this function, so we donβt need m_wasAbortedByClient
any more.
@@ -17,7 +17,7 @@ | |||
{ | |||
var xhr = new XMLHttpRequest(); | |||
|
|||
xhr.open("POST", "http://nonexistent.{{host}}:{{ports[http][0]}}", false); | |||
xhr.open("POST", "http://{{host}}:3", false); // Bad port. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 is not a bad port as far as I can tell from https://fetch.spec.whatwg.org/#bad-port.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed!
04acea0
to
3d0dcaa
Compare
EWS run on previous version of this PR (hash 3d0dcaa) |
3d0dcaa
to
c67bf03
Compare
EWS run on current version of this PR (hash c67bf03) |
c67bf03
to
0c53c73
Compare
https://bugs.webkit.org/show_bug.cgi?id=257397 Reviewed by Darin Adler and Youenn Fablet. window.stop() should fire an abort event on XMLHttpRequest asynchronously, to match the behavior of Blink and Gecko. It should schedule a asynchronous task, which should get cancelled if the JavaScript calls `open()` on the XMLHttpRequest again. This is covered by WPT tests. * LayoutTests/imported/w3c/web-platform-tests/xhr/abort-after-stop.window-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/xhr/open-after-stop.window-expected.txt: Rebaseline tests now that more checks are passing. * LayoutTests/imported/w3c/web-platform-tests/xhr/send-authentication-basic-cors-not-enabled-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/xhr/send-authentication-basic-cors-not-enabled.htm: * LayoutTests/imported/w3c/web-platform-tests/xhr/send-authentication-cors-basic-setrequestheader-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/xhr/send-authentication-cors-basic-setrequestheader.htm: * LayoutTests/imported/w3c/web-platform-tests/xhr/send-authentication-cors-setrequestheader-no-cred-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/xhr/send-authentication-cors-setrequestheader-no-cred.htm: * LayoutTests/imported/w3c/web-platform-tests/xhr/send-network-error-sync-events.sub-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/xhr/send-network-error-sync-events.sub.htm: Fix tests to use get_host_info() instead of hardcoding custom domains which don't work with the WebKit layout tests infrastructure. This improves test coverage. I'll upstream those changes. * Source/WebCore/xml/XMLHttpRequest.cpp: (WebCore::XMLHttpRequest::XMLHttpRequest): (WebCore::XMLHttpRequest::open): (WebCore::XMLHttpRequest::abort): (WebCore::XMLHttpRequest::internalAbort): (WebCore::XMLHttpRequest::abortError): (WebCore::XMLHttpRequest::handleCancellation): (WebCore::XMLHttpRequest::didFail): * Source/WebCore/xml/XMLHttpRequest.h: Align our behavior with Blink and Gecko. Canonical link: https://commits.webkit.org/264765@main
0c53c73
to
02e1d3e
Compare
Committed 264765@main (02e1d3e): https://commits.webkit.org/264765@main Reviewed commits have been landed. Closing PR #14406 and removing active labels. |
02e1d3e
c67bf03
π§ͺ api-macπ§ͺ mac-wk1π§ͺ mac-wk2π§ͺ mac-AS-debug-wk2