From 7daa97c7e5de3dac14b4d1c8a923448b025e3c09 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 10 Apr 2014 22:13:08 -0400 Subject: [PATCH] Remove abstract_self. --- .../script/dom/bindings/codegen/Bindings.conf | 103 +----- .../dom/bindings/codegen/CodegenRust.py | 18 - .../dom/bindings/codegen/Configuration.py | 1 - src/components/script/dom/document.rs | 176 +++++----- src/components/script/dom/documentfragment.rs | 8 +- .../script/dom/domimplementation.rs | 20 +- src/components/script/dom/element.rs | 331 +++++++++--------- src/components/script/dom/eventdispatcher.rs | 11 +- src/components/script/dom/eventtarget.rs | 25 +- .../script/dom/htmldatalistelement.rs | 6 +- .../script/dom/htmlfieldsetelement.rs | 6 +- .../script/dom/htmliframeelement.rs | 12 +- src/components/script/dom/htmlimageelement.rs | 144 ++++---- .../script/dom/htmlscriptelement.rs | 10 +- src/components/script/dom/htmlstyleelement.rs | 2 +- src/components/script/dom/node.rs | 164 ++++----- src/components/script/dom/window.rs | 33 +- .../script/html/hubbub_html_parser.rs | 8 +- src/components/script/script_task.rs | 15 +- 19 files changed, 483 insertions(+), 610 deletions(-) diff --git a/src/components/script/dom/bindings/codegen/Bindings.conf b/src/components/script/dom/bindings/codegen/Bindings.conf index 053fabae1b2..f3723fb7c9b 100644 --- a/src/components/script/dom/bindings/codegen/Bindings.conf +++ b/src/components/script/dom/bindings/codegen/Bindings.conf @@ -9,8 +9,6 @@ # The configuration table maps each interface name to a |descriptor|. # # Valid fields for all descriptors: -# * needsAbstract: a list of members that require a JS<>-wrapped version of -# self to be passed to the native code. # * createGlobal: True for global objects. # * outerObjectHook: string to use in place of default value for outerObject and thisObject # JS class hooks @@ -26,123 +24,46 @@ DOMInterfaces = { 'ClientRect': {}, 'ClientRectList': {}, 'Console': {}, -'Document': { - 'needsAbstract': [ - 'adoptNode', - 'anchors', - 'applets', - 'body', - 'children', - 'createComment', - 'createDocumentFragment', - 'createElement', - 'createElementNS', - 'createProcessingInstruction', - 'createTextNode', - 'embeds', - 'forms', - 'getElementsByClassName', - 'getElementsByTagName', - 'getElementsByTagNameNS', - 'images', - 'importNode', - 'links', - 'location', - 'plugins', - 'scripts', - 'title', - ], -}, +'Document': {}, 'DOMException': {}, 'DOMImplementation': {}, 'DOMParser': {}, -'Element': { - 'needsAbstract': [ - 'attributes', - 'children', - 'className', - 'getAttribute', - 'getAttributeNS', - 'getBoundingClientRect', - 'getClientRects', - 'getElementsByClassName', - 'getElementsByTagName', - 'getElementsByTagNameNS', - 'hasAttribute', - 'hasAttributeNS', - 'id', - 'innerHTML', - 'outerHTML', - 'removeAttribute', - 'removeAttributeNS', - 'setAttribute', - 'setAttributeNS', - ] -}, +'Element': {}, 'Event': {}, 'EventListener': { 'nativeType': 'EventListenerBinding::EventListener', }, -'EventTarget': { - 'needsAbstract': ['dispatchEvent'] -}, +'EventTarget': {}, 'FormData': {}, 'HTMLCollection': {}, 'Location': {}, 'MouseEvent': {}, 'Navigator': {}, -'Node': { - 'needsAbstract': [ - 'appendChild', - 'childNodes', - 'cloneNode', - 'compareDocumentPosition', - 'contains', - 'insertBefore', - 'isEqualNode', - 'namespaceURI', - 'nodeName', - 'nodeValue', - 'normalize', - 'removeChild', - 'replaceChild', - 'textContent', - ] -}, - +'Node': {}, 'NodeList': {}, - 'UIEvent': {}, 'ValidityState': {}, 'Window': { 'createGlobal': True, 'outerObjectHook': 'Some(bindings::utils::outerize_global)', - 'needsAbstract': [ - 'console', - 'location', - 'navigator', - 'self', - 'window', - ], }, 'XMLHttpRequest': {}, 'XMLHttpRequestEventTarget': {}, 'XMLHttpRequestUpload': {}, +#FIXME(jdm): This should be 'register': False, but then we don't generate enum types 'TestBinding': {}, } # FIXME: This should be renamed: https://github.com/mozilla/servo/issues/1625 -def addHTMLElement(element, concrete=None, needsAbstract=[]): +def addHTMLElement(element): DOMInterfaces[element] = { 'nativeType': 'JS<%s>' % element, - 'concreteType': concrete if concrete else element, - 'needsAbstract': needsAbstract } addHTMLElement('Comment') -addHTMLElement('DocumentFragment', concrete='DocumentFragment', needsAbstract=['children']) +addHTMLElement('DocumentFragment') addHTMLElement('DocumentType') addHTMLElement('Text') addHTMLElement('ProcessingInstruction') @@ -158,12 +79,12 @@ addHTMLElement('HTMLBRElement') addHTMLElement('HTMLCanvasElement') addHTMLElement('HTMLDataElement') addHTMLElement('HTMLDivElement') -addHTMLElement('HTMLDataListElement', needsAbstract=['options']) +addHTMLElement('HTMLDataListElement') addHTMLElement('HTMLDirectoryElement') addHTMLElement('HTMLDListElement') addHTMLElement('HTMLElement') addHTMLElement('HTMLEmbedElement') -addHTMLElement('HTMLFieldSetElement', needsAbstract=['elements']) +addHTMLElement('HTMLFieldSetElement') addHTMLElement('HTMLFontElement') addHTMLElement('HTMLFormElement') addHTMLElement('HTMLFrameElement') @@ -172,8 +93,8 @@ addHTMLElement('HTMLHeadElement') addHTMLElement('HTMLHeadingElement') addHTMLElement('HTMLHtmlElement') addHTMLElement('HTMLHRElement') -addHTMLElement('HTMLIFrameElement', needsAbstract=['sandbox']) -addHTMLElement('HTMLImageElement', needsAbstract=['alt', 'src', 'useMap', 'isMap', 'width', 'height', 'name', 'align', 'hspace', 'vspace', 'longDesc', 'border']) +addHTMLElement('HTMLIFrameElement') +addHTMLElement('HTMLImageElement') addHTMLElement('HTMLInputElement') addHTMLElement('HTMLLabelElement') addHTMLElement('HTMLLegendElement') @@ -195,7 +116,7 @@ addHTMLElement('HTMLParamElement') addHTMLElement('HTMLPreElement') addHTMLElement('HTMLProgressElement') addHTMLElement('HTMLQuoteElement') -addHTMLElement('HTMLScriptElement', needsAbstract=['src']) +addHTMLElement('HTMLScriptElement') addHTMLElement('HTMLSelectElement') addHTMLElement('HTMLSourceElement') addHTMLElement('HTMLSpanElement') diff --git a/src/components/script/dom/bindings/codegen/CodegenRust.py b/src/components/script/dom/bindings/codegen/CodegenRust.py index a8b75a75456..f73de0ea365 100644 --- a/src/components/script/dom/bindings/codegen/CodegenRust.py +++ b/src/components/script/dom/bindings/codegen/CodegenRust.py @@ -2494,12 +2494,6 @@ class CGSpecializedMethod(CGAbstractExternMethod): nativeName = MakeNativeName(name) extraPre = '' argsPre = [] - if name in self.descriptor.needsAbstract: - abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType) - extraPre = """ let mut abstract_this = %s::from_raw(this); - let abstract_this = abstract_this.root(&roots); -""" % abstractName - argsPre = ['&mut abstract_this.root_ref()'] return CGWrapper(CGMethodCall(argsPre, nativeName, self.method.isStatic(), self.descriptor, self.method), pre=extraPre + @@ -2552,12 +2546,6 @@ class CGSpecializedGetter(CGAbstractExternMethod): infallible = ('infallible' in self.descriptor.getExtendedAttributes(self.attr, getter=True)) - if name in self.descriptor.needsAbstract: - abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType) - extraPre = """ let mut abstract_this = %s::from_raw(this); - let abstract_this = abstract_this.root(&roots); -""" % abstractName - argsPre = ['&mut abstract_this.root_ref()'] if self.attr.type.nullable() or not infallible: nativeName = "Get" + nativeName return CGWrapper(CGIndenter(CGGetterCall(argsPre, self.attr.type, nativeName, @@ -2614,12 +2602,6 @@ class CGSpecializedSetter(CGAbstractExternMethod): nativeName = "Set" + MakeNativeName(name) argsPre = [] extraPre = '' - if name in self.descriptor.needsAbstract: - abstractName = re.sub(r'<\w+>', '', self.descriptor.nativeType) - extraPre = """ let mut abstract_this = %s::from_raw(this); - let abstract_this = abstract_this.root(&roots); -""" % abstractName - argsPre = ['&mut abstract_this.root_ref()'] return CGWrapper(CGIndenter(CGSetterCall(argsPre, self.attr.type, nativeName, self.descriptor, self.attr)), pre=extraPre + diff --git a/src/components/script/dom/bindings/codegen/Configuration.py b/src/components/script/dom/bindings/codegen/Configuration.py index eedb200c75e..48570a05476 100644 --- a/src/components/script/dom/bindings/codegen/Configuration.py +++ b/src/components/script/dom/bindings/codegen/Configuration.py @@ -136,7 +136,6 @@ class Descriptor(DescriptorProvider): self.returnType = "Unrooted<%s>" % ifaceName self.nativeType = desc.get('nativeType', nativeTypeDefault) self.concreteType = desc.get('concreteType', ifaceName) - self.needsAbstract = desc.get('needsAbstract', []) self.createGlobal = desc.get('createGlobal', False) self.register = desc.get('register', True) self.outerObjectHook = desc.get('outerObjectHook', 'None') diff --git a/src/components/script/dom/document.rs b/src/components/script/dom/document.rs index f435b6186af..e9f237999a7 100644 --- a/src/components/script/dom/document.rs +++ b/src/components/script/dom/document.rs @@ -27,8 +27,8 @@ use dom::htmlheadelement::HTMLHeadElement; use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmltitleelement::HTMLTitleElement; use dom::mouseevent::MouseEvent; -use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, AppendChild}; -use dom::node::{CloneChildren, DoNotCloneChildren, RemoveChild, ReplaceChild}; +use dom::node::{Node, ElementNodeTypeId, DocumentNodeTypeId, NodeHelpers, NodeMethods}; +use dom::node::{CloneChildren, DoNotCloneChildren}; use dom::nodelist::NodeList; use dom::text::Text; use dom::processinginstruction::ProcessingInstruction; @@ -165,7 +165,7 @@ impl Document { /// Remove any existing association between the provided id and any elements in this document. pub fn unregister_named_element(&mut self, - abstract_self: &JSRef, + to_unregister: &JSRef, id: DOMString) { let roots = RootCollection::new(); let mut is_empty = false; @@ -174,7 +174,7 @@ impl Document { Some(elements) => { let position = elements.iter() .map(|elem| elem.root(&roots)) - .position(|element| &*element == abstract_self) + .position(|element| &*element == to_unregister) .expect("This element should be in registered."); elements.remove(position); is_empty = elements.is_empty(); @@ -282,37 +282,35 @@ pub trait DocumentMethods { fn ContentType(&self) -> DOMString; fn GetDoctype(&self) -> Option>; fn GetDocumentElement(&self) -> Option>; - fn GetElementsByTagName(&self, abstract_self: &JSRef, tag_name: DOMString) -> Unrooted; - fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, tag_name: DOMString) -> Unrooted; - fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted; + fn GetElementsByTagName(&self, tag_name: DOMString) -> Unrooted; + fn GetElementsByTagNameNS(&self, maybe_ns: Option, tag_name: DOMString) -> Unrooted; + fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted; fn GetElementById(&self, id: DOMString) -> Option>; - fn CreateElement(&self, abstract_self: &JSRef, local_name: DOMString) -> Fallible>; - fn CreateElementNS(&self, abstract_self: &JSRef, - namespace: Option, - qualified_name: DOMString) -> Fallible>; - fn CreateDocumentFragment(&self, abstract_self: &JSRef) -> Unrooted; - fn CreateTextNode(&self, abstract_self: &JSRef, data: DOMString) -> Unrooted; - fn CreateComment(&self, abstract_self: &JSRef, data: DOMString) -> Unrooted; - fn CreateProcessingInstruction(&self, abstract_self: &JSRef, target: DOMString, data: DOMString) -> Fallible>; - fn ImportNode(&self, abstract_self: &JSRef, node: &JSRef, deep: bool) -> Fallible>; - fn AdoptNode(&self, abstract_self: &JSRef, node: &mut JSRef) -> Fallible>; + fn CreateElement(&self, local_name: DOMString) -> Fallible>; + fn CreateElementNS(&self, namespace: Option, qualified_name: DOMString) -> Fallible>; + fn CreateDocumentFragment(&self) -> Unrooted; + fn CreateTextNode(&self, data: DOMString) -> Unrooted; + fn CreateComment(&self, data: DOMString) -> Unrooted; + fn CreateProcessingInstruction(&self, target: DOMString, data: DOMString) -> Fallible>; + fn ImportNode(&self, node: &JSRef, deep: bool) -> Fallible>; + fn AdoptNode(&self, node: &mut JSRef) -> Fallible>; fn CreateEvent(&self, interface: DOMString) -> Fallible>; - fn Title(&self, _: &JSRef) -> DOMString; - fn SetTitle(&self, abstract_self: &JSRef, title: DOMString) -> ErrorResult; + fn Title(&self) -> DOMString; + fn SetTitle(&self, title: DOMString) -> ErrorResult; fn GetHead(&self) -> Option>; - fn GetBody(&self, _: &JSRef) -> Option>; - fn SetBody(&self, abstract_self: &JSRef, new_body: Option>) -> ErrorResult; + fn GetBody(&self) -> Option>; + fn SetBody(&self, new_body: Option>) -> ErrorResult; fn GetElementsByName(&self, name: DOMString) -> Unrooted; - fn Images(&self, abstract_self: &JSRef) -> Unrooted; - fn Embeds(&self, abstract_self: &JSRef) -> Unrooted; - fn Plugins(&self, abstract_self: &JSRef) -> Unrooted; - fn Links(&self, abstract_self: &JSRef) -> Unrooted; - fn Forms(&self, abstract_self: &JSRef) -> Unrooted; - fn Scripts(&self, abstract_self: &JSRef) -> Unrooted; - fn Anchors(&self, abstract_self: &JSRef) -> Unrooted; - fn Applets(&self, abstract_self: &JSRef) -> Unrooted; - fn Location(&mut self, _abstract_self: &JSRef) -> Unrooted; - fn Children(&self, abstract_self: &JSRef) -> Unrooted; + fn Images(&self) -> Unrooted; + fn Embeds(&self) -> Unrooted; + fn Plugins(&self) -> Unrooted; + fn Links(&self) -> Unrooted; + fn Forms(&self) -> Unrooted; + fn Scripts(&self) -> Unrooted; + fn Anchors(&self) -> Unrooted; + fn Applets(&self) -> Unrooted; + fn Location(&mut self) -> Unrooted; + fn Children(&self) -> Unrooted; } impl<'a> DocumentMethods for JSRef<'a, Document> { @@ -370,14 +368,14 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagname - fn GetElementsByTagName(&self, abstract_self: &JSRef, tag_name: DOMString) -> Unrooted { + fn GetElementsByTagName(&self, tag_name: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); - HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), tag_name) + HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), tag_name) } // http://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens - fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, tag_name: DOMString) -> Unrooted { + fn GetElementsByTagNameNS(&self, maybe_ns: Option, tag_name: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -385,15 +383,15 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { Some(namespace) => Namespace::from_str(namespace), None => Null }; - HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(abstract_self), tag_name, namespace) + HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(self), tag_name, namespace) } // http://dom.spec.whatwg.org/#dom-document-getelementsbyclassname - fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted { + fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); - HTMLCollection::by_class_name(&*window, NodeCast::from_ref(abstract_self), classes) + HTMLCollection::by_class_name(&*window, NodeCast::from_ref(self), classes) } // http://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid @@ -405,18 +403,17 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://dom.spec.whatwg.org/#dom-document-createelement - fn CreateElement(&self, abstract_self: &JSRef, local_name: DOMString) - -> Fallible> { + fn CreateElement(&self, local_name: DOMString) -> Fallible> { if xml_name_type(local_name) == InvalidXMLName { debug!("Not a valid element name"); return Err(InvalidCharacter); } let local_name = local_name.to_ascii_lower(); - Ok(build_element_from_tag(local_name, abstract_self)) + Ok(build_element_from_tag(local_name, self)) } // http://dom.spec.whatwg.org/#dom-document-createelementns - fn CreateElementNS(&self, abstract_self: &JSRef, + fn CreateElementNS(&self, namespace: Option, qualified_name: DOMString) -> Fallible> { let ns = Namespace::from_str(null_str_as_empty_ref(&namespace)); @@ -455,30 +452,30 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } if ns == namespace::HTML { - Ok(build_element_from_tag(local_name_from_qname, abstract_self)) + Ok(build_element_from_tag(local_name_from_qname, self)) } else { - Ok(Element::new(local_name_from_qname, ns, prefix_from_qname, abstract_self)) + Ok(Element::new(local_name_from_qname, ns, prefix_from_qname, self)) } } // http://dom.spec.whatwg.org/#dom-document-createdocumentfragment - fn CreateDocumentFragment(&self, abstract_self: &JSRef) -> Unrooted { - DocumentFragment::new(abstract_self) + fn CreateDocumentFragment(&self) -> Unrooted { + DocumentFragment::new(self) } // http://dom.spec.whatwg.org/#dom-document-createtextnode - fn CreateTextNode(&self, abstract_self: &JSRef, data: DOMString) + fn CreateTextNode(&self, data: DOMString) -> Unrooted { - Text::new(data, abstract_self) + Text::new(data, self) } // http://dom.spec.whatwg.org/#dom-document-createcomment - fn CreateComment(&self, abstract_self: &JSRef, data: DOMString) -> Unrooted { - Comment::new(data, abstract_self) + fn CreateComment(&self, data: DOMString) -> Unrooted { + Comment::new(data, self) } // http://dom.spec.whatwg.org/#dom-document-createprocessinginstruction - fn CreateProcessingInstruction(&self, abstract_self: &JSRef, target: DOMString, + fn CreateProcessingInstruction(&self, target: DOMString, data: DOMString) -> Fallible> { // Step 1. if xml_name_type(target) == InvalidXMLName { @@ -491,11 +488,11 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // Step 3. - Ok(ProcessingInstruction::new(target, data, abstract_self)) + Ok(ProcessingInstruction::new(target, data, self)) } // http://dom.spec.whatwg.org/#dom-document-importnode - fn ImportNode(&self, abstract_self: &JSRef, node: &JSRef, deep: bool) -> Fallible> { + fn ImportNode(&self, node: &JSRef, deep: bool) -> Fallible> { // Step 1. if node.is_document() { return Err(NotSupported); @@ -507,18 +504,18 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { false => DoNotCloneChildren }; - Ok(Node::clone(node, Some(abstract_self), clone_children)) + Ok(Node::clone(node, Some(self), clone_children)) } // http://dom.spec.whatwg.org/#dom-document-adoptnode - fn AdoptNode(&self, abstract_self: &JSRef, node: &mut JSRef) -> Fallible> { + fn AdoptNode(&self, node: &mut JSRef) -> Fallible> { // Step 1. if node.is_document() { return Err(NotSupported); } // Step 2. - Node::adopt(node, abstract_self); + Node::adopt(node, self); // Step 3. Ok(Unrooted::new_rooted(node)) @@ -539,7 +536,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://www.whatwg.org/specs/web-apps/current-work/#document.title - fn Title(&self, _: &JSRef) -> DOMString { + fn Title(&self) -> DOMString { let mut title = ~""; let roots = RootCollection::new(); self.GetDocumentElement().root(&roots).map(|root| { @@ -561,7 +558,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://www.whatwg.org/specs/web-apps/current-work/#document.title - fn SetTitle(&self, abstract_self: &JSRef, title: DOMString) -> ErrorResult { + fn SetTitle(&self, title: DOMString) -> ErrorResult { let roots = RootCollection::new(); self.GetDocumentElement().root(&roots).map(|root| { @@ -577,20 +574,20 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { match title_node { Some(ref mut title_node) => { for mut title_child in title_node.children() { - assert!(RemoveChild(&mut *title_node, &mut title_child).is_ok()); + assert!(title_node.RemoveChild(&mut title_child).is_ok()); } - let mut new_text = self.CreateTextNode(abstract_self, title.clone()).root(&roots); + let mut new_text = self.CreateTextNode(title.clone()).root(&roots); - assert!(AppendChild(&mut *title_node, NodeCast::from_mut_ref(&mut *new_text)).is_ok()); + assert!(title_node.AppendChild(NodeCast::from_mut_ref(&mut *new_text)).is_ok()); }, None => { - let mut new_title = HTMLTitleElement::new(~"title", abstract_self).root(&roots); + let mut new_title = HTMLTitleElement::new(~"title", self).root(&roots); let new_title: &mut JSRef = NodeCast::from_mut_ref(&mut *new_title); - let mut new_text = self.CreateTextNode(abstract_self, title.clone()).root(&roots); + let mut new_text = self.CreateTextNode(title.clone()).root(&roots); - assert!(AppendChild(&mut *new_title, NodeCast::from_mut_ref(&mut *new_text)).is_ok()); - assert!(AppendChild(&mut *head, &mut *new_title).is_ok()); + assert!(new_title.AppendChild(NodeCast::from_mut_ref(&mut *new_text)).is_ok()); + assert!(head.AppendChild(&mut *new_title).is_ok()); }, } }); @@ -613,7 +610,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body - fn GetBody(&self, _: &JSRef) -> Option> { + fn GetBody(&self) -> Option> { let roots = RootCollection::new(); self.get_html_element().and_then(|root| { let root = root.root(&roots); @@ -631,7 +628,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // http://www.whatwg.org/specs/web-apps/current-work/#dom-document-body - fn SetBody(&self, abstract_self: &JSRef, new_body: Option>) -> ErrorResult { + fn SetBody(&self, new_body: Option>) -> ErrorResult { let roots = RootCollection::new(); // Step 1. @@ -646,7 +643,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } // Step 2. - let mut old_body = self.GetBody(abstract_self).root(&roots); + let mut old_body = self.GetBody().root(&roots); //FIXME: covariant lifetime workaround. do not judge. if old_body.as_ref().map(|body| body.deref()) == new_body.as_ref().map(|a| &*a) { return Ok(()); @@ -665,9 +662,9 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { Some(ref mut child) => { let child: &mut JSRef = NodeCast::from_mut_ref(&mut **child); - assert!(ReplaceChild(&mut *root, new_body, child).is_ok()) + assert!(root.ReplaceChild(new_body, child).is_ok()) } - None => assert!(AppendChild(&mut *root, new_body).is_ok()) + None => assert!(root.AppendChild(new_body).is_ok()) }; } } @@ -690,7 +687,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { }) } - fn Images(&self, abstract_self: &JSRef) -> Unrooted { + fn Images(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -702,10 +699,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~ImagesFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Embeds(&self, abstract_self: &JSRef) -> Unrooted { + fn Embeds(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -717,15 +714,15 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~EmbedsFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Plugins(&self, abstract_self: &JSRef) -> Unrooted { + fn Plugins(&self) -> Unrooted { // FIXME: https://github.com/mozilla/servo/issues/1847 - self.Embeds(abstract_self) + self.Embeds() } - fn Links(&self, abstract_self: &JSRef) -> Unrooted { + fn Links(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -738,10 +735,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~LinksFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Forms(&self, abstract_self: &JSRef) -> Unrooted { + fn Forms(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -753,10 +750,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~FormsFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Scripts(&self, abstract_self: &JSRef) -> Unrooted { + fn Scripts(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -768,10 +765,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~ScriptsFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Anchors(&self, abstract_self: &JSRef) -> Unrooted { + fn Anchors(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -783,10 +780,10 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~AnchorsFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Applets(&self, abstract_self: &JSRef) -> Unrooted { + fn Applets(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); @@ -798,19 +795,18 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { } } let filter = ~AppletsFilter; - HTMLCollection::create(&*window, NodeCast::from_ref(abstract_self), filter) + HTMLCollection::create(&*window, NodeCast::from_ref(self), filter) } - fn Location(&mut self, _abstract_self: &JSRef) -> Unrooted { + fn Location(&mut self) -> Unrooted { let roots = RootCollection::new(); let mut window = self.window.root(&roots); - let window_alias = self.window.root(&roots); - window.Location(&*window_alias) + window.Location() } - fn Children(&self, abstract_self: &JSRef) -> Unrooted { + fn Children(&self) -> Unrooted { let roots = RootCollection::new(); let window = self.window.root(&roots); - HTMLCollection::children(&*window, NodeCast::from_ref(abstract_self)) + HTMLCollection::children(&*window, NodeCast::from_ref(self)) } } diff --git a/src/components/script/dom/documentfragment.rs b/src/components/script/dom/documentfragment.rs index aee61d03b51..55e782406b3 100644 --- a/src/components/script/dom/documentfragment.rs +++ b/src/components/script/dom/documentfragment.rs @@ -49,13 +49,13 @@ impl DocumentFragment { } pub trait DocumentFragmentMethods { - fn Children(&self, abstract_self: &JSRef) -> Unrooted; + fn Children(&self) -> Unrooted; } impl<'a> DocumentFragmentMethods for JSRef<'a, DocumentFragment> { - fn Children(&self, abstract_self: &JSRef) -> Unrooted { + fn Children(&self) -> Unrooted { let roots = RootCollection::new(); - let window = window_from_node(abstract_self).root(&roots); - HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) + let window = window_from_node(self).root(&roots); + HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(self)) } } diff --git a/src/components/script/dom/domimplementation.rs b/src/components/script/dom/domimplementation.rs index a8f889ddd8c..e339485fbd9 100644 --- a/src/components/script/dom/domimplementation.rs +++ b/src/components/script/dom/domimplementation.rs @@ -14,7 +14,7 @@ use dom::htmlbodyelement::HTMLBodyElement; use dom::htmlheadelement::HTMLHeadElement; use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmltitleelement::HTMLTitleElement; -use dom::node::{Node, AppendChild}; +use dom::node::{Node, NodeMethods}; use dom::text::Text; use dom::window::{Window, WindowMethods}; use servo_util::str::DOMString; @@ -87,7 +87,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { let mut maybe_elem = if qname.is_empty() { None } else { - match doc.deref().CreateElementNS(&*doc, namespace, qname) { + match doc.CreateElementNS(namespace, qname) { Err(error) => return Err(error), Ok(elem) => Some(elem) } @@ -100,7 +100,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { match maybe_doctype { None => (), Some(ref mut doctype) => { - assert!(AppendChild(doc_node, NodeCast::from_mut_ref(doctype)).is_ok()) + assert!(doc_node.AppendChild(NodeCast::from_mut_ref(doctype)).is_ok()) } } @@ -108,7 +108,7 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { match maybe_elem.root(&roots) { None => (), Some(mut elem) => { - assert!(AppendChild(doc_node, NodeCast::from_mut_ref(&mut *elem)).is_ok()) + assert!(doc_node.AppendChild(NodeCast::from_mut_ref(&mut *elem)).is_ok()) } } } @@ -133,18 +133,18 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { { // Step 3. let mut doc_type = DocumentType::new(~"html", None, None, &*doc).root(&roots); - assert!(AppendChild(&mut *doc_node, NodeCast::from_mut_ref(&mut *doc_type)).is_ok()); + 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); - assert!(AppendChild(&mut *doc_node, &mut *doc_html).is_ok()); + assert!(doc_node.AppendChild(&mut *doc_html).is_ok()); { // Step 5. let mut doc_head = NodeCast::from_unrooted(HTMLHeadElement::new(~"head", &*doc)).root(&roots); - assert!(AppendChild(&mut *doc_html, &mut *doc_head).is_ok()); + assert!(doc_html.AppendChild(&mut *doc_head).is_ok()); // Step 6. match title { @@ -152,18 +152,18 @@ impl<'a> DOMImplementationMethods for JSRef<'a, DOMImplementation> { Some(title_str) => { // Step 6.1. let mut doc_title = NodeCast::from_unrooted(HTMLTitleElement::new(~"title", &*doc)).root(&roots); - assert!(AppendChild(&mut *doc_head, &mut *doc_title).is_ok()); + assert!(doc_head.AppendChild(&mut *doc_title).is_ok()); // Step 6.2. let mut title_text = Text::new(title_str, &*doc).root(&roots); - assert!(AppendChild(&mut *doc_title, NodeCast::from_mut_ref(&mut *title_text)).is_ok()); + 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); - assert!(AppendChild(&mut *doc_html, NodeCast::from_mut_ref(&mut *doc_body)).is_ok()); + assert!(doc_html.AppendChild(NodeCast::from_mut_ref(&mut *doc_body)).is_ok()); } // Step 8. diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs index 2a66aec0221..200ed604777 100644 --- a/src/components/script/dom/element.rs +++ b/src/components/script/dom/element.rs @@ -198,9 +198,6 @@ pub trait AttributeHandlers { fn do_set_attribute(&mut self, local_name: DOMString, value: DOMString, name: DOMString, namespace: Namespace, prefix: Option, cb: |&JSRef| -> bool); - fn SetAttribute_(&mut self, name: DOMString, value: DOMString) -> ErrorResult; - fn SetAttributeNS_(&mut self, namespace_url: Option, - name: DOMString, value: DOMString) -> ErrorResult; fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult; fn notify_attribute_changed(&self, local_name: DOMString); @@ -281,100 +278,10 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { self.get_mut().attrs.get(idx).root(&roots).set_value(set_type, value); } - // http://dom.spec.whatwg.org/#dom-element-setattribute - fn SetAttribute_(&mut self, name: DOMString, value: DOMString) -> ErrorResult { - { - let node: &JSRef = NodeCast::from_ref(self); - node.get().wait_until_safe_to_modify_dom(); - } - - // Step 1. - match xml_name_type(name) { - InvalidXMLName => return Err(InvalidCharacter), - _ => {} - } - - // Step 2. - let name = if self.get().html_element_in_html_document() { - name.to_ascii_lower() - } else { - name - }; - - // Step 3-5. - self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, |attr| { - attr.get().name == name - }); - Ok(()) - } - - fn SetAttributeNS_(&mut self, namespace_url: Option, - name: DOMString, value: DOMString) -> ErrorResult { - { - let node: &JSRef = NodeCast::from_ref(self); - node.get().wait_until_safe_to_modify_dom(); - } - - // Step 1. - let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace_url)); - - let name_type = xml_name_type(name); - match name_type { - // Step 2. - InvalidXMLName => return Err(InvalidCharacter), - // Step 3. - Name => return Err(NamespaceError), - QName => {} - } - - // Step 4. - let (prefix, local_name) = get_attribute_parts(name.clone()); - match prefix { - Some(ref prefix_str) => { - // Step 5. - if namespace == namespace::Null { - return Err(NamespaceError); - } - - // Step 6. - if "xml" == prefix_str.as_slice() && namespace != namespace::XML { - return Err(NamespaceError); - } - - // Step 7b. - if "xmlns" == prefix_str.as_slice() && namespace != namespace::XMLNS { - return Err(NamespaceError); - } - }, - None => {} - } - - // Step 7a. - if "xmlns" == name && namespace != namespace::XMLNS { - return Err(NamespaceError); - } - - // Step 8. - if namespace == namespace::XMLNS && "xmlns" != name && Some(~"xmlns") != prefix { - return Err(NamespaceError); - } - - // Step 9. - self.do_set_attribute(local_name.clone(), value, name, namespace.clone(), prefix, |attr| { - attr.get().local_name == local_name && - attr.get().namespace == namespace - }); - Ok(()) - } - fn remove_attribute(&mut self, namespace: Namespace, name: DOMString) -> ErrorResult { let roots = RootCollection::new(); let (_, local_name) = get_attribute_parts(name.clone()); - let self_alias = self.clone(); - let node: &JSRef = NodeCast::from_ref(&self_alias); - node.wait_until_safe_to_modify_dom(); - let idx = self.get().attrs.iter().map(|attr| attr.root(&roots)).position(|attr| { attr.local_name == local_name }); @@ -382,9 +289,14 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> { match idx { None => (), Some(idx) => { + { + let node: &JSRef = NodeCast::from_ref(self); + node.wait_until_safe_to_modify_dom(); + } + if namespace == namespace::Null { let removed_raw_value = self.get().attrs.get(idx).root(&roots).Value(); - vtable_for(node).before_remove_attr(local_name.clone(), removed_raw_value); + vtable_for(NodeCast::from_ref(self)).before_remove_attr(local_name.clone(), removed_raw_value); } self.get_mut().attrs.remove(idx); @@ -463,27 +375,27 @@ pub trait ElementMethods { fn LocalName(&self) -> DOMString; fn GetPrefix(&self) -> Option; fn TagName(&self) -> DOMString; - fn Id(&self, abstract_self: &JSRef) -> DOMString; - fn SetId(&mut self, abstract_self: &mut JSRef, id: DOMString); - fn ClassName(&self, abstract_self: &JSRef) -> DOMString; - fn SetClassName(&self, abstract_self: &mut JSRef, class: DOMString); - fn Attributes(&mut self, abstract_self: &JSRef) -> Unrooted; - fn GetAttribute(&self, abstract_self: &JSRef, name: DOMString) -> Option; - fn GetAttributeNS(&self, abstract_self: &JSRef, namespace: Option, local_name: DOMString) -> Option; - fn SetAttribute(&self, abstract_self: &mut JSRef, name: DOMString, value: DOMString) -> ErrorResult; - fn SetAttributeNS(&self, abstract_self: &mut JSRef, namespace_url: Option, name: DOMString, value: DOMString) -> ErrorResult; - fn RemoveAttribute(&mut self, abstract_self: &mut JSRef, name: DOMString) -> ErrorResult; - fn RemoveAttributeNS(&mut self, abstract_self: &mut JSRef, namespace: Option, localname: DOMString) -> ErrorResult; - fn HasAttribute(&self, abstract_self: &JSRef, name: DOMString) -> bool; - fn HasAttributeNS(&self, abstract_self: &JSRef, namespace: Option, local_name: DOMString) -> bool; - fn GetElementsByTagName(&self, abstract_self: &JSRef, localname: DOMString) -> Unrooted; - fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, localname: DOMString) -> Unrooted; - fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted; - fn GetClientRects(&self, abstract_self: &JSRef) -> Unrooted; - fn GetBoundingClientRect(&self, abstract_self: &JSRef) -> Unrooted; - fn GetInnerHTML(&self, abstract_self: &JSRef) -> Fallible; - fn GetOuterHTML(&self, abstract_self: &JSRef) -> Fallible; - fn Children(&self, abstract_self: &JSRef) -> Unrooted; + fn Id(&self) -> DOMString; + fn SetId(&mut self, id: DOMString); + fn ClassName(&self) -> DOMString; + fn SetClassName(&mut self, class: DOMString); + fn Attributes(&mut self) -> Unrooted; + fn GetAttribute(&self, name: DOMString) -> Option; + fn GetAttributeNS(&self, namespace: Option, local_name: DOMString) -> Option; + fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult; + fn SetAttributeNS(&mut self, namespace_url: Option, name: DOMString, value: DOMString) -> ErrorResult; + fn RemoveAttribute(&mut self, name: DOMString) -> ErrorResult; + fn RemoveAttributeNS(&mut self, namespace: Option, localname: DOMString) -> ErrorResult; + fn HasAttribute(&self, name: DOMString) -> bool; + fn HasAttributeNS(&self, namespace: Option, local_name: DOMString) -> bool; + fn GetElementsByTagName(&self, localname: DOMString) -> Unrooted; + fn GetElementsByTagNameNS(&self, maybe_ns: Option, localname: DOMString) -> Unrooted; + fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted; + fn GetClientRects(&self) -> Unrooted; + fn GetBoundingClientRect(&self) -> Unrooted; + fn GetInnerHTML(&self) -> Fallible; + fn GetOuterHTML(&self) -> Fallible; + fn Children(&self) -> Unrooted; } impl<'a> ElementMethods for JSRef<'a, Element> { @@ -514,27 +426,27 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } // http://dom.spec.whatwg.org/#dom-element-id - fn Id(&self, abstract_self: &JSRef) -> DOMString { - abstract_self.get_string_attribute("id") + fn Id(&self) -> DOMString { + self.get_string_attribute("id") } // http://dom.spec.whatwg.org/#dom-element-id - fn SetId(&mut self, abstract_self: &mut JSRef, id: DOMString) { - abstract_self.set_string_attribute("id", id); + fn SetId(&mut self, id: DOMString) { + self.set_string_attribute("id", id); } // http://dom.spec.whatwg.org/#dom-element-classname - fn ClassName(&self, abstract_self: &JSRef) -> DOMString { - abstract_self.get_string_attribute("class") + fn ClassName(&self) -> DOMString { + self.get_string_attribute("class") } // http://dom.spec.whatwg.org/#dom-element-classname - fn SetClassName(&self, abstract_self: &mut JSRef, class: DOMString) { - abstract_self.set_string_attribute("class", class); + fn SetClassName(&mut self, class: DOMString) { + self.set_string_attribute("class", class); } // http://dom.spec.whatwg.org/#dom-element-attributes - fn Attributes(&mut self, abstract_self: &JSRef) -> Unrooted { + fn Attributes(&mut self) -> Unrooted { let roots = RootCollection::new(); match self.attr_list { None => (), @@ -543,111 +455,184 @@ impl<'a> ElementMethods for JSRef<'a, Element> { let doc = self.node.owner_doc().root(&roots); let window = doc.deref().window.root(&roots); - let list = AttrList::new(&window.root_ref(), abstract_self); + let list = AttrList::new(&*window, self); self.attr_list.assign(Some(list)); Unrooted::new(self.attr_list.get_ref().clone()) } // http://dom.spec.whatwg.org/#dom-element-getattribute - fn GetAttribute(&self, abstract_self: &JSRef, name: DOMString) -> Option { + fn GetAttribute(&self, name: DOMString) -> Option { let roots = RootCollection::new(); - let name = if abstract_self.get().html_element_in_html_document() { + let name = if self.get().html_element_in_html_document() { name.to_ascii_lower() } else { name }; - abstract_self.get_attribute(Null, name).root(&roots) + self.get_attribute(Null, name).root(&roots) .map(|s| s.deref().Value()) } // http://dom.spec.whatwg.org/#dom-element-getattributens - fn GetAttributeNS(&self, abstract_self: &JSRef, - namespace: Option, - local_name: DOMString) -> Option { + fn GetAttributeNS(&self, + namespace: Option, + local_name: DOMString) -> Option { let roots = RootCollection::new(); let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); - abstract_self.get_attribute(namespace, local_name).root(&roots) + self.get_attribute(namespace, local_name).root(&roots) .map(|attr| attr.deref().Value()) } // http://dom.spec.whatwg.org/#dom-element-setattribute - fn SetAttribute(&self, abstract_self: &mut JSRef, + fn SetAttribute(&mut self, name: DOMString, value: DOMString) -> ErrorResult { - abstract_self.SetAttribute_(name, value) + { + let node: &JSRef = NodeCast::from_ref(self); + node.get().wait_until_safe_to_modify_dom(); + } + + // Step 1. + match xml_name_type(name) { + InvalidXMLName => return Err(InvalidCharacter), + _ => {} + } + + // Step 2. + let name = if self.get().html_element_in_html_document() { + name.to_ascii_lower() + } else { + name + }; + + // Step 3-5. + self.do_set_attribute(name.clone(), value, name.clone(), namespace::Null, None, |attr| { + attr.get().name == name + }); + Ok(()) } // http://dom.spec.whatwg.org/#dom-element-setattributens - fn SetAttributeNS(&self, - abstract_self: &mut JSRef, + fn SetAttributeNS(&mut self, namespace_url: Option, name: DOMString, value: DOMString) -> ErrorResult { - abstract_self.SetAttributeNS_(namespace_url, name, value) + { + let node: &JSRef = NodeCast::from_ref(self); + node.get().wait_until_safe_to_modify_dom(); + } + + // Step 1. + let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace_url)); + + let name_type = xml_name_type(name); + match name_type { + // Step 2. + InvalidXMLName => return Err(InvalidCharacter), + // Step 3. + Name => return Err(NamespaceError), + QName => {} + } + + // Step 4. + let (prefix, local_name) = get_attribute_parts(name.clone()); + match prefix { + Some(ref prefix_str) => { + // Step 5. + if namespace == namespace::Null { + return Err(NamespaceError); + } + + // Step 6. + if "xml" == prefix_str.as_slice() && namespace != namespace::XML { + return Err(NamespaceError); + } + + // Step 7b. + if "xmlns" == prefix_str.as_slice() && namespace != namespace::XMLNS { + return Err(NamespaceError); + } + }, + None => {} + } + + // Step 7a. + if "xmlns" == name && namespace != namespace::XMLNS { + return Err(NamespaceError); + } + + // Step 8. + if namespace == namespace::XMLNS && "xmlns" != name && Some(~"xmlns") != prefix { + return Err(NamespaceError); + } + + // Step 9. + self.do_set_attribute(local_name.clone(), value, name, namespace.clone(), prefix, |attr| { + attr.get().local_name == local_name && + attr.get().namespace == namespace + }); + Ok(()) } // http://dom.spec.whatwg.org/#dom-element-removeattribute fn RemoveAttribute(&mut self, - abstract_self: &mut JSRef, name: DOMString) -> ErrorResult { let name = if self.html_element_in_html_document() { name.to_ascii_lower() } else { name }; - abstract_self.remove_attribute(namespace::Null, name) + self.remove_attribute(namespace::Null, name) } // http://dom.spec.whatwg.org/#dom-element-removeattributens fn RemoveAttributeNS(&mut self, - abstract_self: &mut JSRef, - namespace: Option, - localname: DOMString) -> ErrorResult { + namespace: Option, + localname: DOMString) -> ErrorResult { let namespace = Namespace::from_str(null_str_as_empty_ref(&namespace)); - abstract_self.remove_attribute(namespace, localname) + self.remove_attribute(namespace, localname) } // http://dom.spec.whatwg.org/#dom-element-hasattribute - fn HasAttribute(&self, abstract_self: &JSRef, - name: DOMString) -> bool { - self.GetAttribute(abstract_self, name).is_some() + fn HasAttribute(&self, + name: DOMString) -> bool { + self.GetAttribute(name).is_some() } // http://dom.spec.whatwg.org/#dom-element-hasattributens - fn HasAttributeNS(&self, abstract_self: &JSRef, - namespace: Option, - local_name: DOMString) -> bool { - self.GetAttributeNS(abstract_self, namespace, local_name).is_some() + fn HasAttributeNS(&self, + namespace: Option, + local_name: DOMString) -> bool { + self.GetAttributeNS(namespace, local_name).is_some() } - fn GetElementsByTagName(&self, abstract_self: &JSRef, localname: DOMString) -> Unrooted { + fn GetElementsByTagName(&self, localname: DOMString) -> Unrooted { let roots = RootCollection::new(); - let window = window_from_node(abstract_self).root(&roots); - HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(abstract_self), localname) + let window = window_from_node(self).root(&roots); + HTMLCollection::by_tag_name(&*window, NodeCast::from_ref(self), localname) } - fn GetElementsByTagNameNS(&self, abstract_self: &JSRef, maybe_ns: Option, - localname: DOMString) -> Unrooted { + fn GetElementsByTagNameNS(&self, maybe_ns: Option, + localname: DOMString) -> Unrooted { let roots = RootCollection::new(); let namespace = match maybe_ns { Some(namespace) => Namespace::from_str(namespace), None => Null }; - let window = window_from_node(abstract_self).root(&roots); - HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(abstract_self), localname, namespace) + let window = window_from_node(self).root(&roots); + HTMLCollection::by_tag_name_ns(&*window, NodeCast::from_ref(self), localname, namespace) } - fn GetElementsByClassName(&self, abstract_self: &JSRef, classes: DOMString) -> Unrooted { + fn GetElementsByClassName(&self, classes: DOMString) -> Unrooted { let roots = RootCollection::new(); - let window = window_from_node(abstract_self).root(&roots); - HTMLCollection::by_class_name(&*window, NodeCast::from_ref(abstract_self), classes) + let window = window_from_node(self).root(&roots); + HTMLCollection::by_class_name(&*window, NodeCast::from_ref(self), classes) } // http://dev.w3.org/csswg/cssom-view/#dom-element-getclientrects - fn GetClientRects(&self, abstract_self: &JSRef) -> Unrooted { + fn GetClientRects(&self) -> Unrooted { let roots = RootCollection::new(); - let win = window_from_node(abstract_self).root(&roots); - let node: &JSRef = NodeCast::from_ref(abstract_self); + let win = window_from_node(self).root(&roots); + let node: &JSRef = NodeCast::from_ref(self); let rects = node.get_content_boxes(); let rects: ~[Root] = rects.iter().map(|r| { ClientRect::new( @@ -662,10 +647,10 @@ impl<'a> ElementMethods for JSRef<'a, Element> { } // http://dev.w3.org/csswg/cssom-view/#dom-element-getboundingclientrect - fn GetBoundingClientRect(&self, abstract_self: &JSRef) -> Unrooted { + fn GetBoundingClientRect(&self) -> Unrooted { let roots = RootCollection::new(); - let win = window_from_node(abstract_self).root(&roots); - let node: &JSRef = NodeCast::from_ref(abstract_self); + let win = window_from_node(self).root(&roots); + let node: &JSRef = NodeCast::from_ref(self); let rect = node.get_bounding_content_box(); ClientRect::new( &*win, @@ -675,21 +660,21 @@ impl<'a> ElementMethods for JSRef<'a, Element> { rect.origin.x + rect.size.width) } - fn GetInnerHTML(&self, abstract_self: &JSRef) -> Fallible { + fn GetInnerHTML(&self) -> Fallible { //XXX TODO: XML case let roots = RootCollection::new(); - Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(abstract_self), false, false))) + Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(self), false, false))) } - fn GetOuterHTML(&self, abstract_self: &JSRef) -> Fallible { + fn GetOuterHTML(&self) -> Fallible { let roots = RootCollection::new(); - Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(abstract_self), true, false))) + Ok(serialize(&mut NodeIterator::new(&roots, NodeCast::from_ref(self), true, false))) } - fn Children(&self, abstract_self: &JSRef) -> Unrooted { + fn Children(&self) -> Unrooted { let roots = RootCollection::new(); - let window = window_from_node(abstract_self).root(&roots); - HTMLCollection::children(&window.root_ref(), NodeCast::from_ref(abstract_self)) + let window = window_from_node(self).root(&roots); + HTMLCollection::children(&*window, NodeCast::from_ref(self)) } } diff --git a/src/components/script/dom/eventdispatcher.rs b/src/components/script/dom/eventdispatcher.rs index a70533da2a1..1e0097bbdc4 100644 --- a/src/components/script/dom/eventdispatcher.rs +++ b/src/components/script/dom/eventdispatcher.rs @@ -10,15 +10,18 @@ use dom::event::{Event, PhaseAtTarget, PhaseNone, PhaseBubbling, PhaseCapturing, use dom::node::{Node, NodeHelpers}; // See http://dom.spec.whatwg.org/#concept-event-dispatch for the full dispatch algorithm -pub fn dispatch_event<'a>(target: &JSRef<'a, EventTarget>, - pseudo_target: Option>, - event: &mut JSRef) -> bool { +pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>, + pseudo_target: Option>, + event: &mut JSRef) -> bool { let roots = RootCollection::new(); assert!(!event.get().dispatching); { let event = event.get_mut(); - event.target.assign(Some(pseudo_target.unwrap_or(target.clone()))); + match pseudo_target { + Some(pseudo_target) => event.target.assign(Some(pseudo_target)), + None => event.target.assign(Some(target.clone())), + } event.dispatching = true; } diff --git a/src/components/script/dom/eventtarget.rs b/src/components/script/dom/eventtarget.rs index d743a011227..9cd9c5484f2 100644 --- a/src/components/script/dom/eventtarget.rs +++ b/src/components/script/dom/eventtarget.rs @@ -64,15 +64,22 @@ impl EventTarget { filtered.map(|entry| entry.listener).collect() }) } +} - pub fn dispatch_event_with_target<'a>(&self, - abstract_self: &JSRef<'a, EventTarget>, - abstract_target: Option>, - event: &mut JSRef) -> Fallible { +pub trait EventTargetHelpers { + fn dispatch_event_with_target<'a>(&self, + target: Option>, + event: &mut JSRef) -> Fallible; +} + +impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> { + fn dispatch_event_with_target<'b>(&self, + target: Option>, + event: &mut JSRef) -> Fallible { if event.get().dispatching || !event.get().initialized { return Err(InvalidState); } - Ok(dispatch_event(abstract_self, abstract_target, event)) + Ok(dispatch_event(self, target, event)) } } @@ -85,8 +92,7 @@ pub trait EventTargetMethods { ty: DOMString, listener: Option, capture: bool); - fn DispatchEvent(&self, abstract_self: &JSRef, - event: &mut JSRef) -> Fallible; + fn DispatchEvent(&self, event: &mut JSRef) -> Fallible; } impl<'a> EventTargetMethods for JSRef<'a, EventTarget> { @@ -127,9 +133,8 @@ impl<'a> EventTargetMethods for JSRef<'a, EventTarget> { } } - fn DispatchEvent(&self, abstract_self: &JSRef, - event: &mut JSRef) -> Fallible { - self.dispatch_event_with_target(abstract_self, None, event) + fn DispatchEvent(&self, event: &mut JSRef) -> Fallible { + self.dispatch_event_with_target(None, event) } } diff --git a/src/components/script/dom/htmldatalistelement.rs b/src/components/script/dom/htmldatalistelement.rs index 9fcb291ae4f..ae5dbfbef9e 100644 --- a/src/components/script/dom/htmldatalistelement.rs +++ b/src/components/script/dom/htmldatalistelement.rs @@ -41,11 +41,11 @@ impl HTMLDataListElement { } pub trait HTMLDataListElementMethods { - fn Options(&self, abstract_self: &JSRef) -> Unrooted; + fn Options(&self) -> Unrooted; } impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> { - fn Options(&self, abstract_self: &JSRef) -> Unrooted { + fn Options(&self) -> Unrooted { struct HTMLDataListOptionsFilter; impl CollectionFilter for HTMLDataListOptionsFilter { fn filter(&self, elem: &JSRef, _root: &JSRef) -> bool { @@ -53,7 +53,7 @@ impl<'a> HTMLDataListElementMethods for JSRef<'a, HTMLDataListElement> { } } let roots = RootCollection::new(); - let node: &JSRef = NodeCast::from_ref(abstract_self); + let node: &JSRef = NodeCast::from_ref(self); let filter = ~HTMLDataListOptionsFilter; let window = window_from_node(node).root(&roots); HTMLCollection::create(&*window, node, filter) diff --git a/src/components/script/dom/htmlfieldsetelement.rs b/src/components/script/dom/htmlfieldsetelement.rs index 4f3d06d987c..ef42eb59990 100644 --- a/src/components/script/dom/htmlfieldsetelement.rs +++ b/src/components/script/dom/htmlfieldsetelement.rs @@ -50,7 +50,7 @@ pub trait HTMLFieldSetElementMethods { fn Name(&self) -> DOMString; fn SetName(&mut self, _name: DOMString) -> ErrorResult; fn Type(&self) -> DOMString; - fn Elements(&self, abstract_self: &JSRef) -> Unrooted; + fn Elements(&self) -> Unrooted; fn WillValidate(&self) -> bool; fn Validity(&self) -> Unrooted; fn ValidationMessage(&self) -> DOMString; @@ -84,7 +84,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { } // http://www.whatwg.org/html/#dom-fieldset-elements - fn Elements(&self, abstract_self: &JSRef) -> Unrooted { + fn Elements(&self) -> Unrooted { struct ElementsFilter; impl CollectionFilter for ElementsFilter { fn filter(&self, elem: &JSRef, root: &JSRef) -> bool { @@ -95,7 +95,7 @@ impl<'a> HTMLFieldSetElementMethods for JSRef<'a, HTMLFieldSetElement> { } } let roots = RootCollection::new(); - let node: &JSRef = NodeCast::from_ref(abstract_self); + let node: &JSRef = NodeCast::from_ref(self); let filter = ~ElementsFilter; let window = window_from_node(node).root(&roots); HTMLCollection::create(&*window, node, filter) diff --git a/src/components/script/dom/htmliframeelement.rs b/src/components/script/dom/htmliframeelement.rs index 316468342f1..ee675390183 100644 --- a/src/components/script/dom/htmliframeelement.rs +++ b/src/components/script/dom/htmliframeelement.rs @@ -87,8 +87,8 @@ pub trait HTMLIFrameElementMethods { fn SetSrcdoc(&mut self, _srcdoc: DOMString) -> ErrorResult; fn Name(&self) -> DOMString; fn SetName(&mut self, _name: DOMString) -> ErrorResult; - fn Sandbox(&self, abstract_self: &JSRef) -> DOMString; - fn SetSandbox(&mut self, abstract_self: &mut JSRef, sandbox: DOMString); + fn Sandbox(&self) -> DOMString; + fn SetSandbox(&mut self, sandbox: DOMString); fn AllowFullscreen(&self) -> bool; fn SetAllowFullscreen(&mut self, _allow: bool) -> ErrorResult; fn Width(&self) -> DOMString; @@ -137,13 +137,13 @@ impl<'a> HTMLIFrameElementMethods for JSRef<'a, HTMLIFrameElement> { Ok(()) } - fn Sandbox(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Sandbox(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("sandbox") } - fn SetSandbox(&mut self, abstract_self: &mut JSRef, sandbox: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetSandbox(&mut self, sandbox: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("sandbox", sandbox); } diff --git a/src/components/script/dom/htmlimageelement.rs b/src/components/script/dom/htmlimageelement.rs index efe6a0401d6..39c854c1c05 100644 --- a/src/components/script/dom/htmlimageelement.rs +++ b/src/components/script/dom/htmlimageelement.rs @@ -80,55 +80,55 @@ impl HTMLImageElement { } pub trait HTMLImageElementMethods { - fn Alt(&self, abstract_self: &JSRef) -> DOMString; - fn SetAlt(&mut self, abstract_self: &mut JSRef, alt: DOMString); - fn Src(&self, abstract_self: &JSRef) -> DOMString; - fn SetSrc(&mut self, abstract_self: &mut JSRef, src: DOMString); + fn Alt(&self) -> DOMString; + fn SetAlt(&mut self, alt: DOMString); + fn Src(&self) -> DOMString; + fn SetSrc(&mut self, src: DOMString); fn CrossOrigin(&self) -> DOMString; fn SetCrossOrigin(&mut self, _cross_origin: DOMString) -> ErrorResult; - fn UseMap(&self, abstract_self: &JSRef) -> DOMString; - fn SetUseMap(&mut self, abstract_self: &mut JSRef, use_map: DOMString); - fn IsMap(&self, abstract_self: &JSRef) -> bool; - fn SetIsMap(&self, abstract_self: &mut JSRef, is_map: bool); - fn Width(&self, abstract_self: &JSRef) -> u32; - fn SetWidth(&mut self, abstract_self: &mut JSRef, width: u32); - fn Height(&self, abstract_self: &JSRef) -> u32; - fn SetHeight(&mut self, abstract_self: &mut JSRef, height: u32); + fn UseMap(&self) -> DOMString; + fn SetUseMap(&mut self, use_map: DOMString); + fn IsMap(&self) -> bool; + fn SetIsMap(&mut self, is_map: bool); + fn Width(&self) -> u32; + fn SetWidth(&mut self, width: u32); + fn Height(&self) -> u32; + fn SetHeight(&mut self, height: u32); fn NaturalWidth(&self) -> u32; fn NaturalHeight(&self) -> u32; fn Complete(&self) -> bool; - fn Name(&self, abstract_self: &JSRef) -> DOMString; - fn SetName(&mut self, abstract_self: &mut JSRef, name: DOMString); - fn Align(&self, abstract_self: &JSRef) -> DOMString; - fn SetAlign(&mut self, abstract_self: &mut JSRef, align: DOMString); - fn Hspace(&self, abstract_self: &JSRef) -> u32; - fn SetHspace(&mut self, abstract_self: &mut JSRef, hspace: u32); - fn Vspace(&self, abstract_self: &JSRef) -> u32; - fn SetVspace(&mut self, abstract_self: &mut JSRef, vspace: u32); - fn LongDesc(&self, abstract_self: &JSRef) -> DOMString; - fn SetLongDesc(&mut self, abstract_self: &mut JSRef, longdesc: DOMString); - fn Border(&self, abstract_self: &JSRef) -> DOMString; - fn SetBorder(&mut self, abstract_self: &mut JSRef, border: DOMString); + fn Name(&self) -> DOMString; + fn SetName(&mut self, name: DOMString); + fn Align(&self) -> DOMString; + fn SetAlign(&mut self, align: DOMString); + fn Hspace(&self) -> u32; + fn SetHspace(&mut self, hspace: u32); + fn Vspace(&self) -> u32; + fn SetVspace(&mut self, vspace: u32); + fn LongDesc(&self) -> DOMString; + fn SetLongDesc(&mut self, longdesc: DOMString); + fn Border(&self) -> DOMString; + fn SetBorder(&mut self, border: DOMString); } impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { - fn Alt(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Alt(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("alt") } - fn SetAlt(&mut self, abstract_self: &mut JSRef, alt: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetAlt(&mut self, alt: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("alt", alt) } - fn Src(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Src(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("src") } - fn SetSrc(&mut self, abstract_self: &mut JSRef, src: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetSrc(&mut self, src: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_url_attribute("src", src) } @@ -140,45 +140,45 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { Ok(()) } - fn UseMap(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn UseMap(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("useMap") } - fn SetUseMap(&mut self, abstract_self: &mut JSRef, use_map: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetUseMap(&mut self, use_map: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("useMap", use_map) } - fn IsMap(&self, abstract_self: &JSRef) -> bool { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn IsMap(&self) -> bool { + let element: &JSRef = ElementCast::from_ref(self); from_str::(element.get_string_attribute("hspace")).unwrap() } - fn SetIsMap(&self, abstract_self: &mut JSRef, is_map: bool) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetIsMap(&mut self, is_map: bool) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("isMap", is_map.to_str()) } - fn Width(&self, abstract_self: &JSRef) -> u32 { - let node: &JSRef = NodeCast::from_ref(abstract_self); + fn Width(&self) -> u32 { + let node: &JSRef = NodeCast::from_ref(self); let rect = node.get_bounding_content_box(); to_px(rect.size.width) as u32 } - fn SetWidth(&mut self, abstract_self: &mut JSRef, width: u32) { - let elem: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetWidth(&mut self, width: u32) { + let elem: &mut JSRef = ElementCast::from_mut_ref(self); elem.set_uint_attribute("width", width) } - fn Height(&self, abstract_self: &JSRef) -> u32 { - let node: &JSRef = NodeCast::from_ref(abstract_self); + fn Height(&self) -> u32 { + let node: &JSRef = NodeCast::from_ref(self); let rect = node.get_bounding_content_box(); to_px(rect.size.height) as u32 } - fn SetHeight(&mut self, abstract_self: &mut JSRef, height: u32) { - let elem: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetHeight(&mut self, height: u32) { + let elem: &mut JSRef = ElementCast::from_mut_ref(self); elem.set_uint_attribute("height", height) } @@ -194,63 +194,63 @@ impl<'a> HTMLImageElementMethods for JSRef<'a, HTMLImageElement> { false } - fn Name(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Name(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("name") } - fn SetName(&mut self, abstract_self: &mut JSRef, name: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetName(&mut self, name: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("name", name) } - fn Align(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Align(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("longdesc") } - fn SetAlign(&mut self, abstract_self: &mut JSRef, align: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetAlign(&mut self, align: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("align", align) } - fn Hspace(&self, abstract_self: &JSRef) -> u32 { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Hspace(&self) -> u32 { + let element: &JSRef = ElementCast::from_ref(self); from_str::(element.get_string_attribute("hspace")).unwrap() } - fn SetHspace(&mut self, abstract_self: &mut JSRef, hspace: u32) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetHspace(&mut self, hspace: u32) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_uint_attribute("hspace", hspace) } - fn Vspace(&self, abstract_self: &JSRef) -> u32 { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Vspace(&self) -> u32 { + let element: &JSRef = ElementCast::from_ref(self); from_str::(element.get_string_attribute("vspace")).unwrap() } - fn SetVspace(&mut self, abstract_self: &mut JSRef, vspace: u32) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetVspace(&mut self, vspace: u32) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_uint_attribute("vspace", vspace) } - fn LongDesc(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn LongDesc(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("longdesc") } - fn SetLongDesc(&mut self, abstract_self: &mut JSRef, longdesc: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetLongDesc(&mut self, longdesc: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("longdesc", longdesc) } - fn Border(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Border(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_string_attribute("border") } - fn SetBorder(&mut self, abstract_self: &mut JSRef, border: DOMString) { - let element: &mut JSRef = ElementCast::from_mut_ref(abstract_self); + fn SetBorder(&mut self, border: DOMString) { + let element: &mut JSRef = ElementCast::from_mut_ref(self); element.set_string_attribute("border", border) } } diff --git a/src/components/script/dom/htmlscriptelement.rs b/src/components/script/dom/htmlscriptelement.rs index fabe876a10f..4d7780d49f7 100644 --- a/src/components/script/dom/htmlscriptelement.rs +++ b/src/components/script/dom/htmlscriptelement.rs @@ -42,8 +42,8 @@ impl HTMLScriptElement { } pub trait HTMLScriptElementMethods { - fn Src(&self, abstract_self: &JSRef) -> DOMString; - fn SetSrc(&mut self, _abstract_self: &JSRef, _src: DOMString) -> ErrorResult; + fn Src(&self) -> DOMString; + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult; fn Type(&self) -> DOMString; fn SetType(&mut self, _type: DOMString) -> ErrorResult; fn Charset(&self) -> DOMString; @@ -63,12 +63,12 @@ pub trait HTMLScriptElementMethods { } impl<'a> HTMLScriptElementMethods for JSRef<'a, HTMLScriptElement> { - fn Src(&self, abstract_self: &JSRef) -> DOMString { - let element: &JSRef = ElementCast::from_ref(abstract_self); + fn Src(&self) -> DOMString { + let element: &JSRef = ElementCast::from_ref(self); element.get_url_attribute("src") } - fn SetSrc(&mut self, _abstract_self: &JSRef, _src: DOMString) -> ErrorResult { + fn SetSrc(&mut self, _src: DOMString) -> ErrorResult { Ok(()) } diff --git a/src/components/script/dom/htmlstyleelement.rs b/src/components/script/dom/htmlstyleelement.rs index aac38920342..94255fe92a9 100644 --- a/src/components/script/dom/htmlstyleelement.rs +++ b/src/components/script/dom/htmlstyleelement.rs @@ -98,7 +98,7 @@ impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> { let win = window_from_node(node).root(&roots); let url = win.get().page().get_url(); - let data = node.GetTextContent(node).expect("Element.textContent must be a string"); + let data = node.GetTextContent().expect("Element.textContent must be a string"); let sheet = parse_inline_css(url, data); let LayoutChan(ref layout_chan) = *win.get().page().layout_chan; layout_chan.send(AddStylesheetMsg(sheet)); diff --git a/src/components/script/dom/node.rs b/src/components/script/dom/node.rs index f3aefd223cc..aa444865bdb 100644 --- a/src/components/script/dom/node.rs +++ b/src/components/script/dom/node.rs @@ -224,21 +224,6 @@ pub enum NodeTypeId { ProcessingInstructionNodeTypeId, } -pub fn AppendChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef) -> Fallible> { - let mut self_alias = self_.clone(); - self_.AppendChild(&mut self_alias, node) -} - -pub fn ReplaceChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef, child: &mut JSRef) -> Fallible> { - let mut self_alias = self_.clone(); - self_.ReplaceChild(&mut self_alias, node, child) -} - -pub fn RemoveChild<'a>(self_: &mut JSRef<'a, Node>, node: &mut JSRef) -> Fallible> { - let mut self_alias = self_.clone(); - self_.RemoveChild(&mut self_alias, node) -} - pub trait NodeHelpers { fn ancestors(&self) -> AncestorIterator; fn children(&self) -> AbstractNodeChildrenIterator; @@ -1386,30 +1371,30 @@ impl Node { pub trait NodeMethods { fn NodeType(&self) -> u16; - fn NodeName(&self, abstract_self: &JSRef) -> DOMString; + fn NodeName(&self) -> DOMString; fn GetBaseURI(&self) -> Option; fn GetOwnerDocument(&self) -> Option>; fn GetParentNode(&self) -> Option>; fn GetParentElement(&self) -> Option>; fn HasChildNodes(&self) -> bool; - fn ChildNodes(&mut self, abstract_self: &JSRef) -> Unrooted; + fn ChildNodes(&mut self) -> Unrooted; fn GetFirstChild(&self) -> Option>; fn GetLastChild(&self) -> Option>; fn GetPreviousSibling(&self) -> Option>; fn GetNextSibling(&self) -> Option>; - fn GetNodeValue(&self, abstract_self: &JSRef) -> Option; - fn SetNodeValue(&mut self, abstract_self: &mut JSRef, val: Option) -> ErrorResult; - fn GetTextContent(&self, abstract_self: &JSRef) -> Option; - fn SetTextContent(&mut self, abstract_self: &mut JSRef, value: Option) -> ErrorResult; - fn InsertBefore(&self, abstract_self: &mut JSRef, node: &mut JSRef, child: Option>) -> Fallible>; - fn AppendChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) -> Fallible>; - fn ReplaceChild(&self, parent: &mut JSRef, node: &mut JSRef, child: &mut JSRef) -> Fallible>; - fn RemoveChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) -> Fallible>; - fn Normalize(&mut self, abstract_self: &mut JSRef); - fn CloneNode(&self, abstract_self: &mut JSRef, deep: bool) -> Unrooted; - fn IsEqualNode(&self, abstract_self: &JSRef, maybe_node: Option>) -> bool; - fn CompareDocumentPosition(&self, abstract_self: &JSRef, other: &JSRef) -> u16; - fn Contains(&self, abstract_self: &JSRef, maybe_other: Option>) -> bool; + fn GetNodeValue(&self) -> Option; + fn SetNodeValue(&mut self, val: Option) -> ErrorResult; + fn GetTextContent(&self) -> Option; + fn SetTextContent(&mut self, value: Option) -> ErrorResult; + fn InsertBefore(&mut self, node: &mut JSRef, child: Option>) -> Fallible>; + fn AppendChild(&mut self, node: &mut JSRef) -> Fallible>; + fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible>; + fn RemoveChild(&mut self, node: &mut JSRef) -> Fallible>; + fn Normalize(&mut self); + fn CloneNode(&self, deep: bool) -> Unrooted; + fn IsEqualNode(&self, maybe_node: Option>) -> bool; + fn CompareDocumentPosition(&self, other: &JSRef) -> u16; + fn Contains(&self, maybe_other: Option>) -> bool; fn LookupPrefix(&self, _prefix: Option) -> Option; fn LookupNamespaceURI(&self, _namespace: Option) -> Option; fn IsDefaultNamespace(&self, _namespace: Option) -> bool; @@ -1430,21 +1415,21 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-nodename - fn NodeName(&self, abstract_self: &JSRef) -> DOMString { + fn NodeName(&self) -> DOMString { match self.type_id { ElementNodeTypeId(..) => { - let elem: &JSRef = ElementCast::to_ref(abstract_self).unwrap(); + let elem: &JSRef = ElementCast::to_ref(self).unwrap(); elem.TagName() } TextNodeTypeId => ~"#text", ProcessingInstructionNodeTypeId => { let processing_instruction: &JSRef = - ProcessingInstructionCast::to_ref(abstract_self).unwrap(); + ProcessingInstructionCast::to_ref(self).unwrap(); processing_instruction.Target() } CommentNodeTypeId => ~"#comment", DoctypeNodeTypeId => { - let doctype: &JSRef = DocumentTypeCast::to_ref(abstract_self).unwrap(); + let doctype: &JSRef = DocumentTypeCast::to_ref(self).unwrap(); doctype.get().name.clone() }, DocumentFragmentNodeTypeId => ~"#document-fragment", @@ -1494,7 +1479,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-childnodes - fn ChildNodes(&mut self, abstract_self: &JSRef) -> Unrooted { + fn ChildNodes(&mut self) -> Unrooted { let roots = RootCollection::new(); match self.child_list { None => (), @@ -1503,7 +1488,8 @@ impl<'a> NodeMethods for JSRef<'a, Node> { let doc = self.deref().owner_doc().root(&roots); let window = doc.deref().window.root(&roots); - self.child_list.assign(Some(NodeList::new_child_list(&*window, abstract_self))); + let child_list = NodeList::new_child_list(&*window, self); + self.child_list.assign(Some(child_list)); Unrooted::new(self.child_list.get_ref().clone()) } @@ -1528,12 +1514,12 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-nodevalue - fn GetNodeValue(&self, abstract_self: &JSRef) -> Option { + fn GetNodeValue(&self) -> Option { match self.type_id { CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { - let chardata: &JSRef = CharacterDataCast::to_ref(abstract_self).unwrap(); + let chardata: &JSRef = CharacterDataCast::to_ref(self).unwrap(); Some(chardata.Data()) } _ => { @@ -1543,26 +1529,26 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-nodevalue - fn SetNodeValue(&mut self, abstract_self: &mut JSRef, val: Option) + fn SetNodeValue(&mut self, val: Option) -> ErrorResult { match self.type_id { CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { - self.SetTextContent(abstract_self, val) + self.SetTextContent(val) } _ => Ok(()) } } // http://dom.spec.whatwg.org/#dom-node-textcontent - fn GetTextContent(&self, abstract_self: &JSRef) -> Option { + fn GetTextContent(&self) -> Option { let roots = RootCollection::new(); match self.type_id { DocumentFragmentNodeTypeId | ElementNodeTypeId(..) => { let mut content = ~""; - for node in abstract_self.traverse_preorder(&roots) { + for node in self.traverse_preorder(&roots) { if node.is_text() { let text: &JSRef = TextCast::to_ref(&node).unwrap(); content.push_str(text.get().characterdata.data.as_slice()); @@ -1573,7 +1559,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { - let characterdata: &JSRef = CharacterDataCast::to_ref(abstract_self).unwrap(); + let characterdata: &JSRef = CharacterDataCast::to_ref(self).unwrap(); Some(characterdata.Data()) } DoctypeNodeTypeId | @@ -1584,7 +1570,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-textcontent - fn SetTextContent(&mut self, abstract_self: &mut JSRef, value: Option) + fn SetTextContent(&mut self, value: Option) -> ErrorResult { let roots = RootCollection::new(); let value = null_str_as_empty(&value); @@ -1596,19 +1582,21 @@ impl<'a> NodeMethods for JSRef<'a, Node> { None } else { let document = self.owner_doc().root(&roots); - Some(NodeCast::from_unrooted(document.deref().CreateTextNode(&*document, value))) + Some(NodeCast::from_unrooted(document.deref().CreateTextNode(value))) }.root(&roots); // Step 3. - Node::replace_all(node.root_ref(), abstract_self); + Node::replace_all(node.root_ref(), self); } CommentNodeTypeId | TextNodeTypeId | ProcessingInstructionNodeTypeId => { self.wait_until_safe_to_modify_dom(); - let characterdata: &mut JSRef = CharacterDataCast::to_mut_ref(abstract_self).unwrap(); - characterdata.get_mut().data = value.clone(); + { + let characterdata: &mut JSRef = CharacterDataCast::to_mut_ref(self).unwrap(); + characterdata.get_mut().data = value.clone(); + } // Notify the document that the content of this node is different let document = self.owner_doc().root(&roots); @@ -1621,24 +1609,21 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-insertbefore - fn InsertBefore(&self, abstract_self: &mut JSRef, node: &mut JSRef, child: Option>) - -> Fallible> { - Node::pre_insert(node, abstract_self, child) + fn InsertBefore(&mut self, node: &mut JSRef, child: Option>) -> Fallible> { + Node::pre_insert(node, self, child) } // http://dom.spec.whatwg.org/#dom-node-appendchild - fn AppendChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) - -> Fallible> { - Node::pre_insert(node, abstract_self, None) + fn AppendChild(&mut self, node: &mut JSRef) -> Fallible> { + Node::pre_insert(node, self, None) } // http://dom.spec.whatwg.org/#concept-node-replace - fn ReplaceChild(&self, parent: &mut JSRef, node: &mut JSRef, child: &mut JSRef) - -> Fallible> { + fn ReplaceChild(&mut self, node: &mut JSRef, child: &mut JSRef) -> Fallible> { let roots = RootCollection::new(); // Step 1. - match parent.type_id() { + match self.type_id() { DocumentNodeTypeId | DocumentFragmentNodeTypeId | ElementNodeTypeId(..) => (), @@ -1646,19 +1631,19 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // Step 2. - if node.is_inclusive_ancestor_of(parent) { + if node.is_inclusive_ancestor_of(self) { return Err(HierarchyRequest); } // Step 3. - if !parent.is_parent_of(child) { + if !self.is_parent_of(child) { return Err(NotFound); } // Step 4-5. match node.type_id() { - TextNodeTypeId if parent.is_document() => return Err(HierarchyRequest), - DoctypeNodeTypeId if !parent.is_document() => return Err(HierarchyRequest), + TextNodeTypeId if self.is_document() => return Err(HierarchyRequest), + DoctypeNodeTypeId if !self.is_document() => return Err(HierarchyRequest), DocumentFragmentNodeTypeId | DoctypeNodeTypeId | ElementNodeTypeId(..) | @@ -1669,7 +1654,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // Step 6. - match parent.type_id() { + match self.type_id() { DocumentNodeTypeId => { match node.type_id() { // Step 6.1 @@ -1682,7 +1667,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { 0 => (), // Step 6.1.2 1 => { - if parent.child_elements().any(|c| NodeCast::from_ref(&c) != child) { + if self.child_elements().any(|c| NodeCast::from_ref(&c) != child) { return Err(HierarchyRequest); } if child.following_siblings() @@ -1696,7 +1681,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { }, // Step 6.2 ElementNodeTypeId(..) => { - if parent.child_elements().any(|c| NodeCast::from_ref(&c) != child) { + if self.child_elements().any(|c| NodeCast::from_ref(&c) != child) { return Err(HierarchyRequest); } if child.following_siblings() @@ -1706,10 +1691,10 @@ impl<'a> NodeMethods for JSRef<'a, Node> { }, // Step 6.3 DoctypeNodeTypeId => { - if parent.children().any(|c| c.deref().is_doctype() && &c != child) { + if self.children().any(|c| c.deref().is_doctype() && &c != child) { return Err(HierarchyRequest); } - if parent.children() + if self.children() .take_while(|c| c != child) .any(|c| c.deref().is_element()) { return Err(HierarchyRequest); @@ -1737,15 +1722,15 @@ impl<'a> NodeMethods for JSRef<'a, Node> { }; // Step 9. - let document = document_from_node(parent).root(&roots); + let document = document_from_node(self).root(&roots); Node::adopt(node, &*document); { // Step 10. - Node::remove(child, parent, Suppressed); + Node::remove(child, self, Suppressed); // Step 11. - Node::insert(node, parent, reference_child, Suppressed); + Node::insert(node, self, reference_child, Suppressed); } // Step 12-14. @@ -1764,13 +1749,13 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-removechild - fn RemoveChild(&self, abstract_self: &mut JSRef, node: &mut JSRef) + fn RemoveChild(&mut self, node: &mut JSRef) -> Fallible> { - Node::pre_remove(node, abstract_self) + Node::pre_remove(node, self) } // http://dom.spec.whatwg.org/#dom-node-normalize - fn Normalize(&mut self, abstract_self: &mut JSRef) { + fn Normalize(&mut self) { let roots = RootCollection::new(); let mut prev_text = None; for mut child in self.children() { @@ -1778,20 +1763,19 @@ impl<'a> NodeMethods for JSRef<'a, Node> { let mut child_alias = child.clone(); let characterdata: &JSRef = CharacterDataCast::to_ref(&child).unwrap(); if characterdata.Length() == 0 { - abstract_self.remove_child(&mut child_alias); + self.remove_child(&mut child_alias); } else { match prev_text { Some(ref mut text_node) => { let prev_characterdata: &mut JSRef = CharacterDataCast::to_mut_ref(text_node).unwrap(); let _ = prev_characterdata.AppendData(characterdata.Data()); - abstract_self.remove_child(&mut child_alias); + self.remove_child(&mut child_alias); }, None => prev_text = Some(child_alias) } } } else { - let mut c = child.clone(); - child.Normalize(&mut c); + child.Normalize(); prev_text = None; } @@ -1799,15 +1783,15 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-clonenode - fn CloneNode(&self, abstract_self: &mut JSRef, deep: bool) -> Unrooted { + fn CloneNode(&self, deep: bool) -> Unrooted { match deep { - true => Node::clone(abstract_self, None, CloneChildren), - false => Node::clone(abstract_self, None, DoNotCloneChildren) + true => Node::clone(self, None, CloneChildren), + false => Node::clone(self, None, DoNotCloneChildren) } } // http://dom.spec.whatwg.org/#dom-node-isequalnode - fn IsEqualNode(&self, abstract_self: &JSRef, maybe_node: Option>) -> bool { + fn IsEqualNode(&self, maybe_node: Option>) -> bool { fn is_equal_doctype(node: &JSRef, other: &JSRef) -> bool { let doctype: &JSRef = DocumentTypeCast::to_ref(node).unwrap(); let other_doctype: &JSRef = DocumentTypeCast::to_ref(other).unwrap(); @@ -1879,20 +1863,20 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // Step 1. None => false, // Step 2-6. - Some(ref node) => is_equal_node(abstract_self, node) + Some(ref node) => is_equal_node(self, node) } } // http://dom.spec.whatwg.org/#dom-node-comparedocumentposition - fn CompareDocumentPosition(&self, abstract_self: &JSRef, other: &JSRef) -> u16 { + fn CompareDocumentPosition(&self, other: &JSRef) -> u16 { let roots = RootCollection::new(); - if abstract_self == other { + if self == other { // step 2. 0 } else { - let mut lastself = abstract_self.clone(); + let mut lastself = self.clone(); let mut lastother = other.clone(); - for ancestor in abstract_self.ancestors() { + for ancestor in self.ancestors() { if &ancestor == other { // step 4. return NodeConstants::DOCUMENT_POSITION_CONTAINS + @@ -1901,7 +1885,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { lastself = ancestor.clone(); } for ancestor in other.ancestors() { - if &ancestor == abstract_self { + if &ancestor == self { // step 5. return NodeConstants::DOCUMENT_POSITION_CONTAINED_BY + NodeConstants::DOCUMENT_POSITION_FOLLOWING; @@ -1910,7 +1894,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } if lastself != lastother { - let abstract_uint: uintptr_t = as_uintptr(&*abstract_self); + let abstract_uint: uintptr_t = as_uintptr(&*self); let other_uint: uintptr_t = as_uintptr(&*other); let random = if abstract_uint < other_uint { @@ -1929,7 +1913,7 @@ impl<'a> NodeMethods for JSRef<'a, Node> { // step 6. return NodeConstants::DOCUMENT_POSITION_PRECEDING; } - if &child == abstract_self { + if &child == self { // step 7. return NodeConstants::DOCUMENT_POSITION_FOLLOWING; } @@ -1939,10 +1923,10 @@ impl<'a> NodeMethods for JSRef<'a, Node> { } // http://dom.spec.whatwg.org/#dom-node-contains - fn Contains(&self, abstract_self: &JSRef, maybe_other: Option>) -> bool { + fn Contains(&self, maybe_other: Option>) -> bool { match maybe_other { None => false, - Some(ref other) => abstract_self.is_inclusive_ancestor_of(other) + Some(ref other) => self.is_inclusive_ancestor_of(other) } } diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index dda1a0fa295..04108330cb8 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -118,9 +118,9 @@ pub trait WindowMethods { fn Focus(&self); fn Blur(&self); fn GetFrameElement(&self) -> Option>; - fn Location(&mut self, abstract_self: &JSRef) -> Unrooted; - fn Console(&mut self, abstract_self: &JSRef) -> Unrooted; - fn Navigator(&mut self, abstract_self: &JSRef) -> Unrooted; + fn Location(&mut self) -> Unrooted; + fn Console(&mut self) -> Unrooted; + fn Navigator(&mut self) -> Unrooted; fn Confirm(&self, _message: DOMString) -> bool; fn Prompt(&self, _message: DOMString, _default: DOMString) -> Option; fn Print(&self); @@ -129,8 +129,8 @@ pub trait WindowMethods { fn ClearTimeout(&mut self, handle: i32); fn SetInterval(&mut self, _cx: *JSContext, callback: JSVal, timeout: i32) -> i32; fn ClearInterval(&mut self, handle: i32); - fn Window(&self, abstract_self: &JSRef) -> Unrooted; - fn Self(&self, abstract_self: &JSRef) -> Unrooted; + fn Window(&self) -> Unrooted; + fn Self(&self) -> Unrooted; } impl<'a> WindowMethods for JSRef<'a, Window> { @@ -180,24 +180,27 @@ impl<'a> WindowMethods for JSRef<'a, Window> { None } - fn Location(&mut self, abstract_self: &JSRef) -> Unrooted { + fn Location(&mut self) -> Unrooted { if self.location.is_none() { let page = self.deref().page.clone(); - self.location.assign(Some(Location::new(abstract_self, page))); + let location = Location::new(self, page); + self.location.assign(Some(location)); } Unrooted::new(self.location.get_ref().clone()) } - fn Console(&mut self, abstract_self: &JSRef) -> Unrooted { + fn Console(&mut self) -> Unrooted { if self.console.is_none() { - self.console.assign(Some(Console::new(abstract_self))); + let console = Console::new(self); + self.console.assign(Some(console)); } Unrooted::new(self.console.get_ref().clone()) } - fn Navigator(&mut self, abstract_self: &JSRef) -> Unrooted { + fn Navigator(&mut self) -> Unrooted { if self.navigator.is_none() { - self.navigator.assign(Some(Navigator::new(abstract_self))); + let navigator = Navigator::new(self); + self.navigator.assign(Some(navigator)); } Unrooted::new(self.navigator.get_ref().clone()) } @@ -238,12 +241,12 @@ impl<'a> WindowMethods for JSRef<'a, Window> { self.ClearTimeout(handle); } - fn Window(&self, abstract_self: &JSRef) -> Unrooted { - Unrooted::new_rooted(abstract_self) + fn Window(&self) -> Unrooted { + Unrooted::new_rooted(self) } - fn Self(&self, abstract_self: &JSRef) -> Unrooted { - self.Window(abstract_self) + fn Self(&self) -> Unrooted { + self.Window() } } diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 0121b023783..f9a4f641ffc 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -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, Unrooted, OptionalRootable}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable, Root}; use dom::bindings::utils::Reflectable; use dom::document::Document; use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId}; @@ -13,7 +13,7 @@ use dom::htmlelement::HTMLElement; use dom::htmlheadingelement::{Heading1, Heading2, Heading3, Heading4, Heading5, Heading6}; use dom::htmliframeelement::IFrameSize; use dom::htmlformelement::HTMLFormElement; -use dom::node::{ElementNodeTypeId, NodeHelpers, AppendChild}; +use dom::node::{ElementNodeTypeId, NodeHelpers, NodeMethods}; use dom::types::*; use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser}; use script_task::Page; @@ -422,8 +422,8 @@ pub fn parse_html(page: &Page, unsafe { debug!("append child {:x} {:x}", parent, child); let mut child = from_hubbub_node(child, Some(&roots)).root(&roots); - let mut parent = from_hubbub_node(parent, None).root(&roots); - assert!(AppendChild(&mut *parent, &mut *child).is_ok()); + let mut parent: Root = from_hubbub_node(parent, None).root(&roots); + assert!(parent.AppendChild(&mut *child).is_ok()); } child }, diff --git a/src/components/script/script_task.rs b/src/components/script/script_task.rs index df7e6f2b994..600f28794a1 100644 --- a/src/components/script/script_task.rs +++ b/src/components/script/script_task.rs @@ -17,7 +17,7 @@ use dom::element::{Element, AttributeHandlers}; use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent}; use dom::event::{Event, EventMethods}; use dom::uievent::{UIEvent, UIEventMethods}; -use dom::eventtarget::EventTarget; +use dom::eventtarget::{EventTarget, EventTargetHelpers}; use dom::node; use dom::node::{Node, NodeHelpers}; use dom::window::{TimerId, Window}; @@ -988,11 +988,9 @@ impl ScriptTask { let mut event = Event::new(&*window).root(&roots); event.InitEvent(~"load", false, false); let doctarget: &JSRef = EventTargetCast::from_ref(&*document); - let wintarget: &mut JSRef = EventTargetCast::from_mut_ref(&mut *window); - let wintarget_alias = wintarget.clone(); - let _ = wintarget.get_mut().dispatch_event_with_target(&wintarget_alias, - Some((*doctarget).clone()), - &mut *event); + let wintarget: &JSRef = EventTargetCast::from_ref(&*window); + let _ = wintarget.dispatch_event_with_target(Some((*doctarget).clone()), + &mut *event); let mut fragment_node = page.fragment_node.deref().borrow_mut(); (*fragment_node).assign(fragment.map_or(None, |fragid| page.find_fragment_node(fragid))); @@ -1061,10 +1059,7 @@ impl ScriptTask { let event: &mut JSRef = EventCast::from_mut_ref(&mut *uievent); let wintarget: &mut JSRef = EventTargetCast::from_mut_ref(&mut *window); - let wintarget_alias = wintarget.clone(); - let _ = wintarget.get_mut().dispatch_event_with_target(&wintarget_alias, - None, - &mut *event); + let _ = wintarget.dispatch_event_with_target(None, &mut *event); } None => () }