mirror of
https://github.com/servo/servo.git
synced 2025-06-18 21:34:30 +00:00
Auto merge of #9610 - liviuba:Fix-9553, r=KiChjang
Bypass GetResponseXML to better match spec Resolves https://github.com/servo/servo/issues/9553 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9610) <!-- Reviewable:end -->
This commit is contained in:
commit
361bb24a49
3 changed files with 89 additions and 4 deletions
|
@ -778,8 +778,8 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
},
|
||||
// Step 2
|
||||
XMLHttpRequestResponseType::Document => {
|
||||
let op_doc = self.GetResponseXML();
|
||||
if let Ok(Some(doc)) = op_doc {
|
||||
let op_doc = self.document_response();
|
||||
if let Some(doc) = op_doc {
|
||||
doc.to_jsval(cx, rval.handle_mut());
|
||||
} else {
|
||||
// Substep 1
|
||||
|
@ -1126,19 +1126,28 @@ impl XMLHttpRequest {
|
|||
|
||||
// https://xhr.spec.whatwg.org/#document-response
|
||||
fn document_response(&self) -> Option<Root<Document>> {
|
||||
// Step 1
|
||||
let response = self.response_xml.get();
|
||||
if response.is_some() {
|
||||
return self.response_xml.get();
|
||||
}
|
||||
|
||||
let mime_type = self.final_mime_type();
|
||||
//TODO: prescan the response to determine encoding if final charset is null
|
||||
// TODO: prescan the response to determine encoding if final charset is null
|
||||
let charset = self.final_charset().unwrap_or(UTF_8);
|
||||
let temp_doc: Root<Document>;
|
||||
match mime_type {
|
||||
Some(Mime(mime::TopLevel::Text, mime::SubLevel::Html, _)) => {
|
||||
// Step 5
|
||||
if self.response_type.get() == XMLHttpRequestResponseType::_empty {
|
||||
return None;
|
||||
}
|
||||
// Step 6
|
||||
else {
|
||||
temp_doc = self.document_text_html();
|
||||
}
|
||||
},
|
||||
// Step 7
|
||||
Some(Mime(mime::TopLevel::Text, mime::SubLevel::Xml, _)) |
|
||||
Some(Mime(mime::TopLevel::Application, mime::SubLevel::Xml, _)) |
|
||||
None => {
|
||||
|
@ -1152,10 +1161,14 @@ impl XMLHttpRequest {
|
|||
return None;
|
||||
}
|
||||
},
|
||||
// Step 4
|
||||
_ => { return None; }
|
||||
}
|
||||
// Step 9
|
||||
temp_doc.set_encoding_name(DOMString::from(charset.name()));
|
||||
Some(temp_doc)
|
||||
// Step 13
|
||||
self.response_xml.set(Some(temp_doc.r()));
|
||||
return self.response_xml.get();
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
|
|
|
@ -33814,6 +33814,12 @@
|
|||
"url": "/WebIDL/ecmascript-binding/has-instance.html"
|
||||
}
|
||||
],
|
||||
"XMLHttpRequest/responsexml-get-twice.htm": [
|
||||
{
|
||||
"path": "XMLHttpRequest/responsexml-get-twice.htm",
|
||||
"url": "/XMLHttpRequest/responsexml-get-twice.htm"
|
||||
}
|
||||
],
|
||||
"html/browsers/browsing-the-web/scroll-to-fragid/scroll-frag-percent-encoded.html": [
|
||||
{
|
||||
"path": "html/browsers/browsing-the-web/scroll-to-fragid/scroll-frag-percent-encoded.html",
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
<!doctype html>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
async_test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open("GET", "resources/well-formed.xml")
|
||||
client.responseType = "document"
|
||||
assert_equals(client.responseType, "document")
|
||||
client.send()
|
||||
client.onload = this.step_func_done(function() {
|
||||
var first = client.response
|
||||
var second = client.response
|
||||
assert_not_equals(first, null)
|
||||
assert_not_equals(second, null)
|
||||
assert_equals(first, second)
|
||||
})
|
||||
}, "Getting response, then response")
|
||||
|
||||
async_test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open("GET", "resources/well-formed.xml")
|
||||
client.responseType = "document"
|
||||
assert_equals(client.responseType, "document")
|
||||
client.send()
|
||||
client.onload = this.step_func_done(function() {
|
||||
var first = client.responseXML
|
||||
var second = client.responseXML
|
||||
assert_not_equals(first, null)
|
||||
assert_not_equals(second, null)
|
||||
assert_equals(first, second)
|
||||
})
|
||||
}, "Getting responseXML, then responseXML")
|
||||
|
||||
async_test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open("GET", "resources/well-formed.xml")
|
||||
client.responseType = "document"
|
||||
assert_equals(client.responseType, "document")
|
||||
client.send()
|
||||
client.onload = this.step_func_done(function() {
|
||||
var first = client.responseXML
|
||||
var second = client.response
|
||||
assert_not_equals(first, null)
|
||||
assert_not_equals(second, null)
|
||||
assert_equals(first, second)
|
||||
})
|
||||
}, "Getting responseXML, then response")
|
||||
|
||||
async_test(function() {
|
||||
var client = new XMLHttpRequest()
|
||||
client.open("GET", "resources/well-formed.xml")
|
||||
client.responseType = "document"
|
||||
assert_equals(client.responseType, "document")
|
||||
client.send()
|
||||
client.onload = this.step_func_done(function() {
|
||||
var first = client.response
|
||||
var second = client.responseXML
|
||||
assert_not_equals(first, null)
|
||||
assert_not_equals(second, null)
|
||||
assert_equals(first, second)
|
||||
})
|
||||
}, "Getting response, then responseXML")
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue