diff options
author | bors-servo <release+servo@mozilla.com> | 2014-05-03 14:25:22 -0400 |
---|---|---|
committer | bors-servo <release+servo@mozilla.com> | 2014-05-03 14:25:22 -0400 |
commit | 731e66ff132e41cdc49bc5324c0e15be19c46ec2 (patch) | |
tree | ccce9b42e8a6c54245e53620082efe0b9840eae1 /src/components/script/dom/formdata.rs | |
parent | 4051a8096d7ba7e7f9c86e76d0b4bffd83e85805 (diff) | |
parent | 91278da9dd55582401154e07f9eea34425a332c2 (diff) | |
download | servo-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/formdata.rs')
-rw-r--r-- | src/components/script/dom/formdata.rs | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/components/script/dom/formdata.rs b/src/components/script/dom/formdata.rs index 140c70a12d2..c6631699671 100644 --- a/src/components/script/dom/formdata.rs +++ b/src/components/script/dom/formdata.rs @@ -5,7 +5,7 @@ use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::{Fallible}; use dom::bindings::codegen::BindingDeclarations::FormDataBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, Temporary, OptionalUnrootable}; use dom::blob::Blob; use dom::htmlformelement::HTMLFormElement; use dom::window::Window; @@ -28,33 +28,39 @@ pub struct FormData { } impl FormData { - pub fn new_inherited(form: Option<JS<HTMLFormElement>>, window: JS<Window>) -> FormData { + pub fn new_inherited(form: Option<JSRef<HTMLFormElement>>, window: &JSRef<Window>) -> FormData { FormData { data: HashMap::new(), reflector_: Reflector::new(), - window: window, - form: form + window: window.unrooted(), + form: form.unrooted(), } } - pub fn new(form: Option<JS<HTMLFormElement>>, window: &JS<Window>) -> JS<FormData> { - reflect_dom_object(~FormData::new_inherited(form, window.clone()), window, FormDataBinding::Wrap) + pub fn new(form: Option<JSRef<HTMLFormElement>>, window: &JSRef<Window>) -> Temporary<FormData> { + reflect_dom_object(~FormData::new_inherited(form, window), window, FormDataBinding::Wrap) } - pub fn Constructor(window: &JS<Window>, form: Option<JS<HTMLFormElement>>) - -> Fallible<JS<FormData>> { + pub fn Constructor(window: &JSRef<Window>, form: Option<JSRef<HTMLFormElement>>) -> Fallible<Temporary<FormData>> { Ok(FormData::new(form, window)) } +} + +pub trait FormDataMethods { + fn Append(&mut self, name: DOMString, value: &JSRef<Blob>, filename: Option<DOMString>); + fn Append_(&mut self, name: DOMString, value: DOMString); +} - pub fn Append(&mut self, name: DOMString, value: &JS<Blob>, filename: Option<DOMString>) { +impl<'a> FormDataMethods for JSRef<'a, FormData> { + fn Append(&mut self, name: DOMString, value: &JSRef<Blob>, filename: Option<DOMString>) { let blob = BlobData { - blob: value.clone(), + blob: value.unrooted(), name: filename.unwrap_or(~"default") }; self.data.insert(name.clone(), blob); } - pub fn Append_(&mut self, name: DOMString, value: DOMString) { + fn Append_(&mut self, name: DOMString, value: DOMString) { self.data.insert(name, StringData(value)); } } |