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/location.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/location.rs')
-rw-r--r-- | src/components/script/dom/location.rs | 81 |
1 files changed, 55 insertions, 26 deletions
diff --git a/src/components/script/dom/location.rs b/src/components/script/dom/location.rs index 0933d324c8b..93485f0b264 100644 --- a/src/components/script/dom/location.rs +++ b/src/components/script/dom/location.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::bindings::codegen::BindingDeclarations::LocationBinding; -use dom::bindings::js::JS; +use dom::bindings::js::{JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::window::Window; @@ -29,105 +29,134 @@ impl Location { } } - pub fn new(window: &JS<Window>, page: Rc<Page>) -> JS<Location> { + pub fn new(window: &JSRef<Window>, page: Rc<Page>) -> Temporary<Location> { reflect_dom_object(~Location::new_inherited(page), window, LocationBinding::Wrap) } +} + +pub trait LocationMethods { + fn Assign(&self, _url: DOMString); + fn Replace(&self, _url: DOMString); + fn Reload(&self); + fn Href(&self) -> DOMString; + fn SetHref(&self, _href: DOMString) -> Fallible<()>; + fn Origin(&self) -> DOMString; + fn Protocol(&self) -> DOMString; + fn SetProtocol(&self, _protocol: DOMString); + fn Username(&self) -> DOMString; + fn SetUsername(&self, _username: DOMString); + fn Password(&self) -> DOMString; + fn SetPassword(&self, _password: DOMString); + fn Host(&self) -> DOMString; + fn SetHost(&self, _host: DOMString); + fn Hostname(&self) -> DOMString; + fn SetHostname(&self, _hostname: DOMString); + fn Port(&self) -> DOMString; + fn SetPort(&self, _port: DOMString); + fn Pathname(&self) -> DOMString; + fn SetPathname(&self, _pathname: DOMString); + fn Search(&self) -> DOMString; + fn SetSearch(&self, _search: DOMString); + fn Hash(&self) -> DOMString; + fn SetHash(&self, _hash: DOMString); +} - pub fn Assign(&self, _url: DOMString) { +impl<'a> LocationMethods for JSRef<'a, Location> { + fn Assign(&self, _url: DOMString) { } - pub fn Replace(&self, _url: DOMString) { + fn Replace(&self, _url: DOMString) { } - pub fn Reload(&self) { + fn Reload(&self) { } - pub fn Href(&self) -> DOMString { + fn Href(&self) -> DOMString { self.page.get_url().to_str() } - pub fn SetHref(&self, _href: DOMString) -> Fallible<()> { + fn SetHref(&self, _href: DOMString) -> Fallible<()> { Ok(()) } - pub fn Origin(&self) -> DOMString { + fn Origin(&self) -> DOMString { ~"" } - pub fn Protocol(&self) -> DOMString { + fn Protocol(&self) -> DOMString { ~"" } - pub fn SetProtocol(&self, _protocol: DOMString) { + fn SetProtocol(&self, _protocol: DOMString) { } - pub fn Username(&self) -> DOMString { + fn Username(&self) -> DOMString { ~"" } - pub fn SetUsername(&self, _username: DOMString) { + fn SetUsername(&self, _username: DOMString) { } - pub fn Password(&self) -> DOMString { + fn Password(&self) -> DOMString { ~"" } - pub fn SetPassword(&self, _password: DOMString) { + fn SetPassword(&self, _password: DOMString) { } - pub fn Host(&self) -> DOMString { + fn Host(&self) -> DOMString { ~"" } - pub fn SetHost(&self, _host: DOMString) { + fn SetHost(&self, _host: DOMString) { } - pub fn Hostname(&self) -> DOMString { + fn Hostname(&self) -> DOMString { ~"" } - pub fn SetHostname(&self, _hostname: DOMString) { + fn SetHostname(&self, _hostname: DOMString) { } - pub fn Port(&self) -> DOMString { + fn Port(&self) -> DOMString { ~"" } - pub fn SetPort(&self, _port: DOMString) { + fn SetPort(&self, _port: DOMString) { } - pub fn Pathname(&self) -> DOMString { + fn Pathname(&self) -> DOMString { ~"" } - pub fn SetPathname(&self, _pathname: DOMString) { + fn SetPathname(&self, _pathname: DOMString) { } - pub fn Search(&self) -> DOMString { + fn Search(&self) -> DOMString { ~"" } - pub fn SetSearch(&self, _search: DOMString) { + fn SetSearch(&self, _search: DOMString) { } - pub fn Hash(&self) -> DOMString { + fn Hash(&self) -> DOMString { ~"" } - pub fn SetHash(&self, _hash: DOMString) { + fn SetHash(&self, _hash: DOMString) { } } |