diff options
-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 ca5b14b192c..fbddb713736 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 80e5fb04d6c..2d6f17ffd19 100644 --- a/components/util/str.rs +++ b/components/util/str.rs @@ -24,6 +24,12 @@ impl DOMString { } } +impl Default for DOMString { + fn default() -> Self { + DOMString(String::new()) + } +} + impl Deref for DOMString { type Target = str; |