Bug 45994 - XMLHttpRequest: status and statusText throw DOM Exception 11 when the state is UNSENT or OPENED
Summary: XMLHttpRequest: status and statusText throw DOM Exception 11 when the state i...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: XML (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC All
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: BlinkMergeCandidate
: 77854 101776 (view as bug list)
Depends on: 126219
Blocks:
  Show dependency treegraph
 
Reported: 2010-09-17 14:04 PDT by Jian Li
Modified: 2014-03-18 08:28 PDT (History)
16 users (show)

See Also:


Attachments
Merges the fix (20.43 KB, patch)
2013-11-05 20:36 PST, Ryosuke Niwa
ap: review+
ap: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jian Li 2010-09-17 14:04:31 PDT
XMLHttpRequest: getAllResponseHeaders() throws DOM Exception 11 when the state is OPENED.

Per the spec:
    When the getAllResponseHeaders() method is invoked, the user agent must run the following steps:
    If the state is UNSENT or OPENED return the empty string and terminate these steps.

Test: http://tc.labs.opera.com/apis/XMLHttpRequest/getallresponseheaders-cookies.htm
Comment 1 Jian Li 2010-09-17 17:18:55 PDT
Another test for testing that the state is UNSENT:

http://tc.labs.opera.com/apis/XMLHttpRequest/xmlhttprequest-unsent.htm
Comment 2 Jian Li 2010-09-20 13:37:31 PDT
The exception is also thrown when calling status, statusText, and getResponseHeader().

Per the spec:
  The status attribute must return the result of running these steps:
  If the state is UNSENT or OPENED return 0 and terminate these steps.

  The statusText attribute must return the result of running these steps:
  If the state is UNSENT or OPENED return the empty string and terminate these steps.

  When the getResponseHeader(header) is invoked, the user agent must run these steps:
  If the state is UNSENT or OPENED return null and terminate these steps.

Some more failing tests:
  http://tc.labs.opera.com/apis/XMLHttpRequest/getallresponseheaders-status.htm
  http://tc.labs.opera.com/apis/XMLHttpRequest/getresponseheader-cookies-and-more.htm
  http://tc.labs.opera.com/apis/XMLHttpRequest/xmlhttprequest-network-error.htm
Comment 3 Jarred Nicholls 2011-09-21 12:20:46 PDT
Related: bug #54162
Comment 5 Ryosuke Niwa 2013-11-05 20:36:43 PST
Created attachment 216116 [details]
Merges the fix
Comment 6 youenn fablet 2013-12-20 02:48:34 PST
The patch improves conformance with W3C WPT test XMLHttpRequest/status-async.htm.
It has the expected behavior (and matches Firefox behavior) for all HTTP response codes strictly below 600.

For HTTP response codes above 600, 0 is returned as statusCode (for libsoup-based backends). On the contrary, Firefox returns the received HTTP response code.
Aligning with that behavior may require modifications to the http backends.
This should probably be handled as a separate patch.
Comment 7 Alexey Proskuryakov 2013-12-20 11:13:12 PST
Comment on attachment 216116 [details]
Merges the fix

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

> Source/WebCore/ChangeLog:3
> +        XMLHttpRequest: status, statusText, getResponseHeader() and getAllResponseHeaders() throw DOM Exception 11 when the state is UNSENT or OPENED.

I don't understand what this patch does for getResponseHeader() and getAllResponseHeaders().

Please explain in ChangeLog, or rename the bug and update the ChangeLog if these are no longer part of what's being done in this bug.

Also, this change doesn't just change what's done when the state is UNSENT or OPENED - it also changes what's done in error state.
Comment 8 Alexey Proskuryakov 2013-12-20 11:13:59 PST
Please also update bug 54162 accordingly.
Comment 9 Ryosuke Niwa 2013-12-23 23:54:14 PST
(In reply to comment #8)
> Please also update bug 54162 accordingly.

I don't understand what's happening in that bug.
Comment 10 Ryosuke Niwa 2013-12-24 00:02:29 PST
Committed r161051: <http://trac.webkit.org/changeset/161051>
Comment 11 Alexey Proskuryakov 2013-12-24 01:08:51 PST
Comment on attachment 216116 [details]
Merges the fix

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

> LayoutTests/ChangeLog:19
> +        * js/dom/dfg-custom-getter-throw-expected.txt:
> +        * js/dom/script-tests/dfg-custom-getter-throw-inlined.js: Fixed the test.
> +        (foo): Use responseText instead of status so that it throws when responseType is "arraybuffer".
> +        (bar): Set responseType to "arraybuffer" to cause an exception to be thrown.
> +        * js/dom/script-tests/dfg-custom-getter-throw.js: Ditto.

These tests are now crashing on bots,

http://build.webkit.org/results/Apple%20Mavericks%20Debug%20WK1%20(Tests)/r161053%20(1339)/results.html
Comment 12 Ryosuke Niwa 2013-12-24 12:39:34 PST
Reverted r161051 for reason:

Caused two DFG tests to hit assertions due to a separate bug

Committed r161058: <http://trac.webkit.org/changeset/161058>
Comment 13 Ryosuke Niwa 2013-12-24 12:40:18 PST
The patch is still valid. We just need to fix the bug 126219.
Comment 14 Mark Lam 2014-03-06 16:18:17 PST
Testing with a recent build (r165197), I don't see the JSC issues manifest anymore.  There also have been numerous changes and bug fixes in the area of exception handling and stack management since the time this bug was filed.  Those changes appear to have resolved the issue. 

I will re-land the patch and close this bug.
Comment 15 Mark Lam 2014-03-06 16:21:57 PST
The patch has been re-landed in r165229: <http://trac.webkit.org/r165229>.
Comment 16 youenn fablet 2014-03-18 08:25:13 PDT
*** Bug 77854 has been marked as a duplicate of this bug. ***
Comment 17 youenn fablet 2014-03-18 08:28:36 PDT
*** Bug 101776 has been marked as a duplicate of this bug. ***