Auto merge of #14096 - fflorent:11485-make-dom-methods-taking-mut-JSContent-unsafe, r=nox

11485 make dom methods taking mut js content unsafe

This is a rebased version of PR #11595

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #11485

<!-- Either: -->
- [ ] There are tests for these changes OR
- [x] These changes do not require tests because: no code logic was changed

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->

---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14096)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-11-17 02:44:54 -06:00 committed by GitHub
commit f70fc6644d
28 changed files with 274 additions and 226 deletions

View file

@ -760,47 +760,45 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
#[allow(unsafe_code)]
// https://xhr.spec.whatwg.org/#the-response-attribute
fn Response(&self, cx: *mut JSContext) -> JSVal {
unsafe {
rooted!(in(cx) let mut rval = UndefinedValue());
match self.response_type.get() {
XMLHttpRequestResponseType::_empty | XMLHttpRequestResponseType::Text => {
let ready_state = self.ready_state.get();
// Step 2
if ready_state == XMLHttpRequestState::Done || ready_state == XMLHttpRequestState::Loading {
self.text_response().to_jsval(cx, rval.handle_mut());
} else {
// Step 1
"".to_jsval(cx, rval.handle_mut());
}
},
// Step 1
_ if self.ready_state.get() != XMLHttpRequestState::Done => {
return NullValue();
},
unsafe fn Response(&self, cx: *mut JSContext) -> JSVal {
rooted!(in(cx) let mut rval = UndefinedValue());
match self.response_type.get() {
XMLHttpRequestResponseType::_empty | XMLHttpRequestResponseType::Text => {
let ready_state = self.ready_state.get();
// Step 2
XMLHttpRequestResponseType::Document => {
let op_doc = self.document_response();
if let Some(doc) = op_doc {
doc.to_jsval(cx, rval.handle_mut());
} else {
// Substep 1
return NullValue();
}
},
XMLHttpRequestResponseType::Json => {
self.json_response(cx).to_jsval(cx, rval.handle_mut());
},
XMLHttpRequestResponseType::Blob => {
self.blob_response().to_jsval(cx, rval.handle_mut());
},
_ => {
// XXXManishearth handle other response types
self.response.borrow().to_jsval(cx, rval.handle_mut());
if ready_state == XMLHttpRequestState::Done || ready_state == XMLHttpRequestState::Loading {
self.text_response().to_jsval(cx, rval.handle_mut());
} else {
// Step 1
"".to_jsval(cx, rval.handle_mut());
}
},
// Step 1
_ if self.ready_state.get() != XMLHttpRequestState::Done => {
return NullValue();
},
// Step 2
XMLHttpRequestResponseType::Document => {
let op_doc = self.document_response();
if let Some(doc) = op_doc {
doc.to_jsval(cx, rval.handle_mut());
} else {
// Substep 1
return NullValue();
}
},
XMLHttpRequestResponseType::Json => {
self.json_response(cx).to_jsval(cx, rval.handle_mut());
},
XMLHttpRequestResponseType::Blob => {
self.blob_response().to_jsval(cx, rval.handle_mut());
},
_ => {
// XXXManishearth handle other response types
self.response.borrow().to_jsval(cx, rval.handle_mut());
}
rval.get()
}
rval.get()
}
// https://xhr.spec.whatwg.org/#the-responsetext-attribute