diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2015-11-13 04:51:32 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2015-11-13 04:51:32 +0530 |
commit | 1720595a85ff0a593994fed1d086288746c56aa3 (patch) | |
tree | ef1a944f0733dd77cd8786357bf5dbe2c0efa8fd | |
parent | c44c73aa00ced6235266bd692833e22018f31138 (diff) | |
parent | 00fa3b2f85fde78f7af8e4636ee7b55a9aecc28d (diff) | |
download | servo-1720595a85ff0a593994fed1d086288746c56aa3.tar.gz servo-1720595a85ff0a593994fed1d086288746c56aa3.zip |
Auto merge of #8479 - frewsxcv:domstring-default, r=Ms2ger
Implement Default trait for DOMString
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8479)
<!-- Reviewable:end -->
-rw-r--r-- | components/script/dom/documenttype.rs | 4 | ||||
-rw-r--r-- | components/script/dom/node.rs | 6 | ||||
-rw-r--r-- | components/util/str.rs | 6 |
3 files changed, 11 insertions, 5 deletions
diff --git a/components/script/dom/documenttype.rs b/components/script/dom/documenttype.rs index ed5a64307cc..d8dbf01ed88 100644 --- a/components/script/dom/documenttype.rs +++ b/components/script/dom/documenttype.rs @@ -31,8 +31,8 @@ impl DocumentType { DocumentType { node: Node::new_inherited(document), name: name, - public_id: public_id.unwrap_or(DOMString::new()), - system_id: system_id.unwrap_or(DOMString::new()) + public_id: public_id.unwrap_or_default(), + system_id: system_id.unwrap_or_default(), } } #[allow(unrooted_must_root)] diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index f96da2f5934..b5bc0e525d5 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -825,7 +825,7 @@ impl Node { .map(|elem| elem.upcast::<Node>() == self) .unwrap_or(false), - shortValue: self.GetNodeValue().unwrap_or(DOMString::new()), //FIXME: truncate + shortValue: self.GetNodeValue().unwrap_or_default(), //FIXME: truncate incompleteValue: false, //FIXME: reflect truncation } } @@ -1893,7 +1893,7 @@ impl NodeMethods for Node { // https://dom.spec.whatwg.org/#dom-node-nodevalue fn SetNodeValue(&self, val: Option<DOMString>) { if let Some(character_data) = self.downcast::<CharacterData>() { - character_data.SetData(val.unwrap_or(DOMString::new())); + character_data.SetData(val.unwrap_or_default()); } } @@ -1918,7 +1918,7 @@ impl NodeMethods for Node { // https://dom.spec.whatwg.org/#dom-node-textcontent fn SetTextContent(&self, value: Option<DOMString>) { - let value = value.unwrap_or(DOMString::new()); + let value = value.unwrap_or_default(); match self.type_id() { NodeTypeId::DocumentFragment | NodeTypeId::Element(..) => { diff --git a/components/util/str.rs b/components/util/str.rs index afbced05ac4..9544e1d025e 100644 --- a/components/util/str.rs +++ b/components/util/str.rs @@ -32,6 +32,12 @@ impl DOMString { } } +impl Default for DOMString { + fn default() -> Self { + DOMString(String::new()) + } +} + impl Deref for DOMString { type Target = str; |