Changeset 165229 in webkit


Ignore:
Timestamp:
Mar 6, 2014 4:26:55 PM (10 years ago)
Author:
mark.lam@apple.com
Message:

XMLHttpRequest: status and statusText throw DOM Exception 11 when the state is UNSENT or OPENED.
https://bugs.webkit.org/show_bug.cgi?id=45994

Not reviewed.

Re-landing r161051 (originally by Ryosuke Niwa, reviewed by Alexey Proskuryakov)
since https://bugs.webkit.org/show_bug.cgi?id=126219 is no longer an issue.

Source/WebCore:

  • xml/XMLHttpRequest.cpp:

(WebCore::XMLHttpRequest::status):
(WebCore::XMLHttpRequest::statusText):

  • xml/XMLHttpRequest.h:
  • xml/XMLHttpRequest.idl:

LayoutTests:

  • http/tests/xmlhttprequest/exceptions-expected.txt:
  • http/tests/xmlhttprequest/exceptions.html:
  • http/tests/xmlhttprequest/status-after-abort-expected.txt:
  • http/tests/xmlhttprequest/zero-length-response-expected.txt:
  • js/dom/dfg-custom-getter-throw-expected.txt:
  • js/dom/script-tests/dfg-custom-getter-throw-inlined.js:

(foo):
(bar):

  • js/dom/script-tests/dfg-custom-getter-throw.js:

(foo):
(bar):

Location:
trunk
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r165226 r165229  
     12014-03-06  Mark Lam  <mark.lam@apple.com>
     2
     3        XMLHttpRequest: status and statusText throw DOM Exception 11 when the state is UNSENT or OPENED.
     4        https://bugs.webkit.org/show_bug.cgi?id=45994
     5
     6        Not reviewed.
     7
     8        Re-landing r161051 (originally by Ryosuke Niwa, reviewed by Alexey Proskuryakov)
     9        since https://bugs.webkit.org/show_bug.cgi?id=126219 is no longer an issue.
     10
     11        * http/tests/xmlhttprequest/exceptions-expected.txt:
     12        * http/tests/xmlhttprequest/exceptions.html:
     13        * http/tests/xmlhttprequest/status-after-abort-expected.txt:
     14        * http/tests/xmlhttprequest/zero-length-response-expected.txt:
     15        * js/dom/dfg-custom-getter-throw-expected.txt:
     16        * js/dom/script-tests/dfg-custom-getter-throw-inlined.js:
     17        (foo):
     18        (bar):
     19        * js/dom/script-tests/dfg-custom-getter-throw.js:
     20        (foo):
     21        (bar):
     22
    1232014-03-06  Thiago de Barros Lacerda  <thiago.lacerda@openbossa.org>
    224
  • trunk/LayoutTests/http/tests/xmlhttprequest/exceptions-expected.txt

    r161058 r165229  
    77PASS: req.setRequestHeader() threw exception TypeError: Not enough arguments.
    88PASS: req.setRequestHeader("Foo") threw exception TypeError: Not enough arguments.
    9 PASS: req.status() threw exception Error: InvalidStateError: DOM Exception 11.
    10 PASS: req.statusText() threw exception Error: InvalidStateError: DOM Exception 11.
    119send()
    1210PASS: req.send(null) threw exception Error: InvalidStateError: DOM Exception 11.
  • trunk/LayoutTests/http/tests/xmlhttprequest/exceptions.html

    r161058 r165229  
    6565    shouldThrow('req.setRequestHeader()');
    6666    shouldThrow('req.setRequestHeader("Foo")');
    67     shouldThrow('req.status()');
    68     shouldThrow('req.statusText()');
    6967   
    7068    req.send(null);
  • trunk/LayoutTests/http/tests/xmlhttprequest/status-after-abort-expected.txt

    r161058 r165229  
    33A newly created request. Response status: 0; statusText: ''; readyState: 0
    44Opening...
    5 Onreadystatechange. Response status: [exception]; statusText: '[exception]'; readyState: 1
    6 Opened request. Response status: [exception]; statusText: '[exception]'; readyState: 1
    7 Sent request. Response status: [exception]; statusText: '[exception]'; readyState: 1
     5Onreadystatechange. Response status: 0; statusText: ''; readyState: 1
     6Opened request. Response status: 0; statusText: ''; readyState: 1
     7Sent request. Response status: 0; statusText: ''; readyState: 1
    88Onreadystatechange. Response status: 200; statusText: 'OK'; readyState: 2
    99Onreadystatechange. Response status: 200; statusText: 'OK'; readyState: 3
    1010Onreadystatechange. Response status: 200; statusText: 'OK'; readyState: 4
    1111Aborting the request...
    12 After aborting the request. Response status: 200; statusText: 'OK'; readyState: 0
     12After aborting the request. Response status: 0; statusText: ''; readyState: 0
    1313Reopening the request to check that the status is reset...
    14 Onreadystatechange. Response status: [exception]; statusText: '[exception]'; readyState: 1
     14Onreadystatechange. Response status: 0; statusText: ''; readyState: 1
    1515Done.
    1616
  • trunk/LayoutTests/http/tests/xmlhttprequest/zero-length-response-expected.txt

    r161058 r165229  
    99after setting onreadystatechange: Uninitialized
    1010onreadystatechange: Open
    11   Exception getting status: InvalidStateError: DOM Exception 11
    12   Exception getting StatusText: InvalidStateError: DOM Exception 11
     11  Status: 0
     12  StatusText: ""
    1313  ResponseText: ""
    1414  ResponseXML: null
    1515  ResponseXML serialized: n/a
    1616after open(): Open
    17   Exception getting status: InvalidStateError: DOM Exception 11
    18   Exception getting StatusText: InvalidStateError: DOM Exception 11
     17  Status: 0
     18  StatusText: ""
    1919  ResponseText: ""
    2020  ResponseXML: null
  • trunk/LayoutTests/js/dom/dfg-custom-getter-throw-expected.txt

    r161058 r165229  
    44
    55
    6 PASS bar(i >= 100) is "Returned result: 0"
    7 PASS bar(i >= 100) is "Returned result: 0"
    8 PASS bar(i >= 100) is "Returned result: 0"
    9 PASS bar(i >= 100) is "Returned result: 0"
    10 PASS bar(i >= 100) is "Returned result: 0"
    11 PASS bar(i >= 100) is "Returned result: 0"
    12 PASS bar(i >= 100) is "Returned result: 0"
    13 PASS bar(i >= 100) is "Returned result: 0"
    14 PASS bar(i >= 100) is "Returned result: 0"
    15 PASS bar(i >= 100) is "Returned result: 0"
    16 PASS bar(i >= 100) is "Returned result: 0"
    17 PASS bar(i >= 100) is "Returned result: 0"
    18 PASS bar(i >= 100) is "Returned result: 0"
    19 PASS bar(i >= 100) is "Returned result: 0"
    20 PASS bar(i >= 100) is "Returned result: 0"
    21 PASS bar(i >= 100) is "Returned result: 0"
    22 PASS bar(i >= 100) is "Returned result: 0"
    23 PASS bar(i >= 100) is "Returned result: 0"
    24 PASS bar(i >= 100) is "Returned result: 0"
    25 PASS bar(i >= 100) is "Returned result: 0"
    26 PASS bar(i >= 100) is "Returned result: 0"
    27 PASS bar(i >= 100) is "Returned result: 0"
    28 PASS bar(i >= 100) is "Returned result: 0"
    29 PASS bar(i >= 100) is "Returned result: 0"
    30 PASS bar(i >= 100) is "Returned result: 0"
    31 PASS bar(i >= 100) is "Returned result: 0"
    32 PASS bar(i >= 100) is "Returned result: 0"
    33 PASS bar(i >= 100) is "Returned result: 0"
    34 PASS bar(i >= 100) is "Returned result: 0"
    35 PASS bar(i >= 100) is "Returned result: 0"
    36 PASS bar(i >= 100) is "Returned result: 0"
    37 PASS bar(i >= 100) is "Returned result: 0"
    38 PASS bar(i >= 100) is "Returned result: 0"
    39 PASS bar(i >= 100) is "Returned result: 0"
    40 PASS bar(i >= 100) is "Returned result: 0"
    41 PASS bar(i >= 100) is "Returned result: 0"
    42 PASS bar(i >= 100) is "Returned result: 0"
    43 PASS bar(i >= 100) is "Returned result: 0"
    44 PASS bar(i >= 100) is "Returned result: 0"
    45 PASS bar(i >= 100) is "Returned result: 0"
    46 PASS bar(i >= 100) is "Returned result: 0"
    47 PASS bar(i >= 100) is "Returned result: 0"
    48 PASS bar(i >= 100) is "Returned result: 0"
    49 PASS bar(i >= 100) is "Returned result: 0"
    50 PASS bar(i >= 100) is "Returned result: 0"
    51 PASS bar(i >= 100) is "Returned result: 0"
    52 PASS bar(i >= 100) is "Returned result: 0"
    53 PASS bar(i >= 100) is "Returned result: 0"
    54 PASS bar(i >= 100) is "Returned result: 0"
    55 PASS bar(i >= 100) is "Returned result: 0"
    56 PASS bar(i >= 100) is "Returned result: 0"
    57 PASS bar(i >= 100) is "Returned result: 0"
    58 PASS bar(i >= 100) is "Returned result: 0"
    59 PASS bar(i >= 100) is "Returned result: 0"
    60 PASS bar(i >= 100) is "Returned result: 0"
    61 PASS bar(i >= 100) is "Returned result: 0"
    62 PASS bar(i >= 100) is "Returned result: 0"
    63 PASS bar(i >= 100) is "Returned result: 0"
    64 PASS bar(i >= 100) is "Returned result: 0"
    65 PASS bar(i >= 100) is "Returned result: 0"
    66 PASS bar(i >= 100) is "Returned result: 0"
    67 PASS bar(i >= 100) is "Returned result: 0"
    68 PASS bar(i >= 100) is "Returned result: 0"
    69 PASS bar(i >= 100) is "Returned result: 0"
    70 PASS bar(i >= 100) is "Returned result: 0"
    71 PASS bar(i >= 100) is "Returned result: 0"
    72 PASS bar(i >= 100) is "Returned result: 0"
    73 PASS bar(i >= 100) is "Returned result: 0"
    74 PASS bar(i >= 100) is "Returned result: 0"
    75 PASS bar(i >= 100) is "Returned result: 0"
    76 PASS bar(i >= 100) is "Returned result: 0"
    77 PASS bar(i >= 100) is "Returned result: 0"
    78 PASS bar(i >= 100) is "Returned result: 0"
    79 PASS bar(i >= 100) is "Returned result: 0"
    80 PASS bar(i >= 100) is "Returned result: 0"
    81 PASS bar(i >= 100) is "Returned result: 0"
    82 PASS bar(i >= 100) is "Returned result: 0"
    83 PASS bar(i >= 100) is "Returned result: 0"
    84 PASS bar(i >= 100) is "Returned result: 0"
    85 PASS bar(i >= 100) is "Returned result: 0"
    86 PASS bar(i >= 100) is "Returned result: 0"
    87 PASS bar(i >= 100) is "Returned result: 0"
    88 PASS bar(i >= 100) is "Returned result: 0"
    89 PASS bar(i >= 100) is "Returned result: 0"
    90 PASS bar(i >= 100) is "Returned result: 0"
    91 PASS bar(i >= 100) is "Returned result: 0"
    92 PASS bar(i >= 100) is "Returned result: 0"
    93 PASS bar(i >= 100) is "Returned result: 0"
    94 PASS bar(i >= 100) is "Returned result: 0"
    95 PASS bar(i >= 100) is "Returned result: 0"
    96 PASS bar(i >= 100) is "Returned result: 0"
    97 PASS bar(i >= 100) is "Returned result: 0"
    98 PASS bar(i >= 100) is "Returned result: 0"
    99 PASS bar(i >= 100) is "Returned result: 0"
    100 PASS bar(i >= 100) is "Returned result: 0"
    101 PASS bar(i >= 100) is "Returned result: 0"
    102 PASS bar(i >= 100) is "Returned result: 0"
    103 PASS bar(i >= 100) is "Returned result: 0"
    104 PASS bar(i >= 100) is "Returned result: 0"
    105 PASS bar(i >= 100) is "Returned result: 0"
     6PASS bar(i >= 100) is "Returned result: "
     7PASS bar(i >= 100) is "Returned result: "
     8PASS bar(i >= 100) is "Returned result: "
     9PASS bar(i >= 100) is "Returned result: "
     10PASS bar(i >= 100) is "Returned result: "
     11PASS bar(i >= 100) is "Returned result: "
     12PASS bar(i >= 100) is "Returned result: "
     13PASS bar(i >= 100) is "Returned result: "
     14PASS bar(i >= 100) is "Returned result: "
     15PASS bar(i >= 100) is "Returned result: "
     16PASS bar(i >= 100) is "Returned result: "
     17PASS bar(i >= 100) is "Returned result: "
     18PASS bar(i >= 100) is "Returned result: "
     19PASS bar(i >= 100) is "Returned result: "
     20PASS bar(i >= 100) is "Returned result: "
     21PASS bar(i >= 100) is "Returned result: "
     22PASS bar(i >= 100) is "Returned result: "
     23PASS bar(i >= 100) is "Returned result: "
     24PASS bar(i >= 100) is "Returned result: "
     25PASS bar(i >= 100) is "Returned result: "
     26PASS bar(i >= 100) is "Returned result: "
     27PASS bar(i >= 100) is "Returned result: "
     28PASS bar(i >= 100) is "Returned result: "
     29PASS bar(i >= 100) is "Returned result: "
     30PASS bar(i >= 100) is "Returned result: "
     31PASS bar(i >= 100) is "Returned result: "
     32PASS bar(i >= 100) is "Returned result: "
     33PASS bar(i >= 100) is "Returned result: "
     34PASS bar(i >= 100) is "Returned result: "
     35PASS bar(i >= 100) is "Returned result: "
     36PASS bar(i >= 100) is "Returned result: "
     37PASS bar(i >= 100) is "Returned result: "
     38PASS bar(i >= 100) is "Returned result: "
     39PASS bar(i >= 100) is "Returned result: "
     40PASS bar(i >= 100) is "Returned result: "
     41PASS bar(i >= 100) is "Returned result: "
     42PASS bar(i >= 100) is "Returned result: "
     43PASS bar(i >= 100) is "Returned result: "
     44PASS bar(i >= 100) is "Returned result: "
     45PASS bar(i >= 100) is "Returned result: "
     46PASS bar(i >= 100) is "Returned result: "
     47PASS bar(i >= 100) is "Returned result: "
     48PASS bar(i >= 100) is "Returned result: "
     49PASS bar(i >= 100) is "Returned result: "
     50PASS bar(i >= 100) is "Returned result: "
     51PASS bar(i >= 100) is "Returned result: "
     52PASS bar(i >= 100) is "Returned result: "
     53PASS bar(i >= 100) is "Returned result: "
     54PASS bar(i >= 100) is "Returned result: "
     55PASS bar(i >= 100) is "Returned result: "
     56PASS bar(i >= 100) is "Returned result: "
     57PASS bar(i >= 100) is "Returned result: "
     58PASS bar(i >= 100) is "Returned result: "
     59PASS bar(i >= 100) is "Returned result: "
     60PASS bar(i >= 100) is "Returned result: "
     61PASS bar(i >= 100) is "Returned result: "
     62PASS bar(i >= 100) is "Returned result: "
     63PASS bar(i >= 100) is "Returned result: "
     64PASS bar(i >= 100) is "Returned result: "
     65PASS bar(i >= 100) is "Returned result: "
     66PASS bar(i >= 100) is "Returned result: "
     67PASS bar(i >= 100) is "Returned result: "
     68PASS bar(i >= 100) is "Returned result: "
     69PASS bar(i >= 100) is "Returned result: "
     70PASS bar(i >= 100) is "Returned result: "
     71PASS bar(i >= 100) is "Returned result: "
     72PASS bar(i >= 100) is "Returned result: "
     73PASS bar(i >= 100) is "Returned result: "
     74PASS bar(i >= 100) is "Returned result: "
     75PASS bar(i >= 100) is "Returned result: "
     76PASS bar(i >= 100) is "Returned result: "
     77PASS bar(i >= 100) is "Returned result: "
     78PASS bar(i >= 100) is "Returned result: "
     79PASS bar(i >= 100) is "Returned result: "
     80PASS bar(i >= 100) is "Returned result: "
     81PASS bar(i >= 100) is "Returned result: "
     82PASS bar(i >= 100) is "Returned result: "
     83PASS bar(i >= 100) is "Returned result: "
     84PASS bar(i >= 100) is "Returned result: "
     85PASS bar(i >= 100) is "Returned result: "
     86PASS bar(i >= 100) is "Returned result: "
     87PASS bar(i >= 100) is "Returned result: "
     88PASS bar(i >= 100) is "Returned result: "
     89PASS bar(i >= 100) is "Returned result: "
     90PASS bar(i >= 100) is "Returned result: "
     91PASS bar(i >= 100) is "Returned result: "
     92PASS bar(i >= 100) is "Returned result: "
     93PASS bar(i >= 100) is "Returned result: "
     94PASS bar(i >= 100) is "Returned result: "
     95PASS bar(i >= 100) is "Returned result: "
     96PASS bar(i >= 100) is "Returned result: "
     97PASS bar(i >= 100) is "Returned result: "
     98PASS bar(i >= 100) is "Returned result: "
     99PASS bar(i >= 100) is "Returned result: "
     100PASS bar(i >= 100) is "Returned result: "
     101PASS bar(i >= 100) is "Returned result: "
     102PASS bar(i >= 100) is "Returned result: "
     103PASS bar(i >= 100) is "Returned result: "
     104PASS bar(i >= 100) is "Returned result: "
     105PASS bar(i >= 100) is "Returned result: "
    106106PASS bar(i >= 100) is "Threw exception: Error: InvalidStateError: DOM Exception 11"
    107107PASS bar(i >= 100) is "Threw exception: Error: InvalidStateError: DOM Exception 11"
  • trunk/LayoutTests/js/dom/script-tests/dfg-custom-getter-throw-inlined.js

    r161058 r165229  
    44
    55function foo(x) {
    6     return x.status;
     6    return x.responseText;
    77}
    88
     
    1111}
    1212
    13 function bar(doOpen) {
     13function bar(binary) {
    1414    var x = new XMLHttpRequest();
    15     if (doOpen)
    16         x.open("GET", "http://foo.bar.com/");
     15    x.open("GET", "http://foo.bar.com/");
     16    if (binary)
     17        x.responseType = "arraybuffer";
    1718    try {
    1819        return "Returned result: " + baz(x);
     
    2627
    2728for (var i = 0; i < 200; i = dfgIncrement({f:baz, i:i + 1, n:50})) {
    28     shouldBe("bar(i >= 100)", i >= 100 ? "\"Threw exception: Error: InvalidStateError: DOM Exception 11\"" : "\"Returned result: 0\"");
     29    shouldBe("bar(i >= 100)", i >= 100 ? "\"Threw exception: Error: InvalidStateError: DOM Exception 11\"" : "\"Returned result: \"");
    2930}
    3031
  • trunk/LayoutTests/js/dom/script-tests/dfg-custom-getter-throw.js

    r161058 r165229  
    44
    55function foo(x) {
    6     return x.status;
     6    return x.responseText;
    77}
    88
    9 function bar(doOpen) {
     9function bar(binary) {
    1010    var x = new XMLHttpRequest();
    11     if (doOpen)
    12         x.open("GET", "http://foo.bar.com/");
     11    x.open("GET", "http://foo.bar.com/");
     12    if (binary)
     13        x.responseType = "arraybuffer";
    1314    try {
    1415        return "Returned result: " + foo(x);
     
    1920
    2021for (var i = 0; i < 200; ++i) {
    21     shouldBe("bar(i >= 100)", i >= 100 ? "\"Threw exception: Error: InvalidStateError: DOM Exception 11\"" : "\"Returned result: 0\"");
     22    shouldBe("bar(i >= 100)", i >= 100 ? "\"Threw exception: Error: InvalidStateError: DOM Exception 11\"" : "\"Returned result: \"");
    2223}
    2324
  • trunk/Source/WebCore/ChangeLog

    r165227 r165229  
     12014-03-06  Mark Lam  <mark.lam@apple.com>
     2
     3        XMLHttpRequest: status and statusText throw DOM Exception 11 when the state is UNSENT or OPENED.
     4        https://bugs.webkit.org/show_bug.cgi?id=45994
     5
     6        Not reviewed.
     7
     8        Re-landing r161051 (originally by Ryosuke Niwa, reviewed by Alexey Proskuryakov)
     9        since https://bugs.webkit.org/show_bug.cgi?id=126219 is no longer an issue.
     10
     11        * xml/XMLHttpRequest.cpp:
     12        (WebCore::XMLHttpRequest::status):
     13        (WebCore::XMLHttpRequest::statusText):
     14        * xml/XMLHttpRequest.h:
     15        * xml/XMLHttpRequest.idl:
     16
    1172014-03-06  Brent Fulgham  <bfulgham@apple.com>
    218
  • trunk/Source/WebCore/xml/XMLHttpRequest.cpp

    r163915 r165229  
    10601060}
    10611061
    1062 int XMLHttpRequest::status(ExceptionCode& ec) const
    1063 {
     1062int XMLHttpRequest::status() const
     1063{
     1064    if (m_state == UNSENT || m_state == OPENED || m_error)
     1065        return 0;
     1066
    10641067    if (m_response.httpStatusCode())
    10651068        return m_response.httpStatusCode();
    10661069
    1067     if (m_state == OPENED) {
    1068         // Firefox only raises an exception in this state; we match it.
    1069         // Note the case of local file requests, where we have no HTTP response code! Firefox never raises an exception for those, but we match HTTP case for consistency.
    1070         ec = INVALID_STATE_ERR;
    1071     }
    1072 
    10731070    return 0;
    10741071}
    10751072
    1076 String XMLHttpRequest::statusText(ExceptionCode& ec) const
    1077 {
     1073String XMLHttpRequest::statusText() const
     1074{
     1075    if (m_state == UNSENT || m_state == OPENED || m_error)
     1076        return String();
     1077
    10781078    if (!m_response.httpStatusText().isNull())
    10791079        return m_response.httpStatusText();
    1080 
    1081     if (m_state == OPENED) {
    1082         // See comments in status() above.
    1083         ec = INVALID_STATE_ERR;
    1084     }
    10851080
    10861081    return String();
  • trunk/Source/WebCore/xml/XMLHttpRequest.h

    r163022 r165229  
    8686
    8787    const URL& url() const { return m_url; }
    88     String statusText(ExceptionCode&) const;
    89     int status(ExceptionCode&) const;
     88    String statusText() const;
     89    int status() const;
    9090    State readyState() const;
    9191    bool withCredentials() const { return m_includeCredentials; }
  • trunk/Source/WebCore/xml/XMLHttpRequest.idl

    r163022 r165229  
    8989    [GetterRaisesException, CachedAttribute, CustomGetter] readonly attribute Object response;
    9090
    91     [GetterRaisesException] readonly attribute unsigned short status;
    92     [GetterRaisesException] readonly attribute DOMString statusText;
     91    readonly attribute unsigned short status;
     92    readonly attribute DOMString statusText;
    9393
    9494    // Extension
Note: See TracChangeset for help on using the changeset viewer.