mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Stop mutating Element::namespace.
This commit is contained in:
parent
6df6a7d512
commit
d230077f9f
3 changed files with 22 additions and 17 deletions
|
@ -430,7 +430,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
return Err(InvalidCharacter);
|
||||
}
|
||||
let local_name = local_name.as_slice().to_ascii_lower();
|
||||
Ok(build_element_from_tag(local_name, self))
|
||||
Ok(build_element_from_tag(local_name, namespace::HTML, self))
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-document-createelementns
|
||||
|
@ -473,7 +473,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
|
|||
}
|
||||
|
||||
if ns == namespace::HTML {
|
||||
Ok(build_element_from_tag(local_name_from_qname, self))
|
||||
Ok(build_element_from_tag(local_name_from_qname, ns, self))
|
||||
} else {
|
||||
Ok(Element::new(local_name_from_qname, ns, prefix_from_qname, self))
|
||||
}
|
||||
|
|
|
@ -1252,7 +1252,8 @@ impl Node {
|
|||
ElementNodeTypeId(..) => {
|
||||
let element: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||
let element = element.deref();
|
||||
let element = build_element_from_tag(element.local_name.clone(), &*document);
|
||||
let element = build_element_from_tag(element.local_name.clone(),
|
||||
element.namespace.clone(), &*document);
|
||||
NodeCast::from_temporary(element)
|
||||
},
|
||||
TextNodeTypeId => {
|
||||
|
@ -1289,22 +1290,16 @@ impl Node {
|
|||
},
|
||||
ElementNodeTypeId(..) => {
|
||||
let node_elem: &JSRef<Element> = ElementCast::to_ref(node).unwrap();
|
||||
let node_elem = node_elem.deref();
|
||||
let copy_elem: &mut JSRef<Element> = ElementCast::to_mut_ref(&mut *copy).unwrap();
|
||||
let copy_elem: &JSRef<Element> = ElementCast::to_ref(&*copy).unwrap();
|
||||
|
||||
// XXX: to avoid double borrowing compile error. we might be able to fix this after #1854
|
||||
let copy_elem_alias = copy_elem.clone();
|
||||
|
||||
let copy_elem = copy_elem.deref_mut();
|
||||
// FIXME: https://github.com/mozilla/servo/issues/1737
|
||||
copy_elem.namespace = node_elem.namespace.clone();
|
||||
let window = document.deref().window.root();
|
||||
for attr in node_elem.attrs.borrow().iter().map(|attr| attr.root()) {
|
||||
copy_elem.attrs.borrow_mut().push_unrooted(
|
||||
for attr in node_elem.deref().attrs.borrow().iter().map(|attr| attr.root()) {
|
||||
copy_elem.deref().attrs.borrow_mut().push_unrooted(
|
||||
&Attr::new(&*window,
|
||||
attr.deref().local_name.clone(), attr.deref().value.clone(),
|
||||
attr.deref().name.clone(), attr.deref().namespace.clone(),
|
||||
attr.deref().prefix.clone(), ©_elem_alias));
|
||||
attr.deref().prefix.clone(), copy_elem));
|
||||
}
|
||||
},
|
||||
_ => ()
|
||||
|
|
|
@ -17,10 +17,10 @@ use html::cssparse::{StylesheetProvenance, UrlProvenance, spawn_css_parser};
|
|||
use script_task::Page;
|
||||
|
||||
use hubbub::hubbub;
|
||||
use hubbub::hubbub::{NullNs, XLinkNs, XmlNs, XmlNsNs};
|
||||
use hubbub::hubbub::{NullNs, HtmlNs, MathMlNs, SvgNs, XLinkNs, XmlNs, XmlNsNs};
|
||||
use servo_net::resource_task::{Load, LoadData, Payload, Done, ResourceTask, load_whole_resource};
|
||||
use servo_util::namespace;
|
||||
use servo_util::namespace::Null;
|
||||
use servo_util::namespace::{Namespace, Null};
|
||||
use servo_util::str::{DOMString, HTML_SPACE_CHARACTERS};
|
||||
use servo_util::task::spawn_named;
|
||||
use servo_util::url::parse_url;
|
||||
|
@ -158,7 +158,11 @@ fn js_script_listener(to_parent: Sender<HtmlDiscoveryMessage>,
|
|||
// 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<Document>) -> Temporary<Element> {
|
||||
pub fn build_element_from_tag(tag: DOMString, ns: Namespace, document: &JSRef<Document>) -> Temporary<Element> {
|
||||
if ns != namespace::HTML {
|
||||
return Element::new(tag, ns, None, document);
|
||||
}
|
||||
|
||||
// TODO (Issue #85): use atoms
|
||||
handle_element!(document, tag, "a", HTMLAnchorElement);
|
||||
handle_element!(document, tag, "abbr", HTMLElement);
|
||||
|
@ -369,7 +373,13 @@ 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: Root<Element> = build_element_from_tag(tag.name.clone(), *tmp).root();
|
||||
let namespace = match tag.ns {
|
||||
HtmlNs => namespace::HTML,
|
||||
MathMlNs => namespace::MathML,
|
||||
SvgNs => namespace::SVG,
|
||||
ns => fail!("Not expecting namespace {:?}", ns),
|
||||
};
|
||||
let mut element: Root<Element> = build_element_from_tag(tag.name.clone(), namespace, *tmp).root();
|
||||
|
||||
debug!("-- attach attrs");
|
||||
for attr in tag.attributes.iter() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue