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/blob.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/blob.rs')
-rw-r--r-- | src/components/script/dom/blob.rs | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/components/script/dom/blob.rs b/src/components/script/dom/blob.rs index 04964af092e..ff5958478b6 100644 --- a/src/components/script/dom/blob.rs +++ b/src/components/script/dom/blob.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, Temporary}; use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; use dom::bindings::error::Fallible; use dom::bindings::codegen::BindingDeclarations::BlobBinding; @@ -16,38 +16,46 @@ pub struct Blob { } impl Blob { - pub fn new_inherited(window: JS<Window>) -> Blob { + pub fn new_inherited(window: &JSRef<Window>) -> Blob { Blob { reflector_: Reflector::new(), - window: window + window: window.unrooted() } } - pub fn new(window: &JS<Window>) -> JS<Blob> { - reflect_dom_object(~Blob::new_inherited(window.clone()), + pub fn new(window: &JSRef<Window>) -> Temporary<Blob> { + reflect_dom_object(~Blob::new_inherited(window), window, BlobBinding::Wrap) } -} -impl Blob { - pub fn Constructor(window: &JS<Window>) -> Fallible<JS<Blob>> { + pub fn Constructor(window: &JSRef<Window>) -> Fallible<Temporary<Blob>> { Ok(Blob::new(window)) } +} + +pub trait BlobMethods { + fn Size(&self) -> u64; + fn Type(&self) -> DOMString; + fn Slice(&self, _start: Option<i64>, _end: Option<i64>, _contentType: Option<DOMString>) -> Temporary<Blob>; + fn Close(&self); +} - pub fn Size(&self) -> u64 { +impl<'a> BlobMethods for JSRef<'a, Blob> { + fn Size(&self) -> u64 { 0 } - pub fn Type(&self) -> DOMString { + fn Type(&self) -> DOMString { ~"" } - pub fn Slice(&self, _start: Option<i64>, _end: Option<i64>, _contentType: Option<DOMString>) -> JS<Blob> { - Blob::new(&self.window) + fn Slice(&self, _start: Option<i64>, _end: Option<i64>, _contentType: Option<DOMString>) -> Temporary<Blob> { + let window = self.window.root(); + Blob::new(&window.root_ref()) } - pub fn Close(&self) {} + fn Close(&self) {} } impl Reflectable for Blob { |