mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Use the conversion traits from js.
This commit is contained in:
parent
acb24e80b8
commit
6d2ae85c1f
15 changed files with 285 additions and 647 deletions
|
@ -684,23 +684,23 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
#[allow(unsafe_code)]
|
||||
// https://xhr.spec.whatwg.org/#the-response-attribute
|
||||
fn Response(&self, cx: *mut JSContext) -> JSVal {
|
||||
let mut rval = RootedValue::new(cx, UndefinedValue());
|
||||
match self.response_type.get() {
|
||||
_empty | Text => {
|
||||
let ready_state = self.ready_state.get();
|
||||
if ready_state == XMLHttpRequestState::Done || ready_state == XMLHttpRequestState::Loading {
|
||||
self.text_response().to_jsval(cx, rval.handle_mut());
|
||||
} else {
|
||||
"".to_jsval(cx, rval.handle_mut());
|
||||
}
|
||||
},
|
||||
_ if self.ready_state.get() != XMLHttpRequestState::Done => {
|
||||
return NullValue()
|
||||
},
|
||||
Json => {
|
||||
let decoded = UTF_8.decode(&self.response.borrow(), DecoderTrap::Replace).unwrap().to_owned();
|
||||
let decoded: Vec<u16> = decoded.utf16_units().collect();
|
||||
unsafe {
|
||||
unsafe {
|
||||
let mut rval = RootedValue::new(cx, UndefinedValue());
|
||||
match self.response_type.get() {
|
||||
_empty | Text => {
|
||||
let ready_state = self.ready_state.get();
|
||||
if ready_state == XMLHttpRequestState::Done || ready_state == XMLHttpRequestState::Loading {
|
||||
self.text_response().to_jsval(cx, rval.handle_mut());
|
||||
} else {
|
||||
"".to_jsval(cx, rval.handle_mut());
|
||||
}
|
||||
},
|
||||
_ if self.ready_state.get() != XMLHttpRequestState::Done => {
|
||||
return NullValue()
|
||||
},
|
||||
Json => {
|
||||
let decoded = UTF_8.decode(&self.response.borrow(), DecoderTrap::Replace).unwrap().to_owned();
|
||||
let decoded: Vec<u16> = decoded.utf16_units().collect();
|
||||
if !JS_ParseJSON(cx,
|
||||
decoded.as_ptr(),
|
||||
decoded.len() as u32,
|
||||
|
@ -709,13 +709,13 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
|||
return NullValue();
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// XXXManishearth handle other response types
|
||||
self.response.borrow().to_jsval(cx, rval.handle_mut());
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
// XXXManishearth handle other response types
|
||||
self.response.borrow().to_jsval(cx, rval.handle_mut());
|
||||
}
|
||||
rval.ptr
|
||||
}
|
||||
rval.ptr
|
||||
}
|
||||
|
||||
// https://xhr.spec.whatwg.org/#the-responsetext-attribute
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue