Pass Atom to Attr:new for the prefix argument.

This commit is contained in:
Ms2ger 2014-11-14 16:00:23 +01:00 committed by Tamir Duberstein
parent 89a0c004d5
commit e8b02acb1d
5 changed files with 13 additions and 15 deletions

View file

@ -109,21 +109,21 @@ pub struct Attr {
impl Attr { impl Attr {
fn new_inherited(local_name: Atom, value: AttrValue, name: Atom, namespace: Namespace, fn new_inherited(local_name: Atom, value: AttrValue, name: Atom, namespace: Namespace,
prefix: Option<DOMString>, owner: Option<JSRef<Element>>) -> Attr { prefix: Option<Atom>, owner: Option<JSRef<Element>>) -> Attr {
Attr { Attr {
reflector_: Reflector::new(), reflector_: Reflector::new(),
local_name: local_name, local_name: local_name,
value: DOMRefCell::new(value), value: DOMRefCell::new(value),
name: name, name: name,
namespace: namespace, namespace: namespace,
prefix: prefix.map(|p| Atom::from_slice(&p)), prefix: prefix,
owner: MutNullableHeap::new(owner.map(JS::from_rooted)), owner: MutNullableHeap::new(owner.map(JS::from_rooted)),
} }
} }
pub fn new(window: JSRef<Window>, local_name: Atom, value: AttrValue, pub fn new(window: JSRef<Window>, local_name: Atom, value: AttrValue,
name: Atom, namespace: Namespace, name: Atom, namespace: Namespace,
prefix: Option<DOMString>, owner: Option<JSRef<Element>>) -> Temporary<Attr> { prefix: Option<Atom>, owner: Option<JSRef<Element>>) -> Temporary<Attr> {
reflect_dom_object( reflect_dom_object(
box Attr::new_inherited(local_name, value, name, namespace, prefix, owner), box Attr::new_inherited(local_name, value, name, namespace, prefix, owner),
GlobalRef::Window(window), GlobalRef::Window(window),

View file

@ -17,7 +17,6 @@ use util::str::DOMString;
use libc; use libc;
use libc::c_uint; use libc::c_uint;
use std::borrow::ToOwned;
use std::boxed; use std::boxed;
use std::cell::Cell; use std::cell::Cell;
use std::ffi::CString; use std::ffi::CString;
@ -628,7 +627,7 @@ pub fn validate_qualified_name(qualified_name: &str) -> ErrorResult {
/// Validate a namespace and qualified name and extract their parts. /// Validate a namespace and qualified name and extract their parts.
/// See https://dom.spec.whatwg.org/#validate-and-extract for details. /// See https://dom.spec.whatwg.org/#validate-and-extract for details.
pub fn validate_and_extract(namespace: Option<DOMString>, qualified_name: &str) pub fn validate_and_extract(namespace: Option<DOMString>, qualified_name: &str)
-> Fallible<(Namespace, Option<DOMString>, Atom)> { -> Fallible<(Namespace, Option<Atom>, Atom)> {
// Step 1. // Step 1.
let namespace = namespace::from_domstring(namespace); let namespace = namespace::from_domstring(namespace);
@ -667,7 +666,7 @@ pub fn validate_and_extract(namespace: Option<DOMString>, qualified_name: &str)
}, },
(ns, p) => { (ns, p) => {
// Step 10. // Step 10.
Ok((ns, p.map(|s| s.to_owned()), Atom::from_slice(local_name))) Ok((ns, p.map(Atom::from_slice), Atom::from_slice(local_name)))
} }
} }
} }

View file

@ -1025,7 +1025,7 @@ impl<'a> DocumentMethods for JSRef<'a, Document> {
let (namespace, prefix, local_name) = let (namespace, prefix, local_name) =
try!(validate_and_extract(namespace, &qualified_name)); try!(validate_and_extract(namespace, &qualified_name));
let name = QualName::new(namespace, local_name); let name = QualName::new(namespace, local_name);
Ok(Element::create(name, prefix, self, ElementCreator::ScriptCreated)) Ok(Element::create(name, prefix.map(|p| (*p).to_owned()), self, ElementCreator::ScriptCreated))
} }
// https://dom.spec.whatwg.org/#dom-document-createattribute // https://dom.spec.whatwg.org/#dom-document-createattribute

View file

@ -670,12 +670,12 @@ pub trait AttributeHandlers {
fn set_attribute_from_parser(self, fn set_attribute_from_parser(self,
name: QualName, name: QualName,
value: DOMString, value: DOMString,
prefix: Option<DOMString>); prefix: Option<Atom>);
fn set_attribute(self, name: &Atom, value: AttrValue); fn set_attribute(self, name: &Atom, value: AttrValue);
fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult; fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult;
fn do_set_attribute<F>(self, local_name: Atom, value: AttrValue, fn do_set_attribute<F>(self, local_name: Atom, value: AttrValue,
name: Atom, namespace: Namespace, name: Atom, namespace: Namespace,
prefix: Option<DOMString>, cb: F) prefix: Option<Atom>, cb: F)
where F: Fn(JSRef<Attr>) -> bool; where F: Fn(JSRef<Attr>) -> bool;
fn parse_attribute(self, namespace: &Namespace, local_name: &Atom, fn parse_attribute(self, namespace: &Namespace, local_name: &Atom,
value: DOMString) -> AttrValue; value: DOMString) -> AttrValue;
@ -743,7 +743,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
fn set_attribute_from_parser(self, fn set_attribute_from_parser(self,
qname: QualName, qname: QualName,
value: DOMString, value: DOMString,
prefix: Option<DOMString>) { prefix: Option<Atom>) {
// Don't set if the attribute already exists, so we can handle add_attrs_if_missing // Don't set if the attribute already exists, so we can handle add_attrs_if_missing
if self.attrs.borrow().iter().map(|attr| attr.root()) if self.attrs.borrow().iter().map(|attr| attr.root())
.any(|a| *a.r().local_name() == qname.local && *a.r().namespace() == qname.ns) { .any(|a| *a.r().local_name() == qname.local && *a.r().namespace() == qname.ns) {
@ -753,7 +753,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
let name = match prefix { let name = match prefix {
None => qname.local.clone(), None => qname.local.clone(),
Some(ref prefix) => { Some(ref prefix) => {
let name = format!("{}:{}", *prefix, &*qname.local); let name = format!("{}:{}", &**prefix, &*qname.local);
Atom::from_slice(&name) Atom::from_slice(&name)
}, },
}; };
@ -791,7 +791,7 @@ impl<'a> AttributeHandlers for JSRef<'a, Element> {
value: AttrValue, value: AttrValue,
name: Atom, name: Atom,
namespace: Namespace, namespace: Namespace,
prefix: Option<DOMString>, prefix: Option<Atom>,
cb: F) cb: F)
where F: Fn(JSRef<Attr>) -> bool where F: Fn(JSRef<Attr>) -> bool
{ {
@ -1099,8 +1099,7 @@ impl<'a> ElementMethods for JSRef<'a, Element> {
let qualified_name = Atom::from_slice(&qualified_name); let qualified_name = Atom::from_slice(&qualified_name);
let value = self.parse_attribute(&namespace, &local_name, value); let value = self.parse_attribute(&namespace, &local_name, value);
self.do_set_attribute(local_name.clone(), value, qualified_name, self.do_set_attribute(local_name.clone(), value, qualified_name,
namespace.clone(), prefix.map(|s| s.to_owned()), namespace.clone(), prefix, |attr| {
|attr| {
*attr.local_name() == local_name && *attr.local_name() == local_name &&
*attr.namespace() == namespace *attr.namespace() == namespace
}); });

View file

@ -1778,7 +1778,7 @@ impl Node {
&Attr::new(window.r(), &Attr::new(window.r(),
attr.r().local_name().clone(), attr.r().value().clone(), attr.r().local_name().clone(), attr.r().value().clone(),
attr.r().name().clone(), attr.r().namespace().clone(), attr.r().name().clone(), attr.r().namespace().clone(),
attr.r().GetPrefix(), Some(copy_elem))); attr.r().prefix().clone(), Some(copy_elem)));
} }
}, },
_ => () _ => ()