From ffdc3f5b32a345b88eed774848924e862d47c093 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Fri, 28 Mar 2014 10:17:56 -0400 Subject: Turn on GC all the time. Fix rooting errors during parsing and storing timers. Fix borrow errors during tracing. --- src/components/script/html/hubbub_html_parser.rs | 43 ++++++++++++++---------- 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'src/components/script/html') diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 18945f9062a..771b75f3e9c 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; -use dom::bindings::js::JS; +use dom::bindings::js::{JS, JSRef, RootCollection}; use dom::bindings::utils::Reflectable; use dom::document::Document; use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId}; @@ -75,16 +75,19 @@ pub struct HtmlParserResult { } trait NodeWrapping { - unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr; - unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr) -> Self; + unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr; + unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, roots: Option<&RootCollection>) -> Self; } impl NodeWrapping for JS { - unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr { + unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr { + roots.root_raw(self.reflector().get_jsobject()); cast::transmute(self.get()) } - unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr) -> JS { - JS::from_raw(cast::transmute(n)) + unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, roots: Option<&RootCollection>) -> JS { + let js = JS::from_raw(cast::transmute(n)); + let _ = roots.map(|roots| roots.unroot_raw(js.reflector().get_jsobject())); + js } } @@ -160,7 +163,7 @@ fn js_script_listener(to_parent: Sender, // Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized // via atomization (issue #85). -pub fn build_element_from_tag(tag: DOMString, document: &JS) -> JS { +pub fn build_element_from_tag(tag: DOMString, document: &JSRef) -> JS { // TODO (Issue #85): use atoms handle_element!(document, tag, "a", HTMLAnchorElement); handle_element!(document, tag, "applet", HTMLAppletElement); @@ -246,7 +249,7 @@ pub fn build_element_from_tag(tag: DOMString, document: &JS) -> JS, + document: &mut JSRef, url: Url, resource_task: ResourceTask) -> HtmlParserResult { @@ -292,7 +295,9 @@ pub fn parse_html(page: &Page, let mut parser = hubbub::Parser("UTF-8", false); debug!("created parser"); - parser.set_document_node(unsafe { document.to_hubbub_node() }); + let roots = RootCollection::new(); + + parser.set_document_node(unsafe { document.unrooted().to_hubbub_node(&roots) }); parser.enable_scripting(true); parser.enable_styling(true); @@ -309,7 +314,7 @@ pub fn parse_html(page: &Page, let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; let comment: JS = NodeCast::from(&Comment::new(data, *tmp)); - unsafe { comment.to_hubbub_node() } + unsafe { comment.to_hubbub_node(&roots) } }, create_doctype: |doctype: ~hubbub::Doctype| { debug!("create doctype"); @@ -322,15 +327,16 @@ pub fn parse_html(page: &Page, let tmp = &*tmp_borrow; let doctype_node = DocumentType::new(name, public_id, system_id, *tmp); unsafe { - doctype_node.to_hubbub_node() + doctype_node.to_hubbub_node(&roots) } }, create_element: |tag: ~hubbub::Tag| { - debug!("create element"); + debug!("create element {:?}", tag.name.clone()); // 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); + let _element_root = element.root(&roots); debug!("-- attach attrs"); for attr in tag.attributes.iter() { @@ -389,7 +395,7 @@ pub fn parse_html(page: &Page, _ => {} } - unsafe { element.to_hubbub_node() } + unsafe { element.to_hubbub_node(&roots) } }, create_text: |data: ~str| { debug!("create text"); @@ -397,16 +403,17 @@ pub fn parse_html(page: &Page, let tmp_borrow = doc_cell.borrow(); let tmp = &*tmp_borrow; let text = Text::new(data, *tmp); - unsafe { text.to_hubbub_node() } + unsafe { text.to_hubbub_node(&roots) } }, ref_node: |_| {}, unref_node: |_| {}, append_child: |parent: hubbub::NodeDataPtr, child: hubbub::NodeDataPtr| { unsafe { debug!("append child {:x} {:x}", parent, child); - let mut parent: JS = NodeWrapping::from_hubbub_node(parent); - let mut child: JS = NodeWrapping::from_hubbub_node(child); - assert!(parent.AppendChild(&mut child).is_ok()); + let mut parent: JS = NodeWrapping::from_hubbub_node(parent, None); + let child: JS = NodeWrapping::from_hubbub_node(child, Some(&roots)); + let child = child.root(&roots); + assert!(parent.AppendChild(&mut child.root_ref()).is_ok()); } child }, @@ -457,7 +464,7 @@ pub fn parse_html(page: &Page, }, complete_script: |script| { unsafe { - let script: JS = NodeWrapping::from_hubbub_node(script); + let script: JS = NodeWrapping::from_hubbub_node(script, None); match script.get_attribute(Null, "src") { Some(src) => { debug!("found script: {:s}", src.get().Value()); -- cgit v1.2.3 From d7b96db33ca8f2b8a162df38e0f00e95f5ea6fa1 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 31 Mar 2014 18:41:28 -0400 Subject: Implement safe rooting strategy via Unrooted, Root, JSRef, and JS. --- src/components/script/html/hubbub_html_parser.rs | 91 +++++++++++++----------- 1 file changed, 50 insertions(+), 41 deletions(-) (limited to 'src/components/script/html') diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 771b75f3e9c..a90a696063c 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -4,7 +4,7 @@ use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; -use dom::bindings::js::{JS, JSRef, RootCollection}; +use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable}; use dom::bindings::utils::Reflectable; use dom::document::Document; use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId}; @@ -12,7 +12,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, INode, NodeHelpers}; +use dom::node::{ElementNodeTypeId, NodeHelpers, AppendChild}; use dom::types::*; use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser}; use script_task::Page; @@ -39,7 +39,7 @@ macro_rules! handle_element( $ctor: ident $(, $arg:expr )*) => ( if $string == $localName { - return ElementCast::from(&$ctor::new($localName, $document $(, $arg)*)); + return ElementCast::from_unrooted($ctor::new($localName, $document $(, $arg)*)); } ) ) @@ -74,21 +74,22 @@ pub struct HtmlParserResult { pub discovery_port: Receiver, } -trait NodeWrapping { +trait NodeWrapping { unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr; - unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, roots: Option<&RootCollection>) -> Self; } -impl NodeWrapping for JS { +impl<'a, T: NodeBase+Reflectable> NodeWrapping for JSRef<'a, T> { unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr { roots.root_raw(self.reflector().get_jsobject()); cast::transmute(self.get()) } - unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, roots: Option<&RootCollection>) -> JS { - let js = JS::from_raw(cast::transmute(n)); - let _ = roots.map(|roots| roots.unroot_raw(js.reflector().get_jsobject())); - js - } +} + +unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, + roots: Option<&RootCollection>) -> Unrooted { + let js = JS::from_raw(cast::transmute(n)); + let _ = roots.map(|roots| roots.unroot_raw(js.reflector().get_jsobject())); + Unrooted::new(js) } /** @@ -163,7 +164,7 @@ fn js_script_listener(to_parent: Sender, // Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized // via atomization (issue #85). -pub fn build_element_from_tag(tag: DOMString, document: &JSRef) -> JS { +pub fn build_element_from_tag(tag: DOMString, document: &JSRef) -> Unrooted { // TODO (Issue #85): use atoms handle_element!(document, tag, "a", HTMLAnchorElement); handle_element!(document, tag, "applet", HTMLAppletElement); @@ -245,7 +246,7 @@ pub fn build_element_from_tag(tag: DOMString, document: &JSRef) -> JS< handle_element!(document, tag, "ul", HTMLUListElement); handle_element!(document, tag, "video", HTMLVideoElement); - return ElementCast::from(&HTMLUnknownElement::new(tag, document)); + return ElementCast::from_unrooted(HTMLUnknownElement::new(tag, document)); } pub fn parse_html(page: &Page, @@ -297,7 +298,7 @@ pub fn parse_html(page: &Page, let roots = RootCollection::new(); - parser.set_document_node(unsafe { document.unrooted().to_hubbub_node(&roots) }); + parser.set_document_node(unsafe { document.to_hubbub_node(&roots) }); parser.enable_scripting(true); parser.enable_styling(true); @@ -313,7 +314,8 @@ 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: JS = NodeCast::from(&Comment::new(data, *tmp)); + let comment = Comment::new(data, *tmp).root(&roots); + let comment: &JSRef = NodeCast::from_ref(&*comment); unsafe { comment.to_hubbub_node(&roots) } }, create_doctype: |doctype: ~hubbub::Doctype| { @@ -325,9 +327,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); + let doctype_node = DocumentType::new(name, public_id, system_id, *tmp).root(&roots); unsafe { - doctype_node.to_hubbub_node(&roots) + doctype_node.deref().to_hubbub_node(&roots) } }, create_element: |tag: ~hubbub::Tag| { @@ -335,8 +337,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); - let _element_root = element.root(&roots); + let mut element = build_element_from_tag(tag.name.clone(), *tmp).root(&roots); debug!("-- attach attrs"); for attr in tag.attributes.iter() { @@ -346,21 +347,32 @@ pub fn parse_html(page: &Page, attr.value.clone()).is_ok()); } + //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); + rel.map(|a| a.deref().Value()) + }; + let href = { + let href= element.get_attribute(Null, "href").root(&roots); + href.map(|a| a.deref().Value()) + }; + let src_opt = { + let src_opt = element.get_attribute(Null, "src").root(&roots); + src_opt.map(|a| a.deref().Value()) + }; + // Spawn additional parsing, network loads, etc. from tag and attrs match element.get().node.type_id { // Handle CSS style sheets from elements ElementNodeTypeId(HTMLLinkElementTypeId) => { - match (element.get_attribute(Null, "rel"), - element.get_attribute(Null, "href")) { - (Some(ref rel), Some(ref href)) if rel.get() - .value_ref() - .split(HTML_SPACE_CHARACTERS. - as_slice()) + match (rel, href) { + (Some(ref rel), Some(ref href)) if rel.split(HTML_SPACE_CHARACTERS.as_slice()) .any(|s| { s.eq_ignore_ascii_case("stylesheet") }) => { - debug!("found CSS stylesheet: {:s}", href.get().value_ref()); - let url = parse_url(href.get().value_ref(), Some(url2.clone())); + debug!("found CSS stylesheet: {:s}", *href); + let url = parse_url(href.as_slice(), Some(url2.clone())); css_chan2.send(CSSTaskNewFile(UrlProvenance(url, resource_task.clone()))); } _ => {} @@ -369,11 +381,9 @@ pub fn parse_html(page: &Page, ElementNodeTypeId(HTMLIFrameElementTypeId) => { let iframe_chan = discovery_chan.clone(); - let mut iframe_element: JS = - HTMLIFrameElementCast::to(&element).unwrap(); + let iframe_element: &mut JSRef = + HTMLIFrameElementCast::to_mut_ref(&mut *element).unwrap(); let sandboxed = iframe_element.get().is_sandboxed(); - let elem: JS = ElementCast::from(&iframe_element); - let src_opt = elem.get_attribute(Null, "src").map(|x| x.get().Value()); for src in src_opt.iter() { let iframe_url = parse_url(*src, Some(url2.clone())); iframe_element.get_mut().set_frame(iframe_url.clone()); @@ -402,18 +412,17 @@ 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 text = Text::new(data, *tmp); - unsafe { text.to_hubbub_node(&roots) } + let text = Text::new(data, *tmp).root(&roots); + unsafe { text.deref().to_hubbub_node(&roots) } }, ref_node: |_| {}, unref_node: |_| {}, append_child: |parent: hubbub::NodeDataPtr, child: hubbub::NodeDataPtr| { unsafe { debug!("append child {:x} {:x}", parent, child); - let mut parent: JS = NodeWrapping::from_hubbub_node(parent, None); - let child: JS = NodeWrapping::from_hubbub_node(child, Some(&roots)); - let child = child.root(&roots); - assert!(parent.AppendChild(&mut child.root_ref()).is_ok()); + 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()); } child }, @@ -464,8 +473,8 @@ pub fn parse_html(page: &Page, }, complete_script: |script| { unsafe { - let script: JS = NodeWrapping::from_hubbub_node(script, None); - match script.get_attribute(Null, "src") { + let script: &JSRef = &*from_hubbub_node(script, None).root(&roots); + match script.get_attribute(Null, "src").root(&roots) { Some(src) => { debug!("found script: {:s}", src.get().Value()); let new_url = parse_url(src.get().value_ref(), Some(url3.clone())); @@ -473,11 +482,11 @@ pub fn parse_html(page: &Page, } None => { let mut data = vec!(); - let scriptnode: JS = NodeCast::from(&script); + let scriptnode: &JSRef = NodeCast::from_ref(script); debug!("iterating over children {:?}", scriptnode.first_child()); for child in scriptnode.children() { debug!("child = {:?}", child); - let text: JS = TextCast::to(&child).unwrap(); + let text: &JSRef = TextCast::to_ref(&child).unwrap(); data.push(text.get().characterdata.data.to_str()); // FIXME: Bad copy. } -- cgit v1.2.3 From 76783b029e5e10da7fd61ab356a8f80a1eaf32e0 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 10 Apr 2014 21:29:54 -0400 Subject: Move WebIDL methods to traits implemented by JSRef types. --- src/components/script/html/hubbub_html_parser.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/components/script/html') diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index a90a696063c..0121b023783 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -2,6 +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::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}; @@ -476,7 +477,7 @@ pub fn parse_html(page: &Page, let script: &JSRef = &*from_hubbub_node(script, None).root(&roots); match script.get_attribute(Null, "src").root(&roots) { Some(src) => { - debug!("found script: {:s}", src.get().Value()); + debug!("found script: {:s}", src.deref().Value()); let new_url = parse_url(src.get().value_ref(), Some(url3.clone())); js_chan2.send(JSTaskNewFile(new_url)); } -- cgit v1.2.3 From 7daa97c7e5de3dac14b4d1c8a923448b025e3c09 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 10 Apr 2014 22:13:08 -0400 Subject: Remove abstract_self. --- src/components/script/html/hubbub_html_parser.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/components/script/html') 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 }, -- cgit v1.2.3 From 109410900c75721a77b970be3bdd830968e47151 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Fri, 11 Apr 2014 14:46:34 -0400 Subject: Move all methods on T to JSRef or JS as appropriate. --- src/components/script/html/hubbub_html_parser.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/components/script/html') diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index f9a4f641ffc..9326ed6cb15 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -7,11 +7,11 @@ use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, TextCast, Element use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast; use dom::bindings::js::{JS, JSRef, RootCollection, Unrooted, OptionalRootable, Root}; use dom::bindings::utils::Reflectable; -use dom::document::Document; +use dom::document::{Document, DocumentHelpers}; use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId}; use dom::htmlelement::HTMLElement; use dom::htmlheadingelement::{Heading1, Heading2, Heading3, Heading4, Heading5, Heading6}; -use dom::htmliframeelement::IFrameSize; +use dom::htmliframeelement::{IFrameSize, HTMLIFrameElementHelpers}; use dom::htmlformelement::HTMLFormElement; use dom::node::{ElementNodeTypeId, NodeHelpers, NodeMethods}; use dom::types::*; @@ -364,7 +364,11 @@ pub fn parse_html(page: &Page, }; // Spawn additional parsing, network loads, etc. from tag and attrs - match element.get().node.type_id { + let type_id = { + let node: &JSRef = NodeCast::from_ref(&*element); + node.type_id() + }; + match type_id { // Handle CSS style sheets from elements ElementNodeTypeId(HTMLLinkElementTypeId) => { match (rel, href) { @@ -384,10 +388,10 @@ pub fn parse_html(page: &Page, let iframe_chan = discovery_chan.clone(); let iframe_element: &mut JSRef = HTMLIFrameElementCast::to_mut_ref(&mut *element).unwrap(); - let sandboxed = iframe_element.get().is_sandboxed(); + let sandboxed = iframe_element.is_sandboxed(); for src in src_opt.iter() { let iframe_url = parse_url(*src, Some(url2.clone())); - iframe_element.get_mut().set_frame(iframe_url.clone()); + iframe_element.set_frame(iframe_url.clone()); // Subpage Id let subpage_id = *next_subpage_id.borrow(); @@ -463,14 +467,14 @@ pub fn parse_html(page: &Page, // NOTE: tmp vars are workaround for lifetime issues. Both required. let mut tmp_borrow = doc_cell.borrow_mut(); let tmp = &mut *tmp_borrow; - tmp.get_mut().set_quirks_mode(mode); + tmp.set_quirks_mode(mode); }, encoding_change: |encname| { debug!("encoding change"); // NOTE: tmp vars are workaround for lifetime issues. Both required. let mut tmp_borrow = doc_cell.borrow_mut(); let tmp = &mut *tmp_borrow; - tmp.get_mut().set_encoding_name(encname); + tmp.set_encoding_name(encname); }, complete_script: |script| { unsafe { -- cgit v1.2.3 From 522d3f167b12fa79401eea5525c7b6133cae0f06 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 17 Apr 2014 17:08:00 -0400 Subject: s/Unrooted/Temporary/g --- src/components/script/html/hubbub_html_parser.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/components/script/html') diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 9326ed6cb15..a0490c1621f 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, Root}; +use dom::bindings::js::{JS, JSRef, RootCollection, Temporary, OptionalRootable, Root}; use dom::bindings::utils::Reflectable; use dom::document::{Document, DocumentHelpers}; use dom::element::{AttributeHandlers, HTMLLinkElementTypeId, HTMLIFrameElementTypeId}; @@ -87,10 +87,10 @@ impl<'a, T: NodeBase+Reflectable> NodeWrapping for JSRef<'a, T> { } unsafe fn from_hubbub_node(n: hubbub::NodeDataPtr, - roots: Option<&RootCollection>) -> Unrooted { + roots: Option<&RootCollection>) -> Temporary { let js = JS::from_raw(cast::transmute(n)); let _ = roots.map(|roots| roots.unroot_raw(js.reflector().get_jsobject())); - Unrooted::new(js) + Temporary::new(js) } /** @@ -165,7 +165,7 @@ fn js_script_listener(to_parent: Sender, // Silly macros to handle constructing DOM nodes. This produces bad code and should be optimized // via atomization (issue #85). -pub fn build_element_from_tag(tag: DOMString, document: &JSRef) -> Unrooted { +pub fn build_element_from_tag(tag: DOMString, document: &JSRef) -> Temporary { // TODO (Issue #85): use atoms handle_element!(document, tag, "a", HTMLAnchorElement); handle_element!(document, tag, "applet", HTMLAppletElement); -- cgit v1.2.3 From 7b3e6d1f2125faf598919722b72cc56197d0102c Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 17 Apr 2014 23:26:42 -0400 Subject: Remove all root collections. --- src/components/script/html/hubbub_html_parser.rs | 47 +++++++++++------------- 1 file changed, 21 insertions(+), 26 deletions(-) (limited to 'src/components/script/html') diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index a0490c1621f..452f1c8640b 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, 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 { - unsafe fn to_hubbub_node(&self, roots: &RootCollection) -> hubbub::NodeDataPtr; + unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr; } impl<'a, T: NodeBase+Reflectable> NodeWrapping 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(n: hubbub::NodeDataPtr, - roots: Option<&RootCollection>) -> Temporary { - 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(n: hubbub::NodeDataPtr) -> Temporary { + 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 = 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 = from_hubbub_node(parent, None).root(&roots); + let mut child = from_hubbub_node(child).root(); + let mut parent: Root = 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 = &*from_hubbub_node(script, None).root(&roots); - match script.get_attribute(Null, "src").root(&roots) { + let script: &JSRef = &*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())); -- cgit v1.2.3 From 91278da9dd55582401154e07f9eea34425a332c2 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Thu, 24 Apr 2014 13:03:19 -0400 Subject: Address review comments. --- src/components/script/html/hubbub_html_parser.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/components/script/html') diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs index 452f1c8640b..8cebc7326e6 100644 --- a/src/components/script/html/hubbub_html_parser.rs +++ b/src/components/script/html/hubbub_html_parser.rs @@ -81,7 +81,7 @@ trait NodeWrapping { impl<'a, T: NodeBase+Reflectable> NodeWrapping for JSRef<'a, T> { unsafe fn to_hubbub_node(&self) -> hubbub::NodeDataPtr { - cast::transmute(self.get()) + cast::transmute(self.deref()) } } @@ -293,7 +293,6 @@ pub fn parse_html(page: &Page, let mut parser = hubbub::Parser("UTF-8", false); debug!("created parser"); - parser.set_document_node(unsafe { document.to_hubbub_node() }); parser.enable_scripting(true); parser.enable_styling(true); @@ -393,7 +392,7 @@ pub fn parse_html(page: &Page, let SubpageId(id_num) = subpage_id; *next_subpage_id.borrow_mut() = SubpageId(id_num + 1); - iframe_element.get_mut().size = Some(IFrameSize { + iframe_element.deref_mut().size = Some(IFrameSize { pipeline_id: pipeline_id, subpage_id: subpage_id, }); @@ -477,7 +476,7 @@ pub fn parse_html(page: &Page, 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())); + let new_url = parse_url(src.deref().value_ref(), Some(url3.clone())); js_chan2.send(JSTaskNewFile(new_url)); } None => { @@ -487,7 +486,7 @@ pub fn parse_html(page: &Page, for child in scriptnode.children() { debug!("child = {:?}", child); let text: &JSRef = TextCast::to_ref(&child).unwrap(); - data.push(text.get().characterdata.data.to_str()); // FIXME: Bad copy. + data.push(text.deref().characterdata.data.to_str()); // FIXME: Bad copy. } debug!("script data = {:?}", data); -- cgit v1.2.3