Bug 12194

Summary: Trying to access XMLHttpRequest.responseText or responseXML when they are not available should raise an exception
Product: WebKit Reporter: Alexey Proskuryakov <ap>
Component: XMLAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: jchaffraix
Priority: P3    
Version: 420+   
Hardware: Mac   
OS: OS X 10.4   
Attachments:
Description Flags
Patch + test cases
darin: review+
Patches updated with Darin's comments darin: review+

Description Alexey Proskuryakov 2007-01-10 04:01:22 PST
From XMLHttpRequest spec draft:

------------------------
responseText of type DOMString, readonly
If the state is not receiving or loaded, the user agent must raise an INVALID_STATE_ERR exception. 
...
responseXML of type Document, readonly
If the state is not loaded, user agents must raise an INVALID_STATE_ERR exception.
------------------------
Comment 1 Julien Chaffraix 2007-11-15 19:09:34 PST
Created attachment 17309 [details]
Patch + test cases

Tested other browsers' behaviour :

IE 7:
raises an exception if readyState is not Loaded in both tests

Firefox:
does not raise any exception in both tests

Opera:
Fully implements the standard.

Judging from the results, I have sided with the specification (which is close to IE behaviour) and fully implemented it.

Patch tested on mac without any regression.
Comment 2 Darin Adler 2007-11-16 20:08:44 PST
Comment on attachment 17309 [details]
Patch + test cases

+            if (responseXML)
                 return toJS(exec, responseXML);
-            return jsNull();
+            else
+                return jsNull();

We normally do *not* do else after return in the WebKit project.

+    if (m_state < Receiving) {
+        ec = INVALID_STATE_ERR;
+    }

We do not put braces around single-line bodies of if statements.

+Should see "PASS" four times:
+
+PASSED
+PASSED
+PASSED
+PASSED

Probably should say "PASSED" or "PASS" consistently.

Change looks good, so I'll say r=me, but it would be nice to fix these minor style issues.
Comment 3 Julien Chaffraix 2007-11-17 18:48:39 PST
Created attachment 17333 [details]
Patches updated with Darin's comments
Comment 4 David Kilzer (:ddkilzer) 2007-11-17 21:21:12 PST
Comment on attachment 17333 [details]
Patches updated with Darin's comments

Please set the "review?" flag, not the "review+" flag.  Thanks!
Comment 5 Darin Adler 2007-11-17 22:50:35 PST
Comment on attachment 17333 [details]
Patches updated with Darin's comments

r=me
Comment 6 Mark Rowe (bdash) 2007-11-19 04:31:19 PST
Landed in r27898.