Bug 184108 - Align XMLHttpRequest's open() / send() / abort() with the latest specification
Summary: Align XMLHttpRequest's open() / send() / abort() with the latest specification
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL: https://xhr.spec.whatwg.org/
Keywords: InRadar
Depends on:
Blocks: 184059
  Show dependency treegraph
 
Reported: 2018-03-28 12:45 PDT by Chris Dumez
Modified: 2018-03-28 21:17 PDT (History)
3 users (show)

See Also:


Attachments
WIP Patch (15.23 KB, patch)
2018-03-28 12:47 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (15.08 KB, patch)
2018-03-28 12:48 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (14.83 KB, patch)
2018-03-28 13:01 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (21.66 KB, patch)
2018-03-28 13:39 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
WIP Patch (20.02 KB, patch)
2018-03-28 14:04 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (26.87 KB, patch)
2018-03-28 14:36 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (27.26 KB, patch)
2018-03-28 15:15 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (27.17 KB, patch)
2018-03-28 20:36 PDT, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2018-03-28 12:45:53 PDT
Align XMLHttpRequest's open() / send() / abort() with the latest specification:
- https://xhr.spec.whatwg.org
Comment 1 Chris Dumez 2018-03-28 12:47:22 PDT
Created attachment 336697 [details]
WIP Patch
Comment 2 Chris Dumez 2018-03-28 12:48:19 PDT
Created attachment 336698 [details]
WIP Patch
Comment 3 Chris Dumez 2018-03-28 13:01:08 PDT
Created attachment 336702 [details]
WIP Patch
Comment 4 Chris Dumez 2018-03-28 13:39:46 PDT
Created attachment 336711 [details]
WIP Patch
Comment 5 Chris Dumez 2018-03-28 14:04:02 PDT
Created attachment 336717 [details]
WIP Patch
Comment 6 Chris Dumez 2018-03-28 14:36:35 PDT
Created attachment 336721 [details]
Patch
Comment 7 Chris Dumez 2018-03-28 15:15:58 PDT
Created attachment 336725 [details]
Patch
Comment 8 youenn fablet 2018-03-28 18:50:44 PDT
Comment on attachment 336725 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=336725&action=review

> Source/WebCore/xml/XMLHttpRequest.cpp:338
> +    m_method = normalizeHTTPMethod(method);

We can probably normalize the method after the early returns, at the moment the spec says to set m_method.

> Source/WebCore/xml/XMLHttpRequest.cpp:381
>          changeState(OPENED);

changeState is checking for m_state so we can probably call changeState directly, name is not great though.

> Source/WebCore/xml/XMLHttpRequest.cpp:591
> +    // Also, only async requests support upload progress events.

Do we need this last comment?

> Source/WebCore/xml/XMLHttpRequest.cpp:622
> +            return { };

As per spec, we should check for m_state and m_sendFlag, but I am not clear why we are checking for m_loader?

> Source/WebCore/xml/XMLHttpRequest.cpp:-679
> -    m_state = UNSENT;

Above it is stated "// Clear headers as required by the spec", which is no longer the case.
Maybe we can get rid of this comment or the spec is missing something.
If we add a header, abort and add the same header, would the values be combined?

> LayoutTests/ChangeLog:14
> +        per specification and those tests were also failing in Firefox.

I wonder whether these 3 tests bring actually anything compared to their WPT equivalent.
Comment 9 Chris Dumez 2018-03-28 19:13:07 PDT
Comment on attachment 336725 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=336725&action=review

>> Source/WebCore/xml/XMLHttpRequest.cpp:338
>> +    m_method = normalizeHTTPMethod(method);
> 
> We can probably normalize the method after the early returns, at the moment the spec says to set m_method.

Good idea.

>> Source/WebCore/xml/XMLHttpRequest.cpp:381
>>          changeState(OPENED);
> 
> changeState is checking for m_state so we can probably call changeState directly, name is not great though.

Ok.

>> Source/WebCore/xml/XMLHttpRequest.cpp:591
>> +    // Also, only async requests support upload progress events.
> 
> Do we need this last comment?

I'll drop it.

>> Source/WebCore/xml/XMLHttpRequest.cpp:622
>> +            return { };
> 
> As per spec, we should check for m_state and m_sendFlag, but I am not clear why we are checking for m_loader?

I had to add it or some WPT tests would still fail when:
1. We dispatch the loadstart event (above)
2. In the loadstart event handler, the JS calls both open() and send() again

Because the JS has called open() and send() again, m_state is OPENED and m_sendFlag is true. open() normally cancels any pending load but we have no started the load yet (it happens a few lines below). Adding the m_loader check fixes the issue as we return early when we've re-entered and started a new load.

>> Source/WebCore/xml/XMLHttpRequest.cpp:-679
>> -    m_state = UNSENT;
> 
> Above it is stated "// Clear headers as required by the spec", which is no longer the case.
> Maybe we can get rid of this comment or the spec is missing something.
> If we add a header, abort and add the same header, would the values be combined?

I'll check.
Comment 10 Chris Dumez 2018-03-28 19:56:23 PDT
Comment on attachment 336725 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=336725&action=review

>> LayoutTests/ChangeLog:14
>> +        per specification and those tests were also failing in Firefox.
> 
> I wonder whether these 3 tests bring actually anything compared to their WPT equivalent.

My understanding is that we are not actively trying to avoid duplication between layout tests and WPT?
Comment 11 Chris Dumez 2018-03-28 19:58:38 PDT
Comment on attachment 336725 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=336725&action=review

>>> Source/WebCore/xml/XMLHttpRequest.cpp:622
>>> +            return { };
>> 
>> As per spec, we should check for m_state and m_sendFlag, but I am not clear why we are checking for m_loader?
> 
> I had to add it or some WPT tests would still fail when:
> 1. We dispatch the loadstart event (above)
> 2. In the loadstart event handler, the JS calls both open() and send() again
> 
> Because the JS has called open() and send() again, m_state is OPENED and m_sendFlag is true. open() normally cancels any pending load but we have no started the load yet (it happens a few lines below). Adding the m_loader check fixes the issue as we return early when we've re-entered and started a new load.

This is the test that would fail:
imported/w3c/web-platform-tests/XMLHttpRequest/loadstart-and-state.html

Diff:
-PASS open() during loadstart 
+FAIL open() during loadstart assert_equals: expected "BB-8" but got "R2-D2"

This test is passing in both Firefox and Chrome.
Comment 12 youenn fablet 2018-03-28 20:24:21 PDT
> > I wonder whether these 3 tests bring actually anything compared to their WPT equivalent.
> 
> My understanding is that we are not actively trying to avoid duplication
> between layout tests and WPT?

That makes sense for tests that continue passing.
When a test is obsolete, we should either think of modifying it or removing it if superseded by another test.

I looked at http/tests/xmlhttprequest/onloadend-event-after-abort.html and it is not exactly a copy so they might still be useful.

> >> Source/WebCore/xml/XMLHttpRequest.cpp:622
> >> +            return { };
> > 
> > As per spec, we should check for m_state and m_sendFlag, but I am not clear why we are checking for m_loader?
> 
> I had to add it or some WPT tests would still fail when:
> 1. We dispatch the loadstart event (above)
> 2. In the loadstart event handler, the JS calls both open() and send() again
> 
> Because the JS has called open() and send() again, m_state is OPENED and
> m_sendFlag is true. open() normally cancels any pending load but we have no
> started the load yet (it happens a few lines below). Adding the m_loader
> check fixes the issue as we return early when we've re-entered and started a
> new load.

That makes sense, maybe that is worth a comment.
Comment 13 Chris Dumez 2018-03-28 20:36:14 PDT
Created attachment 336750 [details]
Patch
Comment 14 WebKit Commit Bot 2018-03-28 21:16:31 PDT
Comment on attachment 336750 [details]
Patch

Clearing flags on attachment: 336750

Committed r230066: <https://trac.webkit.org/changeset/230066>
Comment 15 WebKit Commit Bot 2018-03-28 21:16:33 PDT
All reviewed patches have been landed.  Closing bug.
Comment 16 Radar WebKit Bug Importer 2018-03-28 21:17:26 PDT
<rdar://problem/38985134>