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/htmlbuttonelement.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/htmlbuttonelement.rs')
-rw-r--r-- | src/components/script/dom/htmlbuttonelement.rs | 107 |
1 files changed, 67 insertions, 40 deletions
diff --git a/src/components/script/dom/htmlbuttonelement.rs b/src/components/script/dom/htmlbuttonelement.rs index d40fdbe94be..782e9a0c0c8 100644 --- a/src/components/script/dom/htmlbuttonelement.rs +++ b/src/components/script/dom/htmlbuttonelement.rs @@ -4,14 +4,14 @@ use dom::bindings::codegen::BindingDeclarations::HTMLButtonElementBinding; use dom::bindings::codegen::InheritTypes::HTMLButtonElementDerived; -use dom::bindings::js::JS; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::error::ErrorResult; use dom::document::Document; use dom::element::HTMLButtonElementTypeId; use dom::eventtarget::{EventTarget, NodeTargetTypeId}; use dom::htmlelement::HTMLElement; use dom::htmlformelement::HTMLFormElement; -use dom::node::{Node, ElementNodeTypeId}; +use dom::node::{Node, ElementNodeTypeId, window_from_node}; use dom::validitystate::ValidityState; use servo_util::str::DOMString; @@ -30,131 +30,158 @@ impl HTMLButtonElementDerived for EventTarget { } impl HTMLButtonElement { - pub fn new_inherited(localName: DOMString, document: JS<Document>) -> HTMLButtonElement { + pub fn new_inherited(localName: DOMString, document: &JSRef<Document>) -> HTMLButtonElement { HTMLButtonElement { htmlelement: HTMLElement::new_inherited(HTMLButtonElementTypeId, localName, document) } } - pub fn new(localName: DOMString, document: &JS<Document>) -> JS<HTMLButtonElement> { - let element = HTMLButtonElement::new_inherited(localName, document.clone()); + pub fn new(localName: DOMString, document: &JSRef<Document>) -> Temporary<HTMLButtonElement> { + let element = HTMLButtonElement::new_inherited(localName, document); Node::reflect_node(~element, document, HTMLButtonElementBinding::Wrap) } } -impl HTMLButtonElement { - pub fn Autofocus(&self) -> bool { +pub trait HTMLButtonElementMethods { + fn Autofocus(&self) -> bool; + fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult; + fn Disabled(&self) -> bool; + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult; + fn GetForm(&self) -> Option<Temporary<HTMLFormElement>>; + fn FormAction(&self) -> DOMString; + fn SetFormAction(&mut self, _formaction: DOMString) -> ErrorResult; + fn FormEnctype(&self) -> DOMString; + fn SetFormEnctype(&mut self, _formenctype: DOMString) -> ErrorResult; + fn FormMethod(&self) -> DOMString; + fn SetFormMethod(&mut self, _formmethod: DOMString) -> ErrorResult; + fn FormNoValidate(&self) -> bool; + fn SetFormNoValidate(&mut self, _novalidate: bool) -> ErrorResult; + fn FormTarget(&self) -> DOMString; + fn SetFormTarget(&mut self, _formtarget: DOMString) -> ErrorResult; + fn Name(&self) -> DOMString; + fn SetName(&mut self, _name: DOMString) -> ErrorResult; + fn Type(&self) -> DOMString; + fn SetType(&mut self, _type: DOMString) -> ErrorResult; + fn Value(&self) -> DOMString; + fn SetValue(&mut self, _value: DOMString) -> ErrorResult; + fn WillValidate(&self) -> bool; + fn SetWillValidate(&mut self, _will_validate: bool); + fn Validity(&self) -> Temporary<ValidityState>; + fn ValidationMessage(&self) -> DOMString; + fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult; + fn CheckValidity(&self) -> bool; + fn SetCustomValidity(&mut self, _error: DOMString); +} + +impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> { + fn Autofocus(&self) -> bool { false } - pub fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult { + fn SetAutofocus(&mut self, _autofocus: bool) -> ErrorResult { Ok(()) } - pub fn Disabled(&self) -> bool { + fn Disabled(&self) -> bool { false } - pub fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { + fn SetDisabled(&mut self, _disabled: bool) -> ErrorResult { Ok(()) } - pub fn GetForm(&self) -> Option<JS<HTMLFormElement>> { + fn GetForm(&self) -> Option<Temporary<HTMLFormElement>> { None } - pub fn FormAction(&self) -> DOMString { + fn FormAction(&self) -> DOMString { ~"" } - pub fn SetFormAction(&mut self, _formaction: DOMString) -> ErrorResult { + fn SetFormAction(&mut self, _formaction: DOMString) -> ErrorResult { Ok(()) } - pub fn FormEnctype(&self) -> DOMString { + fn FormEnctype(&self) -> DOMString { ~"" } - pub fn SetFormEnctype(&mut self, _formenctype: DOMString) -> ErrorResult { + fn SetFormEnctype(&mut self, _formenctype: DOMString) -> ErrorResult { Ok(()) } - pub fn FormMethod(&self) -> DOMString { + fn FormMethod(&self) -> DOMString { ~"" } - pub fn SetFormMethod(&mut self, _formmethod: DOMString) -> ErrorResult { + fn SetFormMethod(&mut self, _formmethod: DOMString) -> ErrorResult { Ok(()) } - pub fn FormNoValidate(&self) -> bool { + fn FormNoValidate(&self) -> bool { false } - pub fn SetFormNoValidate(&mut self, _novalidate: bool) -> ErrorResult { + fn SetFormNoValidate(&mut self, _novalidate: bool) -> ErrorResult { Ok(()) } - pub fn FormTarget(&self) -> DOMString { + fn FormTarget(&self) -> DOMString { ~"" } - pub fn SetFormTarget(&mut self, _formtarget: DOMString) -> ErrorResult { + fn SetFormTarget(&mut self, _formtarget: 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 Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn SetType(&mut self, _type: DOMString) -> ErrorResult { + fn SetType(&mut self, _type: DOMString) -> ErrorResult { Ok(()) } - pub fn Value(&self) -> DOMString { + fn Value(&self) -> DOMString { ~"" } - pub fn SetValue(&mut self, _value: DOMString) -> ErrorResult { + fn SetValue(&mut self, _value: DOMString) -> ErrorResult { Ok(()) } - pub fn WillValidate(&self) -> bool { + fn WillValidate(&self) -> bool { false } - pub fn SetWillValidate(&mut self, _will_validate: bool) { - } - - pub fn Validity(&self) -> JS<ValidityState> { - let doc = self.htmlelement.element.node.owner_doc(); - let doc = doc.get(); - ValidityState::new(&doc.window) + fn SetWillValidate(&mut self, _will_validate: bool) { } - pub fn SetValidity(&mut self, _validity: JS<ValidityState>) { + fn Validity(&self) -> Temporary<ValidityState> { + let window = window_from_node(self).root(); + ValidityState::new(&*window) } - pub fn ValidationMessage(&self) -> DOMString { + fn ValidationMessage(&self) -> DOMString { ~"" } - pub fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult { + fn SetValidationMessage(&mut self, _message: DOMString) -> ErrorResult { Ok(()) } - pub fn CheckValidity(&self) -> bool { + fn CheckValidity(&self) -> bool { true } - pub fn SetCustomValidity(&mut self, _error: DOMString) { + fn SetCustomValidity(&mut self, _error: DOMString) { } } |