mirror of
https://github.com/servo/servo.git
synced 2025-06-21 07:38:59 +01:00
Don't pass nullable strings to native DOM methods that want non-nullable strings. Fixes #1207.
This commit is contained in:
parent
803cd4b7cf
commit
08afc6d19d
75 changed files with 968 additions and 966 deletions
|
@ -6,7 +6,7 @@ use dom::comment::Comment;
|
|||
use dom::bindings::codegen::DocumentBinding;
|
||||
use dom::bindings::utils::{Reflectable, Reflector, Traceable, reflect_dom_object};
|
||||
use dom::bindings::utils::{ErrorResult, Fallible, NotSupported, InvalidCharacter};
|
||||
use dom::bindings::utils::{DOMString, null_str_as_empty_ref, null_str_as_empty, null_str_as_word_null};
|
||||
use dom::bindings::utils::DOMString;
|
||||
use dom::bindings::utils::{xml_name_type, InvalidXMLName};
|
||||
use dom::documentfragment::DocumentFragment;
|
||||
use dom::element::{Element};
|
||||
|
@ -180,31 +180,29 @@ impl Document {
|
|||
self.window.get_cx()
|
||||
}
|
||||
|
||||
pub fn GetElementsByTagName(&self, tag: &Option<DOMString>) -> @mut HTMLCollection {
|
||||
self.createHTMLCollection(|elem| eq_slice(elem.tag_name, null_str_as_empty(tag)))
|
||||
pub fn GetElementsByTagName(&self, tag: &DOMString) -> @mut HTMLCollection {
|
||||
self.createHTMLCollection(|elem| eq_slice(elem.tag_name, *tag))
|
||||
}
|
||||
|
||||
pub fn GetElementsByTagNameNS(&self, _ns: &Option<DOMString>, _tag: &Option<DOMString>) -> @mut HTMLCollection {
|
||||
pub fn GetElementsByTagNameNS(&self, _ns: &Option<DOMString>, _tag: &DOMString) -> @mut HTMLCollection {
|
||||
HTMLCollection::new(self.window, ~[])
|
||||
}
|
||||
|
||||
pub fn GetElementsByClassName(&self, _class: &Option<DOMString>) -> @mut HTMLCollection {
|
||||
pub fn GetElementsByClassName(&self, _class: &DOMString) -> @mut HTMLCollection {
|
||||
HTMLCollection::new(self.window, ~[])
|
||||
}
|
||||
|
||||
pub fn GetElementById(&self, id: &Option<DOMString>) -> Option<AbstractNode<ScriptView>> {
|
||||
let key: &~str = &null_str_as_empty(id);
|
||||
pub fn GetElementById(&self, id: &DOMString) -> Option<AbstractNode<ScriptView>> {
|
||||
// TODO: "in tree order, within the context object's tree"
|
||||
// http://dom.spec.whatwg.org/#dom-document-getelementbyid.
|
||||
match self.idmap.find_equiv(key) {
|
||||
match self.idmap.find_equiv(id) {
|
||||
None => None,
|
||||
Some(node) => Some(*node),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn CreateElement(&self, abstract_self: AbstractDocument, local_name: &Option<DOMString>) -> Fallible<AbstractNode<ScriptView>> {
|
||||
let local_name = null_str_as_empty(local_name);
|
||||
if xml_name_type(local_name) == InvalidXMLName {
|
||||
pub fn CreateElement(&self, abstract_self: AbstractDocument, local_name: &DOMString) -> Fallible<AbstractNode<ScriptView>> {
|
||||
if xml_name_type(*local_name) == InvalidXMLName {
|
||||
return Err(InvalidCharacter);
|
||||
}
|
||||
let local_name = local_name.to_ascii_lower();
|
||||
|
@ -215,16 +213,16 @@ impl Document {
|
|||
DocumentFragment::new(abstract_self)
|
||||
}
|
||||
|
||||
pub fn CreateTextNode(&self, abstract_self: AbstractDocument, data: &Option<DOMString>) -> AbstractNode<ScriptView> {
|
||||
Text::new(null_str_as_empty(data), abstract_self)
|
||||
pub fn CreateTextNode(&self, abstract_self: AbstractDocument, data: &DOMString) -> AbstractNode<ScriptView> {
|
||||
Text::new(data.clone(), abstract_self)
|
||||
}
|
||||
|
||||
pub fn CreateComment(&self, abstract_self: AbstractDocument, data: &Option<DOMString>) -> AbstractNode<ScriptView> {
|
||||
Comment::new(null_str_as_word_null(data), abstract_self)
|
||||
pub fn CreateComment(&self, abstract_self: AbstractDocument, data: &DOMString) -> AbstractNode<ScriptView> {
|
||||
Comment::new(data.clone(), abstract_self)
|
||||
}
|
||||
|
||||
pub fn CreateEvent(&self, interface: &Option<DOMString>) -> Fallible<AbstractEvent> {
|
||||
match null_str_as_empty_ref(interface) {
|
||||
pub fn CreateEvent(&self, interface: &DOMString) -> Fallible<AbstractEvent> {
|
||||
match interface.as_slice() {
|
||||
"UIEvents" => Ok(UIEvent::new(self.window, UIEventTypeId)),
|
||||
"MouseEvents" => Ok(MouseEvent::new(self.window)),
|
||||
"HTMLEvents" => Ok(Event::new(self.window, HTMLEventTypeId)),
|
||||
|
@ -232,7 +230,7 @@ impl Document {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn Title(&self, _: AbstractDocument) -> Option<DOMString> {
|
||||
pub fn Title(&self, _: AbstractDocument) -> DOMString {
|
||||
let mut title = ~"";
|
||||
match self.doctype {
|
||||
SVG => {
|
||||
|
@ -249,8 +247,7 @@ impl Document {
|
|||
for child in node.children() {
|
||||
if child.is_text() {
|
||||
do child.with_imm_text() |text| {
|
||||
let s = text.element.Data();
|
||||
title = title + null_str_as_empty(&s);
|
||||
title = title + text.element.Data();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -263,10 +260,10 @@ impl Document {
|
|||
let v: ~[&str] = title.word_iter().collect();
|
||||
title = v.connect(" ");
|
||||
title = title.trim().to_owned();
|
||||
Some(title)
|
||||
title
|
||||
}
|
||||
|
||||
pub fn SetTitle(&self, abstract_self: AbstractDocument, title: &Option<DOMString>) -> ErrorResult {
|
||||
pub fn SetTitle(&self, abstract_self: AbstractDocument, title: &DOMString) -> ErrorResult {
|
||||
match self.doctype {
|
||||
SVG => {
|
||||
fail!("no SVG document yet")
|
||||
|
@ -305,9 +302,9 @@ impl Document {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn GetElementsByName(&self, name: &Option<DOMString>) -> @mut HTMLCollection {
|
||||
pub fn GetElementsByName(&self, name: &DOMString) -> @mut HTMLCollection {
|
||||
self.createHTMLCollection(|elem|
|
||||
elem.get_attr("name").is_some() && eq_slice(elem.get_attr("name").unwrap(), null_str_as_empty(name)))
|
||||
elem.get_attr("name").is_some() && eq_slice(elem.get_attr("name").unwrap(), *name))
|
||||
}
|
||||
|
||||
pub fn createHTMLCollection(&self, callback: &fn(elem: &Element) -> bool) -> @mut HTMLCollection {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue