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/htmlformelement.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/htmlformelement.rs')
-rw-r--r-- | src/components/script/dom/htmlformelement.rs | 92 |
1 files changed, 59 insertions, 33 deletions
diff --git a/src/components/script/dom/htmlformelement.rs b/src/components/script/dom/htmlformelement.rs index 3fdf2a4ba7f..445ad6e0831 100644 --- a/src/components/script/dom/htmlformelement.rs +++ b/src/components/script/dom/htmlformelement.rs @@ -4,14 +4,14 @@ use dom::bindings::codegen::BindingDeclarations::HTMLFormElementBinding; use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::{Element, HTMLFormElementTypeId}; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlcollection::{HTMLCollection, Static}; use dom::htmlelement::HTMLElement; -use dom::node::{Node, ElementNodeTypeId}; +use dom::node::{Node, ElementNodeTypeId, window_from_node}; use servo_util::str::DOMString; #[deriving(Encodable)] @@ -29,114 +29,140 @@ impl HTMLFormElementDerived for EventTarget { } impl HTMLFormElement { - pub fn new_inherited(localName: DOMString, document: JS<Document>) -> HTMLFormElement { + pub fn new_inherited(localName: DOMString, document: &JSRef<Document>) -> HTMLFormElement { HTMLFormElement { htmlelement: HTMLElement::new_inherited(HTMLFormElementTypeId, localName, document) } } - pub fn new(localName: DOMString, document: &JS<Document>) -> JS<HTMLFormElement> { - let element = HTMLFormElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef<Document>) -> Temporary<HTMLFormElement> { + let element = HTMLFormElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLFormElementBinding::Wrap) } } -impl HTMLFormElement { - pub fn AcceptCharset(&self) -> DOMString { +pub trait HTMLFormElementMethods { + fn AcceptCharset(&self) -> DOMString; + fn SetAcceptCharset(&mut self, _accept_charset: DOMString) -> ErrorResult; + fn Action(&self) -> DOMString; + fn SetAction(&mut self, _action: DOMString) -> ErrorResult; + fn Autocomplete(&self) -> DOMString; + fn SetAutocomplete(&mut self, _autocomplete: DOMString) -> ErrorResult; + fn Enctype(&self) -> DOMString; + fn SetEnctype(&mut self, _enctype: DOMString) -> ErrorResult; + fn Encoding(&self) -> DOMString; + fn SetEncoding(&mut self, _encoding: DOMString) -> ErrorResult; + fn Method(&self) -> DOMString; + fn SetMethod(&mut self, _method: DOMString) -> ErrorResult; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn NoValidate(&self) -> bool; + fn SetNoValidate(&mut self, _no_validate: bool) -> ErrorResult; + fn Target(&self) -> DOMString; + fn SetTarget(&mut self, _target: DOMString) -> ErrorResult; + fn Elements(&self) -> Temporary<HTMLCollection>; + fn Length(&self) -> i32; + fn Submit(&self) -> ErrorResult; + fn Reset(&self); + fn CheckValidity(&self) -> bool; + fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Temporary<Element>; +} + +impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> { + fn AcceptCharset(&self) -> DOMString { ~"" } - pub fn SetAcceptCharset(&mut self, _accept_charset: DOMString) -> ErrorResult { + fn SetAcceptCharset(&mut self, _accept_charset: DOMString) -> ErrorResult { Ok(()) } - pub fn Action(&self) -> DOMString { + fn Action(&self) -> DOMString { ~"" } - pub fn SetAction(&mut self, _action: DOMString) -> ErrorResult { + fn SetAction(&mut self, _action: DOMString) -> ErrorResult { Ok(()) } - pub fn Autocomplete(&self) -> DOMString { + fn Autocomplete(&self) -> DOMString { ~"" } - pub fn SetAutocomplete(&mut self, _autocomplete: DOMString) -> ErrorResult { + fn SetAutocomplete(&mut self, _autocomplete: DOMString) -> ErrorResult { Ok(()) } - pub fn Enctype(&self) -> DOMString { + fn Enctype(&self) -> DOMString { ~"" } - pub fn SetEnctype(&mut self, _enctype: DOMString) -> ErrorResult { + fn SetEnctype(&mut self, _enctype: DOMString) -> ErrorResult { Ok(()) } - pub fn Encoding(&self) -> DOMString { + fn Encoding(&self) -> DOMString { ~"" } - pub fn SetEncoding(&mut self, _encoding: DOMString) -> ErrorResult { + fn SetEncoding(&mut self, _encoding: DOMString) -> ErrorResult { Ok(()) } - pub fn Method(&self) -> DOMString { + fn Method(&self) -> DOMString { ~"" } - pub fn SetMethod(&mut self, _method: DOMString) -> ErrorResult { + fn SetMethod(&mut self, _method: DOMString) -> ErrorResult { Ok(()) } - pub fn Name(&self) -> DOMString { + fn Name(&self) -> DOMString { ~"" } - pub fn SetName(&mut self, _name: DOMString) -> ErrorResult { + fn SetName(&mut self, _name: DOMString) -> ErrorResult { Ok(()) } - pub fn NoValidate(&self) -> bool { + fn NoValidate(&self) -> bool { false } - pub fn SetNoValidate(&mut self, _no_validate: bool) -> ErrorResult { + fn SetNoValidate(&mut self, _no_validate: bool) -> ErrorResult { Ok(()) } - pub fn Target(&self) -> DOMString { + fn Target(&self) -> DOMString { ~"" } - pub fn SetTarget(&mut self, _target: DOMString) -> ErrorResult { + fn SetTarget(&mut self, _target: DOMString) -> ErrorResult { Ok(()) } - pub fn Elements(&self) -> JS<HTMLCollection> { + fn Elements(&self) -> Temporary<HTMLCollection> { // FIXME: https://github.com/mozilla/servo/issues/1844 - let doc = self.htmlelement.element.node.owner_doc(); - let doc = doc.get(); - HTMLCollection::new(&doc.window, Static(vec!())) + let window = window_from_node(self).root(); + HTMLCollection::new(&*window, Static(vec!())) } - pub fn Length(&self) -> i32 { + fn Length(&self) -> i32 { 0 } - pub fn Submit(&self) -> ErrorResult { + fn Submit(&self) -> ErrorResult { Ok(()) } - pub fn Reset(&self) { + fn Reset(&self) { } - pub fn CheckValidity(&self) -> bool { + fn CheckValidity(&self) -> bool { false } - pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> JS<Element> { + fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Temporary<Element> { fail!("Not implemented.") } } |