mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Remove all root collections.
This commit is contained in:
parent
aaf0a61194
commit
7b3e6d1f21
35 changed files with 329 additions and 475 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::BindingDeclarations::AttrBinding;
|
||||
use dom::bindings::codegen::InheritTypes::NodeCast;
|
||||
use dom::bindings::js::{JS, JSRef, Temporary, RootCollection};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::element::Element;
|
||||
use dom::node::Node;
|
||||
|
@ -65,8 +65,7 @@ impl Attr {
|
|||
}
|
||||
|
||||
pub fn set_value(&mut self, set_type: AttrSettingType, value: DOMString) {
|
||||
let roots = RootCollection::new();
|
||||
let owner = self.owner.root(&roots);
|
||||
let owner = self.owner.root();
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(&*owner);
|
||||
let namespace_is_null = self.namespace == namespace::Null;
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::attr::Attr;
|
||||
use dom::bindings::codegen::BindingDeclarations::AttrListBinding;
|
||||
use dom::bindings::js::{JS, JSRef, Temporary, RootCollection};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::element::Element;
|
||||
use dom::window::Window;
|
||||
|
@ -39,13 +39,11 @@ pub trait AttrListMethods {
|
|||
|
||||
impl<'a> AttrListMethods for JSRef<'a, AttrList> {
|
||||
fn Length(&self) -> u32 {
|
||||
let roots = RootCollection::new();
|
||||
self.owner.root(&roots).attrs.len() as u32
|
||||
self.owner.root().attrs.len() as u32
|
||||
}
|
||||
|
||||
fn Item(&self, index: u32) -> Option<Temporary<Attr>> {
|
||||
let roots = RootCollection::new();
|
||||
self.owner.root(&roots).attrs.as_slice().get(index as uint).map(|x| Temporary::new(x.clone()))
|
||||
self.owner.root().attrs.as_slice().get(index as uint).map(|x| Temporary::new(x.clone()))
|
||||
}
|
||||
|
||||
fn IndexedGetter(&self, index: u32, found: &mut bool) -> Option<Temporary<Attr>> {
|
||||
|
|
|
@ -903,10 +903,10 @@ def instantiateJSToNativeConversionTemplate(templateTuple, replacements,
|
|||
if type and 'JS<' in type:
|
||||
if dealWithOptional or 'Option<' in type:
|
||||
rootBody = """let ${simpleDeclName} = ${declName}.as_ref().map(|inner| {
|
||||
inner.root(&roots) //second root code
|
||||
inner.root() //second root code
|
||||
});"""
|
||||
else:
|
||||
rootBody = "let ${simpleDeclName} = ${declName}.root(&roots); //third root code"
|
||||
rootBody = "let ${simpleDeclName} = ${declName}.root(); //third root code"
|
||||
result.append(CGGeneric(string.Template(rootBody).substitute(replacements)))
|
||||
result.append(CGGeneric(""))
|
||||
|
||||
|
@ -1799,7 +1799,7 @@ class CGAbstractMethod(CGThing):
|
|||
def _returnType(self):
|
||||
return (" -> %s" % self.returnType) if self.returnType != "void" else ""
|
||||
def _unsafe_open(self):
|
||||
return "\n unsafe {\n let roots = RootCollection::new();\n" if self.unsafe else ""
|
||||
return "\n unsafe {\n" if self.unsafe else ""
|
||||
def _unsafe_close(self):
|
||||
return "\n }\n" if self.unsafe else ""
|
||||
|
||||
|
@ -2247,7 +2247,7 @@ class CGCallGenerator(CGThing):
|
|||
self.cgRoot.append(CGGeneric("result = result_fallible.unwrap();"))
|
||||
|
||||
if typeRetValNeedsRooting(returnType):
|
||||
self.cgRoot.append(CGGeneric("let result = result.root(&roots);"))
|
||||
self.cgRoot.append(CGGeneric("let result = result.root();"))
|
||||
|
||||
def define(self):
|
||||
return self.cgRoot.define()
|
||||
|
@ -2498,7 +2498,7 @@ class CGSpecializedMethod(CGAbstractExternMethod):
|
|||
self.descriptor, self.method),
|
||||
pre=extraPre +
|
||||
" let this = JS::from_raw(this);\n" +
|
||||
" let mut this = this.root(&roots);\n").define()
|
||||
" let mut this = this.root();\n").define()
|
||||
|
||||
class CGGenericGetter(CGAbstractBindingMethod):
|
||||
"""
|
||||
|
@ -2552,7 +2552,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
|
|||
self.descriptor, self.attr)),
|
||||
pre=extraPre +
|
||||
" let this = JS::from_raw(this);\n" +
|
||||
" let mut this = this.root(&roots);\n").define()
|
||||
" let mut this = this.root();\n").define()
|
||||
|
||||
class CGGenericSetter(CGAbstractBindingMethod):
|
||||
"""
|
||||
|
@ -2606,7 +2606,7 @@ class CGSpecializedSetter(CGAbstractExternMethod):
|
|||
self.descriptor, self.attr)),
|
||||
pre=extraPre +
|
||||
" let this = JS::from_raw(this);\n" +
|
||||
" let mut this = this.root(&roots);\n").define()
|
||||
" let mut this = this.root();\n").define()
|
||||
|
||||
|
||||
class CGMemberJITInfo(CGThing):
|
||||
|
@ -3531,7 +3531,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
|||
" let index = index.unwrap();\n" +
|
||||
" let this = UnwrapProxy(proxy);\n" +
|
||||
" let this = JS::from_raw(this);\n" +
|
||||
" let mut this = this.root(&roots);\n" +
|
||||
" let mut this = this.root();\n" +
|
||||
CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define() + "\n" +
|
||||
"}\n")
|
||||
|
||||
|
@ -3578,7 +3578,7 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
|||
" let name = Some(jsid_to_str(cx, id));\n" +
|
||||
" let this = UnwrapProxy(proxy);\n" +
|
||||
" let this = JS::from_raw(this);\n" +
|
||||
" let mut this = this.root(&roots);\n" +
|
||||
" let mut this = this.root();\n" +
|
||||
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() + "\n" +
|
||||
"}\n")
|
||||
else:
|
||||
|
@ -3623,7 +3623,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
|||
" let index = index.unwrap();\n" +
|
||||
" let this = UnwrapProxy(proxy);\n" +
|
||||
" let this = JS::from_raw(this);\n" +
|
||||
" let mut this = this.root(&roots);\n" +
|
||||
" let mut this = this.root();\n" +
|
||||
CGIndenter(CGProxyIndexedSetter(self.descriptor)).define() +
|
||||
" return 1;\n" +
|
||||
"}\n")
|
||||
|
@ -3641,7 +3641,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
|||
" let name = Some(jsid_to_str(cx, id));\n" +
|
||||
" let this = UnwrapProxy(proxy);\n" +
|
||||
" let this = JS::from_raw(this);\n" +
|
||||
" let mut this = this.root(&roots);\n" +
|
||||
" let mut this = this.root();\n" +
|
||||
CGIndenter(CGProxyNamedSetter(self.descriptor)).define() + "\n" +
|
||||
"}\n")
|
||||
elif self.descriptor.operations['NamedGetter']:
|
||||
|
@ -3649,7 +3649,7 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
|||
" let name = Some(jsid_to_str(cx, id));\n" +
|
||||
" let this = UnwrapProxy(proxy);\n" +
|
||||
" let this = JS::from_raw(this);\n" +
|
||||
" let mut this = this.root(&roots);\n" +
|
||||
" let mut this = this.root();\n" +
|
||||
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() +
|
||||
" if (found) {\n"
|
||||
" return 0;\n" +
|
||||
|
@ -3676,7 +3676,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
|
|||
" let index = index.unwrap();\n" +
|
||||
" let this = UnwrapProxy(proxy);\n" +
|
||||
" let this = JS::from_raw(this);\n" +
|
||||
" let mut this = this.root(&roots);\n" +
|
||||
" let mut this = this.root();\n" +
|
||||
CGIndenter(CGProxyIndexedGetter(self.descriptor)).define() + "\n" +
|
||||
" *bp = found as JSBool;\n" +
|
||||
" return 1;\n" +
|
||||
|
@ -3690,7 +3690,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
|
|||
" let name = Some(jsid_to_str(cx, id));\n" +
|
||||
" let this = UnwrapProxy(proxy);\n" +
|
||||
" let this = JS::from_raw(this);\n" +
|
||||
" let mut this = this.root(&roots);\n" +
|
||||
" let mut this = this.root();\n" +
|
||||
CGIndenter(CGProxyNamedGetter(self.descriptor)).define() + "\n" +
|
||||
" *bp = found as JSBool;\n"
|
||||
" return 1;\n"
|
||||
|
@ -3744,7 +3744,7 @@ if expando.is_not_null() {
|
|||
" let index = index.unwrap();\n" +
|
||||
" let this = UnwrapProxy(proxy);\n" +
|
||||
" let this = JS::from_raw(this);\n" +
|
||||
" let mut this = this.root(&roots);\n" +
|
||||
" let mut this = this.root();\n" +
|
||||
CGIndenter(CGProxyIndexedGetter(self.descriptor, templateValues)).define())
|
||||
getIndexedOrExpando += """
|
||||
// Even if we don't have this index, we don't forward the
|
||||
|
@ -3762,7 +3762,7 @@ if expando.is_not_null() {
|
|||
" let name = Some(jsid_to_str(cx, id));\n" +
|
||||
" let this = UnwrapProxy(proxy);\n" +
|
||||
" let this = JS::from_raw(this);\n" +
|
||||
" let mut this = this.root(&roots);\n" +
|
||||
" let mut this = this.root();\n" +
|
||||
CGIndenter(CGProxyNamedGetter(self.descriptor, templateValues)).define() +
|
||||
"}\n") % (self.descriptor.concreteType)
|
||||
else:
|
||||
|
@ -3879,9 +3879,8 @@ class CGClassConstructHook(CGAbstractExternMethod):
|
|||
|
||||
def generate_code(self):
|
||||
preamble = """
|
||||
let roots = RootCollection::new();
|
||||
let global = global_object_for_js_object(JS_CALLEE(cx, &*vp).to_object());
|
||||
let global = global.root(&roots);
|
||||
let global = global.root();
|
||||
let obj = global.reflector().get_jsobject();
|
||||
"""
|
||||
nativeName = MakeNativeName(self._ctor.identifier.name)
|
||||
|
@ -4123,7 +4122,6 @@ class CGDictionary(CGThing):
|
|||
return string.Template(
|
||||
"impl ${selfName} {\n"
|
||||
" pub fn new(cx: *JSContext, val: JSVal) -> Result<${selfName}, ()> {\n"
|
||||
" let roots = RootCollection::new();\n" # XXXjdm need to root dict members outside of Init
|
||||
" let object = if val.is_null_or_undefined() {\n"
|
||||
" ptr::null()\n"
|
||||
" } else if val.is_object() {\n"
|
||||
|
@ -4323,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, Temporary, OptionalRootable}',
|
||||
'dom::bindings::js::{JS, JSRef, RootedReference, Temporary, OptionalRootable}',
|
||||
'dom::bindings::utils::{CreateDOMGlobal, CreateInterfaceObjects2}',
|
||||
'dom::bindings::utils::{ConstantSpec, cx_for_dom_object, Default}',
|
||||
'dom::bindings::utils::{dom_object_slot, DOM_OBJECT_SLOT, DOMClass}',
|
||||
|
|
|
@ -54,7 +54,7 @@ impl<T: Reflectable> Temporary<T> {
|
|||
}
|
||||
|
||||
/// Root this unrooted value.
|
||||
pub fn root<'a, 'b>(self, _collection: &'a RootCollection) -> Root<'a, 'b, T> {
|
||||
pub fn root<'a, 'b>(self) -> Root<'a, 'b, T> {
|
||||
local_data::get(StackRoots, |opt| {
|
||||
let collection = opt.unwrap();
|
||||
unsafe {
|
||||
|
@ -119,8 +119,13 @@ impl<T: Reflectable> JS<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)
|
||||
pub fn root<'a, 'b>(&self) -> Root<'a, 'b, T> {
|
||||
local_data::get(StackRoots, |opt| {
|
||||
let collection = opt.unwrap();
|
||||
unsafe {
|
||||
(**collection).new_root(self)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -214,32 +219,32 @@ impl<T: Assignable<U>, U: Reflectable> OptionalAssignable<T> for Option<JS<U>> {
|
|||
}
|
||||
|
||||
pub trait OptionalRootable<T> {
|
||||
fn root<'a, 'b>(self, roots: &'a RootCollection) -> Option<Root<'a, 'b, T>>;
|
||||
fn root<'a, 'b>(self) -> Option<Root<'a, 'b, T>>;
|
||||
}
|
||||
|
||||
impl<T: Reflectable> OptionalRootable<T> for Option<Temporary<T>> {
|
||||
fn root<'a, 'b>(self, roots: &'a RootCollection) -> Option<Root<'a, 'b, T>> {
|
||||
self.map(|inner| inner.root(roots))
|
||||
fn root<'a, 'b>(self) -> Option<Root<'a, 'b, T>> {
|
||||
self.map(|inner| inner.root())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait OptionalRootedRootable<T> {
|
||||
fn root<'a, 'b>(&self, roots: &'a RootCollection) -> Option<Root<'a, 'b, T>>;
|
||||
fn root<'a, 'b>(&self) -> Option<Root<'a, 'b, T>>;
|
||||
}
|
||||
|
||||
impl<T: Reflectable> OptionalRootedRootable<T> for Option<JS<T>> {
|
||||
fn root<'a, 'b>(&self, roots: &'a RootCollection) -> Option<Root<'a, 'b, T>> {
|
||||
self.as_ref().map(|inner| inner.root(roots))
|
||||
fn root<'a, 'b>(&self) -> Option<Root<'a, 'b, T>> {
|
||||
self.as_ref().map(|inner| inner.root())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait ResultRootable<T,U> {
|
||||
fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result<Root<'a, 'b, T>, U>;
|
||||
fn root<'a, 'b>(self) -> Result<Root<'a, 'b, T>, U>;
|
||||
}
|
||||
|
||||
impl<T: Reflectable, U> ResultRootable<T, U> for Result<Temporary<T>, U> {
|
||||
fn root<'a, 'b>(self, roots: &'a RootCollection) -> Result<Root<'a, 'b, T>, U> {
|
||||
self.map(|inner| inner.root(roots))
|
||||
fn root<'a, 'b>(self) -> Result<Root<'a, 'b, T>, U> {
|
||||
self.map(|inner| inner.root())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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, RootCollection, Temporary, Root};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary, Root};
|
||||
use dom::bindings::trace::Untraceable;
|
||||
use dom::browsercontext;
|
||||
use dom::window;
|
||||
|
@ -606,7 +606,6 @@ pub extern fn wrap_for_same_compartment(cx: *JSContext, obj: *JSObject) -> *JSOb
|
|||
|
||||
pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject {
|
||||
unsafe {
|
||||
let roots = RootCollection::new();
|
||||
debug!("outerizing");
|
||||
let obj = *obj.unnamed;
|
||||
let win: Root<window::Window> =
|
||||
|
@ -614,7 +613,7 @@ pub extern fn outerize_global(_cx: *JSContext, obj: JSHandleObject) -> *JSObject
|
|||
IDLInterface::get_prototype_id(None::<window::Window>),
|
||||
IDLInterface::get_prototype_depth(None::<window::Window>))
|
||||
.unwrap()
|
||||
.root(&roots);
|
||||
.root();
|
||||
win.deref().browser_context.get_ref().window_proxy()
|
||||
}
|
||||
}
|
||||
|
@ -631,8 +630,7 @@ pub fn global_object_for_js_object(obj: *JSObject) -> JS<window::Window> {
|
|||
}
|
||||
|
||||
fn cx_for_dom_reflector(obj: *JSObject) -> *JSContext {
|
||||
let roots = RootCollection::new();
|
||||
let win = global_object_for_js_object(obj).root(&roots);
|
||||
let win = global_object_for_js_object(obj).root();
|
||||
let js_info = win.get().page().js_info();
|
||||
match *js_info {
|
||||
Some(ref info) => info.js_context.deref().deref().ptr,
|
||||
|
|
|
@ -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, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::codegen::BindingDeclarations::BlobBinding;
|
||||
|
@ -51,8 +51,7 @@ impl<'a> BlobMethods for JSRef<'a, Blob> {
|
|||
}
|
||||
|
||||
fn Slice(&self, _start: Option<i64>, _end: Option<i64>, _contentType: Option<DOMString>) -> Temporary<Blob> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
Blob::new(&window.root_ref())
|
||||
}
|
||||
|
||||
|
|
|
@ -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, Temporary, RootCollection};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::trace::Traceable;
|
||||
use dom::bindings::utils::Reflectable;
|
||||
use dom::document::Document;
|
||||
|
@ -37,8 +37,7 @@ impl BrowserContext {
|
|||
}
|
||||
|
||||
pub fn active_window(&self) -> Temporary<Window> {
|
||||
let roots = RootCollection::new();
|
||||
let doc = self.active_document().root(&roots);
|
||||
let doc = self.active_document().root();
|
||||
Temporary::new(doc.deref().window.clone())
|
||||
}
|
||||
|
||||
|
@ -48,8 +47,7 @@ impl BrowserContext {
|
|||
}
|
||||
|
||||
pub fn create_window_proxy(&self) -> *JSObject {
|
||||
let roots = RootCollection::new();
|
||||
let win = self.active_window().root(&roots);
|
||||
let win = self.active_window().root();
|
||||
let page = win.get().page();
|
||||
let js_info = page.js_info();
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::InheritTypes::CommentDerived;
|
||||
use dom::bindings::codegen::BindingDeclarations::CommentBinding;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::characterdata::CharacterData;
|
||||
use dom::document::Document;
|
||||
|
@ -41,8 +41,7 @@ impl Comment {
|
|||
}
|
||||
|
||||
pub fn Constructor(owner: &JSRef<Window>, data: DOMString) -> Fallible<Temporary<Comment>> {
|
||||
let roots = RootCollection::new();
|
||||
let document = owner.Document().root(&roots);
|
||||
let document = owner.Document().root();
|
||||
Ok(Comment::new(data, &*document))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLEleme
|
|||
use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, TextCast, ElementCast};
|
||||
use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast};
|
||||
use dom::bindings::codegen::BindingDeclarations::DocumentBinding;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalAssignable};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary, OptionalAssignable};
|
||||
use dom::bindings::js::OptionalRootable;
|
||||
use dom::bindings::trace::Untraceable;
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
|
@ -110,13 +110,11 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
fn damage_and_reflow(&self, damage: DocumentDamageLevel) {
|
||||
let roots = RootCollection::new();
|
||||
self.window.root(&roots).damage_and_reflow(damage);
|
||||
self.window.root().damage_and_reflow(damage);
|
||||
}
|
||||
|
||||
fn wait_until_safe_to_modify_dom(&self) {
|
||||
let roots = RootCollection::new();
|
||||
self.window.root(&roots).wait_until_safe_to_modify_dom();
|
||||
self.window.root().wait_until_safe_to_modify_dom();
|
||||
}
|
||||
|
||||
|
||||
|
@ -124,13 +122,12 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> {
|
|||
fn unregister_named_element(&mut self,
|
||||
to_unregister: &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()
|
||||
.map(|elem| elem.root(&roots))
|
||||
.map(|elem| elem.root())
|
||||
.position(|element| &*element == to_unregister)
|
||||
.expect("This element should be in registered.");
|
||||
elements.remove(position);
|
||||
|
@ -146,7 +143,6 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> {
|
|||
fn register_named_element(&mut self,
|
||||
element: &JSRef<Element>,
|
||||
id: DOMString) {
|
||||
let roots = RootCollection::new();
|
||||
assert!({
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(element);
|
||||
node.is_in_doc()
|
||||
|
@ -154,13 +150,13 @@ impl<'a> DocumentHelpers for JSRef<'a, Document> {
|
|||
|
||||
// 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.").root(&roots);
|
||||
let root = self.GetDocumentElement().expect("The element is in the document, so there must be a document element.").root();
|
||||
match self.idmap.find_mut(&id) {
|
||||
Some(elements) => {
|
||||
let new_node: &JSRef<Node> = NodeCast::from_ref(element);
|
||||
let mut head : uint = 0u;
|
||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||
for node in root.traverse_preorder(&roots) {
|
||||
for node in root.traverse_preorder() {
|
||||
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&node);
|
||||
match elem {
|
||||
Some(elem) => {
|
||||
|
@ -188,9 +184,8 @@ impl Document {
|
|||
window: &JSRef<Window>,
|
||||
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, ~Document) -> JS<Document>)
|
||||
-> Temporary<Document> {
|
||||
let roots = RootCollection::new();
|
||||
assert!(document.reflector().get_jsobject().is_null());
|
||||
let mut raw_doc = reflect_dom_object(document, window, wrap_fn).root(&roots);
|
||||
let mut raw_doc = reflect_dom_object(document, window, wrap_fn).root();
|
||||
assert!(raw_doc.reflector().get_jsobject().is_not_null());
|
||||
|
||||
let mut doc_alias = raw_doc.clone();
|
||||
|
@ -257,15 +252,14 @@ trait PrivateDocumentHelpers {
|
|||
|
||||
impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> {
|
||||
fn createNodeList(&self, callback: |node: &JSRef<Node>| -> bool) -> Temporary<NodeList> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
|
||||
let mut nodes = vec!();
|
||||
match self.GetDocumentElement().root(&roots) {
|
||||
match self.GetDocumentElement().root() {
|
||||
None => {},
|
||||
Some(root) => {
|
||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||
for child in root.traverse_preorder(&roots) {
|
||||
for child in root.traverse_preorder() {
|
||||
if callback(&child) {
|
||||
nodes.push(child);
|
||||
}
|
||||
|
@ -277,8 +271,7 @@ impl<'a> PrivateDocumentHelpers for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
fn get_html_element(&self) -> Option<Temporary<HTMLHtmlElement>> {
|
||||
let roots = RootCollection::new();
|
||||
self.GetDocumentElement().root(&roots).filtered(|root| {
|
||||
self.GetDocumentElement().root().filtered(|root| {
|
||||
root.node.type_id == ElementNodeTypeId(HTMLHtmlElementTypeId)
|
||||
}).map(|elem| {
|
||||
Temporary::new_rooted(HTMLHtmlElementCast::to_ref(&*elem).unwrap())
|
||||
|
@ -330,8 +323,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
// http://dom.spec.whatwg.org/#dom-document-implementation
|
||||
fn Implementation(&mut self) -> Temporary<DOMImplementation> {
|
||||
if self.implementation.is_none() {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
self.implementation.assign(Some(DOMImplementation::new(&*window)));
|
||||
}
|
||||
Temporary::new(self.implementation.get_ref().clone())
|
||||
|
@ -384,15 +376,13 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagname
|
||||
fn GetElementsByTagName(&self, tag_name: DOMString) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), tag_name)
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens
|
||||
fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>, tag_name: DOMString) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
|
||||
let namespace = match maybe_ns {
|
||||
Some(namespace) => Namespace::from_str(namespace),
|
||||
|
@ -403,8 +393,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname
|
||||
fn GetElementsByClassName(&self, classes: DOMString) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
|
||||
HTMLCollection::by_class_name(&*window, NodeCast::from_ref(self), classes)
|
||||
}
|
||||
|
@ -538,8 +527,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-document-createevent
|
||||
fn CreateEvent(&self, interface: DOMString) -> Fallible<Temporary<Event>> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
|
||||
match interface.to_ascii_lower().as_slice() {
|
||||
// FIXME: Implement CustomEvent (http://dom.spec.whatwg.org/#customevent)
|
||||
|
@ -553,10 +541,9 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
// http://www.whatwg.org/specs/web-apps/current-work/#document.title
|
||||
fn Title(&self) -> DOMString {
|
||||
let mut title = ~"";
|
||||
let roots = RootCollection::new();
|
||||
self.GetDocumentElement().root(&roots).map(|root| {
|
||||
self.GetDocumentElement().root().map(|root| {
|
||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||
root.traverse_preorder(&roots)
|
||||
root.traverse_preorder()
|
||||
.find(|node| node.type_id() == ElementNodeTypeId(HTMLTitleElementTypeId))
|
||||
.map(|title_elem| {
|
||||
for child in title_elem.children() {
|
||||
|
@ -574,11 +561,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/#document.title
|
||||
fn SetTitle(&self, title: DOMString) -> ErrorResult {
|
||||
let roots = RootCollection::new();
|
||||
|
||||
self.GetDocumentElement().root(&roots).map(|root| {
|
||||
self.GetDocumentElement().root().map(|root| {
|
||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||
let mut head_node = root.traverse_preorder(&roots).find(|child| {
|
||||
let mut head_node = root.traverse_preorder().find(|child| {
|
||||
child.get().type_id == ElementNodeTypeId(HTMLHeadElementTypeId)
|
||||
});
|
||||
head_node.as_mut().map(|head| {
|
||||
|
@ -591,15 +577,15 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
for mut title_child in title_node.children() {
|
||||
assert!(title_node.RemoveChild(&mut title_child).is_ok());
|
||||
}
|
||||
let mut new_text = self.CreateTextNode(title.clone()).root(&roots);
|
||||
let mut new_text = self.CreateTextNode(title.clone()).root();
|
||||
|
||||
assert!(title_node.AppendChild(NodeCast::from_mut_ref(&mut *new_text)).is_ok());
|
||||
},
|
||||
None => {
|
||||
let mut new_title = HTMLTitleElement::new(~"title", self).root(&roots);
|
||||
let mut new_title = HTMLTitleElement::new(~"title", self).root();
|
||||
let new_title: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut *new_title);
|
||||
|
||||
let mut new_text = self.CreateTextNode(title.clone()).root(&roots);
|
||||
let mut new_text = self.CreateTextNode(title.clone()).root();
|
||||
|
||||
assert!(new_title.AppendChild(NodeCast::from_mut_ref(&mut *new_text)).is_ok());
|
||||
assert!(head.AppendChild(&mut *new_title).is_ok());
|
||||
|
@ -612,9 +598,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-head
|
||||
fn GetHead(&self) -> Option<Temporary<HTMLHeadElement>> {
|
||||
let roots = RootCollection::new();
|
||||
self.get_html_element().and_then(|root| {
|
||||
let root = root.root(&roots);
|
||||
let root = root.root();
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||
node.children().find(|child| {
|
||||
child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId)
|
||||
|
@ -626,9 +611,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body
|
||||
fn GetBody(&self) -> Option<Temporary<HTMLElement>> {
|
||||
let roots = RootCollection::new();
|
||||
self.get_html_element().and_then(|root| {
|
||||
let root = root.root(&roots);
|
||||
let root = root.root();
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||
node.children().find(|child| {
|
||||
match child.type_id() {
|
||||
|
@ -644,7 +628,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body
|
||||
fn SetBody(&self, new_body: Option<JSRef<HTMLElement>>) -> ErrorResult {
|
||||
let roots = RootCollection::new();
|
||||
|
||||
// Step 1.
|
||||
match new_body {
|
||||
|
@ -659,14 +642,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
// Step 2.
|
||||
let mut old_body = self.GetBody().root(&roots);
|
||||
let mut old_body = self.GetBody().root();
|
||||
//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().root(&roots) {
|
||||
match self.get_html_element().root() {
|
||||
// Step 4.
|
||||
None => return Err(HierarchyRequest),
|
||||
Some(ref mut root) => {
|
||||
|
@ -689,7 +672,6 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-getelementsbyname
|
||||
fn GetElementsByName(&self, name: DOMString) -> Temporary<NodeList> {
|
||||
let roots = RootCollection::new();
|
||||
|
||||
self.createNodeList(|node| {
|
||||
if !node.is_element() {
|
||||
|
@ -697,15 +679,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||
element.get_attribute(Null, "name").root(&roots).map_or(false, |mut attr| {
|
||||
element.get_attribute(Null, "name").root().map_or(false, |mut attr| {
|
||||
attr.value_ref() == name
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn Images(&self) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
struct ImagesFilter;
|
||||
|
@ -719,8 +700,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
fn Embeds(&self) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
struct EmbedsFilter;
|
||||
|
@ -739,8 +719,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
fn Links(&self) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
struct LinksFilter;
|
||||
|
@ -755,8 +734,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
fn Forms(&self) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
struct FormsFilter;
|
||||
|
@ -770,8 +748,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
fn Scripts(&self) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
struct ScriptsFilter;
|
||||
|
@ -785,8 +762,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
fn Anchors(&self) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1847
|
||||
struct AnchorsFilter;
|
||||
|
@ -800,8 +776,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
fn Applets(&self) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
|
||||
// FIXME: This should be return OBJECT elements containing applets.
|
||||
struct AppletsFilter;
|
||||
|
@ -815,14 +790,12 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
fn Location(&mut self) -> Temporary<Location> {
|
||||
let roots = RootCollection::new();
|
||||
let mut window = self.window.root(&roots);
|
||||
let mut window = self.window.root();
|
||||
window.Location()
|
||||
}
|
||||
|
||||
fn Children(&self) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
HTMLCollection::children(&*window, NodeCast::from_ref(self))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::InheritTypes::{DocumentFragmentDerived, NodeCast};
|
||||
use dom::bindings::codegen::BindingDeclarations::DocumentFragmentBinding;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::document::Document;
|
||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||
|
@ -40,9 +40,8 @@ impl DocumentFragment {
|
|||
}
|
||||
|
||||
pub fn Constructor(owner: &JSRef<Window>) -> Fallible<Temporary<DocumentFragment>> {
|
||||
let roots = RootCollection::new();
|
||||
let document = owner.Document();
|
||||
let document = document.root(&roots);
|
||||
let document = document.root();
|
||||
|
||||
Ok(DocumentFragment::new(&document.root_ref()))
|
||||
}
|
||||
|
@ -54,8 +53,7 @@ pub trait DocumentFragmentMethods {
|
|||
|
||||
impl<'a> DocumentFragmentMethods for JSRef<'a, DocumentFragment> {
|
||||
fn Children(&self) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(self))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::BindingDeclarations::DOMImplementationBinding;
|
||||
use dom::bindings::codegen::InheritTypes::NodeCast;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalRootable};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary, 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};
|
||||
|
@ -60,7 +60,6 @@ pub trait DOMImplementationMethods {
|
|||
impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
|
||||
// http://dom.spec.whatwg.org/#dom-domimplementation-createdocumenttype
|
||||
fn CreateDocumentType(&self, qname: DOMString, pubid: DOMString, sysid: DOMString) -> Fallible<Temporary<DocumentType>> {
|
||||
let roots = RootCollection::new();
|
||||
match xml_name_type(qname) {
|
||||
// Step 1.
|
||||
InvalidXMLName => Err(InvalidCharacter),
|
||||
|
@ -68,8 +67,8 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
|
|||
Name => Err(NamespaceError),
|
||||
// Step 3.
|
||||
QName => {
|
||||
let owner = self.owner.root(&roots);
|
||||
let document = owner.deref().Document().root(&roots);
|
||||
let owner = self.owner.root();
|
||||
let document = owner.deref().Document().root();
|
||||
Ok(DocumentType::new(qname, Some(pubid), Some(sysid), &*document))
|
||||
}
|
||||
}
|
||||
|
@ -78,11 +77,10 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
|
|||
// http://dom.spec.whatwg.org/#dom-domimplementation-createdocument
|
||||
fn CreateDocument(&self, namespace: Option<DOMString>, qname: DOMString,
|
||||
mut maybe_doctype: Option<JSRef<DocumentType>>) -> Fallible<Temporary<Document>> {
|
||||
let roots = RootCollection::new();
|
||||
let win = self.owner.root(&roots);
|
||||
let win = self.owner.root();
|
||||
|
||||
// Step 1.
|
||||
let mut doc = Document::new(&win.root_ref(), None, NonHTMLDocument, None).root(&roots);
|
||||
let mut doc = Document::new(&win.root_ref(), None, NonHTMLDocument, None).root();
|
||||
// Step 2-3.
|
||||
let mut maybe_elem = if qname.is_empty() {
|
||||
None
|
||||
|
@ -105,7 +103,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
|
|||
}
|
||||
|
||||
// Step 5.
|
||||
match maybe_elem.root(&roots) {
|
||||
match maybe_elem.root() {
|
||||
None => (),
|
||||
Some(mut elem) => {
|
||||
assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut *elem)).is_ok())
|
||||
|
@ -122,28 +120,27 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
|
||||
fn CreateHTMLDocument(&self, title: Option<DOMString>) -> Temporary<Document> {
|
||||
let roots = RootCollection::new();
|
||||
let owner = self.owner.root(&roots);
|
||||
let owner = self.owner.root();
|
||||
|
||||
// Step 1-2.
|
||||
let mut doc = Document::new(&owner.root_ref(), None, HTMLDocument, None).root(&roots);
|
||||
let mut doc = Document::new(&owner.root_ref(), None, HTMLDocument, None).root();
|
||||
let mut doc_alias = doc.clone();
|
||||
let doc_node: &mut JSRef<Node> = NodeCast::from_mut_ref(&mut doc_alias);
|
||||
|
||||
{
|
||||
// Step 3.
|
||||
let mut doc_type = DocumentType::new(~"html", None, None, &*doc).root(&roots);
|
||||
let mut doc_type = DocumentType::new(~"html", None, None, &*doc).root();
|
||||
assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut *doc_type)).is_ok());
|
||||
}
|
||||
|
||||
{
|
||||
// Step 4.
|
||||
let mut doc_html = NodeCast::from_unrooted(HTMLHtmlElement::new(~"html", &*doc)).root(&roots);
|
||||
let mut doc_html = NodeCast::from_unrooted(HTMLHtmlElement::new(~"html", &*doc)).root();
|
||||
assert!(doc_node.AppendChild(&mut *doc_html).is_ok());
|
||||
|
||||
{
|
||||
// Step 5.
|
||||
let mut doc_head = NodeCast::from_unrooted(HTMLHeadElement::new(~"head", &*doc)).root(&roots);
|
||||
let mut doc_head = NodeCast::from_unrooted(HTMLHeadElement::new(~"head", &*doc)).root();
|
||||
assert!(doc_html.AppendChild(&mut *doc_head).is_ok());
|
||||
|
||||
// Step 6.
|
||||
|
@ -151,18 +148,18 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> {
|
|||
None => (),
|
||||
Some(title_str) => {
|
||||
// Step 6.1.
|
||||
let mut doc_title = NodeCast::from_unrooted(HTMLTitleElement::new(~"title", &*doc)).root(&roots);
|
||||
let mut doc_title = NodeCast::from_unrooted(HTMLTitleElement::new(~"title", &*doc)).root();
|
||||
assert!(doc_head.AppendChild(&mut *doc_title).is_ok());
|
||||
|
||||
// Step 6.2.
|
||||
let mut title_text = Text::new(title_str, &*doc).root(&roots);
|
||||
let mut title_text = Text::new(title_str, &*doc).root();
|
||||
assert!(doc_title.AppendChild(NodeCast::from_mut_ref(&mut *title_text)).is_ok());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 7.
|
||||
let mut doc_body = HTMLBodyElement::new(~"body", &*doc).root(&roots);
|
||||
let mut doc_body = HTMLBodyElement::new(~"body", &*doc).root();
|
||||
assert!(doc_html.AppendChild(NodeCast::from_mut_ref(&mut *doc_body)).is_ok());
|
||||
}
|
||||
|
||||
|
|
|
@ -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, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflector, Reflectable, reflect_dom_object};
|
||||
use dom::bindings::error::{Fallible, FailureUnknown};
|
||||
use dom::document::{Document, HTMLDocument, NonHTMLDocument};
|
||||
|
@ -44,8 +44,7 @@ impl<'a> DOMParserMethods for JSRef<'a, DOMParser> {
|
|||
_s: DOMString,
|
||||
ty: DOMParserBinding::SupportedType)
|
||||
-> Fallible<Temporary<Document>> {
|
||||
let roots = RootCollection::new();
|
||||
let owner = self.owner.root(&roots);
|
||||
let owner = self.owner.root();
|
||||
match ty {
|
||||
Text_html => {
|
||||
Ok(Document::new(&owner.root_ref(), None, HTMLDocument, Some(~"text/html")))
|
||||
|
|
|
@ -8,7 +8,7 @@ use dom::attr::{Attr, ReplacedAttr, FirstSetAttr, AttrMethods};
|
|||
use dom::attrlist::AttrList;
|
||||
use dom::bindings::codegen::BindingDeclarations::ElementBinding;
|
||||
use dom::bindings::codegen::InheritTypes::{ElementDerived, NodeCast};
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, TemporaryPushable};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary, TemporaryPushable};
|
||||
use dom::bindings::js::{OptionalAssignable, OptionalRootable, Root};
|
||||
use dom::bindings::utils::{Reflectable, Reflector};
|
||||
use dom::bindings::error::{ErrorResult, Fallible, NamespaceError, InvalidCharacter};
|
||||
|
@ -198,10 +198,9 @@ pub trait ElementHelpers {
|
|||
|
||||
impl<'a> ElementHelpers for JSRef<'a, Element> {
|
||||
fn html_element_in_html_document(&self) -> bool {
|
||||
let roots = RootCollection::new();
|
||||
let is_html = self.namespace == namespace::HTML;
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
is_html && node.owner_doc().root(&roots).is_html_document
|
||||
is_html && node.owner_doc().root().is_html_document
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,13 +227,12 @@ pub trait AttributeHandlers {
|
|||
|
||||
impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
||||
fn get_attribute(&self, namespace: Namespace, name: &str) -> Option<Temporary<Attr>> {
|
||||
let roots = RootCollection::new();
|
||||
if self.html_element_in_html_document() {
|
||||
self.get().attrs.iter().map(|attr| attr.root(&roots)).find(|attr| {
|
||||
self.get().attrs.iter().map(|attr| attr.root()).find(|attr| {
|
||||
name.to_ascii_lower() == attr.local_name && attr.namespace == namespace
|
||||
}).map(|x| Temporary::new_rooted(&*x))
|
||||
} else {
|
||||
self.get().attrs.iter().map(|attr| attr.root(&roots)).find(|attr| {
|
||||
self.get().attrs.iter().map(|attr| attr.root()).find(|attr| {
|
||||
name == attr.local_name && attr.namespace == namespace
|
||||
}).map(|x| Temporary::new_rooted(&*x))
|
||||
}
|
||||
|
@ -275,14 +273,13 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString,
|
||||
name: DOMString, namespace: Namespace,
|
||||
prefix: Option<DOMString>, cb: |&JSRef<Attr>| -> bool) {
|
||||
let roots = RootCollection::new();
|
||||
let idx = self.get().attrs.iter()
|
||||
.map(|attr| attr.root(&roots))
|
||||
.map(|attr| attr.root())
|
||||
.position(|attr| cb(&*attr));
|
||||
let (idx, set_type) = match idx {
|
||||
Some(idx) => (idx, ReplacedAttr),
|
||||
None => {
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
let attr = Attr::new(&*window, local_name.clone(), value.clone(),
|
||||
name, namespace.clone(), prefix, self);
|
||||
self.get_mut().attrs.push_unrooted(attr);
|
||||
|
@ -290,14 +287,13 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
}
|
||||
};
|
||||
|
||||
self.get_mut().attrs.get(idx).root(&roots).set_value(set_type, value);
|
||||
self.get_mut().attrs.get(idx).root().set_value(set_type, value);
|
||||
}
|
||||
|
||||
fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult {
|
||||
let roots = RootCollection::new();
|
||||
let (_, local_name) = get_attribute_parts(name.clone());
|
||||
|
||||
let idx = self.get().attrs.iter().map(|attr| attr.root(&roots)).position(|attr| {
|
||||
let idx = self.get().attrs.iter().map(|attr| attr.root()).position(|attr| {
|
||||
attr.local_name == local_name
|
||||
});
|
||||
|
||||
|
@ -310,7 +306,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
}
|
||||
|
||||
if namespace == namespace::Null {
|
||||
let removed_raw_value = self.get().attrs.get(idx).root(&roots).Value();
|
||||
let removed_raw_value = self.get().attrs.get(idx).root().Value();
|
||||
vtable_for(NodeCast::from_ref(self)).before_remove_attr(local_name.clone(), removed_raw_value);
|
||||
}
|
||||
|
||||
|
@ -322,14 +318,13 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
}
|
||||
|
||||
fn notify_attribute_changed(&self, local_name: DOMString) {
|
||||
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.owner_doc().root(&roots);
|
||||
let document = node.owner_doc().root();
|
||||
document.deref().damage_and_reflow(damage);
|
||||
}
|
||||
}
|
||||
|
@ -349,10 +344,9 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
|
|||
}
|
||||
|
||||
fn get_string_attribute(&self, name: &str) -> DOMString {
|
||||
let roots = RootCollection::new();
|
||||
match self.get_attribute(Null, name) {
|
||||
Some(x) => {
|
||||
let x = x.root(&roots);
|
||||
let x = x.root();
|
||||
x.deref().Value()
|
||||
}
|
||||
None => ~""
|
||||
|
@ -462,7 +456,6 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-element-attributes
|
||||
fn Attributes(&mut self) -> Temporary<AttrList> {
|
||||
let roots = RootCollection::new();
|
||||
match self.attr_list {
|
||||
None => (),
|
||||
Some(ref list) => return Temporary::new(list.clone()),
|
||||
|
@ -470,9 +463,9 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
|
||||
let doc = {
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
node.owner_doc()
|
||||
}.root(&roots);
|
||||
let window = doc.deref().window.root(&roots);
|
||||
node.owner_doc().root()
|
||||
};
|
||||
let window = doc.deref().window.root();
|
||||
let list = AttrList::new(&*window, self);
|
||||
self.attr_list.assign(Some(list));
|
||||
Temporary::new(self.attr_list.get_ref().clone())
|
||||
|
@ -480,13 +473,12 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-element-getattribute
|
||||
fn GetAttribute(&self, name: DOMString) -> Option<DOMString> {
|
||||
let roots = RootCollection::new();
|
||||
let name = if self.html_element_in_html_document() {
|
||||
name.to_ascii_lower()
|
||||
} else {
|
||||
name
|
||||
};
|
||||
self.get_attribute(Null, name).root(&roots)
|
||||
self.get_attribute(Null, name).root()
|
||||
.map(|s| s.deref().Value())
|
||||
}
|
||||
|
||||
|
@ -494,9 +486,8 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
fn GetAttributeNS(&self,
|
||||
namespace: Option<DOMString>,
|
||||
local_name: DOMString) -> Option<DOMString> {
|
||||
let roots = RootCollection::new();
|
||||
let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace));
|
||||
self.get_attribute(namespace, local_name).root(&roots)
|
||||
self.get_attribute(namespace, local_name).root()
|
||||
.map(|attr| attr.deref().Value())
|
||||
}
|
||||
|
||||
|
@ -624,32 +615,28 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
}
|
||||
|
||||
fn GetElementsByTagName(&self, localname: DOMString) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), localname)
|
||||
}
|
||||
|
||||
fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>,
|
||||
localname: DOMString) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let namespace = match maybe_ns {
|
||||
Some(namespace) => Namespace::from_str(namespace),
|
||||
None => Null
|
||||
};
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(self), localname, namespace)
|
||||
}
|
||||
|
||||
fn GetElementsByClassName(&self, classes: DOMString) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
HTMLCollection::by_class_name(&*window, NodeCast::from_ref(self), classes)
|
||||
}
|
||||
|
||||
// http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects
|
||||
fn GetClientRects(&self) -> Temporary<ClientRectList> {
|
||||
let roots = RootCollection::new();
|
||||
let win = window_from_node(self).root(&roots);
|
||||
let win = window_from_node(self).root();
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
let rects = node.get_content_boxes();
|
||||
let rects: ~[Root<ClientRect>] = rects.iter().map(|r| {
|
||||
|
@ -658,7 +645,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
r.origin.y,
|
||||
r.origin.y + r.size.height,
|
||||
r.origin.x,
|
||||
r.origin.x + r.size.width).root(&roots)
|
||||
r.origin.x + r.size.width).root()
|
||||
}).collect();
|
||||
|
||||
ClientRectList::new(&*win, rects.iter().map(|rect| rect.deref().clone()).collect())
|
||||
|
@ -666,8 +653,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
|
||||
// http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect
|
||||
fn GetBoundingClientRect(&self) -> Temporary<ClientRect> {
|
||||
let roots = RootCollection::new();
|
||||
let win = window_from_node(self).root(&roots);
|
||||
let win = window_from_node(self).root();
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
let rect = node.get_bounding_content_box();
|
||||
ClientRect::new(
|
||||
|
@ -680,18 +666,15 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
|
|||
|
||||
fn GetInnerHTML(&self) -> Fallible<DOMString> {
|
||||
//XXX TODO: XML case
|
||||
let roots = RootCollection::new();
|
||||
Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(self), false, false)))
|
||||
Ok(serialize(&mut NodeIterator::new(NodeCast::from_ref(self), false, false)))
|
||||
}
|
||||
|
||||
fn GetOuterHTML(&self) -> Fallible<DOMString> {
|
||||
let roots = RootCollection::new();
|
||||
Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(self), true, false)))
|
||||
Ok(serialize(&mut NodeIterator::new(NodeCast::from_ref(self), true, false)))
|
||||
}
|
||||
|
||||
fn Children(&self) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
HTMLCollection::children(&*window, NodeCast::from_ref(self))
|
||||
}
|
||||
}
|
||||
|
@ -716,7 +699,6 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
}
|
||||
|
||||
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()),
|
||||
_ => (),
|
||||
|
@ -724,14 +706,14 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
|
||||
match name.as_slice() {
|
||||
"style" => {
|
||||
let doc = document_from_node(self).root(&roots);
|
||||
let doc = document_from_node(self).root();
|
||||
let base_url = doc.deref().url().clone();
|
||||
self.get_mut().style_attribute = Some(style::parse_style_attribute(value, &base_url))
|
||||
}
|
||||
"id" => {
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
if node.is_in_doc() {
|
||||
let mut doc = document_from_node(self).root(&roots);
|
||||
let mut doc = document_from_node(self).root();
|
||||
doc.register_named_element(self, value.clone());
|
||||
}
|
||||
}
|
||||
|
@ -742,7 +724,6 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
}
|
||||
|
||||
fn before_remove_attr(&mut self, name: DOMString, value: DOMString) {
|
||||
let roots = RootCollection::new();
|
||||
match self.super_type() {
|
||||
Some(ref mut s) => s.before_remove_attr(name.clone(), value.clone()),
|
||||
_ => (),
|
||||
|
@ -755,7 +736,7 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
"id" => {
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
if node.is_in_doc() {
|
||||
let mut doc = document_from_node(self).root(&roots);
|
||||
let mut doc = document_from_node(self).root();
|
||||
doc.unregister_named_element(self, value);
|
||||
}
|
||||
}
|
||||
|
@ -766,15 +747,14 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
}
|
||||
|
||||
fn bind_to_tree(&mut self) {
|
||||
let roots = RootCollection::new();
|
||||
match self.super_type() {
|
||||
Some(ref mut s) => s.bind_to_tree(),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
match self.get_attribute(Null, "id").root(&roots) {
|
||||
match self.get_attribute(Null, "id").root() {
|
||||
Some(attr) => {
|
||||
let mut doc = document_from_node(self).root(&roots);
|
||||
let mut doc = document_from_node(self).root();
|
||||
doc.register_named_element(self, attr.deref().Value());
|
||||
}
|
||||
_ => ()
|
||||
|
@ -782,15 +762,14 @@ impl<'a> VirtualMethods for JSRef<'a, Element> {
|
|||
}
|
||||
|
||||
fn unbind_from_tree(&mut self) {
|
||||
let roots = RootCollection::new();
|
||||
match self.super_type() {
|
||||
Some(ref mut s) => s.unbind_from_tree(),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
match self.get_attribute(Null, "id").root(&roots) {
|
||||
match self.get_attribute(Null, "id").root() {
|
||||
Some(attr) => {
|
||||
let mut doc = document_from_node(self).root(&roots);
|
||||
let mut doc = document_from_node(self).root();
|
||||
doc.unregister_named_element(self, attr.deref().Value());
|
||||
}
|
||||
_ => ()
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::BindingDeclarations::EventBinding;
|
||||
use dom::bindings::codegen::BindingDeclarations::EventBinding::EventConstants;
|
||||
use dom::bindings::js::{JS, JSRef, Temporary, RootCollection};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::eventtarget::EventTarget;
|
||||
|
@ -89,8 +89,7 @@ impl Event {
|
|||
pub fn Constructor(global: &JSRef<Window>,
|
||||
type_: DOMString,
|
||||
init: &EventBinding::EventInit) -> Fallible<Temporary<Event>> {
|
||||
let roots = RootCollection::new();
|
||||
let mut ev = Event::new(global).root(&roots);
|
||||
let mut ev = Event::new(global).root();
|
||||
ev.InitEvent(type_, init.bubbles, init.cancelable);
|
||||
Ok(Temporary::new_rooted(&*ev))
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::callback::ReportExceptions;
|
||||
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, NodeDerived};
|
||||
use dom::bindings::js::{JSRef, OptionalAssignable, RootCollection, Root};
|
||||
use dom::bindings::js::{JSRef, OptionalAssignable, Root};
|
||||
use dom::eventtarget::{Capturing, Bubbling, EventTarget};
|
||||
use dom::event::{Event, PhaseAtTarget, PhaseNone, PhaseBubbling, PhaseCapturing, EventMethods};
|
||||
use dom::node::{Node, NodeHelpers};
|
||||
|
@ -13,7 +13,6 @@ use dom::node::{Node, NodeHelpers};
|
|||
pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
||||
pseudo_target: Option<JSRef<'b, EventTarget>>,
|
||||
event: &mut JSRef<Event>) -> bool {
|
||||
let roots = RootCollection::new();
|
||||
assert!(!event.get().dispatching);
|
||||
|
||||
{
|
||||
|
@ -32,7 +31,7 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
|
|||
let target_node: &JSRef<Node> = NodeCast::to_ref(target).unwrap();
|
||||
target_node.ancestors().map(|ancestor| {
|
||||
let ancestor_target: &JSRef<EventTarget> = EventTargetCast::from_ref(&ancestor);
|
||||
ancestor_target.unrooted().root(&roots)
|
||||
ancestor_target.unrooted().root()
|
||||
}).collect()
|
||||
} else {
|
||||
vec!()
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::BindingDeclarations::HTMLButtonElementBinding;
|
||||
use dom::bindings::codegen::InheritTypes::HTMLButtonElementDerived;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::error::ErrorResult;
|
||||
use dom::document::Document;
|
||||
use dom::element::HTMLButtonElementTypeId;
|
||||
|
@ -167,8 +167,7 @@ impl<'a> HTMLButtonElementMethods for JSRef<'a, HTMLButtonElement> {
|
|||
}
|
||||
|
||||
fn Validity(&self) -> Temporary<ValidityState> {
|
||||
let roots = RootCollection::new();
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
ValidityState::new(&*window)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast};
|
||||
use dom::bindings::codegen::BindingDeclarations::HTMLCollectionBinding;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::element::{Element, AttributeHandlers};
|
||||
use dom::node::{Node, NodeHelpers};
|
||||
|
@ -129,12 +129,11 @@ pub trait HTMLCollectionMethods {
|
|||
impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
||||
// http://dom.spec.whatwg.org/#dom-htmlcollection-length
|
||||
fn Length(&self) -> u32 {
|
||||
let roots = RootCollection::new();
|
||||
match self.collection {
|
||||
Static(ref elems) => elems.len() as u32,
|
||||
Live(ref root, ref filter) => {
|
||||
let root = root.root(&roots);
|
||||
root.deref().traverse_preorder(&roots)
|
||||
let root = root.root();
|
||||
root.deref().traverse_preorder()
|
||||
.count(|child| {
|
||||
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&child);
|
||||
elem.map_or(false, |elem| filter.filter(elem, &*root))
|
||||
|
@ -145,15 +144,14 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-htmlcollection-item
|
||||
fn Item(&self, index: u32) -> Option<Temporary<Element>> {
|
||||
let roots = RootCollection::new();
|
||||
match self.collection {
|
||||
Static(ref elems) => elems
|
||||
.as_slice()
|
||||
.get(index as uint)
|
||||
.map(|elem| Temporary::new(elem.clone())),
|
||||
Live(ref root, ref filter) => {
|
||||
let root = root.root(&roots);
|
||||
root.deref().traverse_preorder(&roots)
|
||||
let root = root.root();
|
||||
root.deref().traverse_preorder()
|
||||
.filter_map(|node| {
|
||||
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&node);
|
||||
elem.filtered(|&elem| filter.filter(elem, &*root))
|
||||
|
@ -168,7 +166,6 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-htmlcollection-nameditem
|
||||
fn NamedItem(&self, key: DOMString) -> Option<Temporary<Element>> {
|
||||
let roots = RootCollection::new();
|
||||
|
||||
// Step 1.
|
||||
if key.is_empty() {
|
||||
|
@ -178,14 +175,14 @@ impl<'a> HTMLCollectionMethods for JSRef<'a, HTMLCollection> {
|
|||
// Step 2.
|
||||
match self.collection {
|
||||
Static(ref elems) => elems.iter()
|
||||
.map(|elem| elem.root(&roots))
|
||||
.map(|elem| elem.root())
|
||||
.find(|elem| {
|
||||
elem.get_string_attribute("name") == key ||
|
||||
elem.get_string_attribute("id") == key })
|
||||
.map(|maybe_elem| Temporary::new_rooted(&*maybe_elem)),
|
||||
Live(ref root, ref filter) => {
|
||||
let root = root.root(&roots);
|
||||
root.deref().traverse_preorder(&roots)
|
||||
let root = root.root();
|
||||
root.deref().traverse_preorder()
|
||||
.filter_map(|node| {
|
||||
let elem: Option<&JSRef<Element>> = ElementCast::to_ref(&node);
|
||||
elem.filtered(|&elem| filter.filter(elem, &*root))
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::BindingDeclarations::HTMLDataListElementBinding;
|
||||
use dom::bindings::codegen::InheritTypes::{HTMLDataListElementDerived, NodeCast};
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::document::Document;
|
||||
use dom::element::{Element, HTMLDataListElementTypeId};
|
||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||
|
@ -52,10 +52,9 @@ impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> {
|
|||
elem.get().local_name == ~"option"
|
||||
}
|
||||
}
|
||||
let roots = RootCollection::new();
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
let filter = ~HTMLDataListOptionsFilter;
|
||||
let window = window_from_node(node).root(&roots);
|
||||
let window = window_from_node(node).root();
|
||||
HTMLCollection::create(&*window, node, filter)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::error::ErrorResult;
|
||||
use dom::document::Document;
|
||||
use dom::element::{Element, HTMLFieldSetElementTypeId};
|
||||
|
@ -94,10 +94,9 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> {
|
|||
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(self);
|
||||
let filter = ~ElementsFilter;
|
||||
let window = window_from_node(node).root(&roots);
|
||||
let window = window_from_node(node).root();
|
||||
HTMLCollection::create(&*window, node, filter)
|
||||
}
|
||||
|
||||
|
@ -106,8 +105,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> {
|
|||
}
|
||||
|
||||
fn Validity(&self) -> Temporary<ValidityState> {
|
||||
let roots = RootCollection::new();
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
ValidityState::new(&*window)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::BindingDeclarations::HTMLFormElementBinding;
|
||||
use dom::bindings::codegen::InheritTypes::HTMLFormElementDerived;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::error::ErrorResult;
|
||||
use dom::document::Document;
|
||||
use dom::element::{Element, HTMLFormElementTypeId};
|
||||
|
@ -143,8 +143,7 @@ impl<'a> HTMLFormElementMethods for JSRef<'a, HTMLFormElement> {
|
|||
|
||||
fn Elements(&self) -> Temporary<HTMLCollection> {
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1844
|
||||
let roots = RootCollection::new();
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
HTMLCollection::new(&*window, Static(vec!()))
|
||||
}
|
||||
|
||||
|
|
|
@ -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, Temporary, RootCollection};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::trace::Untraceable;
|
||||
use dom::document::Document;
|
||||
use dom::element::{Element, HTMLImageElementTypeId};
|
||||
|
@ -43,11 +43,10 @@ impl<'a> PrivateHTMLImageElementHelpers for JSRef<'a, 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 self_alias = self.clone();
|
||||
let node_alias: &JSRef<Node> = NodeCast::from_ref(&self_alias);
|
||||
let document = node_alias.owner_doc().root(&roots);
|
||||
let window = document.deref().window.root(&roots);
|
||||
let document = node_alias.owner_doc().root();
|
||||
let window = document.deref().window.root();
|
||||
let image_cache = &window.image_cache_task;
|
||||
match value {
|
||||
None => {
|
||||
|
@ -275,14 +274,13 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLImageElement> {
|
|||
}
|
||||
|
||||
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).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
let url = Some(window.get().get_url());
|
||||
self.update_image(Some(value), url);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::BindingDeclarations::HTMLMapElementBinding;
|
||||
use dom::bindings::codegen::InheritTypes::HTMLMapElementDerived;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::error::ErrorResult;
|
||||
use dom::document::Document;
|
||||
use dom::element::HTMLMapElementTypeId;
|
||||
|
@ -57,9 +57,8 @@ impl<'a> HTMLMapElementMethods for JSRef<'a, HTMLMapElement> {
|
|||
}
|
||||
|
||||
fn Areas(&self) -> Temporary<HTMLCollection> {
|
||||
let roots = RootCollection::new();
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1845
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
HTMLCollection::new(&*window, Static(vec!()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ use dom::attr::AttrMethods;
|
|||
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, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::error::ErrorResult;
|
||||
use dom::document::Document;
|
||||
use dom::element::{Element, HTMLObjectElementTypeId};
|
||||
|
@ -62,12 +62,11 @@ 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 roots = RootCollection::new();
|
||||
let elem: &JSRef<Element> = ElementCast::from_ref(self);
|
||||
|
||||
// TODO: support other values
|
||||
match (elem.get_attribute(Null, "type").map(|x| x.root(&roots).Value()),
|
||||
elem.get_attribute(Null, "data").map(|x| x.root(&roots).Value())) {
|
||||
match (elem.get_attribute(Null, "type").map(|x| x.root().Value()),
|
||||
elem.get_attribute(Null, "data").map(|x| x.root().Value())) {
|
||||
(None, Some(uri)) => {
|
||||
if is_image_data(uri) {
|
||||
let data_url = parse_url(uri, url);
|
||||
|
@ -190,8 +189,7 @@ impl<'a> HTMLObjectElementMethods for JSRef<'a, HTMLObjectElement> {
|
|||
}
|
||||
|
||||
fn Validity(&self) -> Temporary<ValidityState> {
|
||||
let roots = RootCollection::new();
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
ValidityState::new(&*window)
|
||||
}
|
||||
|
||||
|
@ -298,14 +296,13 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLObjectElement> {
|
|||
}
|
||||
|
||||
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).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
let url = Some(window.get().get_url());
|
||||
self.process_data_url(window.get().image_cache_task.clone(), url);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::BindingDeclarations::HTMLOutputElementBinding;
|
||||
use dom::bindings::codegen::InheritTypes::HTMLOutputElementDerived;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::error::ErrorResult;
|
||||
use dom::document::Document;
|
||||
use dom::element::HTMLOutputElementTypeId;
|
||||
|
@ -102,8 +102,7 @@ impl<'a> HTMLOutputElementMethods for JSRef<'a, HTMLOutputElement> {
|
|||
}
|
||||
|
||||
fn Validity(&self) -> Temporary<ValidityState> {
|
||||
let roots = RootCollection::new();
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
ValidityState::new(&*window)
|
||||
}
|
||||
|
||||
|
|
|
@ -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, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::error::ErrorResult;
|
||||
use dom::document::Document;
|
||||
use dom::element::{Element, HTMLSelectElementTypeId};
|
||||
|
@ -192,8 +192,7 @@ impl<'a> HTMLSelectElementMethods for JSRef<'a, HTMLSelectElement> {
|
|||
}
|
||||
|
||||
fn Validity(&self) -> Temporary<ValidityState> {
|
||||
let roots = RootCollection::new();
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
ValidityState::new(&*window)
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ use dom::attr::Attr;
|
|||
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::{JSRef, RootCollection};
|
||||
use dom::bindings::js::JSRef;
|
||||
use dom::characterdata::CharacterData;
|
||||
use dom::comment::Comment;
|
||||
use dom::documenttype::DocumentType;
|
||||
|
@ -70,9 +70,8 @@ fn serialize_comment(comment: &JSRef<Comment>) -> ~str {
|
|||
}
|
||||
|
||||
fn serialize_text(text: &JSRef<Text>) -> ~str {
|
||||
let roots = RootCollection::new();
|
||||
let text_node: &JSRef<Node> = NodeCast::from_ref(text);
|
||||
match text_node.parent_node().map(|node| node.root(&roots)) {
|
||||
match text_node.parent_node().map(|node| node.root()) {
|
||||
Some(ref parent) if parent.is_element() => {
|
||||
let elem: &JSRef<Element> = ElementCast::to_ref(&**parent).unwrap();
|
||||
match elem.get().local_name.as_slice() {
|
||||
|
@ -97,17 +96,16 @@ fn serialize_doctype(doctype: &JSRef<DocumentType>) -> ~str {
|
|||
}
|
||||
|
||||
fn serialize_elem(elem: &JSRef<Element>, open_elements: &mut Vec<~str>) -> ~str {
|
||||
let roots = RootCollection::new();
|
||||
let mut rv = ~"<" + elem.get().local_name;
|
||||
for attr in elem.get().attrs.iter() {
|
||||
let attr = attr.root(&roots);
|
||||
let attr = attr.root();
|
||||
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 => {
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(elem);
|
||||
match node.first_child().map(|child| child.root(&roots)) {
|
||||
match node.first_child().map(|child| child.root()) {
|
||||
Some(ref child) if child.is_text() => {
|
||||
let text: &JSRef<CharacterData> = CharacterDataCast::to_ref(&**child).unwrap();
|
||||
if text.get().data.len() > 0 && text.get().data[0] == 0x0A as u8 {
|
||||
|
|
|
@ -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, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::error::ErrorResult;
|
||||
use dom::document::Document;
|
||||
use dom::element::HTMLStyleElementTypeId;
|
||||
|
@ -93,9 +93,8 @@ pub trait StyleElementHelpers {
|
|||
|
||||
impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> {
|
||||
fn parse_own_css(&self) {
|
||||
let roots = RootCollection::new();
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
let win = window_from_node(node).root(&roots);
|
||||
let win = window_from_node(node).root();
|
||||
let url = win.get().page().get_url();
|
||||
|
||||
let data = node.GetTextContent().expect("Element.textContent must be a string");
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::BindingDeclarations::MouseEventBinding;
|
||||
use dom::bindings::codegen::InheritTypes::{UIEventCast, MouseEventDerived};
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, RootedReference, Temporary};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::event::{Event, MouseEventTypeId};
|
||||
|
@ -60,10 +60,9 @@ impl MouseEvent {
|
|||
pub fn Constructor(owner: &JSRef<Window>,
|
||||
type_: DOMString,
|
||||
init: &MouseEventBinding::MouseEventInit) -> Fallible<Temporary<MouseEvent>> {
|
||||
let roots = RootCollection::new();
|
||||
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));
|
||||
let mut ev = MouseEvent::new(owner).root();
|
||||
let view = init.view.as_ref().map(|view| view.root());
|
||||
let related_target = init.relatedTarget.as_ref().map(|relatedTarget| relatedTarget.root());
|
||||
ev.InitMouseEvent(type_, init.bubbles, init.cancelable, view.root_ref(),
|
||||
init.detail, init.screenX, init.screenY,
|
||||
init.clientX, init.clientY, init.ctrlKey,
|
||||
|
|
|
@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, TextCast, NodeCast, Elem
|
|||
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeBase, NodeDerived};
|
||||
use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, EventTargetCast};
|
||||
use dom::bindings::codegen::BindingDeclarations::NodeBinding::NodeConstants;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Temporary, Root};
|
||||
use dom::bindings::js::{JS, JSRef, RootedReference, Temporary, Root};
|
||||
use dom::bindings::js::{OptionalAssignable, TemporaryPushable, OptionalRootedRootable};
|
||||
use dom::bindings::js::{ResultRootable, OptionalRootable};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
|
@ -240,29 +240,26 @@ trait PrivateNodeHelpers {
|
|||
impl<'a> PrivateNodeHelpers for JSRef<'a, Node> {
|
||||
// http://dom.spec.whatwg.org/#node-is-inserted
|
||||
fn node_inserted(&self) {
|
||||
let roots = RootCollection::new();
|
||||
assert!(self.parent_node().is_some());
|
||||
let document = document_from_node(self).root(&roots);
|
||||
let document = document_from_node(self).root();
|
||||
|
||||
if self.is_in_doc() {
|
||||
for node in self.traverse_preorder(&roots) {
|
||||
for node in self.traverse_preorder() {
|
||||
vtable_for(&node).bind_to_tree();
|
||||
}
|
||||
}
|
||||
|
||||
self.parent_node().root(&roots)
|
||||
.map(|parent| vtable_for(&*parent).child_inserted(self));
|
||||
self.parent_node().root().map(|parent| vtable_for(&*parent).child_inserted(self));
|
||||
|
||||
document.deref().content_changed();
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#node-is-removed
|
||||
fn node_removed(&self) {
|
||||
let roots = RootCollection::new();
|
||||
assert!(self.parent_node().is_none());
|
||||
let document = document_from_node(self).root(&roots);
|
||||
let document = document_from_node(self).root();
|
||||
|
||||
for node in self.traverse_preorder(&roots) {
|
||||
for node in self.traverse_preorder() {
|
||||
// XXX how about if the node wasn't in the tree in the first place?
|
||||
vtable_for(&node).unbind_from_tree();
|
||||
}
|
||||
|
@ -278,7 +275,6 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> {
|
|||
///
|
||||
/// Fails unless `new_child` is disconnected from the tree.
|
||||
fn add_child(&mut self, new_child: &mut JSRef<Node>, mut before: Option<JSRef<Node>>) {
|
||||
let roots = RootCollection::new();
|
||||
assert!(new_child.parent_node().is_none());
|
||||
assert!(new_child.prev_sibling().is_none());
|
||||
assert!(new_child.next_sibling().is_none());
|
||||
|
@ -286,14 +282,13 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> {
|
|||
Some(ref mut before) => {
|
||||
// XXX Should assert that parent is self.
|
||||
assert!(before.parent_node().is_some());
|
||||
match before.prev_sibling() {
|
||||
match before.prev_sibling().root() {
|
||||
None => {
|
||||
// XXX Should assert that before is the first child of
|
||||
// self.
|
||||
self.set_first_child(Some(new_child.clone()));
|
||||
},
|
||||
Some(prev_sibling) => {
|
||||
let mut prev_sibling = prev_sibling.root(&roots);
|
||||
Some(mut prev_sibling) => {
|
||||
prev_sibling.set_next_sibling(Some(new_child.clone()));
|
||||
new_child.set_prev_sibling(Some((*prev_sibling).clone()));
|
||||
},
|
||||
|
@ -302,7 +297,7 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> {
|
|||
new_child.set_next_sibling(Some(before.clone()));
|
||||
},
|
||||
None => {
|
||||
match self.last_child().map(|child| child.root(&roots)) {
|
||||
match self.last_child().root() {
|
||||
None => self.set_first_child(Some(new_child.clone())),
|
||||
Some(mut last_child) => {
|
||||
assert!(last_child.next_sibling().is_none());
|
||||
|
@ -322,27 +317,26 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> {
|
|||
///
|
||||
/// Fails unless `child` is a child of this node. (FIXME: This is not yet checked.)
|
||||
fn remove_child(&mut self, child: &mut JSRef<Node>) {
|
||||
let roots = RootCollection::new();
|
||||
assert!(child.parent_node.is_some());
|
||||
|
||||
match child.prev_sibling.root(&roots) {
|
||||
match child.prev_sibling.root() {
|
||||
None => {
|
||||
let next_sibling = child.next_sibling.as_ref().map(|next| next.root(&roots));
|
||||
let next_sibling = child.next_sibling.root();
|
||||
self.set_first_child(next_sibling.root_ref());
|
||||
}
|
||||
Some(ref mut prev_sibling) => {
|
||||
let next_sibling = child.next_sibling.as_ref().map(|next| next.root(&roots));
|
||||
let next_sibling = child.next_sibling.root();
|
||||
prev_sibling.set_next_sibling(next_sibling.root_ref());
|
||||
}
|
||||
}
|
||||
|
||||
match child.next_sibling.root(&roots) {
|
||||
match child.next_sibling.root() {
|
||||
None => {
|
||||
let prev_sibling = child.prev_sibling.as_ref().map(|prev| prev.root(&roots));
|
||||
let prev_sibling = child.prev_sibling.root();
|
||||
self.set_last_child(prev_sibling.root_ref());
|
||||
}
|
||||
Some(ref mut next_sibling) => {
|
||||
let prev_sibling = child.prev_sibling.as_ref().map(|prev| prev.root(&roots));
|
||||
let prev_sibling = child.prev_sibling.root();
|
||||
next_sibling.set_prev_sibling(prev_sibling.root_ref());
|
||||
}
|
||||
}
|
||||
|
@ -357,36 +351,31 @@ impl<'a> PrivateNodeHelpers for JSRef<'a, Node> {
|
|||
//
|
||||
|
||||
fn set_parent_node(&mut self, new_parent_node: Option<JSRef<Node>>) {
|
||||
let roots = RootCollection::new();
|
||||
let doc = self.owner_doc().root(&roots);
|
||||
let doc = self.owner_doc().root();
|
||||
doc.deref().wait_until_safe_to_modify_dom();
|
||||
self.parent_node.assign(new_parent_node);
|
||||
}
|
||||
|
||||
fn set_first_child(&mut self, new_first_child: Option<JSRef<Node>>) {
|
||||
let roots = RootCollection::new();
|
||||
let doc = self.owner_doc().root(&roots);
|
||||
let doc = self.owner_doc().root();
|
||||
doc.deref().wait_until_safe_to_modify_dom();
|
||||
self.first_child.assign(new_first_child);
|
||||
}
|
||||
|
||||
fn set_last_child(&mut self, new_last_child: Option<JSRef<Node>>) {
|
||||
let roots = RootCollection::new();
|
||||
let doc = self.owner_doc().root(&roots);
|
||||
let doc = self.owner_doc().root();
|
||||
doc.deref().wait_until_safe_to_modify_dom();
|
||||
self.last_child.assign(new_last_child);
|
||||
}
|
||||
|
||||
fn set_prev_sibling(&mut self, new_prev_sibling: Option<JSRef<Node>>) {
|
||||
let roots = RootCollection::new();
|
||||
let doc = self.owner_doc().root(&roots);
|
||||
let doc = self.owner_doc().root();
|
||||
doc.deref().wait_until_safe_to_modify_dom();
|
||||
self.prev_sibling.assign(new_prev_sibling);
|
||||
}
|
||||
|
||||
fn set_next_sibling(&mut self, new_next_sibling: Option<JSRef<Node>>) {
|
||||
let roots = RootCollection::new();
|
||||
let doc = self.owner_doc().root(&roots);
|
||||
let doc = self.owner_doc().root();
|
||||
doc.deref().wait_until_safe_to_modify_dom();
|
||||
self.next_sibling.assign(new_next_sibling);
|
||||
}
|
||||
|
@ -427,8 +416,8 @@ pub trait NodeHelpers {
|
|||
fn dump_indent(&self, indent: uint);
|
||||
fn debug_str(&self) -> ~str;
|
||||
|
||||
fn traverse_preorder<'a>(&self, roots: &'a RootCollection) -> TreeIterator<'a>;
|
||||
fn sequential_traverse_postorder<'a>(&self, roots: &'a RootCollection) -> TreeIterator<'a>;
|
||||
fn traverse_preorder<'a>(&self) -> TreeIterator<'a>;
|
||||
fn sequential_traverse_postorder<'a>(&self) -> TreeIterator<'a>;
|
||||
fn inclusively_following_siblings(&self) -> AbstractNodeChildrenIterator;
|
||||
|
||||
fn to_trusted_node_address(&self) -> TrustedNodeAddress;
|
||||
|
@ -546,24 +535,22 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
/// Iterates over this node and all its descendants, in preorder.
|
||||
fn traverse_preorder<'a>(&self, roots: &'a RootCollection) -> TreeIterator<'a> {
|
||||
fn traverse_preorder<'a>(&self) -> TreeIterator<'a> {
|
||||
let mut nodes = vec!();
|
||||
gather_abstract_nodes(self, roots, &mut nodes, false);
|
||||
gather_abstract_nodes(self, &mut nodes, false);
|
||||
TreeIterator::new(nodes)
|
||||
}
|
||||
|
||||
/// Iterates over this node and all its descendants, in postorder.
|
||||
fn sequential_traverse_postorder<'a>(&self, roots: &'a RootCollection) -> TreeIterator<'a> {
|
||||
fn sequential_traverse_postorder<'a>(&self) -> TreeIterator<'a> {
|
||||
let mut nodes = vec!();
|
||||
gather_abstract_nodes(self, roots, &mut nodes, true);
|
||||
gather_abstract_nodes(self, &mut nodes, true);
|
||||
TreeIterator::new(nodes)
|
||||
}
|
||||
|
||||
fn inclusively_following_siblings(&self) -> AbstractNodeChildrenIterator {
|
||||
let roots = RootCollection::new();
|
||||
AbstractNodeChildrenIterator {
|
||||
current_node: Some((*self.unrooted().root(&roots)).clone()),
|
||||
roots: roots,
|
||||
current_node: Some((*self.unrooted().root()).clone()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -572,10 +559,8 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
fn following_siblings(&self) -> AbstractNodeChildrenIterator {
|
||||
let roots = RootCollection::new();
|
||||
AbstractNodeChildrenIterator {
|
||||
current_node: self.next_sibling().map(|node| (*node.root(&roots)).clone()),
|
||||
roots: roots,
|
||||
current_node: self.next_sibling().map(|node| (*node.root()).clone()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -591,8 +576,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
fn get_bounding_content_box(&self) -> Rect<Au> {
|
||||
let roots = RootCollection::new();
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
let page = window.get().page();
|
||||
let (chan, port) = channel();
|
||||
let addr = self.to_trusted_node_address();
|
||||
|
@ -601,8 +585,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
fn get_content_boxes(&self) -> Vec<Rect<Au>> {
|
||||
let roots = RootCollection::new();
|
||||
let window = window_from_node(self).root(&roots);
|
||||
let window = window_from_node(self).root();
|
||||
let page = window.get().page();
|
||||
let (chan, port) = channel();
|
||||
let addr = self.to_trusted_node_address();
|
||||
|
@ -611,10 +594,8 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
fn ancestors(&self) -> AncestorIterator {
|
||||
let roots = RootCollection::new();
|
||||
AncestorIterator {
|
||||
current: self.parent_node.clone().map(|node| (*node.root(&roots)).clone()),
|
||||
roots: roots,
|
||||
current: self.parent_node.clone().map(|node| (*node.root()).clone()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -627,10 +608,8 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
fn children(&self) -> AbstractNodeChildrenIterator {
|
||||
let roots = RootCollection::new();
|
||||
AbstractNodeChildrenIterator {
|
||||
current_node: self.first_child.clone().map(|node| (*node.root(&roots)).clone()),
|
||||
roots: roots,
|
||||
current_node: self.first_child.clone().map(|node| (*node.root()).clone()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -646,8 +625,7 @@ impl<'a> NodeHelpers for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
fn wait_until_safe_to_modify_dom(&self) {
|
||||
let roots = RootCollection::new();
|
||||
let document = self.owner_doc().root(&roots);
|
||||
let document = self.owner_doc().root();
|
||||
document.deref().wait_until_safe_to_modify_dom();
|
||||
}
|
||||
|
||||
|
@ -743,14 +721,13 @@ pub type ChildElementIterator<'a, 'b> = Map<'a, JSRef<'b, Node>,
|
|||
|
||||
pub struct AbstractNodeChildrenIterator<'a> {
|
||||
current_node: Option<JSRef<'a, Node>>,
|
||||
roots: RootCollection,
|
||||
}
|
||||
|
||||
impl<'a> Iterator<JSRef<'a, Node>> for AbstractNodeChildrenIterator<'a> {
|
||||
fn next(&mut self) -> Option<JSRef<'a, Node>> {
|
||||
let node = self.current_node.clone();
|
||||
self.current_node = node.clone().and_then(|node| {
|
||||
node.next_sibling().map(|node| (*node.root(&self.roots)).clone())
|
||||
node.next_sibling().map(|node| (*node.root()).clone())
|
||||
});
|
||||
node
|
||||
}
|
||||
|
@ -758,7 +735,6 @@ impl<'a> Iterator<JSRef<'a, Node>> for AbstractNodeChildrenIterator<'a> {
|
|||
|
||||
pub struct AncestorIterator<'a> {
|
||||
current: Option<JSRef<'a, Node>>,
|
||||
roots: RootCollection,
|
||||
}
|
||||
|
||||
impl<'a> Iterator<JSRef<'a, Node>> for AncestorIterator<'a> {
|
||||
|
@ -769,7 +745,7 @@ impl<'a> Iterator<JSRef<'a, Node>> for AncestorIterator<'a> {
|
|||
|
||||
// FIXME: Do we need two clones here?
|
||||
let x = self.current.get_ref().clone();
|
||||
self.current = x.parent_node().map(|node| (*node.root(&self.roots)).clone());
|
||||
self.current = x.parent_node().map(|node| (*node.root()).clone());
|
||||
Some(x)
|
||||
}
|
||||
}
|
||||
|
@ -802,8 +778,7 @@ impl<'a> Iterator<JSRef<'a, Node>> for TreeIterator<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct NodeIterator<'a> {
|
||||
roots: &'a RootCollection,
|
||||
pub struct NodeIterator {
|
||||
pub start_node: JS<Node>,
|
||||
pub current_node: Option<JS<Node>>,
|
||||
pub depth: uint,
|
||||
|
@ -811,13 +786,11 @@ pub struct NodeIterator<'a> {
|
|||
include_descendants_of_void: bool
|
||||
}
|
||||
|
||||
impl<'a> NodeIterator<'a> {
|
||||
pub fn new<'a, 'b>(roots: &'a RootCollection,
|
||||
start_node: &JSRef<'b, Node>,
|
||||
impl NodeIterator {
|
||||
pub fn new<'a>(start_node: &JSRef<'a, Node>,
|
||||
include_start: bool,
|
||||
include_descendants_of_void: bool) -> NodeIterator<'a> {
|
||||
include_descendants_of_void: bool) -> NodeIterator {
|
||||
NodeIterator {
|
||||
roots: roots,
|
||||
start_node: start_node.unrooted(),
|
||||
current_node: None,
|
||||
depth: 0,
|
||||
|
@ -832,22 +805,22 @@ impl<'a> NodeIterator<'a> {
|
|||
if elem.get().is_void() {
|
||||
None
|
||||
} else {
|
||||
node.first_child().map(|child| (*child.root(self.roots)).clone())
|
||||
node.first_child().map(|child| (*child.root()).clone())
|
||||
}
|
||||
} else {
|
||||
node.first_child().map(|child| (*child.root(self.roots)).clone())
|
||||
node.first_child().map(|child| (*child.root()).clone())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b> Iterator<JSRef<'b, Node>> for NodeIterator<'a> {
|
||||
impl<'a> Iterator<JSRef<'a, Node>> for NodeIterator {
|
||||
fn next(&mut self) -> Option<JSRef<Node>> {
|
||||
self.current_node = match self.current_node.as_ref().map(|node| node.root(self.roots)) {
|
||||
self.current_node = match self.current_node.as_ref().map(|node| node.root()) {
|
||||
None => {
|
||||
if self.include_start {
|
||||
Some(self.start_node.clone())
|
||||
} else {
|
||||
self.next_child(&*self.start_node.root(self.roots))
|
||||
self.next_child(&*self.start_node.root())
|
||||
.map(|child| child.unrooted())
|
||||
}
|
||||
},
|
||||
|
@ -859,21 +832,21 @@ impl<'a, 'b> Iterator<JSRef<'b, Node>> for NodeIterator<'a> {
|
|||
},
|
||||
None if node.deref().unrooted() == self.start_node => None,
|
||||
None => {
|
||||
match node.deref().next_sibling().root(self.roots) {
|
||||
match node.deref().next_sibling().root() {
|
||||
Some(sibling) => Some(sibling.deref().unrooted()),
|
||||
None => {
|
||||
let mut candidate = node.deref().clone();
|
||||
while candidate.next_sibling().is_none() {
|
||||
candidate = (*candidate.parent_node()
|
||||
.expect("Got to root without reaching start node")
|
||||
.root(self.roots)).clone();
|
||||
.root()).clone();
|
||||
self.depth -= 1;
|
||||
if candidate.unrooted() == self.start_node {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if candidate.unrooted() != self.start_node {
|
||||
candidate.next_sibling().map(|node| node.root(self.roots).unrooted())
|
||||
candidate.next_sibling().map(|node| node.root().unrooted())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -883,19 +856,19 @@ impl<'a, 'b> Iterator<JSRef<'b, Node>> for NodeIterator<'a> {
|
|||
}
|
||||
}
|
||||
};
|
||||
self.current_node.clone().map(|node| (*node.root(self.roots)).clone())
|
||||
self.current_node.clone().map(|node| (*node.root()).clone())
|
||||
}
|
||||
}
|
||||
|
||||
fn gather_abstract_nodes<'a>(cur: &JSRef<Node>, roots: &'a RootCollection, refs: &mut Vec<JSRef<Node>>, postorder: bool) {
|
||||
fn gather_abstract_nodes<'a>(cur: &JSRef<Node>, refs: &mut Vec<JSRef<Node>>, postorder: bool) {
|
||||
if !postorder {
|
||||
refs.push((*cur.unrooted().root(roots)).clone());
|
||||
refs.push((*cur.unrooted().root()).clone());
|
||||
}
|
||||
for kid in cur.children() {
|
||||
gather_abstract_nodes(&kid, roots, refs, postorder)
|
||||
gather_abstract_nodes(&kid, refs, postorder)
|
||||
}
|
||||
if postorder {
|
||||
refs.push((*cur.unrooted().root(roots)).clone());
|
||||
refs.push((*cur.unrooted().root()).clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -914,17 +887,15 @@ impl Node {
|
|||
document: &JSRef<Document>,
|
||||
wrap_fn: extern "Rust" fn(*JSContext, &JSRef<Window>, ~N) -> JS<N>)
|
||||
-> Temporary<N> {
|
||||
let roots = RootCollection::new();
|
||||
assert!(node.reflector().get_jsobject().is_null());
|
||||
let window = document.get().window.root(&roots);
|
||||
let node = reflect_dom_object(node, &window.root_ref(), wrap_fn).root(&roots);
|
||||
let window = document.get().window.root();
|
||||
let node = reflect_dom_object(node, &window.root_ref(), wrap_fn).root();
|
||||
assert!(node.reflector().get_jsobject().is_not_null());
|
||||
Temporary::new_rooted(&*node)
|
||||
}
|
||||
|
||||
pub fn new_inherited(type_id: NodeTypeId, doc: JS<Document>) -> Node {
|
||||
let roots = RootCollection::new();
|
||||
let doc = doc.root(&roots);
|
||||
let doc = doc.root();
|
||||
Node::new_(type_id, Some(doc.root_ref()))
|
||||
}
|
||||
|
||||
|
@ -954,9 +925,8 @@ impl Node {
|
|||
|
||||
// http://dom.spec.whatwg.org/#concept-node-adopt
|
||||
pub fn adopt(node: &mut JSRef<Node>, document: &JSRef<Document>) {
|
||||
let roots = RootCollection::new();
|
||||
// Step 1.
|
||||
match node.parent_node().root(&roots) {
|
||||
match node.parent_node().root() {
|
||||
Some(mut parent) => {
|
||||
Node::remove(node, &mut *parent, Unsuppressed);
|
||||
}
|
||||
|
@ -964,9 +934,9 @@ impl Node {
|
|||
}
|
||||
|
||||
// Step 2.
|
||||
let node_doc = document_from_node(node).root(&roots);
|
||||
let node_doc = document_from_node(node).root();
|
||||
if &*node_doc != document {
|
||||
for mut descendant in node.traverse_preorder(&roots) {
|
||||
for mut descendant in node.traverse_preorder() {
|
||||
descendant.set_owner_doc(document);
|
||||
}
|
||||
}
|
||||
|
@ -978,7 +948,6 @@ impl Node {
|
|||
// http://dom.spec.whatwg.org/#concept-node-pre-insert
|
||||
fn pre_insert(node: &mut JSRef<Node>, parent: &mut JSRef<Node>, child: Option<JSRef<Node>>)
|
||||
-> Fallible<Temporary<Node>> {
|
||||
let roots = RootCollection::new();
|
||||
// Step 1.
|
||||
match parent.type_id() {
|
||||
DocumentNodeTypeId |
|
||||
|
@ -1001,13 +970,13 @@ impl Node {
|
|||
// Step 4-5.
|
||||
match node.type_id() {
|
||||
TextNodeTypeId => {
|
||||
match node.parent_node().root(&roots) {
|
||||
match node.parent_node().root() {
|
||||
Some(ref parent) if parent.is_document() => return Err(HierarchyRequest),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
DoctypeNodeTypeId => {
|
||||
match node.parent_node().root(&roots) {
|
||||
match node.parent_node().root() {
|
||||
Some(ref parent) if !parent.is_document() => return Err(HierarchyRequest),
|
||||
_ => ()
|
||||
}
|
||||
|
@ -1098,12 +1067,12 @@ impl Node {
|
|||
|
||||
// Step 7-8.
|
||||
let referenceChild = match child {
|
||||
Some(ref child) if child == node => node.next_sibling().map(|node| (*node.root(&roots)).clone()),
|
||||
Some(ref child) if child == node => node.next_sibling().map(|node| (*node.root()).clone()),
|
||||
_ => child
|
||||
};
|
||||
|
||||
// Step 9.
|
||||
let document = document_from_node(parent).root(&roots);
|
||||
let document = document_from_node(parent).root();
|
||||
Node::adopt(node, &*document);
|
||||
|
||||
// Step 10.
|
||||
|
@ -1157,12 +1126,11 @@ impl Node {
|
|||
|
||||
// http://dom.spec.whatwg.org/#concept-node-replace-all
|
||||
fn replace_all(mut node: Option<JSRef<Node>>, parent: &mut JSRef<Node>) {
|
||||
let roots = RootCollection::new();
|
||||
|
||||
// Step 1.
|
||||
match node {
|
||||
Some(ref mut node) => {
|
||||
let document = document_from_node(parent).root(&roots);
|
||||
let document = document_from_node(parent).root();
|
||||
Node::adopt(node, &*document);
|
||||
}
|
||||
None => (),
|
||||
|
@ -1237,12 +1205,11 @@ impl Node {
|
|||
// http://dom.spec.whatwg.org/#concept-node-clone
|
||||
pub fn clone(node: &JSRef<Node>, maybe_doc: Option<&JSRef<Document>>,
|
||||
clone_children: CloneChildrenFlag) -> Temporary<Node> {
|
||||
let roots = RootCollection::new();
|
||||
|
||||
// Step 1.
|
||||
let mut document = match maybe_doc {
|
||||
Some(doc) => doc.unrooted().root(&roots),
|
||||
None => node.owner_doc().root(&roots)
|
||||
Some(doc) => doc.unrooted().root(),
|
||||
None => node.owner_doc().root()
|
||||
};
|
||||
|
||||
// Step 2.
|
||||
|
@ -1272,7 +1239,7 @@ impl Node {
|
|||
true => HTMLDocument,
|
||||
false => NonHTMLDocument
|
||||
};
|
||||
let window = document.window.root(&roots);
|
||||
let window = document.window.root();
|
||||
let document = Document::new(&*window, Some(document.url().clone()),
|
||||
is_html_doc, None);
|
||||
NodeCast::from_unrooted(document)
|
||||
|
@ -1296,16 +1263,16 @@ impl Node {
|
|||
pi.characterdata.data.clone(), &*document);
|
||||
NodeCast::from_unrooted(pi)
|
||||
},
|
||||
}.root(&roots);
|
||||
}.root();
|
||||
|
||||
// Step 3.
|
||||
let document = if copy.is_document() {
|
||||
let doc: &JSRef<Document> = DocumentCast::to_ref(&*copy).unwrap();
|
||||
doc.unrooted().root(&roots)
|
||||
doc.unrooted().root()
|
||||
} else {
|
||||
document.unrooted().root(&roots)
|
||||
document.unrooted().root()
|
||||
};
|
||||
assert!(&*copy.owner_doc().root(&roots) == &*document);
|
||||
assert!(&*copy.owner_doc().root() == &*document);
|
||||
|
||||
// Step 4 (some data already copied in step 2).
|
||||
match node.get().type_id {
|
||||
|
@ -1326,8 +1293,8 @@ impl Node {
|
|||
let copy_elem = copy_elem.get_mut();
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1737
|
||||
copy_elem.namespace = node_elem.namespace.clone();
|
||||
let window = document.get().window.root(&roots);
|
||||
for attr in node_elem.attrs.iter().map(|attr| attr.root(&roots)) {
|
||||
let window = document.get().window.root();
|
||||
for attr in node_elem.attrs.iter().map(|attr| attr.root()) {
|
||||
copy_elem.attrs.push_unrooted(
|
||||
Attr::new(&*window,
|
||||
attr.deref().local_name.clone(), attr.deref().value.clone(),
|
||||
|
@ -1343,7 +1310,7 @@ impl Node {
|
|||
// Step 6.
|
||||
if clone_children == CloneChildren {
|
||||
for ref child in node.children() {
|
||||
let mut child_copy = Node::clone(&*child, Some(&*document), clone_children).root(&roots);
|
||||
let mut child_copy = Node::clone(&*child, Some(&*document), clone_children).root();
|
||||
let _inserted_node = Node::pre_insert(&mut *child_copy, &mut *copy, None);
|
||||
}
|
||||
}
|
||||
|
@ -1462,10 +1429,9 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-node-parentelement
|
||||
fn GetParentElement(&self) -> Option<Temporary<Element>> {
|
||||
let roots = RootCollection::new();
|
||||
self.parent_node.clone()
|
||||
.and_then(|parent| {
|
||||
let parent = parent.root(&roots);
|
||||
let parent = parent.root();
|
||||
ElementCast::to_ref(&*parent).map(|elem| {
|
||||
Temporary::new_rooted(elem)
|
||||
})
|
||||
|
@ -1479,14 +1445,13 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-node-childnodes
|
||||
fn ChildNodes(&mut self) -> Temporary<NodeList> {
|
||||
let roots = RootCollection::new();
|
||||
match self.child_list {
|
||||
None => (),
|
||||
Some(ref list) => return Temporary::new(list.clone()),
|
||||
}
|
||||
|
||||
let doc = self.owner_doc().root(&roots);
|
||||
let window = doc.deref().window.root(&roots);
|
||||
let doc = self.owner_doc().root();
|
||||
let window = doc.deref().window.root();
|
||||
let child_list = NodeList::new_child_list(&*window, self);
|
||||
self.child_list.assign(Some(child_list));
|
||||
Temporary::new(self.child_list.get_ref().clone())
|
||||
|
@ -1542,12 +1507,11 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-node-textcontent
|
||||
fn GetTextContent(&self) -> Option<DOMString> {
|
||||
let roots = RootCollection::new();
|
||||
match self.type_id {
|
||||
DocumentFragmentNodeTypeId |
|
||||
ElementNodeTypeId(..) => {
|
||||
let mut content = ~"";
|
||||
for node in self.traverse_preorder(&roots) {
|
||||
for node in self.traverse_preorder() {
|
||||
if node.is_text() {
|
||||
let text: &JSRef<Text> = TextCast::to_ref(&node).unwrap();
|
||||
content.push_str(text.get().characterdata.data.as_slice());
|
||||
|
@ -1571,7 +1535,6 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
// http://dom.spec.whatwg.org/#dom-node-textcontent
|
||||
fn SetTextContent(&mut self, value: Option<DOMString>)
|
||||
-> ErrorResult {
|
||||
let roots = RootCollection::new();
|
||||
let value = null_str_as_empty(&value);
|
||||
match self.type_id {
|
||||
DocumentFragmentNodeTypeId |
|
||||
|
@ -1580,9 +1543,9 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
let node = if value.len() == 0 {
|
||||
None
|
||||
} else {
|
||||
let document = self.owner_doc().root(&roots);
|
||||
let document = self.owner_doc().root();
|
||||
Some(NodeCast::from_unrooted(document.deref().CreateTextNode(value)))
|
||||
}.root(&roots);
|
||||
}.root();
|
||||
|
||||
// Step 3.
|
||||
Node::replace_all(node.root_ref(), self);
|
||||
|
@ -1598,7 +1561,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
// Notify the document that the content of this node is different
|
||||
let document = self.owner_doc().root(&roots);
|
||||
let document = self.owner_doc().root();
|
||||
document.deref().content_changed();
|
||||
}
|
||||
DoctypeNodeTypeId |
|
||||
|
@ -1619,7 +1582,6 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#concept-node-replace
|
||||
fn ReplaceChild(&mut self, node: &mut JSRef<Node>, child: &mut JSRef<Node>) -> Fallible<Temporary<Node>> {
|
||||
let roots = RootCollection::new();
|
||||
|
||||
// Step 1.
|
||||
match self.type_id() {
|
||||
|
@ -1714,14 +1676,14 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
}
|
||||
|
||||
// Step 7-8.
|
||||
let next_sibling = child.next_sibling().map(|node| (*node.root(&roots)).clone());
|
||||
let next_sibling = child.next_sibling().map(|node| (*node.root()).clone());
|
||||
let reference_child = match next_sibling {
|
||||
Some(ref sibling) if sibling == node => node.next_sibling().map(|node| (*node.root(&roots)).clone()),
|
||||
Some(ref sibling) if sibling == node => node.next_sibling().map(|node| (*node.root()).clone()),
|
||||
_ => next_sibling
|
||||
};
|
||||
|
||||
// Step 9.
|
||||
let document = document_from_node(self).root(&roots);
|
||||
let document = document_from_node(self).root();
|
||||
Node::adopt(node, &*document);
|
||||
|
||||
{
|
||||
|
@ -1755,7 +1717,6 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-node-normalize
|
||||
fn Normalize(&mut self) {
|
||||
let roots = RootCollection::new();
|
||||
let mut prev_text = None;
|
||||
for mut child in self.children() {
|
||||
if child.is_text() {
|
||||
|
@ -1818,12 +1779,11 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
characterdata.get().data == other_characterdata.get().data
|
||||
}
|
||||
fn is_equal_element_attrs(node: &JSRef<Node>, other: &JSRef<Node>) -> bool {
|
||||
let roots = RootCollection::new();
|
||||
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||
let other_element: &JSRef<Element> = ElementCast::to_ref(other).unwrap();
|
||||
assert!(element.get().attrs.len() == other_element.get().attrs.len());
|
||||
element.get().attrs.iter().map(|attr| attr.root(&roots)).all(|attr| {
|
||||
other_element.get().attrs.iter().map(|attr| attr.root(&roots)).any(|other_attr| {
|
||||
element.get().attrs.iter().map(|attr| attr.root()).all(|attr| {
|
||||
other_element.get().attrs.iter().map(|attr| attr.root()).any(|other_attr| {
|
||||
(attr.namespace == other_attr.namespace) &&
|
||||
(attr.local_name == other_attr.local_name) &&
|
||||
(attr.value == other_attr.value)
|
||||
|
@ -1868,7 +1828,6 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
|
||||
// http://dom.spec.whatwg.org/#dom-node-comparedocumentposition
|
||||
fn CompareDocumentPosition(&self, other: &JSRef<Node>) -> u16 {
|
||||
let roots = RootCollection::new();
|
||||
if self == other {
|
||||
// step 2.
|
||||
0
|
||||
|
@ -1907,7 +1866,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> {
|
|||
NodeConstants::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
|
||||
}
|
||||
|
||||
for child in lastself.traverse_preorder(&roots) {
|
||||
for child in lastself.traverse_preorder() {
|
||||
if &child == other {
|
||||
// step 6.
|
||||
return NodeConstants::DOCUMENT_POSITION_PRECEDING;
|
||||
|
@ -1965,8 +1924,7 @@ pub fn document_from_node<T: NodeBase>(derived: &JSRef<T>) -> Temporary<Document
|
|||
}
|
||||
|
||||
pub fn window_from_node<T: NodeBase>(derived: &JSRef<T>) -> Temporary<Window> {
|
||||
let roots = RootCollection::new();
|
||||
let document = document_from_node(derived).root(&roots);
|
||||
let document = document_from_node(derived).root();
|
||||
Temporary::new(document.deref().window.clone())
|
||||
}
|
||||
|
||||
|
|
|
@ -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, Temporary, RootCollection};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::node::{Node, NodeHelpers};
|
||||
use dom::window::Window;
|
||||
|
@ -54,23 +54,21 @@ pub trait NodeListMethods {
|
|||
|
||||
impl<'a> NodeListMethods for JSRef<'a, NodeList> {
|
||||
fn Length(&self) -> u32 {
|
||||
let roots = RootCollection::new();
|
||||
match self.list_type {
|
||||
Simple(ref elems) => elems.len() as u32,
|
||||
Children(ref node) => {
|
||||
let node = node.root(&roots);
|
||||
let node = node.root();
|
||||
node.deref().children().len() as u32
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn Item(&self, index: u32) -> Option<Temporary<Node>> {
|
||||
let roots = RootCollection::new();
|
||||
match self.list_type {
|
||||
_ if index >= self.Length() => None,
|
||||
Simple(ref elems) => Some(Temporary::new(elems.get(index as uint).clone())),
|
||||
Children(ref node) => {
|
||||
let node = node.root(&roots);
|
||||
let node = node.root();
|
||||
node.deref().children().nth(index as uint)
|
||||
.map(|child| Temporary::new_rooted(&child))
|
||||
}
|
||||
|
|
|
@ -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, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::codegen::BindingDeclarations::TestBindingBinding;
|
||||
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong;
|
||||
use self::TestBindingBinding::TestEnum;
|
||||
|
@ -232,8 +232,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn EnumAttribute(&self) -> TestEnum { _empty }
|
||||
fn SetEnumAttribute(&self, _: TestEnum) {}
|
||||
fn InterfaceAttribute(&self) -> Temporary<Blob> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
Blob::new(&*window)
|
||||
}
|
||||
fn SetInterfaceAttribute(&self, _: &JSRef<Blob>) {}
|
||||
|
@ -268,8 +267,7 @@ impl<'a> TestBindingMethods for JSRef<'a, TestBinding> {
|
|||
fn SetStringAttributeNullable(&self, _: Option<DOMString>) {}
|
||||
fn GetEnumAttributeNullable(&self) -> Option<TestEnum> { Some(_empty) }
|
||||
fn GetInterfaceAttributeNullable(&self) -> Option<Temporary<Blob>> {
|
||||
let roots = RootCollection::new();
|
||||
let window = self.window.root(&roots);
|
||||
let window = self.window.root();
|
||||
Some(Blob::new(&(*window)))
|
||||
}
|
||||
fn SetInterfaceAttributeNullable(&self, _: Option<JSRef<Blob>>) {}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::BindingDeclarations::TextBinding;
|
||||
use dom::bindings::codegen::InheritTypes::TextDerived;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::characterdata::CharacterData;
|
||||
use dom::document::Document;
|
||||
|
@ -41,8 +41,7 @@ impl Text {
|
|||
}
|
||||
|
||||
pub fn Constructor(owner: &JSRef<Window>, text: DOMString) -> Fallible<Temporary<Text>> {
|
||||
let roots = RootCollection::new();
|
||||
let document = owner.Document().root(&roots);
|
||||
let document = owner.Document().root();
|
||||
Ok(Text::new(text.clone(), &*document))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
use dom::bindings::codegen::BindingDeclarations::UIEventBinding;
|
||||
use dom::bindings::codegen::InheritTypes::{EventCast, UIEventDerived};
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, RootedReference, Temporary};
|
||||
use dom::bindings::js::{JS, JSRef, RootedReference, Temporary};
|
||||
use dom::bindings::error::Fallible;
|
||||
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
|
||||
use dom::event::{Event, EventMethods, EventTypeId, UIEventTypeId};
|
||||
|
@ -45,9 +45,8 @@ impl UIEvent {
|
|||
pub fn Constructor(owner: &JSRef<Window>,
|
||||
type_: DOMString,
|
||||
init: &UIEventBinding::UIEventInit) -> Fallible<Temporary<UIEvent>> {
|
||||
let roots = RootCollection::new();
|
||||
let mut ev = UIEvent::new(owner).root(&roots);
|
||||
let view = init.view.as_ref().map(|view| view.root(&roots));
|
||||
let mut ev = UIEvent::new(owner).root();
|
||||
let view = init.view.as_ref().map(|view| view.root());
|
||||
ev.InitUIEvent(type_, init.parent.bubbles, init.parent.cancelable,
|
||||
view.root_ref(), init.detail);
|
||||
Ok(Temporary::new_rooted(&*ev))
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
use dom::attr::AttrMethods;
|
||||
use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast};
|
||||
use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast;
|
||||
use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalRootable, Root};
|
||||
use dom::bindings::js::{JS, JSRef, Temporary, OptionalRootable, Root};
|
||||
use dom::bindings::utils::Reflectable;
|
||||
use dom::document::{Document, DocumentHelpers};
|
||||
use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId};
|
||||
|
@ -76,21 +76,17 @@ pub struct HtmlParserResult {
|
|||
}
|
||||
|
||||
trait NodeWrapping<T> {
|
||||
unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr;
|
||||
unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr;
|
||||
}
|
||||
|
||||
impl<'a, T: NodeBase+Reflectable> NodeWrapping<T> for JSRef<'a, T> {
|
||||
unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr {
|
||||
roots.root_raw(self.reflector().get_jsobject());
|
||||
unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr {
|
||||
cast::transmute(self.get())
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn from_hubbub_node<T: Reflectable>(n: hubbub::NodeDataPtr,
|
||||
roots: Option<&RootCollection>) -> Temporary<T> {
|
||||
let js = JS::from_raw(cast::transmute(n));
|
||||
let _ = roots.map(|roots| roots.unroot_raw(js.reflector().get_jsobject()));
|
||||
Temporary::new(js)
|
||||
unsafe fn from_hubbub_node<T: Reflectable>(n: hubbub::NodeDataPtr) -> Temporary<T> {
|
||||
Temporary::new(JS::from_raw(cast::transmute(n)))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -297,9 +293,8 @@ pub fn parse_html(page: &Page,
|
|||
let mut parser = hubbub::Parser("UTF-8", false);
|
||||
debug!("created parser");
|
||||
|
||||
let roots = RootCollection::new();
|
||||
|
||||
parser.set_document_node(unsafe { document.to_hubbub_node(&roots) });
|
||||
parser.set_document_node(unsafe { document.to_hubbub_node() });
|
||||
parser.enable_scripting(true);
|
||||
parser.enable_styling(true);
|
||||
|
||||
|
@ -315,9 +310,9 @@ pub fn parse_html(page: &Page,
|
|||
// NOTE: tmp vars are workaround for lifetime issues. Both required.
|
||||
let tmp_borrow = doc_cell.borrow();
|
||||
let tmp = &*tmp_borrow;
|
||||
let comment = Comment::new(data, *tmp).root(&roots);
|
||||
let comment = Comment::new(data, *tmp).root();
|
||||
let comment: &JSRef<Node> = NodeCast::from_ref(&*comment);
|
||||
unsafe { comment.to_hubbub_node(&roots) }
|
||||
unsafe { comment.to_hubbub_node() }
|
||||
},
|
||||
create_doctype: |doctype: ~hubbub::Doctype| {
|
||||
debug!("create doctype");
|
||||
|
@ -328,9 +323,9 @@ pub fn parse_html(page: &Page,
|
|||
// NOTE: tmp vars are workaround for lifetime issues. Both required.
|
||||
let tmp_borrow = doc_cell.borrow();
|
||||
let tmp = &*tmp_borrow;
|
||||
let doctype_node = DocumentType::new(name, public_id, system_id, *tmp).root(&roots);
|
||||
let doctype_node = DocumentType::new(name, public_id, system_id, *tmp).root();
|
||||
unsafe {
|
||||
doctype_node.deref().to_hubbub_node(&roots)
|
||||
doctype_node.deref().to_hubbub_node()
|
||||
}
|
||||
},
|
||||
create_element: |tag: ~hubbub::Tag| {
|
||||
|
@ -338,7 +333,7 @@ pub fn parse_html(page: &Page,
|
|||
// NOTE: tmp vars are workaround for lifetime issues. Both required.
|
||||
let tmp_borrow = doc_cell.borrow();
|
||||
let tmp = &*tmp_borrow;
|
||||
let mut element = build_element_from_tag(tag.name.clone(), *tmp).root(&roots);
|
||||
let mut element = build_element_from_tag(tag.name.clone(), *tmp).root();
|
||||
|
||||
debug!("-- attach attrs");
|
||||
for attr in tag.attributes.iter() {
|
||||
|
@ -351,15 +346,15 @@ pub fn parse_html(page: &Page,
|
|||
//FIXME: workaround for https://github.com/mozilla/rust/issues/13246;
|
||||
// we get unrooting order failures if these are inside the match.
|
||||
let rel = {
|
||||
let rel = element.get_attribute(Null, "rel").root(&roots);
|
||||
let rel = element.get_attribute(Null, "rel").root();
|
||||
rel.map(|a| a.deref().Value())
|
||||
};
|
||||
let href = {
|
||||
let href= element.get_attribute(Null, "href").root(&roots);
|
||||
let href= element.get_attribute(Null, "href").root();
|
||||
href.map(|a| a.deref().Value())
|
||||
};
|
||||
let src_opt = {
|
||||
let src_opt = element.get_attribute(Null, "src").root(&roots);
|
||||
let src_opt = element.get_attribute(Null, "src").root();
|
||||
src_opt.map(|a| a.deref().Value())
|
||||
};
|
||||
|
||||
|
@ -410,23 +405,23 @@ pub fn parse_html(page: &Page,
|
|||
_ => {}
|
||||
}
|
||||
|
||||
unsafe { element.to_hubbub_node(&roots) }
|
||||
unsafe { element.to_hubbub_node() }
|
||||
},
|
||||
create_text: |data: ~str| {
|
||||
debug!("create text");
|
||||
// NOTE: tmp vars are workaround for lifetime issues. Both required.
|
||||
let tmp_borrow = doc_cell.borrow();
|
||||
let tmp = &*tmp_borrow;
|
||||
let text = Text::new(data, *tmp).root(&roots);
|
||||
unsafe { text.deref().to_hubbub_node(&roots) }
|
||||
let text = Text::new(data, *tmp).root();
|
||||
unsafe { text.deref().to_hubbub_node() }
|
||||
},
|
||||
ref_node: |_| {},
|
||||
unref_node: |_| {},
|
||||
append_child: |parent: hubbub::NodeDataPtr, child: hubbub::NodeDataPtr| {
|
||||
unsafe {
|
||||
debug!("append child {:x} {:x}", parent, child);
|
||||
let mut child = from_hubbub_node(child, Some(&roots)).root(&roots);
|
||||
let mut parent: Root<Node> = from_hubbub_node(parent, None).root(&roots);
|
||||
let mut child = from_hubbub_node(child).root();
|
||||
let mut parent: Root<Node> = from_hubbub_node(parent).root();
|
||||
assert!(parent.AppendChild(&mut *child).is_ok());
|
||||
}
|
||||
child
|
||||
|
@ -478,8 +473,8 @@ pub fn parse_html(page: &Page,
|
|||
},
|
||||
complete_script: |script| {
|
||||
unsafe {
|
||||
let script: &JSRef<Element> = &*from_hubbub_node(script, None).root(&roots);
|
||||
match script.get_attribute(Null, "src").root(&roots) {
|
||||
let script: &JSRef<Element> = &*from_hubbub_node(script).root();
|
||||
match script.get_attribute(Null, "src").root() {
|
||||
Some(src) => {
|
||||
debug!("found script: {:s}", src.deref().Value());
|
||||
let new_url = parse_url(src.get().value_ref(), Some(url3.clone()));
|
||||
|
|
|
@ -278,12 +278,11 @@ impl Page {
|
|||
|
||||
/// Adds the given damage.
|
||||
pub fn damage(&self, level: DocumentDamageLevel) {
|
||||
let roots = RootCollection::new();
|
||||
let root = match *self.frame() {
|
||||
None => return,
|
||||
Some(ref frame) => frame.document.root(&roots).GetDocumentElement()
|
||||
Some(ref frame) => frame.document.root().GetDocumentElement()
|
||||
};
|
||||
match root.root(&roots) {
|
||||
match root.root() {
|
||||
None => {},
|
||||
Some(root) => {
|
||||
let root: &JSRef<Node> = NodeCast::from_ref(&*root);
|
||||
|
@ -358,16 +357,15 @@ impl Page {
|
|||
goal: ReflowGoal,
|
||||
script_chan: ScriptChan,
|
||||
compositor: &ScriptListener) {
|
||||
let roots = RootCollection::new();
|
||||
|
||||
let root = match *self.frame() {
|
||||
None => return,
|
||||
Some(ref frame) => {
|
||||
frame.document.root(&roots).GetDocumentElement()
|
||||
frame.document.root().GetDocumentElement()
|
||||
}
|
||||
};
|
||||
|
||||
match root.root(&roots) {
|
||||
match root.root() {
|
||||
None => {},
|
||||
Some(root) => {
|
||||
debug!("script: performing reflow for goal {:?}", goal);
|
||||
|
@ -411,17 +409,16 @@ impl Page {
|
|||
}
|
||||
|
||||
fn find_fragment_node(&self, fragid: ~str) -> Option<Temporary<Element>> {
|
||||
let roots = RootCollection::new();
|
||||
let document = self.frame().get_ref().document.root(&roots);
|
||||
let document = self.frame().get_ref().document.root();
|
||||
match document.deref().GetElementById(fragid.to_owned()) {
|
||||
Some(node) => Some(node),
|
||||
None => {
|
||||
let doc_node: &JSRef<Node> = NodeCast::from_ref(&*document);
|
||||
let mut anchors = doc_node.traverse_preorder(&roots)
|
||||
let mut anchors = doc_node.traverse_preorder()
|
||||
.filter(|node| node.is_anchor_element());
|
||||
anchors.find(|node| {
|
||||
let elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||
elem.get_attribute(Null, "name").root(&roots).map_or(false, |attr| {
|
||||
elem.get_attribute(Null, "name").root().map_or(false, |attr| {
|
||||
attr.get().value_ref() == fragid
|
||||
})
|
||||
}).map(|node| Temporary::new_rooted(ElementCast::to_ref(&node).unwrap()))
|
||||
|
@ -450,10 +447,9 @@ impl Page {
|
|||
}
|
||||
|
||||
pub fn hit_test(&self, point: &Point2D<f32>) -> Option<UntrustedNodeAddress> {
|
||||
let roots = RootCollection::new();
|
||||
let frame = self.frame();
|
||||
let document = frame.get_ref().document.root(&roots);
|
||||
let root = document.deref().GetDocumentElement().root(&roots);
|
||||
let document = frame.get_ref().document.root();
|
||||
let root = document.deref().GetDocumentElement().root();
|
||||
if root.is_none() {
|
||||
return None;
|
||||
}
|
||||
|
@ -473,10 +469,9 @@ impl Page {
|
|||
}
|
||||
|
||||
pub fn get_nodes_under_mouse(&self, point: &Point2D<f32>) -> Option<Vec<UntrustedNodeAddress>> {
|
||||
let roots = RootCollection::new();
|
||||
let frame = self.frame();
|
||||
let document = frame.get_ref().document.root(&roots);
|
||||
let root = document.deref().GetDocumentElement().root(&roots);
|
||||
let document = frame.get_ref().document.root();
|
||||
let root = document.deref().GetDocumentElement().root();
|
||||
if root.is_none() {
|
||||
return None;
|
||||
}
|
||||
|
@ -763,13 +758,12 @@ impl ScriptTask {
|
|||
|
||||
/// Handles a timer that fired.
|
||||
fn handle_fire_timer_msg(&self, id: PipelineId, timer_id: TimerId) {
|
||||
let roots = RootCollection::new();
|
||||
|
||||
let mut page_tree = self.page_tree.borrow_mut();
|
||||
let page = page_tree.find(id).expect("ScriptTask: received fire timer msg for a
|
||||
pipeline ID not associated with this script task. This is a bug.").page();
|
||||
let frame = page.frame();
|
||||
let mut window = frame.get_ref().window.root(&roots);
|
||||
let mut window = frame.get_ref().window.root();
|
||||
|
||||
let is_interval;
|
||||
match window.get().active_timers.find(&timer_id) {
|
||||
|
@ -880,7 +874,6 @@ impl ScriptTask {
|
|||
fn load(&self, pipeline_id: PipelineId, url: Url) {
|
||||
debug!("ScriptTask: loading {:?} on page {:?}", url, pipeline_id);
|
||||
|
||||
let roots = RootCollection::new();
|
||||
|
||||
let mut page_tree = self.page_tree.borrow_mut();
|
||||
let page_tree = page_tree.find(pipeline_id).expect("ScriptTask: received a load
|
||||
|
@ -907,9 +900,9 @@ impl ScriptTask {
|
|||
page_tree.page.clone(),
|
||||
self.chan.clone(),
|
||||
self.compositor.dup(),
|
||||
self.image_cache_task.clone()).root(&roots);
|
||||
self.image_cache_task.clone()).root();
|
||||
page.initialize_js_info(cx.clone(), window.reflector().get_jsobject());
|
||||
let mut document = Document::new(&*window, Some(url.clone()), HTMLDocument, None).root(&roots);
|
||||
let mut document = Document::new(&*window, Some(url.clone()), HTMLDocument, None).root();
|
||||
window.get_mut().init_browser_context(&*document);
|
||||
|
||||
{
|
||||
|
@ -1010,7 +1003,7 @@ impl ScriptTask {
|
|||
// We have no concept of a document loader right now, so just dispatch the
|
||||
// "load" event as soon as we've finished executing all scripts parsed during
|
||||
// the initial load.
|
||||
let mut event = Event::new(&*window).root(&roots);
|
||||
let mut event = Event::new(&*window).root();
|
||||
event.InitEvent(~"load", false, false);
|
||||
let doctarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*document);
|
||||
let wintarget: &JSRef<EventTarget> = EventTargetCast::from_ref(&*window);
|
||||
|
@ -1048,7 +1041,6 @@ impl ScriptTask {
|
|||
|
||||
match event {
|
||||
ResizeEvent(new_width, new_height) => {
|
||||
let roots = RootCollection::new();
|
||||
debug!("script got resize event: {:u}, {:u}", new_width, new_height);
|
||||
|
||||
let window = {
|
||||
|
@ -1066,7 +1058,7 @@ impl ScriptTask {
|
|||
}
|
||||
|
||||
let mut fragment_node = page.fragment_node.deref().borrow_mut();
|
||||
match fragment_node.take().map(|node| node.root(&roots)) {
|
||||
match fragment_node.take().map(|node| node.root()) {
|
||||
Some(node) => self.scroll_fragment_point(pipeline_id, &*node),
|
||||
None => {}
|
||||
}
|
||||
|
@ -1074,11 +1066,11 @@ impl ScriptTask {
|
|||
frame.as_ref().map(|frame| Temporary::new(frame.window.clone()))
|
||||
};
|
||||
|
||||
match window.root(&roots) {
|
||||
match window.root() {
|
||||
Some(mut window) => {
|
||||
// http://dev.w3.org/csswg/cssom-view/#resizing-viewports
|
||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-resize
|
||||
let mut uievent = UIEvent::new(&*window).root(&roots);
|
||||
let mut uievent = UIEvent::new(&*window).root();
|
||||
uievent.InitUIEvent(~"resize", false, false,
|
||||
Some((*window).clone()), 0i32);
|
||||
let event: &mut JSRef<Event> = EventCast::from_mut_ref(&mut *uievent);
|
||||
|
@ -1104,7 +1096,6 @@ impl ScriptTask {
|
|||
}
|
||||
|
||||
ClickEvent(_button, point) => {
|
||||
let roots = RootCollection::new();
|
||||
debug!("ClickEvent: clicked at {:?}", point);
|
||||
let mut page_tree = self.page_tree.borrow_mut();
|
||||
let page = get_page(&mut *page_tree, pipeline_id);
|
||||
|
@ -1113,14 +1104,14 @@ impl ScriptTask {
|
|||
debug!("node address is {:?}", node_address);
|
||||
let mut node =
|
||||
node::from_untrusted_node_address(self.js_runtime.deref().ptr,
|
||||
node_address).root(&roots);
|
||||
node_address).root();
|
||||
debug!("clicked on {:s}", node.deref().debug_str());
|
||||
|
||||
// Traverse node generations until a node that is an element is
|
||||
// found.
|
||||
while !node.deref().is_element() {
|
||||
match node.deref().parent_node() {
|
||||
Some(parent) => node = parent.root(&roots),
|
||||
Some(parent) => node = parent.root(),
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
|
@ -1139,7 +1130,6 @@ impl ScriptTask {
|
|||
MouseDownEvent(..) => {}
|
||||
MouseUpEvent(..) => {}
|
||||
MouseMoveEvent(point) => {
|
||||
let roots = RootCollection::new();
|
||||
let mut page_tree = self.page_tree.borrow_mut();
|
||||
let page = get_page(&mut *page_tree, pipeline_id);
|
||||
match page.get_nodes_under_mouse(&point) {
|
||||
|
@ -1152,7 +1142,7 @@ impl ScriptTask {
|
|||
match *mouse_over_targets {
|
||||
Some(ref mut mouse_over_targets) => {
|
||||
for node in mouse_over_targets.mut_iter() {
|
||||
let mut node = node.root(&roots);
|
||||
let mut node = node.root();
|
||||
node.set_hover_state(false);
|
||||
}
|
||||
}
|
||||
|
@ -1162,12 +1152,12 @@ impl ScriptTask {
|
|||
for node_address in node_address.iter() {
|
||||
let mut node =
|
||||
node::from_untrusted_node_address(
|
||||
self.js_runtime.deref().ptr, *node_address).root(&roots);
|
||||
self.js_runtime.deref().ptr, *node_address).root();
|
||||
// Traverse node generations until a node that is an element is
|
||||
// found.
|
||||
while !node.is_element() {
|
||||
match node.parent_node() {
|
||||
Some(parent) => node = parent.root(&roots),
|
||||
Some(parent) => node = parent.root(),
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
|
@ -1211,10 +1201,9 @@ impl ScriptTask {
|
|||
}
|
||||
|
||||
fn load_url_from_element(&self, page: &Page, element: &JSRef<Element>) {
|
||||
let roots = RootCollection::new();
|
||||
// if the node's element is "a," load url from href attr
|
||||
let attr = element.get_attribute(Null, "href");
|
||||
for href in attr.root(&roots).iter() {
|
||||
for href in attr.root().iter() {
|
||||
debug!("ScriptTask: clicked on link to {:s}", href.Value());
|
||||
let click_frag = href.get().value_ref().starts_with("#");
|
||||
let base_url = Some(page.get_url());
|
||||
|
@ -1222,7 +1211,7 @@ impl ScriptTask {
|
|||
let url = parse_url(href.get().value_ref(), base_url);
|
||||
|
||||
if click_frag {
|
||||
match page.find_fragment_node(url.fragment.unwrap()).root(&roots) {
|
||||
match page.find_fragment_node(url.fragment.unwrap()).root() {
|
||||
Some(node) => self.scroll_fragment_point(page.id, &*node),
|
||||
None => {}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue