Implement safe rooting strategy via Unrooted, Root, JSRef, and JS.

This commit is contained in:
Josh Matthews 2014-03-31 18:41:28 -04:00
parent ffdc3f5b32
commit d7b96db33c
109 changed files with 1568 additions and 1326 deletions

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::AttrBinding;
use dom::bindings::codegen::InheritTypes::NodeCast;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::element::Element;
use dom::node::Node;
@ -45,7 +45,7 @@ impl Reflectable for Attr {
impl Attr {
fn new_inherited(local_name: DOMString, value: DOMString,
name: DOMString, namespace: Namespace,
prefix: Option<DOMString>, owner: JS<Element>) -> Attr {
prefix: Option<DOMString>, owner: &JSRef<Element>) -> Attr {
Attr {
reflector_: Reflector::new(),
local_name: local_name,
@ -53,25 +53,27 @@ impl Attr {
name: name, //TODO: Intern attribute names
namespace: namespace,
prefix: prefix,
owner: owner,
owner: owner.unrooted(),
}
}
pub fn new(window: &JSRef<Window>, local_name: DOMString, value: DOMString,
name: DOMString, namespace: Namespace,
prefix: Option<DOMString>, owner: JS<Element>) -> JS<Attr> {
prefix: Option<DOMString>, owner: &JSRef<Element>) -> Unrooted<Attr> {
let attr = Attr::new_inherited(local_name, value, name, namespace, prefix, owner);
reflect_dom_object(~attr, window, AttrBinding::Wrap)
}
pub fn set_value(&mut self, set_type: AttrSettingType, value: DOMString) {
let node: JS<Node> = NodeCast::from(&self.owner);
let roots = RootCollection::new();
let owner = self.owner.root(&roots);
let node: &JSRef<Node> = NodeCast::from_ref(&*owner);
let namespace_is_null = self.namespace == namespace::Null;
match set_type {
ReplacedAttr => {
if namespace_is_null {
vtable_for(&node).before_remove_attr(self.local_name.clone(), self.value.clone());
vtable_for(node).before_remove_attr(self.local_name.clone(), self.value.clone());
}
}
FirstSetAttr => {}
@ -80,7 +82,7 @@ impl Attr {
self.value = value;
if namespace_is_null {
vtable_for(&node).after_set_attr(self.local_name.clone(), self.value.clone());
vtable_for(node).after_set_attr(self.local_name.clone(), self.value.clone());
}
}

View file

@ -4,7 +4,7 @@
use dom::attr::Attr;
use dom::bindings::codegen::BindingDeclarations::AttrListBinding;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::element::Element;
use dom::window::Window;
@ -25,7 +25,7 @@ impl AttrList {
}
}
pub fn new(window: &JSRef<Window>, elem: &JSRef<Element>) -> JS<AttrList> {
pub fn new(window: &JSRef<Window>, elem: &JSRef<Element>) -> Unrooted<AttrList> {
reflect_dom_object(~AttrList::new_inherited(window.unrooted(), elem.unrooted()),
window, AttrListBinding::Wrap)
}
@ -34,11 +34,11 @@ impl AttrList {
self.owner.get().attrs.len() as u32
}
pub fn Item(&self, index: u32) -> Option<JS<Attr>> {
self.owner.get().attrs.as_slice().get(index as uint).map(|x| x.clone())
pub fn Item(&self, index: u32) -> Option<Unrooted<Attr>> {
self.owner.get().attrs.as_slice().get(index as uint).map(|x| Unrooted::new(x.clone()))
}
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<JS<Attr>> {
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Unrooted<Attr>> {
let item = self.Item(index);
*found = item.is_some();
item

View file

@ -1008,6 +1008,13 @@ def typeNeedsCx(type, retVal=False):
return True
return type.isCallback() or type.isAny() or type.isObject()
def typeRetValNeedsRooting(type):
if type is None:
return False
if type.nullable():
type = type.inner
return type.isGeckoInterface() and not type.isCallback()
def memberIsCreator(member):
return member.getExtendedAttribute("Creator") is not None
@ -1039,7 +1046,7 @@ def getRetvalDeclarationForType(returnType, descriptorProvider):
if returnType.isGeckoInterface():
descriptor = descriptorProvider.getDescriptor(
returnType.unroll().inner.identifier.name)
result = CGGeneric(descriptor.nativeType)
result = CGGeneric(descriptor.returnType)
if returnType.nullable():
result = CGWrapper(result, pre="Option<", post=">")
return result
@ -2235,6 +2242,14 @@ class CGCallGenerator(CGThing):
self.cgRoot.append(CGGeneric("}"))
self.cgRoot.append(CGGeneric("result = result_fallible.unwrap();"))
if typeRetValNeedsRooting(returnType):
rooted_value = CGGeneric("result.root(&roots).root_ref().unrooted()")
if returnType.nullable():
rooted_value = CGWrapper(rooted_value, pre="result.map(|result| ", post=")")
rooted_value = CGWrapper(rooted_value, pre="let result = ", post=";")
self.cgRoot.append(rooted_value)
def define(self):
return self.cgRoot.define()
@ -4306,7 +4321,7 @@ class CGBindingRoot(CGThing):
'js::glue::{RUST_JS_NumberValue, RUST_JSID_IS_STRING}',
'dom::types::*',
'dom::bindings',
'dom::bindings::js::{JS, JSRef, RootCollection, RootedReference}',
'dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted}',
'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}',
'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}',
'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}',
@ -5277,8 +5292,9 @@ class GlobalGenRoots():
descriptors = config.getDescriptors(register=True, hasInterfaceObject=True)
allprotos = [CGGeneric("#![allow(unused_imports)]\n"),
CGGeneric("use dom::types::*;\n"),
CGGeneric("use dom::bindings::js::{JS, JSRef};\n"),
CGGeneric("use dom::bindings::js::{JS, JSRef, Unrooted};\n"),
CGGeneric("use dom::bindings::trace::JSTraceable;\n"),
CGGeneric("use dom::bindings::utils::Reflectable;\n"),
CGGeneric("use serialize::{Encodable, Encoder};\n"),
CGGeneric("use js::jsapi::JSTracer;\n\n")]
for descriptor in descriptors:
@ -5310,7 +5326,7 @@ class GlobalGenRoots():
}
#[inline(always)]
fn to<T: ${toBound}>(base: &JS<T>) -> Option<JS<Self>> {
fn to<T: ${toBound}+Reflectable>(base: &JS<T>) -> Option<JS<Self>> {
match base.get().${checkFn}() {
true => unsafe { Some(base.clone().transmute()) },
false => None
@ -5318,7 +5334,23 @@ class GlobalGenRoots():
}
#[inline(always)]
unsafe fn to_unchecked<T: ${toBound}>(base: &JS<T>) -> JS<Self> {
fn to_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a JSRef<'b, T>) -> Option<&'a JSRef<'b, Self>> {
match base.get().${checkFn}() {
true => unsafe { Some(base.transmute()) },
false => None
}
}
#[inline(always)]
fn to_mut_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a mut JSRef<'b, T>) -> Option<&'a mut JSRef<'b, Self>> {
match base.get().${checkFn}() {
true => unsafe { Some(base.transmute_mut()) },
false => None
}
}
#[inline(always)]
unsafe fn to_unchecked<T: ${toBound}+Reflectable>(base: &JS<T>) -> JS<Self> {
assert!(base.get().${checkFn}());
base.clone().transmute()
}
@ -5330,6 +5362,10 @@ class GlobalGenRoots():
fn from_mut_ref<'a, 'b, T: ${fromBound}>(derived: &'a mut JSRef<'b, T>) -> &'a mut JSRef<'b, Self> {
unsafe { derived.transmute_mut() }
}
fn from_unrooted<T: ${fromBound}+Reflectable>(derived: Unrooted<T>) -> Unrooted<Self> {
unsafe { derived.transmute() }
}
}
''').substitute({'checkFn': 'is_' + name.lower(),
'castTraitName': name + 'Cast',

View file

@ -133,6 +133,7 @@ class Descriptor(DescriptorProvider):
else:
nativeTypeDefault = 'JS<%s>' % ifaceName
self.returnType = "Unrooted<%s>" % ifaceName
self.nativeType = desc.get('nativeType', nativeTypeDefault)
self.concreteType = desc.get('concreteType', ifaceName)
self.needsAbstract = desc.get('needsAbstract', [])

View file

@ -10,8 +10,52 @@ use layout_interface::TrustedNodeAddress;
use std::cast;
use std::cell::{Cell, RefCell};
use std::ptr;
//use std::ops::{Deref, DerefMut};
/// A type that represents a JS-owned value that may or may not be rooted.
/// Importantly, it requires rooting in order to interact with the value in any way.
/// Can be assigned into JS-owned member fields (ie. JS<T> types) safely via the
/// `JS<T>::assign` method or `OptionalAssignable::assign` (for Option<JS<T>> fields).
pub struct Unrooted<T> {
inner: JS<T>
}
impl<T> Eq for Unrooted<T> {
fn eq(&self, other: &Unrooted<T>) -> bool {
self.inner == other.inner
}
}
impl<T: Reflectable> Unrooted<T> {
/// Create a new Unrooted value from a JS-owned value.
pub fn new(inner: JS<T>) -> Unrooted<T> {
Unrooted {
inner: inner
}
}
/// Create a new Unrooted value from a rooted value.
pub fn new_rooted<'a>(root: &JSRef<'a, T>) -> Unrooted<T> {
Unrooted {
inner: root.unrooted()
}
}
/// Root this unrooted value.
pub fn root<'a, 'b>(self, collection: &'a RootCollection) -> Root<'a, 'b, T> {
collection.new_root(&self.inner)
}
unsafe fn inner(&self) -> JS<T> {
self.inner.clone()
}
//XXXjdm It would be lovely if this could be private.
pub unsafe fn transmute<To>(self) -> Unrooted<To> {
cast::transmute(self)
}
}
/// A rooted, JS-owned value. Must only be used as a field in other JS-owned types.
pub struct JS<T> {
ptr: RefCell<*mut T>
}
@ -32,12 +76,15 @@ impl <T> Clone for JS<T> {
}
impl<T: Reflectable> JS<T> {
/// Create a new JS-reflected DOM object; returns an Unrooted type because the new value
/// is not safe to use until it is rooted.
pub fn new(obj: ~T,
window: &JSRef<Window>,
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, ~T) -> JS<T>) -> JS<T> {
wrap_fn(window.get().get_cx(), window, obj)
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, ~T) -> JS<T>) -> Unrooted<T> {
Unrooted::new(wrap_fn(window.get().get_cx(), window, obj))
}
/// Create a new JS-owned value wrapped from a raw Rust pointer.
pub unsafe fn from_raw(raw: *mut T) -> JS<T> {
JS {
ptr: RefCell::new(raw)
@ -45,6 +92,7 @@ impl<T: Reflectable> JS<T> {
}
/// Create a new JS-owned value wrapped from an address known to be a Node pointer.
pub unsafe fn from_trusted_node_address(inner: TrustedNodeAddress) -> JS<T> {
let TrustedNodeAddress(addr) = inner;
JS {
@ -52,7 +100,8 @@ impl<T: Reflectable> JS<T> {
}
}
pub fn root<'a>(&self, collection: &'a RootCollection) -> Root<'a, T> {
/// Root this JS-owned value to prevent its collection as garbage.
pub fn root<'a, 'b>(&self, collection: &'a RootCollection) -> Root<'a, 'b, T> {
collection.new_root(self)
}
}
@ -67,7 +116,7 @@ impl<T: Reflectable> Reflectable for JS<T> {
}
}
impl<T> JS<T> {
impl<T: Reflectable> JS<T> {
pub fn get<'a>(&'a self) -> &'a T {
let borrowed = self.ptr.borrow();
unsafe {
@ -88,6 +137,13 @@ impl<T> JS<T> {
pub unsafe fn unsafe_get(&self) -> *mut T {
cast::transmute_copy(&self.ptr)
}
/// Store an unrooted value in this field. This is safe under the assumption that JS<T>
/// values are only used as fields in DOM types that are reachable in the GC graph,
/// so this unrooted value becomes transitively rooted for the lifetime of its new owner.
pub fn assign(&mut self, val: Unrooted<T>) {
*self = unsafe { val.inner() };
}
}
impl<From, To> JS<From> {
@ -105,17 +161,86 @@ pub trait RootedReference<T> {
fn root_ref<'a>(&'a self) -> Option<JSRef<'a, T>>;
}
impl<'a, T: Reflectable> RootedReference<T> for Option<Root<'a, T>> {
impl<'a, 'b, T: Reflectable> RootedReference<T> for Option<Root<'a, 'b, T>> {
fn root_ref<'a>(&'a self) -> Option<JSRef<'a, T>> {
self.as_ref().map(|root| root.root_ref())
}
}
// This trait should never be public; it allows access to unrooted values, and is thus
// easy to misuse.
/*definitely not public*/ trait Assignable<T> {
fn get_js(&self) -> JS<T>;
}
impl<T> Assignable<T> for JS<T> {
fn get_js(&self) -> JS<T> {
self.clone()
}
}
impl<'a, T> Assignable<T> for JSRef<'a, T> {
fn get_js(&self) -> JS<T> {
self.unrooted()
}
}
// Assignable should not be exposed publically, since it's used to
// extract unrooted values in a safe way WHEN USED CORRECTLY.
impl<T: Reflectable> Assignable<T> for Unrooted<T> {
fn get_js(&self) -> JS<T> {
unsafe { self.inner() }
}
}
pub trait OptionalAssignable<T> {
fn assign(&mut self, val: Option<T>);
}
impl<T: Assignable<U>, U: Reflectable> OptionalAssignable<T> for Option<JS<U>> {
fn assign(&mut self, val: Option<T>) {
*self = val.map(|val| val.get_js());
}
}
pub trait OptionalRootable<T> {
fn root<'a, 'b>(self, roots: &'a RootCollection) -> Option<Root<'a, 'b, T>>;
}
impl<T: Reflectable> OptionalRootable<T> for Option<Unrooted<T>> {
fn root<'a, 'b>(self, roots: &'a RootCollection) -> Option<Root<'a, 'b, T>> {
self.map(|inner| inner.root(roots))
}
}
pub trait ResultRootable<T,U> {
fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result<Root<'a, 'b, T>, U>;
}
impl<T: Reflectable, U> ResultRootable<T, U> for Result<Unrooted<T>, U> {
fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result<Root<'a, 'b, T>, U> {
self.map(|inner| inner.root(roots))
}
}
/// Provides a facility to push unrooted values onto lists of rooted values. This is safe
/// under the assumption that said lists are reachable via the GC graph, and therefore the
/// new values are transitively rooted for the lifetime of their new owner.
pub trait UnrootedPushable<T> {
fn push_unrooted(&mut self, val: Unrooted<T>);
}
impl<T: Reflectable> UnrootedPushable<T> for Vec<JS<T>> {
fn push_unrooted(&mut self, val: Unrooted<T>) {
unsafe { self.push(val.inner()) };
}
}
#[deriving(Eq, Clone)]
struct RootReference(*JSObject);
impl RootReference {
fn new<'a, T: Reflectable>(unrooted: &Root<'a, T>) -> RootReference {
fn new<'a, 'b, T: Reflectable>(unrooted: &Root<'a, 'b, T>) -> RootReference {
RootReference(unrooted.rooted())
}
@ -126,6 +251,7 @@ impl RootReference {
static MAX_STACK_ROOTS: uint = 10;
/// An opaque, LIFO rooting mechanism.
pub struct RootCollection {
roots: [Cell<RootReference>, ..MAX_STACK_ROOTS],
current: Cell<uint>,
@ -139,7 +265,7 @@ impl RootCollection {
}
}
fn new_root<'a, T: Reflectable>(&'a self, unrooted: &JS<T>) -> Root<'a, T> {
fn new_root<'a, 'b, T: Reflectable>(&'a self, unrooted: &JS<T>) -> Root<'a, 'b, T> {
Root::new(self, unrooted)
}
@ -147,13 +273,15 @@ impl RootCollection {
let current = self.current.get();
assert!(current < MAX_STACK_ROOTS);
self.roots[current].set(unrooted);
debug!(" rooting {:?}", unrooted);
self.current.set(current + 1);
}
fn root<'a, T: Reflectable>(&self, unrooted: &Root<'a, T>) {
fn root<'a, 'b, T: Reflectable>(&self, unrooted: &Root<'a, 'b, T>) {
self.root_impl(RootReference::new(unrooted));
}
/// Root a raw JS pointer.
pub fn root_raw(&self, unrooted: *JSObject) {
self.root_impl(RootReference(unrooted));
}
@ -162,29 +290,41 @@ impl RootCollection {
let mut current = self.current.get();
assert!(current != 0);
current -= 1;
debug!("unrooting {:?} (expecting {:?}", self.roots[current].get(), rooted);
assert!(self.roots[current].get() == rooted);
self.roots[current].set(RootReference::null());
self.current.set(current);
}
fn unroot<'a, T: Reflectable>(&self, rooted: &Root<'a, T>) {
fn unroot<'a, 'b, T: Reflectable>(&self, rooted: &Root<'a, 'b, T>) {
self.unroot_impl(RootReference::new(rooted));
}
/// Unroot a raw JS pointer. Must occur in reverse order to its rooting.
pub fn unroot_raw(&self, rooted: *JSObject) {
self.unroot_impl(RootReference(rooted));
}
}
pub struct Root<'a, T> {
/// A rooted JS value. The JS value is pinned for the duration of this object's lifetime;
/// roots are additive, so this object's destruction will not invalidate other roots
/// for the same JS value. Roots cannot outlive the associated RootCollection object.
/// Attempts to transfer ownership of a Root via moving will trigger dynamic unrooting
/// failures due to incorrect ordering.
pub struct Root<'a, 'b, T> {
root_list: &'a RootCollection,
jsref: JSRef<'b, T>,
ptr: RefCell<*mut T>,
}
impl<'a, T: Reflectable> Root<'a, T> {
fn new(roots: &'a RootCollection, unrooted: &JS<T>) -> Root<'a, T> {
impl<'a, 'b, T: Reflectable> Root<'a, 'b, T> {
fn new(roots: &'a RootCollection, unrooted: &JS<T>) -> Root<'a, 'b, T> {
let root = Root {
root_list: roots,
jsref: JSRef {
ptr: unrooted.ptr.clone(),
chain: unsafe { ::std::cast::transmute_region(&()) },
},
ptr: unrooted.ptr.clone()
};
roots.root(&root);
@ -209,24 +349,27 @@ impl<'a, T: Reflectable> Root<'a, T> {
self.reflector().get_jsobject()
}
fn internal_root_ref<'a>(&'a self) -> &'a JSRef<'b, T> {
&'a self.jsref
}
fn mut_internal_root_ref<'a>(&'a mut self) -> &'a mut JSRef<'b, T> {
&'a mut self.jsref
}
pub fn root_ref<'b>(&'b self) -> JSRef<'b,T> {
unsafe {
JSRef {
ptr: self.ptr.clone(),
chain: ::std::cast::transmute_region(&()),
}
}
self.internal_root_ref().clone()
}
}
#[unsafe_destructor]
impl<'a, T: Reflectable> Drop for Root<'a, T> {
impl<'a, 'b, T: Reflectable> Drop for Root<'a, 'b, T> {
fn drop(&mut self) {
self.root_list.unroot(self);
}
}
impl<'a, T: Reflectable> Reflectable for Root<'a, T> {
impl<'a, 'b, T: Reflectable> Reflectable for Root<'a, 'b, T> {
fn reflector<'a>(&'a self) -> &'a Reflector {
self.get().reflector()
}
@ -236,17 +379,29 @@ impl<'a, T: Reflectable> Reflectable for Root<'a, T> {
}
}
/*impl<'a, T> Deref for Root<'a, T> {
fn deref<'a>(&'a self) -> &'a T {
impl<'a, 'b, T: Reflectable> Deref<JSRef<'b, T>> for Root<'a, 'b, T> {
fn deref<'c>(&'c self) -> &'c JSRef<'b, T> {
self.internal_root_ref()
}
}
impl<'a, 'b, T: Reflectable> DerefMut<JSRef<'b, T>> for Root<'a, 'b, T> {
fn deref_mut<'c>(&'c mut self) -> &'c mut JSRef<'b, T> {
self.mut_internal_root_ref()
}
}
impl<'a, T: Reflectable> Deref<T> for JSRef<'a, T> {
fn deref<'b>(&'b self) -> &'b T {
self.get()
}
}
impl<'a, T> DerefMut for Root<'a, T> {
fn deref_mut<'a>(&'a mut self) -> &'a mut T {
impl<'a, T: Reflectable> DerefMut<T> for JSRef<'a, T> {
fn deref_mut<'b>(&'b mut self) -> &'b mut T {
self.get_mut()
}
}*/
}
/// Encapsulates a reference to something that is guaranteed to be alive. This is freely copyable.
pub struct JSRef<'a, T> {

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::PrototypeList;
use dom::bindings::codegen::PrototypeList::MAX_PROTO_CHAIN_LENGTH;
use dom::bindings::conversions::{FromJSValConvertible, IDLInterface};
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::trace::Untraceable;
use dom::browsercontext;
use dom::window;
@ -391,7 +391,7 @@ pub fn reflect_dom_object<T: Reflectable>
(obj: ~T,
window: &JSRef<window::Window>,
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<window::Window>, ~T) -> JS<T>)
-> JS<T> {
-> Unrooted<T> {
JS::new(obj, window, wrap_fn)
}
@ -613,18 +613,20 @@ pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject
}
/// Returns the global object of the realm that the given JS object was created in.
pub fn global_object_for_js_object(obj: *JSObject) -> JS<window::Window> {
pub fn global_object_for_js_object(obj: *JSObject) -> Unrooted<window::Window> {
unsafe {
let global = GetGlobalForObjectCrossCompartment(obj);
let clasp = JS_GetClass(global);
assert!(((*clasp).flags & (JSCLASS_IS_DOMJSCLASS | JSCLASS_IS_GLOBAL)) != 0);
FromJSValConvertible::from_jsval(ptr::null(), ObjectOrNullValue(global), ())
.ok().expect("found DOM global that doesn't unwrap to Window")
Unrooted::new(
FromJSValConvertible::from_jsval(ptr::null(), ObjectOrNullValue(global), ())
.ok().expect("found DOM global that doesn't unwrap to Window"))
}
}
fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
let win = global_object_for_js_object(obj);
let roots = RootCollection::new();
let win = global_object_for_js_object(obj).root(&roots);
let js_info = win.get().page().js_info();
match *js_info {
Some(ref info) => info.js_context.deref().deref().ptr,

View file

@ -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, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::error::Fallible;
use dom::bindings::codegen::BindingDeclarations::BlobBinding;
@ -23,7 +23,7 @@ impl Blob {
}
}
pub fn new(window: &JSRef<Window>) -> JS<Blob> {
pub fn new(window: &JSRef<Window>) -> Unrooted<Blob> {
reflect_dom_object(~Blob::new_inherited(window.unrooted()),
window,
BlobBinding::Wrap)
@ -31,7 +31,7 @@ impl Blob {
}
impl Blob {
pub fn Constructor(window: &JSRef<Window>) -> Fallible<JS<Blob>> {
pub fn Constructor(window: &JSRef<Window>) -> Fallible<Unrooted<Blob>> {
Ok(Blob::new(window))
}
@ -43,7 +43,7 @@ impl Blob {
~""
}
pub fn Slice(&self, _start: Option<i64>, _end: Option<i64>, _contentType: Option<DOMString>) -> JS<Blob> {
pub fn Slice(&self, _start: Option<i64>, _end: Option<i64>, _contentType: Option<DOMString>) -> Unrooted<Blob> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
Blob::new(&window.root_ref())

View file

@ -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};
use dom::bindings::trace::Traceable;
use dom::bindings::utils::Reflectable;
use dom::document::Document;
@ -22,7 +22,7 @@ pub struct BrowserContext {
}
impl BrowserContext {
pub fn new(document: &JS<Document>) -> BrowserContext {
pub fn new(document: &JSRef<Document>) -> BrowserContext {
let mut context = BrowserContext {
history: vec!(SessionHistoryEntry::new(document)),
active_index: 0,
@ -71,9 +71,9 @@ pub struct SessionHistoryEntry {
}
impl SessionHistoryEntry {
fn new(document: &JS<Document>) -> SessionHistoryEntry {
fn new(document: &JSRef<Document>) -> SessionHistoryEntry {
SessionHistoryEntry {
document: document.clone(),
document: document.unrooted(),
children: vec!()
}
}

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::BindingDeclarations::ClientRectBinding;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window;
use servo_util::geometry::Au;
@ -34,7 +34,7 @@ impl ClientRect {
pub fn new(window: &JSRef<Window>,
top: Au, bottom: Au,
left: Au, right: Au) -> JS<ClientRect> {
left: Au, right: Au) -> Unrooted<ClientRect> {
let rect = ClientRect::new_inherited(window.unrooted(), top, bottom, left, right);
reflect_dom_object(~rect, window, ClientRectBinding::Wrap)
}

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::BindingDeclarations::ClientRectListBinding;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::clientrect::ClientRect;
use dom::window::Window;
@ -17,16 +17,16 @@ pub struct ClientRectList {
impl ClientRectList {
pub fn new_inherited(window: JS<Window>,
rects: Vec<JS<ClientRect>>) -> ClientRectList {
rects: Vec<JSRef<ClientRect>>) -> ClientRectList {
ClientRectList {
reflector_: Reflector::new(),
rects: rects,
rects: rects.iter().map(|rect| rect.unrooted()).collect(),
window: window,
}
}
pub fn new(window: &JSRef<Window>,
rects: Vec<JS<ClientRect>>) -> JS<ClientRectList> {
rects: Vec<JSRef<ClientRect>>) -> Unrooted<ClientRectList> {
reflect_dom_object(~ClientRectList::new_inherited(window.unrooted(), rects),
window, ClientRectListBinding::Wrap)
}
@ -35,15 +35,15 @@ impl ClientRectList {
self.rects.len() as u32
}
pub fn Item(&self, index: u32) -> Option<JS<ClientRect>> {
pub fn Item(&self, index: u32) -> Option<Unrooted<ClientRect>> {
if index < self.rects.len() as u32 {
Some(self.rects.get(index as uint).clone())
Some(Unrooted::new(self.rects.get(index as uint).clone()))
} else {
None
}
}
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<JS<ClientRect>> {
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Unrooted<ClientRect>> {
*found = index < self.rects.len() as u32;
self.Item(index)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::InheritTypes::CommentDerived;
use dom::bindings::codegen::BindingDeclarations::CommentBinding;
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::error::Fallible;
use dom::characterdata::CharacterData;
use dom::document::Document;
@ -35,12 +35,12 @@ impl Comment {
}
}
pub fn new(text: DOMString, document: &JSRef<Document>) -> JS<Comment> {
pub fn new(text: DOMString, document: &JSRef<Document>) -> Unrooted<Comment> {
let node = Comment::new_inherited(text, document.unrooted());
Node::reflect_node(~node, document, CommentBinding::Wrap)
}
pub fn Constructor(owner: &JSRef<Window>, data: DOMString) -> Fallible<JS<Comment>> {
pub fn Constructor(owner: &JSRef<Window>, data: DOMString) -> Fallible<Unrooted<Comment>> {
let roots = RootCollection::new();
let document = owner.get().Document();
let document = document.root(&roots);

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::BindingDeclarations::ConsoleBinding;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JSRef, Unrooted};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window;
use servo_util::str::DOMString;
@ -20,7 +20,7 @@ impl Console {
}
}
pub fn new(window: &JSRef<Window>) -> JS<Console> {
pub fn new(window: &JSRef<Window>) -> Unrooted<Console> {
reflect_dom_object(~Console::new_inherited(), window, ConsoleBinding::Wrap)
}

View file

@ -3,11 +3,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLElementCast};
use dom::bindings::codegen::InheritTypes::{DocumentBase, NodeCast, DocumentCast};
use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, TextCast, ElementCast};
use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast};
use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast};
use dom::bindings::codegen::BindingDeclarations::DocumentBinding;
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalAssignable};
use dom::bindings::js::OptionalRootable;
use dom::bindings::trace::Untraceable;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::error::{ErrorResult, Fallible, NotSupported, InvalidCharacter, HierarchyRequest, NamespaceError};
@ -22,14 +22,14 @@ use dom::element::{HTMLBodyElementTypeId, HTMLFrameSetElementTypeId};
use dom::event::Event;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlcollection::{HTMLCollection, CollectionFilter};
use dom::nodelist::NodeList;
use dom::htmlelement::HTMLElement;
use dom::htmlheadelement::HTMLHeadElement;
use dom::htmlhtmlelement::HTMLHtmlElement;
use dom::htmltitleelement::HTMLTitleElement;
use dom::mouseevent::MouseEvent;
use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, INode};
use dom::node::{CloneChildren, DoNotCloneChildren};
use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, AppendChild};
use dom::node::{CloneChildren, DoNotCloneChildren, RemoveChild, ReplaceChild};
use dom::nodelist::NodeList;
use dom::text::Text;
use dom::processinginstruction::ProcessingInstruction;
use dom::uievent::UIEvent;
@ -77,21 +77,19 @@ impl DocumentDerived for EventTarget {
}
impl Document {
pub fn reflect_document<D: Reflectable+DocumentBase>
(document: ~D,
window: &JSRef<Window>,
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, ~D) -> JS<D>)
-> JS<D> {
pub fn reflect_document(document: ~Document,
window: &JSRef<Window>,
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, ~Document) -> JS<Document>)
-> Unrooted<Document> {
let roots = RootCollection::new();
assert!(document.reflector().get_jsobject().is_null());
let raw_doc = reflect_dom_object(document, window, wrap_fn);
let mut raw_doc = reflect_dom_object(document, window, wrap_fn).root(&roots);
assert!(raw_doc.reflector().get_jsobject().is_not_null());
let document = DocumentCast::from(&raw_doc);
let document_root = document.root(&roots);
let mut node: JS<Node> = NodeCast::from(&document);
node.get_mut().set_owner_doc(&document_root.root_ref());
raw_doc
let mut doc_alias = raw_doc.clone();
let node: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut doc_alias);
node.get_mut().set_owner_doc(&*raw_doc);
Unrooted::new_rooted(&*raw_doc)
}
pub fn new_inherited(window: JS<Window>,
@ -124,7 +122,7 @@ impl Document {
}
}
pub fn new(window: &JSRef<Window>, url: Option<Url>, doctype: IsHTMLDocument, content_type: Option<DOMString>) -> JS<Document> {
pub fn new(window: &JSRef<Window>, url: Option<Url>, doctype: IsHTMLDocument, content_type: Option<DOMString>) -> Unrooted<Document> {
let document = Document::new_inherited(window.unrooted(), url, doctype, content_type);
Document::reflect_document(~document, window, DocumentBinding::Wrap)
}
@ -138,7 +136,7 @@ impl Document {
impl Document {
// http://dom.spec.whatwg.org/#dom-document
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<JS<Document>> {
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Unrooted<Document>> {
Ok(Document::new(owner, None, NonHTMLDocument, None))
}
}
@ -155,13 +153,13 @@ impl Reflectable for Document {
impl Document {
// http://dom.spec.whatwg.org/#dom-document-implementation
pub fn Implementation(&mut self) -> JS<DOMImplementation> {
pub fn Implementation(&mut self) -> Unrooted<DOMImplementation> {
if self.implementation.is_none() {
let roots = RootCollection::new();
let window = self.window.root(&roots);
self.implementation = Some(DOMImplementation::new(&window.root_ref()));
self.implementation.assign(Some(DOMImplementation::new(&*window)));
}
self.implementation.get_ref().clone()
Unrooted::new(self.implementation.get_ref().clone())
}
// http://dom.spec.whatwg.org/#dom-document-url
@ -205,25 +203,29 @@ impl Document {
}
// http://dom.spec.whatwg.org/#dom-document-doctype
pub fn GetDoctype(&self) -> Option<JS<DocumentType>> {
self.node.children().find(|child| child.is_doctype())
.map(|node| DocumentTypeCast::to(&node).unwrap())
pub fn GetDoctype(&self) -> Option<Unrooted<DocumentType>> {
self.node.children().find(|child| {
child.is_doctype()
}).map(|node| {
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(&node).unwrap();
Unrooted::new(doctype.unrooted())
})
}
// http://dom.spec.whatwg.org/#dom-document-documentelement
pub fn GetDocumentElement(&self) -> Option<JS<Element>> {
self.node.child_elements().next()
pub fn GetDocumentElement(&self) -> Option<Unrooted<Element>> {
self.node.child_elements().next().map(|elem| Unrooted::new_rooted(&elem))
}
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagname
pub fn GetElementsByTagName(&self, abstract_self: &JSRef<Document>, tag_name: DOMString) -> JS<HTMLCollection> {
pub fn GetElementsByTagName(&self, abstract_self: &JSRef<Document>, tag_name: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
HTMLCollection::by_tag_name(&window.root_ref(), NodeCast::from_ref(abstract_self), tag_name)
HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), tag_name)
}
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens
pub fn GetElementsByTagNameNS(&self, abstract_self: &JSRef<Document>, maybe_ns: Option<DOMString>, tag_name: DOMString) -> JS<HTMLCollection> {
pub fn GetElementsByTagNameNS(&self, abstract_self: &JSRef<Document>, maybe_ns: Option<DOMString>, tag_name: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
@ -231,28 +233,28 @@ impl Document {
Some(namespace) => Namespace::from_str(namespace),
None => Null
};
HTMLCollection::by_tag_name_ns(&window.root_ref(), NodeCast::from_ref(abstract_self), tag_name, namespace)
HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(abstract_self), tag_name, namespace)
}
// http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname
pub fn GetElementsByClassName(&self, abstract_self: &JSRef<Document>, classes: DOMString) -> JS<HTMLCollection> {
pub fn GetElementsByClassName(&self, abstract_self: &JSRef<Document>, classes: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
HTMLCollection::by_class_name(&window.root_ref(), NodeCast::from_ref(abstract_self), classes)
HTMLCollection::by_class_name(&*window, NodeCast::from_ref(abstract_self), classes)
}
// http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
pub fn GetElementById(&self, id: DOMString) -> Option<JS<Element>> {
pub fn GetElementById(&self, id: DOMString) -> Option<Unrooted<Element>> {
match self.idmap.find_equiv(&id) {
None => None,
Some(ref elements) => Some(elements.get(0).clone()),
Some(ref elements) => Some(Unrooted::new(elements.get(0).clone())),
}
}
// http://dom.spec.whatwg.org/#dom-document-createelement
pub fn CreateElement(&self, abstract_self: &JSRef<Document>, local_name: DOMString)
-> Fallible<JS<Element>> {
-> Fallible<Unrooted<Element>> {
if xml_name_type(local_name) == InvalidXMLName {
debug!("Not a valid element name");
return Err(InvalidCharacter);
@ -264,7 +266,7 @@ impl Document {
// http://dom.spec.whatwg.org/#dom-document-createelementns
pub fn CreateElementNS(&self, abstract_self: &JSRef<Document>,
namespace: Option<DOMString>,
qualified_name: DOMString) -> Fallible<JS<Element>> {
qualified_name: DOMString) -> Fallible<Unrooted<Element>> {
let ns = Namespace::from_str(null_str_as_empty_ref(&namespace));
match xml_name_type(qualified_name) {
InvalidXMLName => {
@ -308,24 +310,24 @@ impl Document {
}
// http://dom.spec.whatwg.org/#dom-document-createdocumentfragment
pub fn CreateDocumentFragment(&self, abstract_self: &JSRef<Document>) -> JS<DocumentFragment> {
pub fn CreateDocumentFragment(&self, abstract_self: &JSRef<Document>) -> Unrooted<DocumentFragment> {
DocumentFragment::new(abstract_self)
}
// http://dom.spec.whatwg.org/#dom-document-createtextnode
pub fn CreateTextNode(&self, abstract_self: &JSRef<Document>, data: DOMString)
-> JS<Text> {
-> Unrooted<Text> {
Text::new(data, abstract_self)
}
// http://dom.spec.whatwg.org/#dom-document-createcomment
pub fn CreateComment(&self, abstract_self: &JSRef<Document>, data: DOMString) -> JS<Comment> {
pub fn CreateComment(&self, abstract_self: &JSRef<Document>, data: DOMString) -> Unrooted<Comment> {
Comment::new(data, abstract_self)
}
// http://dom.spec.whatwg.org/#dom-document-createprocessinginstruction
pub fn CreateProcessingInstruction(&self, abstract_self: &JSRef<Document>, target: DOMString,
data: DOMString) -> Fallible<JS<ProcessingInstruction>> {
data: DOMString) -> Fallible<Unrooted<ProcessingInstruction>> {
// Step 1.
if xml_name_type(target) == InvalidXMLName {
return Err(InvalidCharacter);
@ -341,9 +343,9 @@ impl Document {
}
// http://dom.spec.whatwg.org/#dom-document-importnode
pub fn ImportNode(&self, abstract_self: &JSRef<Document>, node: &JSRef<Node>, deep: bool) -> Fallible<JS<Node>> {
pub fn ImportNode(&self, abstract_self: &JSRef<Document>, node: &JSRef<Node>, deep: bool) -> Fallible<Unrooted<Node>> {
// Step 1.
if node.unrooted().is_document() {
if node.is_document() {
return Err(NotSupported);
}
@ -357,30 +359,29 @@ impl Document {
}
// http://dom.spec.whatwg.org/#dom-document-adoptnode
pub fn AdoptNode(&self, abstract_self: &JSRef<Document>, node: &JSRef<Node>) -> Fallible<JS<Node>> {
pub fn AdoptNode(&self, abstract_self: &JSRef<Document>, node: &mut JSRef<Node>) -> Fallible<Unrooted<Node>> {
// Step 1.
if node.unrooted().is_document() {
if node.is_document() {
return Err(NotSupported);
}
// Step 2.
let mut adoptee = node.clone();
Node::adopt(&mut adoptee, abstract_self);
Node::adopt(node, abstract_self);
// Step 3.
Ok(adoptee.unrooted())
Ok(Unrooted::new_rooted(node))
}
// http://dom.spec.whatwg.org/#dom-document-createevent
pub fn CreateEvent(&self, interface: DOMString) -> Fallible<JS<Event>> {
pub fn CreateEvent(&self, interface: DOMString) -> Fallible<Unrooted<Event>> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
match interface.to_ascii_lower().as_slice() {
// FIXME: Implement CustomEvent (http://dom.spec.whatwg.org/#customevent)
"uievents" | "uievent" => Ok(EventCast::from(&UIEvent::new(&window.root_ref()))),
"mouseevents" | "mouseevent" => Ok(EventCast::from(&MouseEvent::new(&window.root_ref()))),
"htmlevents" | "events" | "event" => Ok(Event::new(&window.root_ref())),
"uievents" | "uievent" => Ok(EventCast::from_unrooted(UIEvent::new(&*window))),
"mouseevents" | "mouseevent" => Ok(EventCast::from_unrooted(MouseEvent::new(&*window))),
"htmlevents" | "events" | "event" => Ok(Event::new(&*window)),
_ => Err(NotSupported)
}
}
@ -388,14 +389,15 @@ impl Document {
// http://www.whatwg.org/specs/web-apps/current-work/#document.title
pub fn Title(&self, _: &JSRef<Document>) -> DOMString {
let mut title = ~"";
self.GetDocumentElement().map(|root| {
let root: JS<Node> = NodeCast::from(&root);
root.traverse_preorder()
let roots = RootCollection::new();
self.GetDocumentElement().root(&roots).map(|root| {
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
root.traverse_preorder(&roots)
.find(|node| node.type_id() == ElementNodeTypeId(HTMLTitleElementTypeId))
.map(|title_elem| {
for child in title_elem.children() {
for child in title_elem.deref().children() {
if child.is_text() {
let text: JS<Text> = TextCast::to(&child).unwrap();
let text: &JSRef<Text> = TextCast::to_ref(&child).unwrap();
title.push_str(text.get().characterdata.data.as_slice());
}
}
@ -410,9 +412,9 @@ impl Document {
pub fn SetTitle(&self, abstract_self: &JSRef<Document>, title: DOMString) -> ErrorResult {
let roots = RootCollection::new();
self.GetDocumentElement().map(|root| {
let root: JS<Node> = NodeCast::from(&root);
let mut head_node = root.traverse_preorder().find(|child| {
self.GetDocumentElement().root(&roots).map(|root| {
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
let mut head_node = root.traverse_preorder(&roots).find(|child| {
child.get().type_id == ElementNodeTypeId(HTMLHeadElementTypeId)
});
head_node.as_mut().map(|head| {
@ -422,25 +424,21 @@ impl Document {
match title_node {
Some(ref mut title_node) => {
for title_child in title_node.children() {
let title_child = title_child.root(&roots);
assert!(title_node.RemoveChild(&mut title_child.root_ref()).is_ok());
for mut title_child in title_node.children() {
assert!(RemoveChild(&mut *title_node, &mut title_child).is_ok());
}
let new_text = self.CreateTextNode(abstract_self, title.clone());
let new_text = new_text.root(&roots);
let mut new_text = self.CreateTextNode(abstract_self, title.clone()).root(&roots);
assert!(title_node.AppendChild(NodeCast::from_mut_ref(&mut new_text.root_ref())).is_ok());
assert!(AppendChild(&mut *title_node, NodeCast::from_mut_ref(&mut *new_text)).is_ok());
},
None => {
let mut new_title: JS<Node> =
NodeCast::from(&HTMLTitleElement::new(~"title", abstract_self));
let new_title_root = new_title.root(&roots);
let mut new_title = HTMLTitleElement::new(~"title", abstract_self).root(&roots);
let new_title: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut *new_title);
let new_text = self.CreateTextNode(abstract_self, title.clone());
let new_text = new_text.root(&roots);
let mut new_text = self.CreateTextNode(abstract_self, title.clone()).root(&roots);
assert!(new_title.AppendChild(NodeCast::from_mut_ref(&mut new_text.root_ref())).is_ok());
assert!(head.AppendChild(&mut new_title_root.root_ref()).is_ok());
assert!(AppendChild(&mut *new_title, NodeCast::from_mut_ref(&mut *new_text)).is_ok());
assert!(AppendChild(&mut *head, &mut *new_title).is_ok());
},
}
});
@ -448,33 +446,44 @@ impl Document {
Ok(())
}
fn get_html_element(&self) -> Option<JS<HTMLHtmlElement>> {
self.GetDocumentElement().filtered(|root| {
root.get().node.type_id == ElementNodeTypeId(HTMLHtmlElementTypeId)
}).map(|elem| HTMLHtmlElementCast::to(&elem).unwrap())
fn get_html_element(&self) -> Option<Unrooted<HTMLHtmlElement>> {
let roots = RootCollection::new();
self.GetDocumentElement().root(&roots).filtered(|root| {
root.node.type_id == ElementNodeTypeId(HTMLHtmlElementTypeId)
}).map(|elem| {
Unrooted::new_rooted(HTMLHtmlElementCast::to_ref(&*elem).unwrap())
})
}
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-head
pub fn GetHead(&self) -> Option<JS<HTMLHeadElement>> {
pub fn GetHead(&self) -> Option<Unrooted<HTMLHeadElement>> {
let roots = RootCollection::new();
self.get_html_element().and_then(|root| {
let node: JS<Node> = NodeCast::from(&root);
let root = root.root(&roots);
let node: &JSRef<Node> = NodeCast::from_ref(&*root);
node.children().find(|child| {
child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId)
}).map(|node| HTMLHeadElementCast::to(&node).unwrap())
}).map(|node| {
Unrooted::new_rooted(HTMLHeadElementCast::to_ref(&node).unwrap())
})
})
}
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body
pub fn GetBody(&self, _: &JSRef<Document>) -> Option<JS<HTMLElement>> {
pub fn GetBody(&self, _: &JSRef<Document>) -> Option<Unrooted<HTMLElement>> {
let roots = RootCollection::new();
self.get_html_element().and_then(|root| {
let node: JS<Node> = NodeCast::from(&root);
let root = root.root(&roots);
let node: &JSRef<Node> = NodeCast::from_ref(&*root);
node.children().find(|child| {
match child.type_id() {
ElementNodeTypeId(HTMLBodyElementTypeId) |
ElementNodeTypeId(HTMLFrameSetElementTypeId) => true,
_ => false
}
}).map(|node| HTMLElementCast::to(&node).unwrap())
}).map(|node| {
Unrooted::new_rooted(HTMLElementCast::to_ref(&node).unwrap())
})
})
}
@ -494,28 +503,28 @@ impl Document {
}
// Step 2.
let old_body: Option<JS<HTMLElement>> = self.GetBody(abstract_self);
if old_body == new_body.as_ref().map(|new_body| new_body.unrooted()) {
let mut old_body = self.GetBody(abstract_self).root(&roots);
//FIXME: covariant lifetime workaround. do not judge.
if old_body.as_ref().map(|body| body.deref()) == new_body.as_ref().map(|a| &*a) {
return Ok(());
}
// Step 3.
match self.get_html_element() {
match self.get_html_element().root(&roots) {
// Step 4.
None => return Err(HierarchyRequest),
Some(root) => {
Some(ref mut root) => {
let mut new_body_unwrapped = new_body.unwrap();
let new_body: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut new_body_unwrapped);
let mut root: JS<Node> = NodeCast::from(&root);
let root: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut **root);
match old_body {
Some(child) => {
let child: JS<Node> = NodeCast::from(&child);
let child = child.root(&roots);
Some(ref mut child) => {
let child: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut **child);
assert!(root.ReplaceChild(new_body, &mut child.root_ref()).is_ok())
assert!(ReplaceChild(&mut *root, new_body, child).is_ok())
}
None => assert!(root.AppendChild(new_body).is_ok())
None => assert!(AppendChild(&mut *root, new_body).is_ok())
};
}
}
@ -523,20 +532,22 @@ impl Document {
}
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyname
pub fn GetElementsByName(&self, name: DOMString) -> JS<NodeList> {
pub fn GetElementsByName(&self, name: DOMString) -> Unrooted<NodeList> {
let roots = RootCollection::new();
self.createNodeList(|node| {
if !node.get().is_element() {
return false;
}
let element: JS<Element> = ElementCast::to(&node.unrooted()).unwrap();
element.get_attribute(Null, "name").map_or(false, |attr| {
attr.get().value_ref() == name
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
element.get_attribute(Null, "name").root(&roots).map_or(false, |mut attr| {
attr.value_ref() == name
})
})
}
pub fn Images(&self, abstract_self: &JSRef<Document>) -> JS<HTMLCollection> {
pub fn Images(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
@ -548,10 +559,10 @@ impl Document {
}
}
let filter = ~ImagesFilter;
HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter)
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter)
}
pub fn Embeds(&self, abstract_self: &JSRef<Document>) -> JS<HTMLCollection> {
pub fn Embeds(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
@ -563,15 +574,15 @@ impl Document {
}
}
let filter = ~EmbedsFilter;
HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter)
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter)
}
pub fn Plugins(&self, abstract_self: &JSRef<Document>) -> JS<HTMLCollection> {
pub fn Plugins(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> {
// FIXME: https://github.com/mozilla/servo/issues/1847
self.Embeds(abstract_self)
}
pub fn Links(&self, abstract_self: &JSRef<Document>) -> JS<HTMLCollection> {
pub fn Links(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
@ -580,14 +591,14 @@ impl Document {
impl CollectionFilter for LinksFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
(elem.get().local_name == ~"a" || elem.get().local_name == ~"area") &&
elem.unrooted().get_attribute(Null, "href").is_some()
elem.get_attribute(Null, "href").is_some()
}
}
let filter = ~LinksFilter;
HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter)
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter)
}
pub fn Forms(&self, abstract_self: &JSRef<Document>) -> JS<HTMLCollection> {
pub fn Forms(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
@ -599,10 +610,10 @@ impl Document {
}
}
let filter = ~FormsFilter;
HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter)
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter)
}
pub fn Scripts(&self, abstract_self: &JSRef<Document>) -> JS<HTMLCollection> {
pub fn Scripts(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
@ -614,10 +625,10 @@ impl Document {
}
}
let filter = ~ScriptsFilter;
HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter)
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter)
}
pub fn Anchors(&self, abstract_self: &JSRef<Document>) -> JS<HTMLCollection> {
pub fn Anchors(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
@ -625,14 +636,14 @@ impl Document {
struct AnchorsFilter;
impl CollectionFilter for AnchorsFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
elem.get().local_name == ~"a" && elem.unrooted().get_attribute(Null, "name").is_some()
elem.get().local_name == ~"a" && elem.get_attribute(Null, "name").is_some()
}
}
let filter = ~AnchorsFilter;
HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter)
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter)
}
pub fn Applets(&self, abstract_self: &JSRef<Document>) -> JS<HTMLCollection> {
pub fn Applets(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
@ -644,40 +655,39 @@ impl Document {
}
}
let filter = ~AppletsFilter;
HTMLCollection::create(&window.root_ref(), NodeCast::from_ref(abstract_self), filter)
HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter)
}
pub fn Location(&mut self, _abstract_self: &JSRef<Document>) -> JS<Location> {
pub fn Location(&mut self, _abstract_self: &JSRef<Document>) -> Unrooted<Location> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
self.window.get_mut().Location(&window.root_ref())
self.window.get_mut().Location(&*window)
}
pub fn Children(&self, abstract_self: &JSRef<Document>) -> JS<HTMLCollection> {
pub fn Children(&self, abstract_self: &JSRef<Document>) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self))
HTMLCollection::children(&*window, NodeCast::from_ref(abstract_self))
}
pub fn createNodeList(&self, callback: |node: &JSRef<Node>| -> bool) -> JS<NodeList> {
pub fn createNodeList(&self, callback: |node: &JSRef<Node>| -> bool) -> Unrooted<NodeList> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
let mut nodes = vec!();
match self.GetDocumentElement() {
match self.GetDocumentElement().root(&roots) {
None => {},
Some(root) => {
let root: JS<Node> = NodeCast::from(&root);
for child in root.traverse_preorder() {
let child = child.root(&roots);
if callback(&child.root_ref()) {
nodes.push(child.root_ref().unrooted());
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
for child in root.traverse_preorder(&roots) {
if callback(&child) {
nodes.push(child);
}
}
}
}
NodeList::new_simple_list(&window.root_ref(), nodes)
NodeList::new_simple_list(&*window, nodes)
}
pub fn content_changed(&self) {
@ -697,12 +707,14 @@ impl Document {
pub fn unregister_named_element(&mut self,
abstract_self: &JSRef<Element>,
id: DOMString) {
let roots = RootCollection::new();
let mut is_empty = false;
match self.idmap.find_mut(&id) {
None => {},
Some(elements) => {
let position = elements.iter()
.position(|element| element == &abstract_self.unrooted())
.map(|elem| elem.root(&roots))
.position(|element| &*element == abstract_self)
.expect("This element should be in registered.");
elements.remove(position);
is_empty = elements.is_empty();
@ -717,26 +729,28 @@ impl Document {
pub fn register_named_element(&mut self,
element: &JSRef<Element>,
id: DOMString) {
let roots = RootCollection::new();
assert!({
let node: JS<Node> = NodeCast::from(&element.unrooted());
let node: &JSRef<Node> = NodeCast::from_ref(element);
node.is_in_doc()
});
// FIXME https://github.com/mozilla/rust/issues/13195
// Use mangle() when it exists again.
let root = self.GetDocumentElement().expect("The element is in the document, so there must be a document element.");
let root = self.GetDocumentElement().expect("The element is in the document, so there must be a document element.").root(&roots);
match self.idmap.find_mut(&id) {
Some(elements) => {
let new_node = NodeCast::from_ref(element);
let new_node: &JSRef<Node> = NodeCast::from_ref(element);
let mut head : uint = 0u;
let root: JS<Node> = NodeCast::from(&root);
for node in root.traverse_preorder() {
match ElementCast::to(&node) {
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
for node in root.traverse_preorder(&roots) {
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&node);
match elem {
Some(elem) => {
if elements.get(head) == &elem {
if elements.get(head) == &elem.unrooted() {
head = head + 1;
}
if new_node.unrooted() == node || head == elements.len() {
if new_node == &node || head == elements.len() {
break;
}
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast};
use dom::bindings::codegen::BindingDeclarations::DocumentFragmentBinding;
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::error::Fallible;
use dom::document::Document;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -34,14 +34,14 @@ impl DocumentFragment {
}
}
pub fn new(document: &JSRef<Document>) -> JS<DocumentFragment> {
pub fn new(document: &JSRef<Document>) -> Unrooted<DocumentFragment> {
let node = DocumentFragment::new_inherited(document.unrooted());
Node::reflect_node(~node, document, DocumentFragmentBinding::Wrap)
}
}
impl DocumentFragment {
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<JS<DocumentFragment>> {
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Unrooted<DocumentFragment>> {
let roots = RootCollection::new();
let document = owner.get().Document();
let document = document.root(&roots);
@ -51,9 +51,9 @@ impl DocumentFragment {
}
impl DocumentFragment {
pub fn Children(&self, abstract_self: &JSRef<DocumentFragment>) -> JS<HTMLCollection> {
pub fn Children(&self, abstract_self: &JSRef<DocumentFragment>) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = window_from_node(&abstract_self.unrooted()).root(&roots);
let window = window_from_node(abstract_self).root(&roots);
HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self))
}
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::InheritTypes::DocumentTypeDerived;
use dom::bindings::codegen::BindingDeclarations::DocumentTypeBinding;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::node::{Node, DoctypeNodeTypeId};
@ -46,7 +46,7 @@ impl DocumentType {
public_id: Option<DOMString>,
system_id: Option<DOMString>,
document: &JSRef<Document>)
-> JS<DocumentType> {
-> Unrooted<DocumentType> {
let documenttype = DocumentType::new_inherited(name,
public_id,
system_id,

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::DOMExceptionBinding;
use dom::bindings::codegen::BindingDeclarations::DOMExceptionBinding::DOMExceptionConstants;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JSRef, Unrooted};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::window::Window;
use servo_util::str::DOMString;
@ -49,7 +49,7 @@ impl DOMException {
}
}
pub fn new(window: &JSRef<Window>, code: DOMErrorName) -> JS<DOMException> {
pub fn new(window: &JSRef<Window>, code: DOMErrorName) -> Unrooted<DOMException> {
reflect_dom_object(~DOMException::new_inherited(code), window, DOMExceptionBinding::Wrap)
}
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::DOMImplementationBinding;
use dom::bindings::codegen::InheritTypes::NodeCast;
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable};
use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
use dom::bindings::error::{Fallible, InvalidCharacter, NamespaceError};
use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type};
@ -14,7 +14,7 @@ use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlheadelement::HTMLHeadElement;
use dom::htmlhtmlelement::HTMLHtmlElement;
use dom::htmltitleelement::HTMLTitleElement;
use dom::node::{Node, INode};
use dom::node::{Node, AppendChild};
use dom::text::Text;
use dom::window::Window;
use servo_util::str::DOMString;
@ -33,7 +33,7 @@ impl DOMImplementation {
}
}
pub fn new(owner: &JSRef<Window>) -> JS<DOMImplementation> {
pub fn new(owner: &JSRef<Window>) -> Unrooted<DOMImplementation> {
reflect_dom_object(~DOMImplementation::new_inherited(owner.unrooted()), owner,
DOMImplementationBinding::Wrap)
}
@ -52,7 +52,7 @@ impl Reflectable for DOMImplementation {
// http://dom.spec.whatwg.org/#domimplementation
impl DOMImplementation {
// http://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype
pub fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible<JS<DocumentType>> {
pub fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible<Unrooted<DocumentType>> {
let roots = RootCollection::new();
match xml_name_type(qname) {
// Step 1.
@ -70,37 +70,39 @@ impl DOMImplementation {
// http://dom.spec.whatwg.org/#dom-domimplementation-createdocument
pub fn CreateDocument(&self, namespace: Option<DOMString>, qname: DOMString,
mut maybe_doctype: Option<JSRef<DocumentType>>) -> Fallible<JS<Document>> {
mut maybe_doctype: Option<JSRef<DocumentType>>) -> Fallible<Unrooted<Document>> {
let roots = RootCollection::new();
let win = self.owner.root(&roots);
// Step 1.
let doc = Document::new(&win.root_ref(), None, NonHTMLDocument, None);
let doc_root = doc.root(&roots);
let mut doc_node: JS<Node> = NodeCast::from(&doc);
let mut doc = Document::new(&win.root_ref(), None, NonHTMLDocument, None).root(&roots);
// Step 2-3.
let mut maybe_elem = if qname.is_empty() {
None
} else {
match doc.get().CreateElementNS(&doc_root.root_ref(), namespace, qname) {
match doc.get().CreateElementNS(&*doc, namespace, qname) {
Err(error) => return Err(error),
Ok(elem) => Some(elem)
}
};
// Step 4.
match maybe_doctype {
None => (),
Some(ref mut doctype) => assert!(doc_node.AppendChild(NodeCast::from_mut_ref(doctype)).is_ok())
}
{
let doc_node: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut *doc);
// Step 5.
match maybe_elem {
None => (),
Some(ref elem) => {
let elem = elem.root(&roots);
assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut elem.root_ref())).is_ok())
// Step 4.
match maybe_doctype {
None => (),
Some(ref mut doctype) => {
assert!(AppendChild(doc_node, NodeCast::from_mut_ref(doctype)).is_ok())
}
}
// Step 5.
match maybe_elem.root(&roots) {
None => (),
Some(mut elem) => {
assert!(AppendChild(doc_node, NodeCast::from_mut_ref(&mut *elem)).is_ok())
}
}
}
@ -108,65 +110,59 @@ impl DOMImplementation {
// FIXME: https://github.com/mozilla/servo/issues/1522
// Step 7.
Ok(doc)
Ok(Unrooted::new_rooted(&*doc))
}
// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
pub fn CreateHTMLDocument(&self, title: Option<DOMString>) -> JS<Document> {
pub fn CreateHTMLDocument(&self, title: Option<DOMString>) -> Unrooted<Document> {
let roots = RootCollection::new();
let owner = self.owner.root(&roots);
// Step 1-2.
let doc = Document::new(&owner.root_ref(), None, HTMLDocument, None);
let doc_root = doc.root(&roots);
let mut doc_node: JS<Node> = NodeCast::from(&doc);
let mut doc = Document::new(&owner.root_ref(), None, HTMLDocument, None).root(&roots);
let mut doc_alias = doc.clone();
let doc_node: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut doc_alias);
{
// Step 3.
let doc_type = DocumentType::new(~"html", None, None, &doc_root.root_ref());
let doc_type = doc_type.root(&roots);
assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut doc_type.root_ref())).is_ok());
let mut doc_type = DocumentType::new(~"html", None, None, &*doc).root(&roots);
assert!(AppendChild(&mut *doc_node, NodeCast::from_mut_ref(&mut *doc_type)).is_ok());
}
{
// Step 4.
let mut doc_html = NodeCast::from(&HTMLHtmlElement::new(~"html", &doc_root.root_ref()));
let doc_html_root = {doc_html.root(&roots)};
assert!(doc_node.AppendChild(&mut doc_html_root.root_ref()).is_ok());
let mut doc_html = NodeCast::from_unrooted(HTMLHtmlElement::new(~"html", &*doc)).root(&roots);
assert!(AppendChild(&mut *doc_node, &mut *doc_html).is_ok());
{
// Step 5.
let mut doc_head = NodeCast::from(&HTMLHeadElement::new(~"head", &doc_root.root_ref()));
let doc_head_root = doc_head.root(&roots);
assert!(doc_html.AppendChild(&mut doc_head_root.root_ref()).is_ok());
let mut doc_head = NodeCast::from_unrooted(HTMLHeadElement::new(~"head", &*doc)).root(&roots);
assert!(AppendChild(&mut *doc_html, &mut *doc_head).is_ok());
// Step 6.
match title {
None => (),
Some(title_str) => {
// Step 6.1.
let mut doc_title = NodeCast::from(&HTMLTitleElement::new(~"title", &doc_root.root_ref()));
let doc_title_root = doc_title.root(&roots);
assert!(doc_head.AppendChild(&mut doc_title_root.root_ref()).is_ok());
let mut doc_title = NodeCast::from_unrooted(HTMLTitleElement::new(~"title", &*doc)).root(&roots);
assert!(AppendChild(&mut *doc_head, &mut *doc_title).is_ok());
// Step 6.2.
let title_text = Text::new(title_str, &doc_root.root_ref());
let title_text = title_text.root(&roots);
assert!(doc_title.AppendChild(NodeCast::from_mut_ref(&mut title_text.root_ref())).is_ok());
let mut title_text = Text::new(title_str, &*doc).root(&roots);
assert!(AppendChild(&mut *doc_title, NodeCast::from_mut_ref(&mut *title_text)).is_ok());
}
}
}
// Step 7.
let doc_body = HTMLBodyElement::new(~"body", &doc_root.root_ref());
let doc_body = doc_body.root(&roots);
assert!(doc_html.AppendChild(NodeCast::from_mut_ref(&mut doc_body.root_ref())).is_ok());
let mut doc_body = HTMLBodyElement::new(~"body", &*doc).root(&roots);
assert!(AppendChild(&mut *doc_html, NodeCast::from_mut_ref(&mut *doc_body)).is_ok());
}
// Step 8.
// FIXME: https://github.com/mozilla/servo/issues/1522
// Step 9.
doc
Unrooted::new_rooted(&*doc)
}
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::DOMParserBinding;
use dom::bindings::codegen::BindingDeclarations::DOMParserBinding::SupportedTypeValues::{Text_html, Text_xml};
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
use dom::bindings::error::{Fallible, FailureUnknown};
use dom::document::{Document, HTMLDocument, NonHTMLDocument};
@ -25,19 +25,19 @@ impl DOMParser {
}
}
pub fn new(owner: &JSRef<Window>) -> JS<DOMParser> {
pub fn new(owner: &JSRef<Window>) -> Unrooted<DOMParser> {
reflect_dom_object(~DOMParser::new_inherited(owner.unrooted()), owner,
DOMParserBinding::Wrap)
}
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<JS<DOMParser>> {
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Unrooted<DOMParser>> {
Ok(DOMParser::new(owner))
}
pub fn ParseFromString(&self,
_s: DOMString,
ty: DOMParserBinding::SupportedType)
-> Fallible<JS<Document>> {
-> Fallible<Unrooted<Document>> {
let roots = RootCollection::new();
let owner = self.owner.root(&roots);
match ty {

View file

@ -4,11 +4,12 @@
//! Element nodes.
use dom::attr::{Attr, AttrSettingType, ReplacedAttr, FirstSetAttr};
use dom::attr::{Attr, ReplacedAttr, FirstSetAttr};
use dom::attrlist::AttrList;
use dom::bindings::codegen::BindingDeclarations::ElementBinding;
use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast};
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, UnrootedPushable};
use dom::bindings::js::{OptionalAssignable, OptionalRootable, Root};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::bindings::error::{ErrorResult, Fallible, NamespaceError, InvalidCharacter};
use dom::bindings::utils::{QName, Name, InvalidXMLName, xml_name_type};
@ -152,14 +153,15 @@ impl Element {
}
}
pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option<DOMString>, document: &JSRef<Document>) -> JS<Element> {
pub fn new(local_name: DOMString, namespace: Namespace, prefix: Option<DOMString>, document: &JSRef<Document>) -> Unrooted<Element> {
let element = Element::new_inherited(ElementTypeId, local_name, namespace, prefix, document.unrooted());
Node::reflect_node(~element, document, ElementBinding::Wrap)
}
pub fn html_element_in_html_document(&self) -> bool {
let roots = RootCollection::new();
self.namespace == namespace::HTML &&
self.node.owner_doc().get().is_html_document
self.node.owner_doc().root(&roots).is_html_document
}
}
@ -168,7 +170,7 @@ impl Element {
if self.namespace != namespace::HTML {
return false
}
let owner_doc: *JS<Document> = self.node.owner_doc();
let owner_doc: *JS<Document> = self.node.owner_doc_for_layout();
let owner_doc: **Document = owner_doc as **Document;
(**owner_doc).is_html_document
}
@ -189,15 +191,15 @@ impl Element {
}
pub trait AttributeHandlers {
fn get_attribute(&self, namespace: Namespace, name: &str) -> Option<JS<Attr>>;
fn get_attribute(&self, namespace: Namespace, name: &str) -> Option<Unrooted<Attr>>;
fn set_attr(&mut self, name: DOMString, value: DOMString) -> ErrorResult;
fn set_attribute(&mut self, namespace: Namespace, name: DOMString,
value: DOMString) -> ErrorResult;
fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString,
name: DOMString, namespace: Namespace,
prefix: Option<DOMString>, cb: |&JS<Attr>| -> bool);
fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult;
fn SetAttributeNS(&mut self, namespace_url: Option<DOMString>,
prefix: Option<DOMString>, cb: |&JSRef<Attr>| -> bool);
fn SetAttribute_(&mut self, name: DOMString, value: DOMString) -> ErrorResult;
fn SetAttributeNS_(&mut self, namespace_url: Option<DOMString>,
name: DOMString, value: DOMString) -> ErrorResult;
fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult;
@ -212,18 +214,18 @@ pub trait AttributeHandlers {
fn set_uint_attribute(&mut self, name: &str, value: u32);
}
impl AttributeHandlers for JS<Element> {
fn get_attribute(&self, namespace: Namespace, name: &str) -> Option<JS<Attr>> {
impl<'a> AttributeHandlers for JSRef<'a, Element> {
fn get_attribute(&self, namespace: Namespace, name: &str) -> Option<Unrooted<Attr>> {
if self.get().html_element_in_html_document() {
self.get().attrs.iter().find(|attr| {
let attr = attr.get();
name.to_ascii_lower() == attr.local_name && attr.namespace == namespace
}).map(|x| x.clone())
}).map(|x| Unrooted::new(x.clone()))
} else {
self.get().attrs.iter().find(|attr| {
let attr = attr.get();
name == attr.local_name && attr.namespace == namespace
}).map(|x| x.clone())
}).map(|x| Unrooted::new(x.clone()))
}
}
@ -245,10 +247,11 @@ impl AttributeHandlers for JS<Element> {
None => {}
}
let node: JS<Node> = NodeCast::from(self);
node.get().wait_until_safe_to_modify_dom();
let self_alias = self.clone();
let node: &JSRef<Node> = NodeCast::from_ref(&self_alias);
node.wait_until_safe_to_modify_dom();
let position: |&JS<Attr>| -> bool =
let position: |&JSRef<Attr>| -> bool =
if self.get().html_element_in_html_document() {
|attr| attr.get().local_name.eq_ignore_ascii_case(local_name)
} else {
@ -260,33 +263,31 @@ impl AttributeHandlers for JS<Element> {
fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString,
name: DOMString, namespace: Namespace,
prefix: Option<DOMString>, cb: |&JS<Attr>| -> bool) {
prefix: Option<DOMString>, cb: |&JSRef<Attr>| -> bool) {
let roots = RootCollection::new();
let node: JS<Node> = NodeCast::from(self);
let idx = self.get().attrs.iter().position(cb);
let (mut attr, set_type): (JS<Attr>, AttrSettingType) = match idx {
Some(idx) => {
let attr = self.get_mut().attrs.get(idx).clone();
(attr, ReplacedAttr)
}
let idx = self.get().attrs.iter()
.map(|attr| attr.root(&roots))
.position(|attr| cb(&*attr));
let (idx, set_type) = match idx {
Some(idx) => (idx, ReplacedAttr),
None => {
let doc = node.get().owner_doc().get();
let window = doc.window.root(&roots);
let attr = Attr::new(&window.root_ref(), local_name.clone(), value.clone(),
name, namespace.clone(), prefix, self.clone());
self.get_mut().attrs.push(attr.clone());
(attr, FirstSetAttr)
let window = window_from_node(self).root(&roots);
let attr = Attr::new(&*window, local_name.clone(), value.clone(),
name, namespace.clone(), prefix, self);
self.get_mut().attrs.push_unrooted(attr);
(self.get().attrs.len() - 1, FirstSetAttr)
}
};
attr.get_mut().set_value(set_type, value);
self.get_mut().attrs.get_mut(idx).get_mut().set_value(set_type, value);
}
// http://dom.spec.whatwg.org/#dom-element-setattribute
fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult {
let node: JS<Node> = NodeCast::from(self);
node.get().wait_until_safe_to_modify_dom();
fn SetAttribute_(&mut self, name: DOMString, value: DOMString) -> ErrorResult {
{
let node: &JSRef<Node> = NodeCast::from_ref(self);
node.get().wait_until_safe_to_modify_dom();
}
// Step 1.
match xml_name_type(name) {
@ -308,10 +309,12 @@ impl AttributeHandlers for JS<Element> {
Ok(())
}
fn SetAttributeNS(&mut self, namespace_url: Option<DOMString>,
name: DOMString, value: DOMString) -> ErrorResult {
let node: JS<Node> = NodeCast::from(self);
node.get().wait_until_safe_to_modify_dom();
fn SetAttributeNS_(&mut self, namespace_url: Option<DOMString>,
name: DOMString, value: DOMString) -> ErrorResult {
{
let node: &JSRef<Node> = NodeCast::from_ref(self);
node.get().wait_until_safe_to_modify_dom();
}
// Step 1.
let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace_url));
@ -368,8 +371,9 @@ impl AttributeHandlers for JS<Element> {
fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult {
let (_, local_name) = get_attribute_parts(name.clone());
let node: JS<Node> = NodeCast::from(self);
node.get().wait_until_safe_to_modify_dom();
let self_alias = self.clone();
let node: &JSRef<Node> = NodeCast::from_ref(&self_alias);
node.wait_until_safe_to_modify_dom();
let idx = self.get().attrs.iter().position(|attr| {
attr.get().local_name == local_name
@ -380,7 +384,7 @@ impl AttributeHandlers for JS<Element> {
Some(idx) => {
if namespace == namespace::Null {
let removed_raw_value = self.get().attrs.get(idx).get().Value();
vtable_for(&node).before_remove_attr(local_name.clone(), removed_raw_value);
vtable_for(node).before_remove_attr(local_name.clone(), removed_raw_value);
}
self.get_mut().attrs.remove(idx);
@ -391,14 +395,15 @@ impl AttributeHandlers for JS<Element> {
}
fn notify_attribute_changed(&self, local_name: DOMString) {
let node: JS<Node> = NodeCast::from(self);
let roots = RootCollection::new();
let node: &JSRef<Node> = NodeCast::from_ref(self);
if node.is_in_doc() {
let damage = match local_name.as_slice() {
"style" | "id" | "class" => MatchSelectorsDocumentDamage,
_ => ContentChangedDocumentDamage
};
let document = node.get().owner_doc();
document.get().damage_and_reflow(damage);
let document = node.owner_doc().root(&roots);
document.deref().damage_and_reflow(damage);
}
}
@ -417,8 +422,12 @@ impl AttributeHandlers for JS<Element> {
}
fn get_string_attribute(&self, name: &str) -> DOMString {
let roots = RootCollection::new();
match self.get_attribute(Null, name) {
Some(x) => x.get().Value(),
Some(x) => {
let x = x.root(&roots);
x.deref().Value()
}
None => ~""
}
}
@ -478,65 +487,72 @@ impl Element {
// http://dom.spec.whatwg.org/#dom-element-id
pub fn Id(&self, abstract_self: &JSRef<Element>) -> DOMString {
abstract_self.unrooted().get_string_attribute("id")
abstract_self.get_string_attribute("id")
}
// http://dom.spec.whatwg.org/#dom-element-id
pub fn SetId(&mut self, abstract_self: &mut JSRef<Element>, id: DOMString) {
abstract_self.unrooted().set_string_attribute("id", id);
abstract_self.set_string_attribute("id", id);
}
// http://dom.spec.whatwg.org/#dom-element-classname
pub fn ClassName(&self, abstract_self: &JSRef<Element>) -> DOMString {
abstract_self.unrooted().get_string_attribute("class")
abstract_self.get_string_attribute("class")
}
// http://dom.spec.whatwg.org/#dom-element-classname
pub fn SetClassName(&self, abstract_self: &mut JSRef<Element>, class: DOMString) {
abstract_self.unrooted().set_string_attribute("class", class);
abstract_self.set_string_attribute("class", class);
}
// http://dom.spec.whatwg.org/#dom-element-attributes
pub fn Attributes(&mut self, abstract_self: &JSRef<Element>) -> JS<AttrList> {
pub fn Attributes(&mut self, abstract_self: &JSRef<Element>) -> Unrooted<AttrList> {
let roots = RootCollection::new();
match self.attr_list {
None => {
let doc = self.node.owner_doc();
let doc = doc.get();
let window = doc.window.root(&roots);
let doc = self.node.owner_doc().root(&roots);
let window = doc.deref().window.root(&roots);
let list = AttrList::new(&window.root_ref(), abstract_self);
self.attr_list = Some(list.clone());
list
self.attr_list.assign(Some(list));
Unrooted::new(self.attr_list.get_ref().clone())
}
Some(ref list) => list.clone()
Some(ref list) => Unrooted::new(list.clone())
}
}
// http://dom.spec.whatwg.org/#dom-element-getattribute
pub fn GetAttribute(&self, abstract_self: &JSRef<Element>, name: DOMString) -> Option<DOMString> {
let roots = RootCollection::new();
let name = if abstract_self.get().html_element_in_html_document() {
name.to_ascii_lower()
} else {
name
};
abstract_self.unrooted().get_attribute(Null, name).map(|s| s.get().Value())
abstract_self.get_attribute(Null, name)
.map(|s| {
let s = s.root(&roots);
s.deref().Value()
})
}
// http://dom.spec.whatwg.org/#dom-element-getattributens
pub fn GetAttributeNS(&self, abstract_self: &JSRef<Element>,
namespace: Option<DOMString>,
local_name: DOMString) -> Option<DOMString> {
let roots = RootCollection::new();
let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace));
abstract_self.unrooted()
.get_attribute(namespace, local_name)
.map(|attr| attr.get().value.clone())
abstract_self.get_attribute(namespace, local_name)
.map(|attr| {
let attr = attr.root(&roots);
attr.deref().Value()
})
}
// http://dom.spec.whatwg.org/#dom-element-setattribute
pub fn SetAttribute(&self, abstract_self: &mut JSRef<Element>,
name: DOMString,
value: DOMString) -> ErrorResult {
abstract_self.unrooted().SetAttribute(name, value)
abstract_self.SetAttribute_(name, value)
}
// http://dom.spec.whatwg.org/#dom-element-setattributens
@ -545,7 +561,7 @@ impl Element {
namespace_url: Option<DOMString>,
name: DOMString,
value: DOMString) -> ErrorResult {
abstract_self.unrooted().SetAttributeNS(namespace_url, name, value)
abstract_self.SetAttributeNS_(namespace_url, name, value)
}
// http://dom.spec.whatwg.org/#dom-element-removeattribute
@ -557,7 +573,7 @@ impl Element {
} else {
name
};
abstract_self.unrooted().remove_attribute(namespace::Null, name)
abstract_self.remove_attribute(namespace::Null, name)
}
// http://dom.spec.whatwg.org/#dom-element-removeattributens
@ -566,7 +582,7 @@ impl Element {
namespace: Option<DOMString>,
localname: DOMString) -> ErrorResult {
let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace));
abstract_self.unrooted().remove_attribute(namespace, localname)
abstract_self.remove_attribute(namespace, localname)
}
// http://dom.spec.whatwg.org/#dom-element-hasattribute
@ -582,63 +598,55 @@ impl Element {
self.GetAttributeNS(abstract_self, namespace, local_name).is_some()
}
pub fn GetElementsByTagName(&self, abstract_self: &JSRef<Element>, localname: DOMString) -> JS<HTMLCollection> {
pub fn GetElementsByTagName(&self, abstract_self: &JSRef<Element>, localname: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let doc = self.node.owner_doc();
let doc = doc.get();
let window = doc.window.root(&roots);
HTMLCollection::by_tag_name(&window.root_ref(), NodeCast::from_ref(abstract_self), localname)
let window = window_from_node(abstract_self).root(&roots);
HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), localname)
}
pub fn GetElementsByTagNameNS(&self, abstract_self: &JSRef<Element>, maybe_ns: Option<DOMString>,
localname: DOMString) -> JS<HTMLCollection> {
localname: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let doc = self.node.owner_doc();
let doc = doc.get();
let namespace = match maybe_ns {
Some(namespace) => Namespace::from_str(namespace),
None => Null
};
let window = doc.window.root(&roots);
HTMLCollection::by_tag_name_ns(&window.root_ref(), NodeCast::from_ref(abstract_self), localname, namespace)
let window = window_from_node(abstract_self).root(&roots);
HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(abstract_self), localname, namespace)
}
pub fn GetElementsByClassName(&self, abstract_self: &JSRef<Element>, classes: DOMString) -> JS<HTMLCollection> {
pub fn GetElementsByClassName(&self, abstract_self: &JSRef<Element>, classes: DOMString) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let doc = self.node.owner_doc();
let doc = doc.get();
let window = doc.window.root(&roots);
HTMLCollection::by_class_name(&window.root_ref(), NodeCast::from_ref(abstract_self), classes)
let window = window_from_node(abstract_self).root(&roots);
HTMLCollection::by_class_name(&*window, NodeCast::from_ref(abstract_self), classes)
}
// http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects
pub fn GetClientRects(&self, abstract_self: &JSRef<Element>) -> JS<ClientRectList> {
pub fn GetClientRects(&self, abstract_self: &JSRef<Element>) -> Unrooted<ClientRectList> {
let roots = RootCollection::new();
let doc = self.node.owner_doc();
let win = doc.get().window.root(&roots);
let node: JS<Node> = NodeCast::from(&abstract_self.unrooted());
let win = window_from_node(abstract_self).root(&roots);
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self);
let rects = node.get_content_boxes();
let rects = rects.iter().map(|r| {
let rects: ~[Root<ClientRect>] = rects.iter().map(|r| {
ClientRect::new(
&win.root_ref(),
&*win,
r.origin.y,
r.origin.y + r.size.height,
r.origin.x,
r.origin.x + r.size.width)
r.origin.x + r.size.width).root(&roots)
}).collect();
ClientRectList::new(&win.root_ref(), rects)
ClientRectList::new(&*win, rects.iter().map(|rect| rect.deref().clone()).collect())
}
// http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect
pub fn GetBoundingClientRect(&self, abstract_self: &JSRef<Element>) -> JS<ClientRect> {
pub fn GetBoundingClientRect(&self, abstract_self: &JSRef<Element>) -> Unrooted<ClientRect> {
let roots = RootCollection::new();
let doc = self.node.owner_doc();
let win = doc.get().window.root(&roots);
let node: JS<Node> = NodeCast::from(&abstract_self.unrooted());
let win = window_from_node(abstract_self).root(&roots);
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self);
let rect = node.get_bounding_content_box();
ClientRect::new(
&win.root_ref(),
&*win,
rect.origin.y,
rect.origin.y + rect.size.height,
rect.origin.x,
@ -647,16 +655,18 @@ impl Element {
pub fn GetInnerHTML(&self, abstract_self: &JSRef<Element>) -> Fallible<DOMString> {
//XXX TODO: XML case
Ok(serialize(&mut NodeIterator::new(NodeCast::from(&abstract_self.unrooted()), false, false)))
let roots = RootCollection::new();
Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(abstract_self), false, false)))
}
pub fn GetOuterHTML(&self, abstract_self: &JSRef<Element>) -> Fallible<DOMString> {
Ok(serialize(&mut NodeIterator::new(NodeCast::from(&abstract_self.unrooted()), true, false)))
let roots = RootCollection::new();
Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(abstract_self), true, false)))
}
pub fn Children(&self, abstract_self: &JSRef<Element>) -> JS<HTMLCollection> {
pub fn Children(&self, abstract_self: &JSRef<Element>) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
let window = window_from_node(&abstract_self.unrooted()).root(&roots);
let window = window_from_node(abstract_self).root(&roots);
HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self))
}
}
@ -674,10 +684,10 @@ pub fn get_attribute_parts(name: DOMString) -> (Option<~str>, ~str) {
(prefix, local_name)
}
impl VirtualMethods for JS<Element> {
impl<'a> VirtualMethods for JSRef<'a, Element> {
fn super_type(&self) -> Option<~VirtualMethods:> {
let node: JS<Node> = NodeCast::from(self);
Some(~node as ~VirtualMethods:)
let node: &JSRef<Node> = NodeCast::from_ref(self);
Some(~node.clone() as ~VirtualMethods:)
}
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
@ -687,20 +697,18 @@ impl VirtualMethods for JS<Element> {
_ => (),
}
let node: JS<Node> = NodeCast::from(self);
match name.as_slice() {
"style" => {
let doc = node.get().owner_doc();
let doc = document_from_node(self).root(&roots);
let base_url = doc.get().url().clone();
self.get_mut().style_attribute = Some(style::parse_style_attribute(value, &base_url))
}
"id" if node.is_in_doc() => {
// XXX: this dual declaration are workaround to avoid the compile error:
// "borrowed value does not live long enough"
let mut doc = node.get().owner_doc().clone();
let doc = doc.get_mut();
let elem = self.root(&roots);
doc.register_named_element(&elem.root_ref(), value.clone());
"id" => {
let node: &JSRef<Node> = NodeCast::from_ref(self);
if node.is_in_doc() {
let mut doc = document_from_node(self).root(&roots);
doc.register_named_element(self, value.clone());
}
}
_ => ()
}
@ -715,18 +723,16 @@ impl VirtualMethods for JS<Element> {
_ => (),
}
let node: JS<Node> = NodeCast::from(self);
match name.as_slice() {
"style" => {
self.get_mut().style_attribute = None
}
"id" if node.is_in_doc() => {
// XXX: this dual declaration are workaround to avoid the compile error:
// "borrowed value does not live long enough"
let mut doc = node.get().owner_doc().clone();
let doc = doc.get_mut();
let elem = self.root(&roots);
doc.unregister_named_element(&elem.root_ref(), value);
"id" => {
let node: &JSRef<Node> = NodeCast::from_ref(self);
if node.is_in_doc() {
let mut doc = document_from_node(self).root(&roots);
doc.unregister_named_element(self, value);
}
}
_ => ()
}
@ -743,9 +749,9 @@ impl VirtualMethods for JS<Element> {
match self.get_attribute(Null, "id") {
Some(attr) => {
let mut doc = document_from_node(self);
let elem = self.root(&roots);
doc.get_mut().register_named_element(&elem.root_ref(), attr.get().Value());
let attr = attr.root(&roots);
let mut doc = document_from_node(self).root(&roots);
doc.register_named_element(self, attr.deref().Value());
}
_ => ()
}
@ -758,11 +764,10 @@ impl VirtualMethods for JS<Element> {
_ => (),
}
match self.get_attribute(Null, "id") {
match self.get_attribute(Null, "id").root(&roots) {
Some(attr) => {
let mut doc = document_from_node(self);
let elem = self.root(&roots);
doc.get_mut().unregister_named_element(&elem.root_ref(), attr.get().Value());
let mut doc = document_from_node(self).root(&roots);
doc.unregister_named_element(self, attr.deref().Value());
}
_ => ()
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::EventBinding;
use dom::bindings::codegen::BindingDeclarations::EventBinding::EventConstants;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::error::Fallible;
use dom::eventtarget::EventTarget;
@ -80,7 +80,7 @@ impl Event {
}
}
pub fn new(window: &JSRef<Window>) -> JS<Event> {
pub fn new(window: &JSRef<Window>) -> Unrooted<Event> {
reflect_dom_object(~Event::new_inherited(HTMLEventTypeId),
window,
EventBinding::Wrap)
@ -94,12 +94,12 @@ impl Event {
self.type_.clone()
}
pub fn GetTarget(&self) -> Option<JS<EventTarget>> {
self.target.clone()
pub fn GetTarget(&self) -> Option<Unrooted<EventTarget>> {
self.target.as_ref().map(|target| Unrooted::new(target.clone()))
}
pub fn GetCurrentTarget(&self) -> Option<JS<EventTarget>> {
self.current_target.clone()
pub fn GetCurrentTarget(&self) -> Option<Unrooted<EventTarget>> {
self.current_target.as_ref().map(|target| Unrooted::new(target.clone()))
}
pub fn DefaultPrevented(&self) -> bool {
@ -157,10 +157,11 @@ impl Event {
pub fn Constructor(global: &JSRef<Window>,
type_: DOMString,
init: &EventBinding::EventInit) -> Fallible<JS<Event>> {
let mut ev = Event::new(global);
ev.get_mut().InitEvent(type_, init.bubbles, init.cancelable);
Ok(ev)
init: &EventBinding::EventInit) -> Fallible<Unrooted<Event>> {
let roots = RootCollection::new();
let mut ev = Event::new(global).root(&roots);
ev.InitEvent(type_, init.bubbles, init.cancelable);
Ok(Unrooted::new_rooted(&*ev))
}
}

View file

@ -4,35 +4,32 @@
use dom::bindings::callback::ReportExceptions;
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, NodeDerived};
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JSRef, OptionalAssignable, RootCollection, Root};
use dom::eventtarget::{Capturing, Bubbling, EventTarget};
use dom::event::{Event, PhaseAtTarget, PhaseNone, PhaseBubbling, PhaseCapturing};
use dom::node::{Node, NodeHelpers};
// See http://dom.spec.whatwg.org/#concept-event-dispatch for the full dispatch algorithm
pub fn dispatch_event(target: &JSRef<EventTarget>,
pseudo_target: Option<JSRef<EventTarget>>,
event: &mut JSRef<Event>) -> bool {
pub fn dispatch_event<'a>(target: &JSRef<'a, EventTarget>,
pseudo_target: Option<JSRef<'a, EventTarget>>,
event: &mut JSRef<Event>) -> bool {
let roots = RootCollection::new();
assert!(!event.get().dispatching);
{
let event = event.get_mut();
event.target = pseudo_target.map(|pseudo_target| {
pseudo_target.unrooted()
}).or_else(|| {
Some(target.unrooted())
});
event.target.assign(Some(pseudo_target.unwrap_or(target.clone())));
event.dispatching = true;
}
let type_ = event.get().type_.clone();
//TODO: no chain if not participating in a tree
let chain: Vec<JS<EventTarget>> = if target.get().is_node() {
let target_node: JS<Node> = NodeCast::to(&target.unrooted()).unwrap();
let mut chain: Vec<Root<EventTarget>> = if target.get().is_node() {
let target_node: &JSRef<Node> = NodeCast::to_ref(target).unwrap();
target_node.ancestors().map(|ancestor| {
let ancestor_target: JS<EventTarget> = EventTargetCast::from(&ancestor);
ancestor_target
let ancestor_target: &JSRef<EventTarget> = EventTargetCast::from_ref(&ancestor);
ancestor_target.unrooted().root(&roots)
}).collect()
} else {
vec!()
@ -44,9 +41,9 @@ pub fn dispatch_event(target: &JSRef<EventTarget>,
/* capturing */
for cur_target in chain.as_slice().rev_iter() {
let stopped = match cur_target.get().get_listeners_for(type_, Capturing) {
let stopped = match cur_target.get_listeners_for(type_, Capturing) {
Some(listeners) => {
event.get_mut().current_target = Some(cur_target.clone());
event.current_target.assign(Some(cur_target.deref().clone()));
for listener in listeners.iter() {
//FIXME: this should have proper error handling, or explicitly
// drop the exception on the floor
@ -72,7 +69,7 @@ pub fn dispatch_event(target: &JSRef<EventTarget>,
{
let event = event.get_mut();
event.phase = PhaseAtTarget;
event.current_target = Some(target.unrooted());
event.current_target.assign(Some(target.clone()));
}
let opt_listeners = target.get().get_listeners(type_);
@ -95,7 +92,7 @@ pub fn dispatch_event(target: &JSRef<EventTarget>,
for cur_target in chain.iter() {
let stopped = match cur_target.get().get_listeners_for(type_, Bubbling) {
Some(listeners) => {
event.get_mut().current_target = Some(cur_target.clone());
event.get_mut().current_target.assign(Some(cur_target.deref().clone()));
for listener in listeners.iter() {
//FIXME: this should have proper error handling or explicitly
// drop exceptions on the floor.
@ -116,6 +113,12 @@ pub fn dispatch_event(target: &JSRef<EventTarget>,
}
}
// Root ordering restrictions mean we need to unroot the chain entries
// in the same order they were rooted.
while chain.len() > 0 {
let _ = chain.pop();
}
let event = event.get_mut();
event.dispatching = false;
event.phase = PhaseNone;

View file

@ -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, JSRef};
use dom::bindings::js::JSRef;
use dom::bindings::utils::{Reflectable, Reflector};
use dom::bindings::error::{Fallible, InvalidState};
use dom::bindings::codegen::BindingDeclarations::EventListenerBinding;
@ -107,10 +107,10 @@ impl EventTarget {
self.dispatch_event_with_target(abstract_self, None, event)
}
pub fn dispatch_event_with_target(&self,
abstract_self: &JSRef<EventTarget>,
abstract_target: Option<JSRef<EventTarget>>,
event: &mut JSRef<Event>) -> Fallible<bool> {
pub fn dispatch_event_with_target<'a>(&self,
abstract_self: &JSRef<'a, EventTarget>,
abstract_target: Option<JSRef<'a, EventTarget>>,
event: &mut JSRef<Event>) -> Fallible<bool> {
if event.get().dispatching || !event.get().initialized {
return Err(InvalidState);
}
@ -128,7 +128,7 @@ impl Reflectable for EventTarget {
}
}
impl VirtualMethods for JS<EventTarget> {
impl<'a> VirtualMethods for JSRef<'a, EventTarget> {
fn super_type(&self) -> Option<~VirtualMethods:> {
None
}

View file

@ -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, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::blob::Blob;
use dom::htmlformelement::HTMLFormElement;
use dom::window::Window;
@ -37,12 +37,12 @@ impl FormData {
}
}
pub fn new(form: Option<JSRef<HTMLFormElement>>, window: &JSRef<Window>) -> JS<FormData> {
pub fn new(form: Option<JSRef<HTMLFormElement>>, window: &JSRef<Window>) -> Unrooted<FormData> {
reflect_dom_object(~FormData::new_inherited(form, window.unrooted()), window, FormDataBinding::Wrap)
}
pub fn Constructor(window: &JSRef<Window>, form: Option<JSRef<HTMLFormElement>>)
-> Fallible<JS<FormData>> {
-> Fallible<Unrooted<FormData>> {
Ok(FormData::new(form, window))
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLAnchorElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLAnchorElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLAnchorElementTypeId;
@ -34,7 +34,7 @@ impl HTMLAnchorElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLAnchorElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLAnchorElement> {
let element = HTMLAnchorElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLAnchorElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLAppletElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLAppletElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLAppletElementTypeId;
@ -34,7 +34,7 @@ impl HTMLAppletElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLAppletElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLAppletElement> {
let element = HTMLAppletElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLAppletElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLAreaElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLAreaElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLAreaElementTypeId;
@ -34,7 +34,7 @@ impl HTMLAreaElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLAreaElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLAreaElement> {
let element = HTMLAreaElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLAreaElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLAudioElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLAudioElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLAudioElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -33,7 +33,7 @@ impl HTMLAudioElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLAudioElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLAudioElement> {
let element = HTMLAudioElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLAudioElementBinding::Wrap)
}

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLBaseElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLBaseElementDerived;
use dom::bindings::error::ErrorResult;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLBaseElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -34,7 +34,7 @@ impl HTMLBaseElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLBaseElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLBaseElement> {
let element = HTMLBaseElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLBaseElementBinding::Wrap)
}

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLBodyElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLBodyElementDerived;
use dom::bindings::error::ErrorResult;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLBodyElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -34,7 +34,7 @@ impl HTMLBodyElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLBodyElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLBodyElement> {
let element = HTMLBodyElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLBodyElementBinding::Wrap)
}

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLBRElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLBRElementDerived;
use dom::bindings::error::ErrorResult;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLBRElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -34,7 +34,7 @@ impl HTMLBRElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLBRElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLBRElement> {
let element = HTMLBRElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLBRElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLButtonElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLButtonElementDerived;
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLButtonElementTypeId;
@ -36,7 +36,7 @@ impl HTMLButtonElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLButtonElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLButtonElement> {
let element = HTMLButtonElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLButtonElementBinding::Wrap)
}
@ -59,7 +59,7 @@ impl HTMLButtonElement {
Ok(())
}
pub fn GetForm(&self) -> Option<JS<HTMLFormElement>> {
pub fn GetForm(&self) -> Option<Unrooted<HTMLFormElement>> {
None
}
@ -134,11 +134,10 @@ impl HTMLButtonElement {
pub fn SetWillValidate(&mut self, _will_validate: bool) {
}
pub fn Validity(&self) -> JS<ValidityState> {
pub fn Validity(&self) -> Unrooted<ValidityState> {
let roots = RootCollection::new();
let doc = self.htmlelement.element.node.owner_doc();
let doc = doc.get();
ValidityState::new(&doc.window.root(&roots).root_ref())
let doc = self.htmlelement.element.node.owner_doc().root(&roots);
ValidityState::new(&*doc.deref().window.root(&roots))
}
pub fn SetValidity(&mut self, _validity: JS<ValidityState>) {

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLCanvasElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLCanvasElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::{ErrorResult};
use dom::document::Document;
use dom::element::HTMLCanvasElementTypeId;
@ -34,7 +34,7 @@ impl HTMLCanvasElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLCanvasElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLCanvasElement> {
let element = HTMLCanvasElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLCanvasElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast};
use dom::bindings::codegen::BindingDeclarations::HTMLCollectionBinding;
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::element::{Element, AttributeHandlers};
use dom::node::{Node, NodeHelpers};
@ -46,19 +46,19 @@ impl HTMLCollection {
}
}
pub fn new(window: &JSRef<Window>, collection: CollectionTypeId) -> JS<HTMLCollection> {
pub fn new(window: &JSRef<Window>, collection: CollectionTypeId) -> Unrooted<HTMLCollection> {
reflect_dom_object(~HTMLCollection::new_inherited(window.unrooted(), collection),
window, HTMLCollectionBinding::Wrap)
}
}
impl HTMLCollection {
pub fn create(window: &JSRef<Window>, root: &JSRef<Node>, filter: ~CollectionFilter) -> JS<HTMLCollection> {
pub fn create(window: &JSRef<Window>, root: &JSRef<Node>, filter: ~CollectionFilter) -> Unrooted<HTMLCollection> {
HTMLCollection::new(window, Live(root.unrooted(), filter))
}
pub fn by_tag_name(window: &JSRef<Window>, root: &JSRef<Node>, tag: DOMString)
-> JS<HTMLCollection> {
-> Unrooted<HTMLCollection> {
struct TagNameFilter {
tag: DOMString
}
@ -74,7 +74,7 @@ impl HTMLCollection {
}
pub fn by_tag_name_ns(window: &JSRef<Window>, root: &JSRef<Node>, tag: DOMString,
namespace: Namespace) -> JS<HTMLCollection> {
namespace: Namespace) -> Unrooted<HTMLCollection> {
struct TagNameNSFilter {
tag: DOMString,
namespace: Namespace
@ -92,13 +92,13 @@ impl HTMLCollection {
}
pub fn by_class_name(window: &JSRef<Window>, root: &JSRef<Node>, classes: DOMString)
-> JS<HTMLCollection> {
-> Unrooted<HTMLCollection> {
struct ClassNameFilter {
classes: Vec<DOMString>
}
impl CollectionFilter for ClassNameFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
self.classes.iter().all(|class| elem.unrooted().has_class(*class))
self.classes.iter().all(|class| elem.has_class(*class))
}
}
let filter = ClassNameFilter {
@ -107,11 +107,11 @@ impl HTMLCollection {
HTMLCollection::create(window, root, ~filter)
}
pub fn children(window: &JSRef<Window>, root: &JSRef<Node>) -> JS<HTMLCollection> {
pub fn children(window: &JSRef<Window>, root: &JSRef<Node>) -> Unrooted<HTMLCollection> {
struct ElementChildFilter;
impl CollectionFilter for ElementChildFilter {
fn filter(&self, elem: &JSRef<Element>, root: &JSRef<Node>) -> bool {
root.unrooted().is_parent_of(NodeCast::from_ref(elem))
root.is_parent_of(NodeCast::from_ref(elem))
}
}
HTMLCollection::create(window, root, ~ElementChildFilter)
@ -125,43 +125,43 @@ impl HTMLCollection {
match self.collection {
Static(ref elems) => elems.len() as u32,
Live(ref root, ref filter) => {
let root_root = root.root(&roots);
root.traverse_preorder()
let root = root.root(&roots);
root.deref().traverse_preorder(&roots)
.count(|child| {
let elem: Option<JS<Element>> = ElementCast::to(&child);
elem.map_or(false, |elem| {
let elem = elem.root(&roots);
filter.filter(&elem.root_ref(), &root_root.root_ref())
})
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&child);
elem.map_or(false, |elem| filter.filter(elem, &*root))
}) as u32
}
}
}
// http://dom.spec.whatwg.org/#dom-htmlcollection-item
pub fn Item(&self, index: u32) -> Option<JS<Element>> {
pub fn Item(&self, index: u32) -> Option<Unrooted<Element>> {
let roots = RootCollection::new();
match self.collection {
Static(ref elems) => elems
.as_slice()
.get(index as uint)
.map(|elem| elem.clone()),
.map(|elem| Unrooted::new(elem.clone())),
Live(ref root, ref filter) => {
let root_root = root.root(&roots);
root.traverse_preorder()
.filter_map(|node| ElementCast::to(&node))
.filter(|elem| {
let elem = elem.root(&roots);
filter.filter(&elem.root_ref(), &root_root.root_ref())
let root = root.root(&roots);
root.deref().traverse_preorder(&roots)
.filter_map(|node| {
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&node);
elem.filtered(|&elem| filter.filter(elem, &*root))
.and_then(|elem| Some(elem.clone()))
})
.nth(index as uint).clone()
.nth(index as uint)
.clone()
.map(|elem| Unrooted::new_rooted(&elem))
}
}
}
// http://dom.spec.whatwg.org/#dom-htmlcollection-nameditem
pub fn NamedItem(&self, key: DOMString) -> Option<JS<Element>> {
pub fn NamedItem(&self, key: DOMString) -> Option<Unrooted<Element>> {
let roots = RootCollection::new();
// Step 1.
if key.is_empty() {
return None;
@ -170,35 +170,36 @@ impl HTMLCollection {
// Step 2.
match self.collection {
Static(ref elems) => elems.iter()
.map(|elem| elem.root(&roots))
.find(|elem| {
elem.get_string_attribute("name") == key ||
elem.get_string_attribute("id") == key })
.map(|maybe_elem| maybe_elem.clone()),
.map(|maybe_elem| Unrooted::new_rooted(&*maybe_elem)),
Live(ref root, ref filter) => {
let root_root = root.root(&roots);
root.traverse_preorder()
.filter_map(|node| ElementCast::to(&node))
.filter(|elem| {
let elem = elem.root(&roots);
filter.filter(&elem.root_ref(), &root_root.root_ref())
let root = root.root(&roots);
root.deref().traverse_preorder(&roots)
.filter_map(|node| {
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&node);
elem.filtered(|&elem| filter.filter(elem, &*root))
.and_then(|elem| Some(elem.clone()))
})
.find(|elem| {
elem.get_string_attribute("name") == key ||
elem.get_string_attribute("id") == key })
.map(|maybe_elem| maybe_elem.clone())
.map(|maybe_elem| Unrooted::new_rooted(&maybe_elem))
}
}
}
}
impl HTMLCollection {
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<JS<Element>> {
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Unrooted<Element>> {
let maybe_elem = self.Item(index);
*found = maybe_elem.is_some();
maybe_elem
}
pub fn NamedGetter(&self, maybe_name: Option<DOMString>, found: &mut bool) -> Option<JS<Element>> {
pub fn NamedGetter(&self, maybe_name: Option<DOMString>, found: &mut bool) -> Option<Unrooted<Element>> {
match maybe_name {
Some(name) => {
let maybe_elem = self.NamedItem(name);

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLDataElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLDataElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLDataElementTypeId;
@ -34,7 +34,7 @@ impl HTMLDataElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLDataElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLDataElement> {
let element = HTMLDataElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLDataElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLDataListElementBinding;
use dom::bindings::codegen::InheritTypes::{HTMLDataListElementDerived, NodeCast};
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::document::Document;
use dom::element::{Element, HTMLDataListElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -34,14 +34,14 @@ impl HTMLDataListElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLDataListElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLDataListElement> {
let element = HTMLDataListElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLDataListElementBinding::Wrap)
}
}
impl HTMLDataListElement {
pub fn Options(&self, abstract_self: &JSRef<HTMLDataListElement>) -> JS<HTMLCollection> {
pub fn Options(&self, abstract_self: &JSRef<HTMLDataListElement>) -> Unrooted<HTMLCollection> {
struct HTMLDataListOptionsFilter;
impl CollectionFilter for HTMLDataListOptionsFilter {
fn filter(&self, elem: &JSRef<Element>, _root: &JSRef<Node>) -> bool {
@ -51,7 +51,7 @@ impl HTMLDataListElement {
let roots = RootCollection::new();
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self);
let filter = ~HTMLDataListOptionsFilter;
let window = window_from_node(&node.unrooted()).root(&roots);
HTMLCollection::create(&window.root_ref(), node, filter)
let window = window_from_node(node).root(&roots);
HTMLCollection::create(&*window, node, filter)
}
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLDirectoryElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLDirectoryElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLDirectoryElementTypeId;
@ -34,7 +34,7 @@ impl HTMLDirectoryElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLDirectoryElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLDirectoryElement> {
let element = HTMLDirectoryElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLDirectoryElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLDivElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLDivElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLDivElementTypeId;
@ -34,7 +34,7 @@ impl HTMLDivElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLDivElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLDivElement> {
let element = HTMLDivElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLDivElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLDListElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLDListElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLDListElementTypeId;
@ -34,7 +34,7 @@ impl HTMLDListElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLDListElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLDListElement> {
let element = HTMLDListElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLDListElementBinding::Wrap)
}

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLElementBinding;
use dom::bindings::codegen::InheritTypes::ElementCast;
use dom::bindings::codegen::InheritTypes::HTMLElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::{ErrorResult, Fallible};
use dom::document::Document;
use dom::element::{Element, ElementTypeId, HTMLElementTypeId};
@ -39,7 +39,7 @@ impl HTMLElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLElement> {
let element = HTMLElement::new_inherited(HTMLElementTypeId, localName, document.unrooted());
Node::reflect_node(~element, document, HTMLElementBinding::Wrap)
}
@ -143,7 +143,7 @@ impl HTMLElement {
Ok(())
}
pub fn GetOffsetParent(&self) -> Option<JS<Element>> {
pub fn GetOffsetParent(&self) -> Option<Unrooted<Element>> {
None
}
@ -164,9 +164,9 @@ impl HTMLElement {
}
}
impl VirtualMethods for JS<HTMLElement> {
impl<'a> VirtualMethods for JSRef<'a, HTMLElement> {
fn super_type(&self) -> Option<~VirtualMethods:> {
let element: JS<Element> = ElementCast::from(self);
Some(~element as ~VirtualMethods:)
let element: &JSRef<Element> = ElementCast::from_ref(self);
Some(~element.clone() as ~VirtualMethods:)
}
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLEmbedElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLEmbedElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLEmbedElementTypeId;
@ -34,7 +34,7 @@ impl HTMLEmbedElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLEmbedElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLEmbedElement> {
let element = HTMLEmbedElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLEmbedElementBinding::Wrap)
}
@ -89,7 +89,7 @@ impl HTMLEmbedElement {
Ok(())
}
pub fn GetSVGDocument(&self) -> Option<JS<Document>> {
pub fn GetSVGDocument(&self) -> Option<Unrooted<Document>> {
None
}
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLFieldSetElementBinding;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLFieldSetElementDerived, NodeCast};
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::{Element, HTMLFieldSetElementTypeId};
@ -37,7 +37,7 @@ impl HTMLFieldSetElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLFieldSetElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLFieldSetElement> {
let element = HTMLFieldSetElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLFieldSetElementBinding::Wrap)
}
@ -52,7 +52,7 @@ impl HTMLFieldSetElement {
Ok(())
}
pub fn GetForm(&self) -> Option<JS<HTMLFormElement>> {
pub fn GetForm(&self) -> Option<Unrooted<HTMLFormElement>> {
None
}
@ -69,33 +69,32 @@ impl HTMLFieldSetElement {
}
// http://www.whatwg.org/html/#dom-fieldset-elements
pub fn Elements(&self, abstract_self: &JSRef<HTMLFieldSetElement>) -> JS<HTMLCollection> {
pub fn Elements(&self, abstract_self: &JSRef<HTMLFieldSetElement>) -> Unrooted<HTMLCollection> {
struct ElementsFilter;
impl CollectionFilter for ElementsFilter {
fn filter(&self, elem: &JSRef<Element>, root: &JSRef<Node>) -> bool {
static tag_names: StaticStringVec = &["button", "fieldset", "input",
"keygen", "object", "output", "select", "textarea"];
let root: &JS<Element> = &ElementCast::to(&root.unrooted()).unwrap();
&elem.unrooted() != root && tag_names.iter().any(|&tag_name| tag_name == elem.get().local_name)
let root: &JSRef<Element> = ElementCast::to_ref(root).unwrap();
elem != root && tag_names.iter().any(|&tag_name| tag_name == elem.get().local_name)
}
}
let roots = RootCollection::new();
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self);
let filter = ~ElementsFilter;
let window = window_from_node(&node.unrooted()).root(&roots);
HTMLCollection::create(&window.root_ref(), node, filter)
let window = window_from_node(node).root(&roots);
HTMLCollection::create(&*window, node, filter)
}
pub fn WillValidate(&self) -> bool {
false
}
pub fn Validity(&self) -> JS<ValidityState> {
pub fn Validity(&self) -> Unrooted<ValidityState> {
let roots = RootCollection::new();
let doc = self.htmlelement.element.node.owner_doc();
let doc = doc.get();
let window = doc.window.root(&roots);
ValidityState::new(&window.root_ref())
let doc = self.htmlelement.element.node.owner_doc().root(&roots);
let window = doc.deref().window.root(&roots);
ValidityState::new(&*window)
}
pub fn ValidationMessage(&self) -> DOMString {

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLFontElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLFontElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLFontElementTypeId;
@ -34,7 +34,7 @@ impl HTMLFontElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLFontElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLFontElement> {
let element = HTMLFontElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLFontElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLFormElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived;
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::{Element, HTMLFormElementTypeId};
@ -35,7 +35,7 @@ impl HTMLFormElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLFormElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLFormElement> {
let element = HTMLFormElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLFormElementBinding::Wrap)
}
@ -114,13 +114,12 @@ impl HTMLFormElement {
Ok(())
}
pub fn Elements(&self) -> JS<HTMLCollection> {
pub fn Elements(&self) -> Unrooted<HTMLCollection> {
// FIXME: https://github.com/mozilla/servo/issues/1844
let roots = RootCollection::new();
let doc = self.htmlelement.element.node.owner_doc();
let doc = doc.get();
let window = doc.window.root(&roots);
HTMLCollection::new(&window.root_ref(), Static(vec!()))
let doc = self.htmlelement.element.node.owner_doc().root(&roots);
let window = doc.deref().window.root(&roots);
HTMLCollection::new(&*window, Static(vec!()))
}
pub fn Length(&self) -> i32 {
@ -138,7 +137,7 @@ impl HTMLFormElement {
false
}
pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> JS<Element> {
pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Unrooted<Element> {
fail!("Not implemented.")
}
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLFrameElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLFrameElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLFrameElementTypeId;
@ -35,7 +35,7 @@ impl HTMLFrameElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLFrameElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLFrameElement> {
let element = HTMLFrameElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLFrameElementBinding::Wrap)
}
@ -90,11 +90,11 @@ impl HTMLFrameElement {
Ok(())
}
pub fn GetContentDocument(&self) -> Option<JS<Document>> {
pub fn GetContentDocument(&self) -> Option<Unrooted<Document>> {
None
}
pub fn GetContentWindow(&self) -> Option<JS<Window>> {
pub fn GetContentWindow(&self) -> Option<Unrooted<Window>> {
None
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLFrameSetElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLFrameSetElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLFrameSetElementTypeId;
@ -34,7 +34,7 @@ impl HTMLFrameSetElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLFrameSetElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLFrameSetElement> {
let element = HTMLFrameSetElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLFrameSetElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLHeadElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLHeadElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLHeadElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -33,7 +33,7 @@ impl HTMLHeadElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLHeadElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLHeadElement> {
let element = HTMLHeadElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLHeadElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLHeadingElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLHeadingElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLHeadingElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -45,7 +45,7 @@ impl HTMLHeadingElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>, level: HeadingLevel) -> JS<HTMLHeadingElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>, level: HeadingLevel) -> Unrooted<HTMLHeadingElement> {
let element = HTMLHeadingElement::new_inherited(localName, document.unrooted(), level);
Node::reflect_node(~element, document, HTMLHeadingElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLHRElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLHRElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLHRElementTypeId;
@ -34,7 +34,7 @@ impl HTMLHRElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLHRElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLHRElement> {
let element = HTMLHRElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLHRElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLHtmlElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLHtmlElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLHtmlElementTypeId;
@ -34,7 +34,7 @@ impl HTMLHtmlElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLHtmlElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLHtmlElement> {
let element = HTMLHtmlElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLHtmlElementBinding::Wrap)
}

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLIFrameElementBinding;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLIFrameElementDerived, HTMLElementCast};
use dom::bindings::error::ErrorResult;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::trace::Untraceable;
use dom::document::Document;
use dom::element::{HTMLIFrameElementTypeId, Element};
@ -74,7 +74,7 @@ impl HTMLIFrameElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLIFrameElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLIFrameElement> {
let element = HTMLIFrameElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLIFrameElementBinding::Wrap)
}
@ -106,12 +106,12 @@ impl HTMLIFrameElement {
}
pub fn Sandbox(&self, abstract_self: &JSRef<HTMLIFrameElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("sandbox")
}
pub fn SetSandbox(&mut self, abstract_self: &mut JSRef<HTMLIFrameElement>, sandbox: DOMString) {
let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("sandbox", sandbox);
}
@ -139,11 +139,11 @@ impl HTMLIFrameElement {
Ok(())
}
pub fn GetContentDocument(&self) -> Option<JS<Document>> {
pub fn GetContentDocument(&self) -> Option<Unrooted<Document>> {
None
}
pub fn GetContentWindow(&self) -> Option<JS<Window>> {
pub fn GetContentWindow(&self) -> Option<Unrooted<Window>> {
None
}
@ -195,15 +195,15 @@ impl HTMLIFrameElement {
Ok(())
}
pub fn GetSVGDocument(&self) -> Option<JS<Document>> {
pub fn GetSVGDocument(&self) -> Option<Unrooted<Document>> {
None
}
}
impl VirtualMethods for JS<HTMLIFrameElement> {
impl<'a> VirtualMethods for JSRef<'a, HTMLIFrameElement> {
fn super_type(&self) -> Option<~VirtualMethods:> {
let htmlelement: JS<HTMLElement> = HTMLElementCast::from(self);
Some(~htmlelement as ~VirtualMethods:)
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
Some(~htmlelement.clone() as ~VirtualMethods:)
}
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLImageElementBinding;
use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, HTMLElementCast, HTMLImageElementDerived};
use dom::bindings::error::ErrorResult;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection};
use dom::bindings::trace::Untraceable;
use dom::document::Document;
use dom::element::{Element, HTMLImageElementTypeId};
@ -43,7 +43,7 @@ impl HTMLImageElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLImageElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLImageElement> {
let element = HTMLImageElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLImageElementBinding::Wrap)
}
@ -57,9 +57,10 @@ impl HTMLImageElement {
/// Makes the local `image` member match the status of the `src` attribute and starts
/// prefetching the image. This method must be called after `src` is changed.
fn update_image(&mut self, value: Option<DOMString>, url: Option<Url>) {
let roots = RootCollection::new();
let elem = &mut self.htmlelement.element;
let document = elem.node.owner_doc();
let window = document.get().window.get();
let document = elem.node.owner_doc().root(&roots);
let window = document.deref().window.root(&roots);
let image_cache = &window.image_cache_task;
match value {
None => {
@ -80,22 +81,22 @@ impl HTMLImageElement {
}
pub fn Alt(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("alt")
}
pub fn SetAlt(&mut self, abstract_self: &JSRef<HTMLImageElement>, alt: DOMString) {
let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
pub fn SetAlt(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, alt: DOMString) {
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("alt", alt)
}
pub fn Src(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("src")
}
pub fn SetSrc(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, src: DOMString) {
let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_url_attribute("src", src)
}
@ -108,44 +109,44 @@ impl HTMLImageElement {
}
pub fn UseMap(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("useMap")
}
pub fn SetUseMap(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, use_map: DOMString) {
let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("useMap", use_map)
}
pub fn IsMap(&self, abstract_self: &JSRef<HTMLImageElement>) -> bool {
let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
from_str::<bool>(element.get_string_attribute("hspace")).unwrap()
}
pub fn SetIsMap(&self, abstract_self: &mut JSRef<HTMLImageElement>, is_map: bool) {
let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("isMap", is_map.to_str())
}
pub fn Width(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32 {
let node: JS<Node> = NodeCast::from(&abstract_self.unrooted());
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self);
let rect = node.get_bounding_content_box();
to_px(rect.size.width) as u32
}
pub fn SetWidth(&mut self, abstract_self: &JSRef<HTMLImageElement>, width: u32) {
let mut elem: JS<Element> = ElementCast::from(&abstract_self.unrooted());
pub fn SetWidth(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, width: u32) {
let elem: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
elem.set_uint_attribute("width", width)
}
pub fn Height(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32 {
let node: JS<Node> = NodeCast::from(&abstract_self.unrooted());
let node: &JSRef<Node> = NodeCast::from_ref(abstract_self);
let rect = node.get_bounding_content_box();
to_px(rect.size.height) as u32
}
pub fn SetHeight(&mut self, abstract_self: &JSRef<HTMLImageElement>, height: u32) {
let mut elem: JS<Element> = ElementCast::from(&abstract_self.unrooted());
pub fn SetHeight(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, height: u32) {
let elem: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
elem.set_uint_attribute("height", height)
}
@ -162,87 +163,88 @@ impl HTMLImageElement {
}
pub fn Name(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("name")
}
pub fn SetName(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, name: DOMString) {
let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("name", name)
}
pub fn Align(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("longdesc")
}
pub fn SetAlign(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, align: DOMString) {
let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("align", align)
}
pub fn Hspace(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32 {
let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
from_str::<u32>(element.get_string_attribute("hspace")).unwrap()
}
pub fn SetHspace(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, hspace: u32) {
let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_uint_attribute("hspace", hspace)
}
pub fn Vspace(&self, abstract_self: &JSRef<HTMLImageElement>) -> u32 {
let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
from_str::<u32>(element.get_string_attribute("vspace")).unwrap()
}
pub fn SetVspace(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, vspace: u32) {
let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_uint_attribute("vspace", vspace)
}
pub fn LongDesc(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("longdesc")
}
pub fn SetLongDesc(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, longdesc: DOMString) {
let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("longdesc", longdesc)
}
pub fn Border(&self, abstract_self: &JSRef<HTMLImageElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_string_attribute("border")
}
pub fn SetBorder(&mut self, abstract_self: &mut JSRef<HTMLImageElement>, border: DOMString) {
let mut element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &mut JSRef<Element> = ElementCast::from_mut_ref(abstract_self);
element.set_string_attribute("border", border)
}
}
impl VirtualMethods for JS<HTMLImageElement> {
impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
fn super_type(&self) -> Option<~VirtualMethods:> {
let htmlelement: JS<HTMLElement> = HTMLElementCast::from(self);
Some(~htmlelement as ~VirtualMethods:)
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
Some(~htmlelement.clone() as ~VirtualMethods:)
}
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
let roots = RootCollection::new();
match self.super_type() {
Some(ref mut s) => s.after_set_attr(name.clone(), value.clone()),
_ => (),
}
if "src" == name {
let window = window_from_node(self);
let window = window_from_node(self).root(&roots);
let url = Some(window.get().get_url());
self.get_mut().update_image(Some(value), url);
}
}
fn before_remove_attr(&mut self, name: DOMString, value: DOMString) {
match self.super_type() {
match self.super_type() {
Some(ref mut s) => s.before_remove_attr(name.clone(), value.clone()),
_ => (),
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLInputElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLInputElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::{ErrorResult, Fallible};
use dom::document::Document;
use dom::element::HTMLInputElementTypeId;
@ -34,7 +34,7 @@ impl HTMLInputElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLInputElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLInputElement> {
let element = HTMLInputElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLInputElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLLabelElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLLabelElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLLabelElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -33,7 +33,7 @@ impl HTMLLabelElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLLabelElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLLabelElement> {
let element = HTMLLabelElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLLabelElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLLegendElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLLegendElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLLegendElementTypeId;
@ -34,7 +34,7 @@ impl HTMLLegendElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLLegendElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLLegendElement> {
let element = HTMLLegendElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLLegendElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLLIElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLLIElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLLIElementTypeId;
@ -34,7 +34,7 @@ impl HTMLLIElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLLIElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLLIElement> {
let element = HTMLLIElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLLIElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLLinkElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLLinkElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLLinkElementTypeId;
@ -34,7 +34,7 @@ impl HTMLLinkElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLLinkElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLLinkElement> {
let element = HTMLLinkElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLLinkElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLMainElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLMainElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLMainElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -33,7 +33,7 @@ impl HTMLMainElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLMainElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLMainElement> {
let element = HTMLMainElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLMainElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLMapElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLMapElementDerived;
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLMapElementTypeId;
@ -35,7 +35,7 @@ impl HTMLMapElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLMapElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLMapElement> {
let element = HTMLMapElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLMapElementBinding::Wrap)
}
@ -50,12 +50,11 @@ impl HTMLMapElement {
Ok(())
}
pub fn Areas(&self) -> JS<HTMLCollection> {
pub fn Areas(&self) -> Unrooted<HTMLCollection> {
let roots = RootCollection::new();
// FIXME: https://github.com/mozilla/servo/issues/1845
let doc = self.htmlelement.element.node.owner_doc();
let doc = doc.get();
let window = doc.window.root(&roots);
HTMLCollection::new(&window.root_ref(), Static(vec!()))
let doc = self.htmlelement.element.node.owner_doc().root(&roots);
let window = doc.deref().window.root(&roots);
HTMLCollection::new(&*window, Static(vec!()))
}
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLMetaElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLMetaElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLMetaElementTypeId;
@ -34,7 +34,7 @@ impl HTMLMetaElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLMetaElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLMetaElement> {
let element = HTMLMetaElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLMetaElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLMeterElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLMeterElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLMeterElementTypeId;
@ -34,7 +34,7 @@ impl HTMLMeterElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLMeterElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLMeterElement> {
let element = HTMLMeterElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLMeterElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLModElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLModElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLModElementTypeId;
@ -34,7 +34,7 @@ impl HTMLModElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLModElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLModElement> {
let element = HTMLModElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLModElementBinding::Wrap)
}

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLObjectElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLObjectElementDerived;
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast};
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::{Element, HTMLObjectElementTypeId};
@ -47,7 +47,7 @@ impl HTMLObjectElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLObjectElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLObjectElement> {
let element = HTMLObjectElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLObjectElementBinding::Wrap)
}
@ -57,15 +57,16 @@ trait ProcessDataURL {
fn process_data_url(&mut self, image_cache: ImageCacheTask, url: Option<Url>);
}
impl ProcessDataURL for JS<HTMLObjectElement> {
impl<'a> ProcessDataURL for JSRef<'a, HTMLObjectElement> {
// Makes the local `data` member match the status of the `data` attribute and starts
/// prefetching the image. This method must be called after `data` is changed.
fn process_data_url(&mut self, image_cache: ImageCacheTask, url: Option<Url>) {
let elem: JS<Element> = ElementCast::from(self);
let roots = RootCollection::new();
let elem: &JSRef<Element> = ElementCast::from_ref(self);
// TODO: support other values
match (elem.get_attribute(Null, "type").map(|x| x.get().Value()),
elem.get_attribute(Null, "data").map(|x| x.get().Value())) {
match (elem.get_attribute(Null, "type").map(|x| x.root(&roots).Value()),
elem.get_attribute(Null, "data").map(|x| x.root(&roots).Value())) {
(None, Some(uri)) => {
if is_image_data(uri) {
let data_url = parse_url(uri, url);
@ -111,7 +112,7 @@ impl HTMLObjectElement {
Ok(())
}
pub fn GetForm(&self) -> Option<JS<HTMLFormElement>> {
pub fn GetForm(&self) -> Option<Unrooted<HTMLFormElement>> {
None
}
@ -131,11 +132,11 @@ impl HTMLObjectElement {
Ok(())
}
pub fn GetContentDocument(&self) -> Option<JS<Document>> {
pub fn GetContentDocument(&self) -> Option<Unrooted<Document>> {
None
}
pub fn GetContentWindow(&self) -> Option<JS<Window>> {
pub fn GetContentWindow(&self) -> Option<Unrooted<Window>> {
None
}
@ -143,11 +144,10 @@ impl HTMLObjectElement {
false
}
pub fn Validity(&self) -> JS<ValidityState> {
pub fn Validity(&self) -> Unrooted<ValidityState> {
let roots = RootCollection::new();
let doc = self.htmlelement.element.node.owner_doc();
let doc = doc.get();
let window = doc.window.root(&roots);
let doc = self.htmlelement.element.node.owner_doc().root(&roots);
let window = doc.deref().window.root(&roots);
ValidityState::new(&window.root_ref())
}
@ -242,25 +242,26 @@ impl HTMLObjectElement {
Ok(())
}
pub fn GetSVGDocument(&self) -> Option<JS<Document>> {
pub fn GetSVGDocument(&self) -> Option<Unrooted<Document>> {
None
}
}
impl VirtualMethods for JS<HTMLObjectElement> {
impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> {
fn super_type(&self) -> Option<~VirtualMethods:> {
let htmlelement: JS<HTMLElement> = HTMLElementCast::from(self);
Some(~htmlelement as ~VirtualMethods:)
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
Some(~htmlelement.clone() as ~VirtualMethods:)
}
fn after_set_attr(&mut self, name: DOMString, value: DOMString) {
let roots = RootCollection::new();
match self.super_type() {
Some(ref mut s) => s.after_set_attr(name.clone(), value),
_ => (),
}
if "data" == name {
let window = window_from_node(self);
let window = window_from_node(self).root(&roots);
let url = Some(window.get().get_url());
self.process_data_url(window.get().image_cache_task.clone(), url);
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLOListElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLOListElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLOListElementTypeId;
@ -34,7 +34,7 @@ impl HTMLOListElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLOListElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLOListElement> {
let element = HTMLOListElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLOListElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLOptGroupElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLOptGroupElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLOptGroupElementTypeId;
@ -34,7 +34,7 @@ impl HTMLOptGroupElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLOptGroupElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLOptGroupElement> {
let element = HTMLOptGroupElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLOptGroupElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLOptionElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLOptionElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLOptionElementTypeId;
@ -35,7 +35,7 @@ impl HTMLOptionElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLOptionElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLOptionElement> {
let element = HTMLOptionElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLOptionElementBinding::Wrap)
}
@ -50,7 +50,7 @@ impl HTMLOptionElement {
Ok(())
}
pub fn GetForm(&self) -> Option<JS<HTMLFormElement>> {
pub fn GetForm(&self) -> Option<Unrooted<HTMLFormElement>> {
None
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLOutputElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLOutputElementDerived;
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLOutputElementTypeId;
@ -36,14 +36,14 @@ impl HTMLOutputElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLOutputElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLOutputElement> {
let element = HTMLOutputElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLOutputElementBinding::Wrap)
}
}
impl HTMLOutputElement {
pub fn GetForm(&self) -> Option<JS<HTMLFormElement>> {
pub fn GetForm(&self) -> Option<Unrooted<HTMLFormElement>> {
None
}
@ -82,12 +82,11 @@ impl HTMLOutputElement {
pub fn SetWillValidate(&mut self, _will_validate: bool) {
}
pub fn Validity(&self) -> JS<ValidityState> {
pub fn Validity(&self) -> Unrooted<ValidityState> {
let roots = RootCollection::new();
let doc = self.htmlelement.element.node.owner_doc();
let doc = doc.get();
let window = doc.window.root(&roots);
ValidityState::new(&window.root_ref())
let doc = self.htmlelement.element.node.owner_doc().root(&roots);
let window = doc.deref().window.root(&roots);
ValidityState::new(&*window)
}
pub fn SetValidity(&mut self, _validity: JS<ValidityState>) {

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLParagraphElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLParagraphElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLParagraphElementTypeId;
@ -34,7 +34,7 @@ impl HTMLParagraphElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLParagraphElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLParagraphElement> {
let element = HTMLParagraphElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLParagraphElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLParamElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLParamElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLParamElementTypeId;
@ -34,7 +34,7 @@ impl HTMLParamElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLParamElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLParamElement> {
let element = HTMLParamElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLParamElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLPreElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLPreElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLPreElementTypeId;
@ -34,7 +34,7 @@ impl HTMLPreElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLPreElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLPreElement> {
let element = HTMLPreElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLPreElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLProgressElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLProgressElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::{ErrorResult, Fallible};
use dom::document::Document;
use dom::element::HTMLProgressElementTypeId;
@ -34,7 +34,7 @@ impl HTMLProgressElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLProgressElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLProgressElement> {
let element = HTMLProgressElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLProgressElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLQuoteElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLQuoteElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLQuoteElementTypeId;
@ -34,7 +34,7 @@ impl HTMLQuoteElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLQuoteElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLQuoteElement> {
let element = HTMLQuoteElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLQuoteElementBinding::Wrap)
}

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLScriptElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLScriptElementDerived;
use dom::bindings::codegen::InheritTypes::ElementCast;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::{HTMLScriptElementTypeId, Element, AttributeHandlers};
@ -35,7 +35,7 @@ impl HTMLScriptElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLScriptElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLScriptElement> {
let element = HTMLScriptElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLScriptElementBinding::Wrap)
}
@ -43,7 +43,7 @@ impl HTMLScriptElement {
impl HTMLScriptElement {
pub fn Src(&self, abstract_self: &JSRef<HTMLScriptElement>) -> DOMString {
let element: JS<Element> = ElementCast::from(&abstract_self.unrooted());
let element: &JSRef<Element> = ElementCast::from_ref(abstract_self);
element.get_url_attribute("src")
}

View file

@ -5,7 +5,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLSelectElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLSelectElementDerived;
use dom::bindings::codegen::UnionTypes::{HTMLElementOrLong, HTMLOptionElementOrHTMLOptGroupElement};
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::{Element, HTMLSelectElementTypeId};
@ -38,7 +38,7 @@ impl HTMLSelectElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLSelectElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLSelectElement> {
let element = HTMLSelectElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLSelectElementBinding::Wrap)
}
@ -61,7 +61,7 @@ impl HTMLSelectElement {
Ok(())
}
pub fn GetForm(&self) -> Option<JS<HTMLFormElement>> {
pub fn GetForm(&self) -> Option<Unrooted<HTMLFormElement>> {
None
}
@ -109,15 +109,15 @@ impl HTMLSelectElement {
Ok(())
}
pub fn Item(&self, _index: u32) -> Option<JS<Element>> {
pub fn Item(&self, _index: u32) -> Option<Unrooted<Element>> {
None
}
pub fn NamedItem(&self, _name: DOMString) -> Option<JS<HTMLOptionElement>> {
pub fn NamedItem(&self, _name: DOMString) -> Option<Unrooted<HTMLOptionElement>> {
None
}
pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option<JS<Element>> {
pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option<Unrooted<Element>> {
None
}
@ -153,12 +153,11 @@ impl HTMLSelectElement {
pub fn SetWillValidate(&mut self, _will_validate: bool) {
}
pub fn Validity(&self) -> JS<ValidityState> {
pub fn Validity(&self) -> Unrooted<ValidityState> {
let roots = RootCollection::new();
let doc = self.htmlelement.element.node.owner_doc();
let doc = doc.get();
let window = doc.window.root(&roots);
ValidityState::new(&window.root_ref())
let doc = self.htmlelement.element.node.owner_doc().root(&roots);
let window = doc.deref().window.root(&roots);
ValidityState::new(&*window)
}
pub fn SetValidity(&mut self, _validity: JS<ValidityState>) {

View file

@ -4,15 +4,15 @@
use servo_util::namespace;
use dom::attr::Attr;
use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, CommentCast};
use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, CommentCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, CharacterDataCast};
use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast;
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JSRef, RootCollection};
use dom::characterdata::CharacterData;
use dom::comment::Comment;
use dom::documenttype::DocumentType;
use dom::element::Element;
use dom::node::NodeIterator;
use dom::node::{Node, NodeIterator};
use dom::node::{DoctypeNodeTypeId, DocumentFragmentNodeTypeId, CommentNodeTypeId};
use dom::node::{DocumentNodeTypeId, ElementNodeTypeId, ProcessingInstructionNodeTypeId};
use dom::node::{TextNodeTypeId, NodeHelpers};
@ -20,7 +20,6 @@ use dom::processinginstruction::ProcessingInstruction;
use dom::text::Text;
pub fn serialize(iterator: &mut NodeIterator) -> ~str {
let roots = RootCollection::new();
let mut html = ~"";
let mut open_elements: Vec<~str> = vec!();
@ -31,29 +30,25 @@ pub fn serialize(iterator: &mut NodeIterator) -> ~str {
html.push_str(
match node.type_id() {
ElementNodeTypeId(..) => {
let elem: JS<Element> = ElementCast::to(&node).unwrap();
let elem = elem.root(&roots);
serialize_elem(&elem.root_ref(), &mut open_elements)
let elem: &JSRef<Element> = ElementCast::to_ref(&node).unwrap();
serialize_elem(elem, &mut open_elements)
}
CommentNodeTypeId => {
let comment: JS<Comment> = CommentCast::to(&node).unwrap();
let comment = comment.root(&roots);
serialize_comment(&comment.root_ref())
let comment: &JSRef<Comment> = CommentCast::to_ref(&node).unwrap();
serialize_comment(comment)
}
TextNodeTypeId => {
let text: JS<Text> = TextCast::to(&node).unwrap();
let text = text.root(&roots);
serialize_text(&text.root_ref())
let text: &JSRef<Text> = TextCast::to_ref(&node).unwrap();
serialize_text(text)
}
DoctypeNodeTypeId => {
let doctype: JS<DocumentType> = DocumentTypeCast::to(&node).unwrap();
let doctype = doctype.root(&roots);
serialize_doctype(&doctype.root_ref())
let doctype: &JSRef<DocumentType> = DocumentTypeCast::to_ref(&node).unwrap();
serialize_doctype(doctype)
}
ProcessingInstructionNodeTypeId => {
let processing_instruction: JS<ProcessingInstruction> = ProcessingInstructionCast::to(&node).unwrap();
let processing_instruction = processing_instruction.root(&roots);
serialize_processing_instruction(&processing_instruction.root_ref())
let processing_instruction: &JSRef<ProcessingInstruction> =
ProcessingInstructionCast::to_ref(&node).unwrap();
serialize_processing_instruction(processing_instruction)
}
DocumentFragmentNodeTypeId => {
~""
@ -75,9 +70,11 @@ fn serialize_comment(comment: &JSRef<Comment>) -> ~str {
}
fn serialize_text(text: &JSRef<Text>) -> ~str {
match text.get().characterdata.node.parent_node {
let roots = RootCollection::new();
let text_node: &JSRef<Node> = NodeCast::from_ref(text);
match text_node.parent_node().map(|node| node.root(&roots)) {
Some(ref parent) if parent.is_element() => {
let elem: JS<Element> = ElementCast::to(parent).unwrap();
let elem: &JSRef<Element> = ElementCast::to_ref(&**parent).unwrap();
match elem.get().local_name.as_slice() {
"style" | "script" | "xmp" | "iframe" |
"noembed" | "noframes" | "plaintext" |
@ -104,14 +101,15 @@ fn serialize_elem(elem: &JSRef<Element>, open_elements: &mut Vec<~str>) -> ~str
let mut rv = ~"<" + elem.get().local_name;
for attr in elem.get().attrs.iter() {
let attr = attr.root(&roots);
rv.push_str(serialize_attr(&attr.root_ref()));
rv.push_str(serialize_attr(&*attr));
};
rv.push_str(">");
match elem.get().local_name.as_slice() {
"pre" | "listing" | "textarea" if elem.get().namespace == namespace::HTML => {
match elem.get().node.first_child {
let node: &JSRef<Node> = NodeCast::from_ref(elem);
match node.first_child().map(|child| child.root(&roots)) {
Some(ref child) if child.is_text() => {
let text: JS<CharacterData> = CharacterDataCast::to(child).unwrap();
let text: &JSRef<CharacterData> = CharacterDataCast::to_ref(&**child).unwrap();
if text.get().data.len() > 0 && text.get().data[0] == 0x0A as u8 {
rv.push_str("\x0A");
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLSourceElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLSourceElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLSourceElementTypeId;
@ -34,7 +34,7 @@ impl HTMLSourceElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLSourceElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLSourceElement> {
let element = HTMLSourceElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLSourceElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLSpanElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLSpanElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLSpanElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -33,7 +33,7 @@ impl HTMLSpanElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLSpanElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLSpanElement> {
let element = HTMLSpanElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLSpanElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLStyleElementBinding;
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLStyleElementDerived, NodeCast};
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLStyleElementTypeId;
@ -37,7 +37,7 @@ impl HTMLStyleElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLStyleElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLStyleElement> {
let element = HTMLStyleElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLStyleElementBinding::Wrap)
}
@ -80,28 +80,27 @@ pub trait StyleElementHelpers {
fn parse_own_css(&self);
}
impl StyleElementHelpers for JS<HTMLStyleElement> {
impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> {
fn parse_own_css(&self) {
let roots = RootCollection::new();
let node: JS<Node> = NodeCast::from(self);
let node_root = node.root(&roots);
let win = window_from_node(&node);
let node: &JSRef<Node> = NodeCast::from_ref(self);
let win = window_from_node(node).root(&roots);
let url = win.get().page().get_url();
let data = node.get().GetTextContent(&node_root.root_ref()).expect("Element.textContent must be a string");
let data = node.get().GetTextContent(node).expect("Element.textContent must be a string");
let sheet = parse_inline_css(url, data);
let LayoutChan(ref layout_chan) = *win.get().page().layout_chan;
layout_chan.send(AddStylesheetMsg(sheet));
}
}
impl VirtualMethods for JS<HTMLStyleElement> {
impl<'a> VirtualMethods for JSRef<'a, HTMLStyleElement> {
fn super_type(&self) -> Option<~VirtualMethods:> {
let htmlelement: JS<HTMLElement> = HTMLElementCast::from(self);
Some(~htmlelement as ~VirtualMethods:)
let htmlelement: &JSRef<HTMLElement> = HTMLElementCast::from_ref(self);
Some(~htmlelement.clone() as ~VirtualMethods:)
}
fn child_inserted(&mut self, child: &JS<Node>) {
fn child_inserted(&mut self, child: &JSRef<Node>) {
match self.super_type() {
Some(ref mut s) => s.child_inserted(child),
_ => (),

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLTableCaptionElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLTableCaptionElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLTableCaptionElementTypeId;
@ -34,7 +34,7 @@ impl HTMLTableCaptionElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLTableCaptionElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLTableCaptionElement> {
let element = HTMLTableCaptionElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLTableCaptionElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLTableColElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLTableColElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLTableColElementTypeId;
@ -34,7 +34,7 @@ impl HTMLTableColElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLTableColElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLTableColElement> {
let element = HTMLTableColElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLTableColElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLTableDataCellElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLTableDataCellElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLTableDataCellElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -33,7 +33,7 @@ impl HTMLTableDataCellElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLTableDataCellElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLTableDataCellElement> {
let element = HTMLTableDataCellElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLTableDataCellElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLTableElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLTableElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLTableElementTypeId;
@ -34,7 +34,7 @@ impl HTMLTableElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLTableElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLTableElement> {
let element = HTMLTableElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLTableElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLTableHeaderCellElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLTableHeaderCellElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLTableHeaderCellElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -33,7 +33,7 @@ impl HTMLTableHeaderCellElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLTableHeaderCellElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLTableHeaderCellElement> {
let element = HTMLTableHeaderCellElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLTableHeaderCellElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLTableRowElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLTableRowElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLTableRowElementTypeId;
@ -34,7 +34,7 @@ impl HTMLTableRowElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLTableRowElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLTableRowElement> {
let element = HTMLTableRowElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLTableRowElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLTableSectionElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLTableSectionElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLTableSectionElementTypeId;
@ -34,7 +34,7 @@ impl HTMLTableSectionElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLTableSectionElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLTableSectionElement> {
let element = HTMLTableSectionElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLTableSectionElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLTemplateElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLTemplateElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLTemplateElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -33,7 +33,7 @@ impl HTMLTemplateElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLTemplateElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLTemplateElement> {
let element = HTMLTemplateElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLTemplateElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLTextAreaElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLTextAreaElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::{ErrorResult, Fallible};
use dom::document::Document;
use dom::element::HTMLTextAreaElementTypeId;
@ -34,7 +34,7 @@ impl HTMLTextAreaElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLTextAreaElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLTextAreaElement> {
let element = HTMLTextAreaElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLTextAreaElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLTimeElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLTimeElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLTimeElementTypeId;
@ -34,7 +34,7 @@ impl HTMLTimeElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLTimeElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLTimeElement> {
let element = HTMLTimeElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLTimeElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLTitleElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLTitleElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLTitleElementTypeId;
@ -34,7 +34,7 @@ impl HTMLTitleElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLTitleElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLTitleElement> {
let element = HTMLTitleElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLTitleElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLTrackElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLTrackElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLTrackElementTypeId;
@ -34,7 +34,7 @@ impl HTMLTrackElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLTrackElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLTrackElement> {
let element = HTMLTrackElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLTrackElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLUListElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLUListElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLUListElementTypeId;
@ -34,7 +34,7 @@ impl HTMLUListElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLUListElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLUListElement> {
let element = HTMLUListElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLUListElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLUnknownElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLUnknownElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::document::Document;
use dom::element::HTMLUnknownElementTypeId;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -33,7 +33,7 @@ impl HTMLUnknownElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLUnknownElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLUnknownElement> {
let element = HTMLUnknownElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLUnknownElementBinding::Wrap)
}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::HTMLVideoElementBinding;
use dom::bindings::codegen::InheritTypes::HTMLVideoElementDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::bindings::error::ErrorResult;
use dom::document::Document;
use dom::element::HTMLVideoElementTypeId;
@ -34,7 +34,7 @@ impl HTMLVideoElement {
}
}
pub fn new(localName: DOMString, document: &JSRef<Document>) -> JS<HTMLVideoElement> {
pub fn new(localName: DOMString, document: &JSRef<Document>) -> Unrooted<HTMLVideoElement> {
let element = HTMLVideoElement::new_inherited(localName, document.unrooted());
Node::reflect_node(~element, document, HTMLVideoElementBinding::Wrap)
}

View file

@ -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, JSRef};
use dom::bindings::js::{JSRef, Unrooted};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::error::Fallible;
use dom::window::Window;
@ -29,7 +29,7 @@ impl Location {
}
}
pub fn new(window: &JSRef<Window>, page: Rc<Page>) -> JS<Location> {
pub fn new(window: &JSRef<Window>, page: Rc<Page>) -> Unrooted<Location> {
reflect_dom_object(~Location::new_inherited(page),
window,
LocationBinding::Wrap)

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::MouseEventBinding;
use dom::bindings::codegen::InheritTypes::MouseEventDerived;
use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference};
use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Unrooted};
use dom::bindings::error::Fallible;
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::event::{Event, MouseEventTypeId};
@ -51,7 +51,7 @@ impl MouseEvent {
}
}
pub fn new(window: &JSRef<Window>) -> JS<MouseEvent> {
pub fn new(window: &JSRef<Window>) -> Unrooted<MouseEvent> {
reflect_dom_object(~MouseEvent::new_inherited(),
window,
MouseEventBinding::Wrap)
@ -59,9 +59,9 @@ impl MouseEvent {
pub fn Constructor(owner: &JSRef<Window>,
type_: DOMString,
init: &MouseEventBinding::MouseEventInit) -> Fallible<JS<MouseEvent>> {
init: &MouseEventBinding::MouseEventInit) -> Fallible<Unrooted<MouseEvent>> {
let roots = RootCollection::new();
let mut ev = MouseEvent::new(owner);
let mut ev = MouseEvent::new(owner).root(&roots);
let view = init.view.as_ref().map(|view| view.root(&roots));
let related_target = init.relatedTarget.as_ref().map(|relatedTarget| relatedTarget.root(&roots));
ev.get_mut().InitMouseEvent(type_, init.bubbles, init.cancelable, view.root_ref(),
@ -69,7 +69,7 @@ impl MouseEvent {
init.clientX, init.clientY, init.ctrlKey,
init.altKey, init.shiftKey, init.metaKey,
init.button, related_target.root_ref());
Ok(ev)
Ok(Unrooted::new_rooted(&*ev))
}
pub fn ScreenX(&self) -> i32 {
@ -113,8 +113,8 @@ impl MouseEvent {
0
}
pub fn GetRelatedTarget(&self) -> Option<JS<EventTarget>> {
self.related_target.clone()
pub fn GetRelatedTarget(&self) -> Option<Unrooted<EventTarget>> {
self.related_target.clone().map(|target| Unrooted::new(target))
}
pub fn GetModifierState(&self, _keyArg: DOMString) -> bool {

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::BindingDeclarations::NavigatorBinding;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JSRef, Unrooted};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::bindings::error::Fallible;
use dom::window::Window;
@ -21,7 +21,7 @@ impl Navigator {
}
}
pub fn new(window: &JSRef<Window>) -> JS<Navigator> {
pub fn new(window: &JSRef<Window>) -> Unrooted<Navigator> {
reflect_dom_object(~Navigator::new_inherited(),
window,
NavigatorBinding::Wrap)

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use dom::bindings::codegen::BindingDeclarations::NodeListBinding;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted, RootCollection};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::node::{Node, NodeHelpers};
use dom::window::Window;
@ -32,35 +32,44 @@ impl NodeList {
}
pub fn new(window: &JSRef<Window>,
list_type: NodeListType) -> JS<NodeList> {
list_type: NodeListType) -> Unrooted<NodeList> {
reflect_dom_object(~NodeList::new_inherited(window.unrooted(), list_type),
window, NodeListBinding::Wrap)
}
pub fn new_simple_list(window: &JSRef<Window>, elements: Vec<JS<Node>>) -> JS<NodeList> {
NodeList::new(window, Simple(elements))
pub fn new_simple_list(window: &JSRef<Window>, elements: Vec<JSRef<Node>>) -> Unrooted<NodeList> {
NodeList::new(window, Simple(elements.iter().map(|element| element.unrooted()).collect()))
}
pub fn new_child_list(window: &JSRef<Window>, node: &JSRef<Node>) -> JS<NodeList> {
pub fn new_child_list(window: &JSRef<Window>, node: &JSRef<Node>) -> Unrooted<NodeList> {
NodeList::new(window, Children(node.unrooted()))
}
pub fn Length(&self) -> u32 {
let roots = RootCollection::new();
match self.list_type {
Simple(ref elems) => elems.len() as u32,
Children(ref node) => node.children().len() as u32
Children(ref node) => {
let node = node.root(&roots);
node.deref().children().len() as u32
}
}
}
pub fn Item(&self, index: u32) -> Option<JS<Node>> {
pub fn Item(&self, index: u32) -> Option<Unrooted<Node>> {
let roots = RootCollection::new();
match self.list_type {
_ if index >= self.Length() => None,
Simple(ref elems) => Some(elems.get(index as uint).clone()),
Children(ref node) => node.children().nth(index as uint)
Simple(ref elems) => Some(Unrooted::new(elems.get(index as uint).clone())),
Children(ref node) => {
let node = node.root(&roots);
node.deref().children().nth(index as uint)
.map(|child| Unrooted::new_rooted(&child))
}
}
}
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<JS<Node>> {
pub fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Unrooted<Node>> {
let item = self.Item(index);
*found = item.is_some();
item

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::ProcessingInstructionBinding;
use dom::bindings::codegen::InheritTypes::ProcessingInstructionDerived;
use dom::bindings::js::{JS, JSRef};
use dom::bindings::js::{JS, JSRef, Unrooted};
use dom::characterdata::CharacterData;
use dom::document::Document;
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
@ -35,7 +35,7 @@ impl ProcessingInstruction {
}
}
pub fn new(target: DOMString, data: DOMString, document: &JSRef<Document>) -> JS<ProcessingInstruction> {
pub fn new(target: DOMString, data: DOMString, document: &JSRef<Document>) -> Unrooted<ProcessingInstruction> {
let node = ProcessingInstruction::new_inherited(target, data, document.unrooted());
Node::reflect_node(~node, document, ProcessingInstructionBinding::Wrap)
}

View file

@ -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, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::codegen::BindingDeclarations::TestBindingBinding;
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong;
use self::TestBindingBinding::TestEnum;
@ -51,10 +51,10 @@ impl TestBinding {
pub fn SetByteStringAttribute(&self, _: ByteString) {}
pub fn EnumAttribute(&self) -> TestEnum { _empty }
pub fn SetEnumAttribute(&self, _: TestEnum) {}
pub fn InterfaceAttribute(&self) -> JS<Blob> {
pub fn InterfaceAttribute(&self) -> Unrooted<Blob> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
Blob::new(&window.root_ref())
Blob::new(&*window)
}
pub fn SetInterfaceAttribute(&self, _: &JSRef<Blob>) {}
pub fn AnyAttribute(&self, _: *JSContext) -> JSVal { NullValue() }
@ -87,10 +87,10 @@ impl TestBinding {
pub fn GetStringAttributeNullable(&self) -> Option<DOMString> { Some(~"") }
pub fn SetStringAttributeNullable(&self, _: Option<DOMString>) {}
pub fn GetEnumAttributeNullable(&self) -> Option<TestEnum> { Some(_empty) }
pub fn GetInterfaceAttributeNullable(&self) -> Option<JS<Blob>> {
pub fn GetInterfaceAttributeNullable(&self) -> Option<Unrooted<Blob>> {
let roots = RootCollection::new();
let window = self.window.root(&roots);
Some(Blob::new(&window.root_ref()))
Some(Blob::new(&(*window)))
}
pub fn SetInterfaceAttributeNullable(&self, _: Option<JSRef<Blob>>) {}

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::BindingDeclarations::TextBinding;
use dom::bindings::codegen::InheritTypes::TextDerived;
use dom::bindings::js::{JS, JSRef, RootCollection};
use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted};
use dom::bindings::error::Fallible;
use dom::characterdata::CharacterData;
use dom::document::Document;
@ -35,19 +35,19 @@ impl Text {
}
}
pub fn new(text: DOMString, document: &JSRef<Document>) -> JS<Text> {
pub fn new(text: DOMString, document: &JSRef<Document>) -> Unrooted<Text> {
let node = Text::new_inherited(text, document.unrooted());
Node::reflect_node(~node, document, TextBinding::Wrap)
}
pub fn Constructor(owner: &JSRef<Window>, text: DOMString) -> Fallible<JS<Text>> {
pub fn Constructor(owner: &JSRef<Window>, text: DOMString) -> Fallible<Unrooted<Text>> {
let roots = RootCollection::new();
let document = owner.get().Document();
let document = document.root(&roots);
Ok(Text::new(text.clone(), &document.root_ref()))
}
pub fn SplitText(&self, _offset: u32) -> Fallible<JS<Text>> {
pub fn SplitText(&self, _offset: u32) -> Fallible<Unrooted<Text>> {
fail!("unimplemented")
}

Some files were not shown because too many files have changed in this diff Show more