aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/script/dom/xmlhttprequest.rs
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2014-05-03 14:25:22 -0400
committerbors-servo <release+servo@mozilla.com>2014-05-03 14:25:22 -0400
commit731e66ff132e41cdc49bc5324c0e15be19c46ec2 (patch)
treeccce9b42e8a6c54245e53620082efe0b9840eae1 /src/components/script/dom/xmlhttprequest.rs
parent4051a8096d7ba7e7f9c86e76d0b4bffd83e85805 (diff)
parent91278da9dd55582401154e07f9eea34425a332c2 (diff)
downloadservo-731e66ff132e41cdc49bc5324c0e15be19c46ec2.tar.gz
servo-731e66ff132e41cdc49bc5324c0e15be19c46ec2.zip
auto merge of #2101 : jdm/servo/newroot_rebase, r=Ms2ger
As described in #1764, this strategy uses the following properties: * DOM members are `JS<T>` types. These cannot be used with being explicitly rooted, but they are required for compiler-derived trace hooks. * Methods that take DOM type arguments receive `&[mut] JSRef<T>`. These are rooted value references that are cloneable but cannot escape. * Methods that return DOM values use `Unrooted<T>`. These are values that may or may not be rooted elsewhere, but callers must root them in order to interact with them in any way. One unsoundness hole exists - `Unrooted` values must be rooted ASAP, or there exists the danger that JSAPI calls could be made that could cause the underlying JS value to be GCed. * All methods are implemented on `JSRef<T>`, enforcing the requirement that all DOM values are rooted for the duration of a method call (with a few exceptions for layout-related code, which cannot root values and therefore interacts with `JS<T>` and `&T` values - this is safe under the assumption that layout code interacts with DOM nodes that are in the tree, therefore rooted, and does not run concurrently with content code)
Diffstat (limited to 'src/components/script/dom/xmlhttprequest.rs')
-rw-r--r--src/components/script/dom/xmlhttprequest.rs95
1 files changed, 63 insertions, 32 deletions
diff --git a/src/components/script/dom/xmlhttprequest.rs b/src/components/script/dom/xmlhttprequest.rs
index 76099a4d0d0..5543f508315 100644
--- a/src/components/script/dom/xmlhttprequest.rs
+++ b/src/components/script/dom/xmlhttprequest.rs
@@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::XMLHttpRequestDerived;
use dom::document::Document;
use dom::eventtarget::{EventTarget, XMLHttpRequestTargetTypeId};
use dom::bindings::error::Fallible;
-use dom::bindings::js::JS;
+use dom::bindings::js::{JS, JSRef, Temporary, OptionalSettable};
use js::jsapi::JSContext;
use js::jsval::{JSVal, NullValue};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
@@ -31,7 +31,7 @@ pub struct XMLHttpRequest {
ready_state: u16,
timeout: u32,
with_credentials: bool,
- upload: JS<XMLHttpRequestUpload>,
+ upload: Option<JS<XMLHttpRequestUpload>>,
response_url: DOMString,
status: u16,
status_text: ByteString,
@@ -41,95 +41,126 @@ pub struct XMLHttpRequest {
}
impl XMLHttpRequest {
- pub fn new_inherited(owner: &JS<Window>) -> XMLHttpRequest {
- XMLHttpRequest {
+ pub fn new_inherited(owner: &JSRef<Window>) -> XMLHttpRequest {
+ let mut xhr = XMLHttpRequest {
eventtarget: XMLHttpRequestEventTarget::new_inherited(XMLHttpRequestTypeId),
ready_state: 0,
timeout: 0u32,
with_credentials: false,
- upload: XMLHttpRequestUpload::new(owner),
+ upload: None,
response_url: ~"",
status: 0,
status_text: ByteString::new(vec!()),
response_type: _empty,
response_text: ~"",
response_xml: None
- }
+ };
+ xhr.upload.assign(Some(XMLHttpRequestUpload::new(owner)));
+ xhr
}
- pub fn new(window: &JS<Window>) -> JS<XMLHttpRequest> {
+ pub fn new(window: &JSRef<Window>) -> Temporary<XMLHttpRequest> {
reflect_dom_object(~XMLHttpRequest::new_inherited(window),
window,
XMLHttpRequestBinding::Wrap)
}
- pub fn Constructor(owner: &JS<Window>) -> Fallible<JS<XMLHttpRequest>> {
+ pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<XMLHttpRequest>> {
Ok(XMLHttpRequest::new(owner))
}
- pub fn ReadyState(&self) -> u16 {
+}
+
+pub trait XMLHttpRequestMethods {
+ fn ReadyState(&self) -> u16;
+ fn Open(&self, _method: ByteString, _url: DOMString);
+ fn Open_(&self, _method: ByteString, _url: DOMString, _async: bool,
+ _username: Option<DOMString>, _password: Option<DOMString>);
+ fn SetRequestHeader(&self, _name: ByteString, _value: ByteString);
+ fn Timeout(&self) -> u32;
+ fn SetTimeout(&mut self, timeout: u32);
+ fn WithCredentials(&self) -> bool;
+ fn SetWithCredentials(&mut self, with_credentials: bool);
+ fn Upload(&self) -> Temporary<XMLHttpRequestUpload>;
+ fn Send(&self, _data: Option<DOMString>);
+ fn Abort(&self);
+ fn ResponseURL(&self) -> DOMString;
+ fn Status(&self) -> u16;
+ fn StatusText(&self) -> ByteString;
+ fn GetResponseHeader(&self, _name: ByteString) -> Option<ByteString>;
+ fn GetAllResponseHeaders(&self) -> ByteString;
+ fn OverrideMimeType(&self, _mime: DOMString);
+ fn ResponseType(&self) -> XMLHttpRequestResponseType;
+ fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType);
+ fn Response(&self, _cx: *JSContext) -> JSVal;
+ fn ResponseText(&self) -> DOMString;
+ fn GetResponseXML(&self) -> Option<Temporary<Document>>;
+}
+
+impl<'a> XMLHttpRequestMethods for JSRef<'a, XMLHttpRequest> {
+ fn ReadyState(&self) -> u16 {
self.ready_state
}
- pub fn Open(&self, _method: ByteString, _url: DOMString) {
+ fn Open(&self, _method: ByteString, _url: DOMString) {
}
- pub fn Open_(&self, _method: ByteString, _url: DOMString, _async: bool,
+ fn Open_(&self, _method: ByteString, _url: DOMString, _async: bool,
_username: Option<DOMString>, _password: Option<DOMString>) {
}
- pub fn SetRequestHeader(&self, _name: ByteString, _value: ByteString) {
+ fn SetRequestHeader(&self, _name: ByteString, _value: ByteString) {
}
- pub fn Timeout(&self) -> u32 {
+ fn Timeout(&self) -> u32 {
self.timeout
}
- pub fn SetTimeout(&mut self, timeout: u32) {
+ fn SetTimeout(&mut self, timeout: u32) {
self.timeout = timeout
}
- pub fn WithCredentials(&self) -> bool {
+ fn WithCredentials(&self) -> bool {
self.with_credentials
}
- pub fn SetWithCredentials(&mut self, with_credentials: bool) {
+ fn SetWithCredentials(&mut self, with_credentials: bool) {
self.with_credentials = with_credentials
}
- pub fn Upload(&self) -> JS<XMLHttpRequestUpload> {
- self.upload.clone()
+ fn Upload(&self) -> Temporary<XMLHttpRequestUpload> {
+ Temporary::new(self.upload.get_ref().clone())
}
- pub fn Send(&self, _data: Option<DOMString>) {
+ fn Send(&self, _data: Option<DOMString>) {
}
- pub fn Abort(&self) {
+ fn Abort(&self) {
}
- pub fn ResponseURL(&self) -> DOMString {
+ fn ResponseURL(&self) -> DOMString {
self.response_url.clone()
}
- pub fn Status(&self) -> u16 {
+ fn Status(&self) -> u16 {
self.status
}
- pub fn StatusText(&self) -> ByteString {
+ fn StatusText(&self) -> ByteString {
self.status_text.clone()
}
- pub fn GetResponseHeader(&self, _name: ByteString) -> Option<ByteString> {
+ fn GetResponseHeader(&self, _name: ByteString) -> Option<ByteString> {
None
}
- pub fn GetAllResponseHeaders(&self) -> ByteString {
+ fn GetAllResponseHeaders(&self) -> ByteString {
ByteString::new(vec!())
}
- pub fn OverrideMimeType(&self, _mime: DOMString) {
+ fn OverrideMimeType(&self, _mime: DOMString) {
}
- pub fn ResponseType(&self) -> XMLHttpRequestResponseType {
+ fn ResponseType(&self) -> XMLHttpRequestResponseType {
self.response_type
}
- pub fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType) {
+ fn SetResponseType(&mut self, response_type: XMLHttpRequestResponseType) {
self.response_type = response_type
}
- pub fn Response(&self, _cx: *JSContext) -> JSVal {
+ fn Response(&self, _cx: *JSContext) -> JSVal {
NullValue()
}
- pub fn ResponseText(&self) -> DOMString {
+ fn ResponseText(&self) -> DOMString {
self.response_text.clone()
}
- pub fn GetResponseXML(&self) -> Option<JS<Document>> {
- self.response_xml.clone()
+ fn GetResponseXML(&self) -> Option<Temporary<Document>> {
+ self.response_xml.clone().map(|response| Temporary::new(response))
}
}