aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorMs2ger <Ms2ger@gmail.com>2015-11-03 14:16:55 +0100
committerMs2ger <Ms2ger@gmail.com>2015-11-04 12:09:11 +0100
commit6b75078503f25a61084a3e9cae1b7d57de21772f (patch)
treeddfc15e73be407657f687f55d9c8b7bce5b9596c /components/script
parente6aa976462fad0aafb2d59d0a590b69a8c8b5ba9 (diff)
downloadservo-6b75078503f25a61084a3e9cae1b7d57de21772f.tar.gz
servo-6b75078503f25a61084a3e9cae1b7d57de21772f.zip
Make DOMString a newtype around String, rather than a typedef.
This should make it somewhat easier to experiment with alternative representations in the future. To reduce churn, this commit leaves the String field public, though. Also, this will allow us to use the default String type to represent the IDL USVString type, which explicitly forbids unpaired surrogates, ans as such is a better match to the Rust String type.
Diffstat (limited to 'components/script')
-rw-r--r--components/script/devtools.rs7
-rw-r--r--components/script/dom/activation.rs3
-rw-r--r--components/script/dom/attr.rs16
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py2
-rw-r--r--components/script/dom/bindings/conversions.rs13
-rw-r--r--components/script/dom/bindings/error.rs5
-rw-r--r--components/script/dom/bindings/trace.rs3
-rw-r--r--components/script/dom/bindings/utils.rs2
-rw-r--r--components/script/dom/blob.rs8
-rw-r--r--components/script/dom/canvasgradient.rs3
-rw-r--r--components/script/dom/canvasrenderingcontext2d.rs18
-rw-r--r--components/script/dom/characterdata.rs6
-rw-r--r--components/script/dom/console.rs11
-rw-r--r--components/script/dom/create.rs9
-rw-r--r--components/script/dom/css.rs2
-rw-r--r--components/script/dom/cssstyledeclaration.rs20
-rw-r--r--components/script/dom/dedicatedworkerglobalscope.rs3
-rw-r--r--components/script/dom/document.rs60
-rw-r--r--components/script/dom/domexception.rs8
-rw-r--r--components/script/dom/domimplementation.rs10
-rw-r--r--components/script/dom/domparser.rs2
-rw-r--r--components/script/dom/domtokenlist.rs4
-rw-r--r--components/script/dom/element.rs14
-rw-r--r--components/script/dom/event.rs2
-rw-r--r--components/script/dom/filereader.rs8
-rw-r--r--components/script/dom/formdata.rs2
-rw-r--r--components/script/dom/htmlanchorelement.rs4
-rw-r--r--components/script/dom/htmlbodyelement.rs2
-rw-r--r--components/script/dom/htmlbuttonelement.rs2
-rw-r--r--components/script/dom/htmlcanvaselement.rs4
-rw-r--r--components/script/dom/htmlelement.rs8
-rw-r--r--components/script/dom/htmlformelement.rs8
-rw-r--r--components/script/dom/htmliframeelement.rs2
-rw-r--r--components/script/dom/htmlimageelement.rs6
-rw-r--r--components/script/dom/htmlinputelement.rs53
-rw-r--r--components/script/dom/htmllinkelement.rs3
-rw-r--r--components/script/dom/htmloptionelement.rs4
-rw-r--r--components/script/dom/htmlscriptelement.rs9
-rw-r--r--components/script/dom/htmlselectelement.rs8
-rw-r--r--components/script/dom/htmltableelement.rs4
-rw-r--r--components/script/dom/htmltablerowelement.rs2
-rw-r--r--components/script/dom/htmltablesectionelement.rs2
-rw-r--r--components/script/dom/htmltextareaelement.rs6
-rw-r--r--components/script/dom/htmltitleelement.rs2
-rw-r--r--components/script/dom/location.rs2
-rw-r--r--components/script/dom/macros.rs4
-rw-r--r--components/script/dom/messageevent.rs2
-rw-r--r--components/script/dom/namednodemap.rs2
-rw-r--r--components/script/dom/navigatorinfo.rs16
-rw-r--r--components/script/dom/node.rs14
-rw-r--r--components/script/dom/servohtmlparser.rs3
-rw-r--r--components/script/dom/storage.rs4
-rw-r--r--components/script/dom/text.rs2
-rw-r--r--components/script/dom/textdecoder.rs2
-rw-r--r--components/script/dom/textencoder.rs2
-rw-r--r--components/script/dom/url.rs2
-rw-r--r--components/script/dom/urlsearchparams.rs2
-rw-r--r--components/script/dom/userscripts.rs5
-rw-r--r--components/script/dom/webglactiveinfo.rs6
-rw-r--r--components/script/dom/webglprogram.rs9
-rw-r--r--components/script/dom/webglrenderingcontext.rs7
-rw-r--r--components/script/dom/webglshader.rs7
-rw-r--r--components/script/dom/websocket.rs15
-rw-r--r--components/script/dom/window.rs8
-rw-r--r--components/script/dom/worker.rs6
-rw-r--r--components/script/dom/workerglobalscope.rs2
-rw-r--r--components/script/dom/workerlocation.rs2
-rw-r--r--components/script/dom/xmlhttprequest.rs22
-rw-r--r--components/script/parse/html.rs13
-rw-r--r--components/script/script_task.rs10
-rw-r--r--components/script/textinput.rs14
-rw-r--r--components/script/webdriver_handlers.rs16
72 files changed, 297 insertions, 272 deletions
diff --git a/components/script/devtools.rs b/components/script/devtools.rs
index ae7c1a14129..b12619b51b0 100644
--- a/components/script/devtools.rs
+++ b/components/script/devtools.rs
@@ -23,6 +23,7 @@ use script_task::get_page;
use std::ffi::CStr;
use std::rc::Rc;
use std::str;
+use util::str::DOMString;
use uuid::Uuid;
#[allow(unsafe_code)]
@@ -39,7 +40,7 @@ pub fn handle_evaluate_js(global: &GlobalRef, eval: String, reply: IpcSender<Eva
EvaluateJSReply::NumberValue(
FromJSValConvertible::from_jsval(cx, rval.handle(), ()).unwrap())
} else if rval.ptr.is_string() {
- EvaluateJSReply::StringValue(jsstring_to_str(cx, rval.ptr.to_string()))
+ EvaluateJSReply::StringValue(jsstring_to_str(cx, rval.ptr.to_string()).0)
} else if rval.ptr.is_null() {
EvaluateJSReply::NullValue
} else {
@@ -159,9 +160,9 @@ pub fn handle_modify_attribute(page: &Rc<Page>,
for modification in modifications {
match modification.newValue {
Some(string) => {
- let _ = elem.SetAttribute(modification.attributeName, string);
+ let _ = elem.SetAttribute(DOMString(modification.attributeName), DOMString(string));
},
- None => elem.RemoveAttribute(modification.attributeName),
+ None => elem.RemoveAttribute(DOMString(modification.attributeName)),
}
}
}
diff --git a/components/script/dom/activation.rs b/components/script/dom/activation.rs
index 15db5e9f3eb..59af792007a 100644
--- a/components/script/dom/activation.rs
+++ b/components/script/dom/activation.rs
@@ -10,6 +10,7 @@ use dom::eventtarget::EventTarget;
use dom::mouseevent::MouseEvent;
use dom::node::window_from_node;
use std::borrow::ToOwned;
+use util::str::DOMString;
/// Trait for elements with defined activation behavior
pub trait Activatable {
@@ -46,7 +47,7 @@ pub trait Activatable {
// https://html.spec.whatwg.org/multipage/#fire-a-synthetic-mouse-event
let win = window_from_node(element);
let target = element.upcast();
- let mouse = MouseEvent::new(win.r(), "click".to_owned(),
+ let mouse = MouseEvent::new(win.r(), DOMString("click".to_owned()),
EventBubbles::DoesNotBubble, EventCancelable::NotCancelable, Some(win.r()), 1,
0, 0, 0, 0, ctrlKey, shiftKey, altKey, metaKey,
0, None);
diff --git a/components/script/dom/attr.rs b/components/script/dom/attr.rs
index d3aea55d60f..024522acfe8 100644
--- a/components/script/dom/attr.rs
+++ b/components/script/dom/attr.rs
@@ -46,7 +46,7 @@ impl AttrValue {
}
pub fn from_atomic_tokens(atoms: Vec<Atom>) -> AttrValue {
- let tokens = str_join(&atoms, "\x20");
+ let tokens = DOMString(str_join(&atoms, "\x20"));
AttrValue::TokenList(tokens, atoms)
}
@@ -212,12 +212,12 @@ impl Attr {
impl AttrMethods for Attr {
// https://dom.spec.whatwg.org/#dom-attr-localname
fn LocalName(&self) -> DOMString {
- (**self.local_name()).to_owned()
+ DOMString((**self.local_name()).to_owned())
}
// https://dom.spec.whatwg.org/#dom-attr-value
fn Value(&self) -> DOMString {
- (**self.value()).to_owned()
+ DOMString((**self.value()).to_owned())
}
// https://dom.spec.whatwg.org/#dom-attr-value
@@ -253,7 +253,7 @@ impl AttrMethods for Attr {
// https://dom.spec.whatwg.org/#dom-attr-name
fn Name(&self) -> DOMString {
- (*self.name).to_owned()
+ DOMString((*self.name).to_owned())
}
// https://dom.spec.whatwg.org/#dom-attr-namespaceuri
@@ -261,13 +261,13 @@ impl AttrMethods for Attr {
let Namespace(ref atom) = self.namespace;
match &**atom {
"" => None,
- url => Some(url.to_owned()),
+ url => Some(DOMString(url.to_owned())),
}
}
// https://dom.spec.whatwg.org/#dom-attr-prefix
fn GetPrefix(&self) -> Option<DOMString> {
- self.prefix().as_ref().map(|p| (**p).to_owned())
+ self.prefix().as_ref().map(|p| DOMString((**p).to_owned()))
}
// https://dom.spec.whatwg.org/#dom-attr-ownerelement
@@ -326,8 +326,8 @@ impl Attr {
let Namespace(ref ns) = self.namespace;
AttrInfo {
namespace: (**ns).to_owned(),
- name: self.Name(),
- value: self.Value(),
+ name: self.Name().0,
+ value: self.Value().0,
}
}
}
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 4134fb104fe..9348a198ef0 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -829,7 +829,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
default = "None"
else:
assert defaultValue.type.tag() == IDLType.Tags.domstring
- default = '"%s".to_owned()' % defaultValue.value
+ default = 'DOMString("%s".to_owned())' % defaultValue.value
if type.nullable():
default = "Some(%s)" % default
diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs
index 9078fe77ed4..98918e9d7ea 100644
--- a/components/script/dom/bindings/conversions.rs
+++ b/components/script/dom/bindings/conversions.rs
@@ -431,6 +431,13 @@ impl ToJSValConvertible for str {
}
//http://heycam.github.io/webidl/#es-DOMString
+impl ToJSValConvertible for String {
+ fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
+ (**self).to_jsval(cx, rval);
+ }
+}
+
+//http://heycam.github.io/webidl/#es-DOMString
impl ToJSValConvertible for DOMString {
fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
(**self).to_jsval(cx, rval);
@@ -451,7 +458,7 @@ pub enum StringificationBehavior {
pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
let mut length = 0;
let latin1 = unsafe { JS_StringHasLatin1Chars(s) };
- if latin1 {
+ DOMString(if latin1 {
let chars = unsafe {
JS_GetLatin1StringCharsAndLength(cx, ptr::null(), s, &mut length)
};
@@ -496,7 +503,7 @@ pub fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString {
}
}
s
- }
+ })
}
/// Convert the given `jsid` to a `DOMString`. Fails if the `jsid` is not a
@@ -548,7 +555,7 @@ impl FromJSValConvertible for USVString {
}
let latin1 = unsafe { JS_StringHasLatin1Chars(jsstr) };
if latin1 {
- return Ok(USVString(jsstring_to_str(cx, jsstr)));
+ return Ok(USVString(jsstring_to_str(cx, jsstr).0));
}
unsafe {
let mut length = 0;
diff --git a/components/script/dom/bindings/error.rs b/components/script/dom/bindings/error.rs
index 3e9c2871a38..c0f03ae3c60 100644
--- a/components/script/dom/bindings/error.rs
+++ b/components/script/dom/bindings/error.rs
@@ -18,7 +18,6 @@ use libc;
use std::ffi::CString;
use std::{mem, ptr};
use util::mem::HeapSizeOf;
-use util::str::DOMString;
/// DOM exceptions that can be thrown by a native DOM method.
#[derive(Debug, Clone, HeapSizeOf)]
@@ -65,9 +64,9 @@ pub enum Error {
TypeMismatch,
/// TypeError JavaScript Error
- Type(DOMString),
+ Type(String),
/// RangeError JavaScript Error
- Range(DOMString),
+ Range(String),
/// A JavaScript exception is already pending.
JSFailed,
diff --git a/components/script/dom/bindings/trace.rs b/components/script/dom/bindings/trace.rs
index 84869943239..6c2f9367350 100644
--- a/components/script/dom/bindings/trace.rs
+++ b/components/script/dom/bindings/trace.rs
@@ -83,7 +83,7 @@ use string_cache::{Atom, Namespace};
use style::properties::PropertyDeclarationBlock;
use style::values::specified::Length;
use url::Url;
-use util::str::{LengthOrPercentageOrAuto};
+use util::str::{DOMString, LengthOrPercentageOrAuto};
/// A trait to allow tracing (only) DOM objects.
@@ -285,6 +285,7 @@ no_jsmanaged_fields!(MemProfilerChan);
no_jsmanaged_fields!(PseudoElement);
no_jsmanaged_fields!(Length);
no_jsmanaged_fields!(ElementState);
+no_jsmanaged_fields!(DOMString);
impl JSTraceable for Box<ScriptChan + Send> {
#[inline]
diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs
index 31961ca21b0..9783a9f6539 100644
--- a/components/script/dom/bindings/utils.rs
+++ b/components/script/dom/bindings/utils.rs
@@ -452,7 +452,7 @@ pub fn find_enum_string_index(cx: *mut JSContext,
}
let search = jsstring_to_str(cx, jsstr);
- Ok(values.iter().position(|value| value == &search))
+ Ok(values.iter().position(|value| search == *value))
}
/// Returns wether `obj` is a platform object
diff --git a/components/script/dom/blob.rs b/components/script/dom/blob.rs
index b42bcce573e..37a526eb15c 100644
--- a/components/script/dom/blob.rs
+++ b/components/script/dom/blob.rs
@@ -21,12 +21,12 @@ use util::str::DOMString;
pub struct Blob {
reflector_: Reflector,
bytes: Option<Vec<u8>>,
- typeString: DOMString,
+ typeString: String,
global: GlobalField,
isClosed_: Cell<bool>
}
-fn is_ascii_printable(string: &DOMString) -> bool {
+fn is_ascii_printable(string: &str) -> bool {
// Step 5.1 in Sec 5.1 of File API spec
// http://dev.w3.org/2006/webapi/FileAPI/#constructorBlob
string.chars().all(|c| { c >= '\x20' && c <= '\x7E' })
@@ -60,7 +60,7 @@ impl Blob {
pub fn Constructor_(global: GlobalRef, blobParts: DOMString,
blobPropertyBag: &BlobBinding::BlobPropertyBag) -> Fallible<Root<Blob>> {
//TODO: accept other blobParts types - ArrayBuffer or ArrayBufferView or Blob
- let bytes: Option<Vec<u8>> = Some(blobParts.into_bytes());
+ let bytes: Option<Vec<u8>> = Some(blobParts.0.into_bytes());
let typeString = if is_ascii_printable(&blobPropertyBag.type_) {
&*blobPropertyBag.type_
} else {
@@ -85,7 +85,7 @@ impl BlobMethods for Blob {
// https://dev.w3.org/2006/webapi/FileAPI/#dfn-type
fn Type(&self) -> DOMString {
- self.typeString.clone()
+ DOMString(self.typeString.clone())
}
// https://dev.w3.org/2006/webapi/FileAPI/#slice-method-algo
diff --git a/components/script/dom/canvasgradient.rs b/components/script/dom/canvasgradient.rs
index a9cf8a2d878..3fa8d8ef996 100644
--- a/components/script/dom/canvasgradient.rs
+++ b/components/script/dom/canvasgradient.rs
@@ -12,6 +12,7 @@ use dom::bindings::js::Root;
use dom::bindings::num::Finite;
use dom::bindings::reflector::{Reflector, reflect_dom_object};
use dom::canvasrenderingcontext2d::parse_color;
+use util::str::DOMString;
// https://html.spec.whatwg.org/multipage/#canvasgradient
#[dom_struct]
@@ -44,7 +45,7 @@ impl CanvasGradient {
impl CanvasGradientMethods for CanvasGradient {
// https://html.spec.whatwg.org/multipage/#dom-canvasgradient-addcolorstop
- fn AddColorStop(&self, offset: Finite<f64>, color: String) -> ErrorResult {
+ fn AddColorStop(&self, offset: Finite<f64>, color: DOMString) -> ErrorResult {
if *offset < 0f64 || *offset > 1f64 {
return Err(Error::IndexSize);
}
diff --git a/components/script/dom/canvasrenderingcontext2d.rs b/components/script/dom/canvasrenderingcontext2d.rs
index 377816faae4..47ede77d7de 100644
--- a/components/script/dom/canvasrenderingcontext2d.rs
+++ b/components/script/dom/canvasrenderingcontext2d.rs
@@ -536,10 +536,10 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
fn GlobalCompositeOperation(&self) -> DOMString {
let state = self.state.borrow();
- match state.global_composition {
+ DOMString(match state.global_composition {
CompositionOrBlending::Composition(op) => op.to_str().to_owned(),
CompositionOrBlending::Blending(op) => op.to_str().to_owned(),
- }
+ })
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-globalcompositeoperation
@@ -760,7 +760,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
CanvasFillOrStrokeStyle::Color(ref rgba) => {
let mut result = String::new();
serialize(rgba, &mut result).unwrap();
- StringOrCanvasGradientOrCanvasPattern::eString(result)
+ StringOrCanvasGradientOrCanvasPattern::eString(DOMString(result))
},
CanvasFillOrStrokeStyle::Gradient(ref gradient) => {
StringOrCanvasGradientOrCanvasPattern::eCanvasGradient(Root::from_ref(&*gradient))
@@ -800,7 +800,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
CanvasFillOrStrokeStyle::Color(ref rgba) => {
let mut result = String::new();
serialize(rgba, &mut result).unwrap();
- StringOrCanvasGradientOrCanvasPattern::eString(result)
+ StringOrCanvasGradientOrCanvasPattern::eString(DOMString(result))
},
CanvasFillOrStrokeStyle::Gradient(ref gradient) => {
StringOrCanvasGradientOrCanvasPattern::eCanvasGradient(Root::from_ref(&*gradient))
@@ -1001,11 +1001,11 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
fn LineCap(&self) -> DOMString {
let state = self.state.borrow();
- match state.line_cap {
+ DOMString(match state.line_cap {
LineCapStyle::Butt => "butt".to_owned(),
LineCapStyle::Round => "round".to_owned(),
LineCapStyle::Square => "square".to_owned(),
- }
+ })
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linecap
@@ -1019,11 +1019,11 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
fn LineJoin(&self) -> DOMString {
let state = self.state.borrow();
- match state.line_join {
+ DOMString(match state.line_join {
LineJoinStyle::Round => "round".to_owned(),
LineJoinStyle::Bevel => "bevel".to_owned(),
LineJoinStyle::Miter => "miter".to_owned(),
- }
+ })
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-linejoin
@@ -1098,7 +1098,7 @@ impl CanvasRenderingContext2DMethods for CanvasRenderingContext2D {
fn ShadowColor(&self) -> DOMString {
let mut result = String::new();
serialize(&self.state.borrow().shadow_color, &mut result).unwrap();
- result
+ DOMString(result)
}
// https://html.spec.whatwg.org/multipage/#dom-context-2d-shadowcolor
diff --git a/components/script/dom/characterdata.rs b/components/script/dom/characterdata.rs
index 5c1558086ea..d001db1cc6b 100644
--- a/components/script/dom/characterdata.rs
+++ b/components/script/dom/characterdata.rs
@@ -65,7 +65,7 @@ impl CharacterDataMethods for CharacterData {
// Steps 4.
Some(count_bytes) => &data_from_offset[..count_bytes],
};
- Ok(substring.to_owned())
+ Ok(DOMString(substring.to_owned()))
}
// https://dom.spec.whatwg.org/#dom-characterdata-appenddatadata
@@ -103,7 +103,7 @@ impl CharacterDataMethods for CharacterData {
new_data.push_str(prefix);
new_data.push_str(&arg);
new_data.push_str(suffix);
- new_data
+ DOMString(new_data)
};
*self.data.borrow_mut() = new_data;
self.content_changed();
@@ -150,7 +150,7 @@ impl CharacterData {
}
#[inline]
pub fn append_data(&self, data: &str) {
- self.data.borrow_mut().push_str(data);
+ self.data.borrow_mut().0.push_str(data);
self.content_changed();
}
diff --git a/components/script/dom/console.rs b/components/script/dom/console.rs
index 9303a433e36..86b6d27193a 100644
--- a/components/script/dom/console.rs
+++ b/components/script/dom/console.rs
@@ -74,20 +74,17 @@ impl ConsoleMethods for Console {
// https://developer.mozilla.org/en-US/docs/Web/API/Console/assert
fn Assert(&self, condition: bool, message: Option<DOMString>) {
if !condition {
- let message = match message {
- Some(ref message) => &**message,
- None => "no message",
- };
+ let message = message.unwrap_or_else(|| DOMString("no message".to_owned()));
println!("Assertion failed: {}", message);
- propagate_console_msg(&self, prepare_message(LogLevel::Error, message.to_owned()));
+ propagate_console_msg(&self, prepare_message(LogLevel::Error, message));
}
}
}
-fn prepare_message(logLevel: LogLevel, message: String) -> ConsoleMessage {
+fn prepare_message(logLevel: LogLevel, message: DOMString) -> ConsoleMessage {
//TODO: Sending fake values for filename, lineNumber and columnNumber in LogMessage; adjust later
ConsoleMessage {
- message: message,
+ message: message.0,
logLevel: logLevel,
filename: "test".to_owned(),
lineNumber: 1,
diff --git a/components/script/dom/create.rs b/components/script/dom/create.rs
index 97a5ffcc89c..4e2b07399b1 100644
--- a/components/script/dom/create.rs
+++ b/components/script/dom/create.rs
@@ -76,23 +76,24 @@ use dom::htmlunknownelement::HTMLUnknownElement;
use dom::htmlvideoelement::HTMLVideoElement;
use std::borrow::ToOwned;
use string_cache::{Atom, QualName};
+use util::str::DOMString;
pub fn create_element(name: QualName, prefix: Option<Atom>,
document: &Document, creator: ElementCreator)
-> Root<Element> {
- let prefix = prefix.map(|p| (*p).to_owned());
+ let prefix = prefix.map(|p| DOMString((*p).to_owned()));
if name.ns != ns!(HTML) {
- return Element::new((*name.local).to_owned(), name.ns, prefix, document);
+ return Element::new(DOMString((*name.local).to_owned()), name.ns, prefix, document);
}
macro_rules! make(
($ctor:ident) => ({
- let obj = $ctor::new((*name.local).to_owned(), prefix, document);
+ let obj = $ctor::new(DOMString((*name.local).to_owned()), prefix, document);
Root::upcast(obj)
});
($ctor:ident, $($arg:expr),+) => ({
- let obj = $ctor::new((*name.local).to_owned(), prefix, document, $($arg),+);
+ let obj = $ctor::new(DOMString((*name.local).to_owned()), prefix, document, $($arg),+);
Root::upcast(obj)
})
);
diff --git a/components/script/dom/css.rs b/components/script/dom/css.rs
index a4cd3a132ec..e1963410869 100644
--- a/components/script/dom/css.rs
+++ b/components/script/dom/css.rs
@@ -20,7 +20,7 @@ impl CSS {
return Err(Error::InvalidCharacter);
}
let mut escaped = DOMString::new();
- serialize_identifier(&ident, &mut escaped).unwrap();
+ serialize_identifier(&ident, &mut escaped.0).unwrap();
Ok(escaped)
}
}
diff --git a/components/script/dom/cssstyledeclaration.rs b/components/script/dom/cssstyledeclaration.rs
index a3f2f048b22..91e2af7b0b0 100644
--- a/components/script/dom/cssstyledeclaration.rs
+++ b/components/script/dom/cssstyledeclaration.rs
@@ -39,10 +39,10 @@ macro_rules! css_properties(
( $([$getter:ident, $setter:ident, $cssprop:expr]),* ) => (
$(
fn $getter(&self) -> DOMString {
- self.GetPropertyValue($cssprop.to_owned())
+ self.GetPropertyValue(DOMString($cssprop.to_owned()))
}
fn $setter(&self, value: DOMString) -> ErrorResult {
- self.SetPropertyValue($cssprop.to_owned(), value)
+ self.SetPropertyValue(DOMString($cssprop.to_owned()), value)
}
)*
);
@@ -50,7 +50,7 @@ macro_rules! css_properties(
fn serialize_list(list: &[Ref<PropertyDeclaration>]) -> DOMString {
let str_iter = list.iter().map(|d| d.value());
- str_join(str_iter, " ")
+ DOMString(str_join(str_iter, " "))
}
impl CSSStyleDeclaration {
@@ -113,7 +113,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
}
});
- result.unwrap_or("".to_owned())
+ DOMString(result.unwrap_or(String::new()))
}
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-getpropertyvalue
@@ -153,7 +153,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
// Step 3 & 4
let result = match owner.get_inline_style_declaration(&property) {
- Some(declaration) => declaration.value(),
+ Some(declaration) => DOMString(declaration.value()),
None => DOMString::new(),
};
result
@@ -170,15 +170,15 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
if let Some(longhand_properties) = longhand_properties {
// Step 2.1 & 2.2 & 2.3
if longhand_properties.iter()
- .map(|&longhand| self.GetPropertyPriority(longhand.to_owned()))
+ .map(|&longhand| self.GetPropertyPriority(DOMString(longhand.to_owned())))
.all(|priority| priority == "important") {
- return "important".to_owned();
+ return DOMString("important".to_owned());
}
// Step 3
} else {
if self.owner.get_important_inline_style_declaration(&property).is_some() {
- return "important".to_owned();
+ return DOMString("important".to_owned());
}
}
@@ -309,12 +309,12 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-cssfloat
fn CssFloat(&self) -> DOMString {
- self.GetPropertyValue("float".to_owned())
+ self.GetPropertyValue(DOMString("float".to_owned()))
}
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-cssfloat
fn SetCssFloat(&self, value: DOMString) -> ErrorResult {
- self.SetPropertyValue("float".to_owned(), value)
+ self.SetPropertyValue(DOMString("float".to_owned()), value)
}
// https://dev.w3.org/csswg/cssom/#the-cssstyledeclaration-interface
diff --git a/components/script/dom/dedicatedworkerglobalscope.rs b/components/script/dom/dedicatedworkerglobalscope.rs
index 598654e7ab9..2acbb13e7d6 100644
--- a/components/script/dom/dedicatedworkerglobalscope.rs
+++ b/components/script/dom/dedicatedworkerglobalscope.rs
@@ -35,6 +35,7 @@ use std::mem::replace;
use std::rc::Rc;
use std::sync::mpsc::{Receiver, RecvError, Select, Sender, channel};
use url::Url;
+use util::str::DOMString;
use util::task::spawn_named;
use util::task_state;
use util::task_state::{IN_WORKER, SCRIPT};
@@ -263,7 +264,7 @@ impl DedicatedWorkerGlobalScope {
{
let _ar = AutoWorkerReset::new(global.r(), worker);
- scope.execute_script(source);
+ scope.execute_script(DOMString(source));
}
let reporter_name = format!("worker-reporter-{}", random::<u64>());
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 7a6b569897e..90e5697dd33 100644
--- a/components/script/dom/document.rs
+++ b/components/script/dom/document.rs
@@ -123,7 +123,7 @@ pub struct Document {
implementation: MutNullableHeap<JS<DOMImplementation>>,
location: MutNullableHeap<JS<Location>>,
content_type: DOMString,
- last_modified: Option<DOMString>,
+ last_modified: Option<String>,
encoding_name: DOMRefCell<DOMString>,
is_html_document: bool,
url: Url,
@@ -494,7 +494,8 @@ impl Document {
pub fn set_ready_state(&self, state: DocumentReadyState) {
self.ready_state.set(state);
- let event = Event::new(GlobalRef::Window(&self.window), "readystatechange".to_owned(),
+ let event = Event::new(GlobalRef::Window(&self.window),
+ DOMString("readystatechange".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable);
let target = self.upcast::<EventTarget>();
@@ -552,7 +553,7 @@ impl Document {
/// Handles any updates when the document's title has changed.
pub fn title_changed(&self) {
// https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowsertitlechange
- self.trigger_mozbrowser_event(MozBrowserEvent::TitleChange(self.Title()));
+ self.trigger_mozbrowser_event(MozBrowserEvent::TitleChange(self.Title().0));
self.send_title_to_compositor();
}
@@ -561,7 +562,7 @@ impl Document {
pub fn send_title_to_compositor(&self) {
let window = self.window();
let compositor = window.compositor();
- compositor.send(ScriptToCompositorMsg::SetTitle(window.pipeline(), Some(self.Title()))).unwrap();
+ compositor.send(ScriptToCompositorMsg::SetTitle(window.pipeline(), Some(self.Title().0))).unwrap();
}
pub fn dirty_all_nodes(&self) {
@@ -615,7 +616,7 @@ impl Document {
let y = point.y as i32;
let clickCount = 1;
let event = MouseEvent::new(&self.window,
- mouse_event_type_string,
+ DOMString(mouse_event_type_string),
EventBubbles::Bubbles,
EventCancelable::Cancelable,
Some(&self.window),
@@ -653,7 +654,7 @@ impl Document {
let y = point.y.to_i32().unwrap_or(0);
let mouse_event = MouseEvent::new(&self.window,
- event_name,
+ DOMString(event_name),
EventBubbles::Bubbles,
EventCancelable::Cancelable,
Some(&self.window),
@@ -802,7 +803,7 @@ impl Document {
|t| t.Target() == target).cloned());
let event = TouchEvent::new(window,
- event_name.to_owned(),
+ DOMString(event_name.to_owned()),
EventBubbles::Bubbles,
EventCancelable::Cancelable,
Some(window),
@@ -843,16 +844,17 @@ impl Document {
let is_composing = false;
let is_repeating = state == KeyState::Repeated;
- let ev_type = match state {
+ let ev_type = DOMString(match state {
KeyState::Pressed | KeyState::Repeated => "keydown",
KeyState::Released => "keyup",
- }.to_owned();
+ }.to_owned());
let props = KeyboardEvent::key_properties(key, modifiers);
let keyevent = KeyboardEvent::new(&self.window, ev_type, true, true,
Some(&self.window), 0, Some(key),
- props.key_string.to_owned(), props.code.to_owned(),
+ DOMString(props.key_string.to_owned()),
+ DOMString(props.code.to_owned()),
props.location, is_repeating, is_composing,
ctrl, alt, shift, meta,
None, props.key_code);
@@ -863,9 +865,10 @@ impl Document {
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keys-cancelable-keys
if state != KeyState::Released && props.is_printable() && !prevented {
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keypress-event-order
- let event = KeyboardEvent::new(&self.window, "keypress".to_owned(),
+ let event = KeyboardEvent::new(&self.window, DOMString("keypress".to_owned()),
true, true, Some(&self.window), 0, Some(key),
- props.key_string.to_owned(), props.code.to_owned(),
+ DOMString(props.key_string.to_owned()),
+ DOMString(props.code.to_owned()),
props.location, is_repeating, is_composing,
ctrl, alt, shift, meta,
props.char_code, 0);
@@ -1176,7 +1179,8 @@ impl Document {
return;
}
self.domcontentloaded_dispatched.set(true);
- let event = Event::new(GlobalRef::Window(self.window()), "DOMContentLoaded".to_owned(),
+ let event = Event::new(GlobalRef::Window(self.window()),
+ DOMString("DOMContentLoaded".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable);
let doctarget = self.upcast::<EventTarget>();
@@ -1251,7 +1255,7 @@ impl Document {
url: Option<Url>,
is_html_document: IsHTMLDocument,
content_type: Option<DOMString>,
- last_modified: Option<DOMString>,
+ last_modified: Option<String>,
source: DocumentSource,
doc_loader: DocumentLoader) -> Document {
let url = url.unwrap_or_else(|| Url::parse("about:blank").unwrap());
@@ -1270,19 +1274,19 @@ impl Document {
location: Default::default(),
content_type: match content_type {
Some(string) => string,
- None => match is_html_document {
+ None => DOMString(match is_html_document {
// https://dom.spec.whatwg.org/#dom-domimplementation-createhtmldocument
IsHTMLDocument::HTMLDocument => "text/html".to_owned(),
// https://dom.spec.whatwg.org/#concept-document-content-type
IsHTMLDocument::NonHTMLDocument => "application/xml".to_owned()
- }
+ })
},
last_modified: last_modified,
url: url,
// https://dom.spec.whatwg.org/#concept-document-quirks
quirks_mode: Cell::new(NoQuirks),
// https://dom.spec.whatwg.org/#concept-document-encoding
- encoding_name: DOMRefCell::new("UTF-8".to_owned()),
+ encoding_name: DOMRefCell::new(DOMString("UTF-8".to_owned())),
is_html_document: is_html_document == IsHTMLDocument::HTMLDocument,
images: Default::default(),
embeds: Default::default(),
@@ -1329,7 +1333,7 @@ impl Document {
url: Option<Url>,
doctype: IsHTMLDocument,
content_type: Option<DOMString>,
- last_modified: Option<DOMString>,
+ last_modified: Option<String>,
source: DocumentSource,
doc_loader: DocumentLoader) -> Root<Document> {
let document = reflect_dom_object(box Document::new_inherited(window, url, doctype,
@@ -1416,7 +1420,7 @@ impl DocumentMethods for Document {
// https://dom.spec.whatwg.org/#dom-document-url
fn URL(&self) -> DOMString {
- self.url().serialize()
+ DOMString(self.url().serialize())
}
// https://html.spec.whatwg.org/multipage/#dom-document-activeelement
@@ -1458,10 +1462,10 @@ impl DocumentMethods for Document {
// https://dom.spec.whatwg.org/#dom-document-compatmode
fn CompatMode(&self) -> DOMString {
- match self.quirks_mode.get() {
+ DOMString(match self.quirks_mode.get() {
LimitedQuirks | NoQuirks => "CSS1Compat".to_owned(),
Quirks => "BackCompat".to_owned()
- }
+ })
}
// https://dom.spec.whatwg.org/#dom-document-characterset
@@ -1652,10 +1656,10 @@ impl DocumentMethods for Document {
// https://html.spec.whatwg.org/multipage/#dom-document-lastmodified
fn LastModified(&self) -> DOMString {
- match self.last_modified {
+ DOMString(match self.last_modified {
Some(ref t) => t.clone(),
None => time::now().strftime("%m/%d/%Y %H:%M:%S").unwrap().to_string(),
- }
+ })
}
// https://dom.spec.whatwg.org/#dom-document-createrange
@@ -1712,7 +1716,7 @@ impl DocumentMethods for Document {
Some(ref title) => {
// Steps 3-4.
let value = Node::collect_text_contents(title.children());
- str_join(split_html_space_chars(&value), " ")
+ DOMString(str_join(split_html_space_chars(&value), " "))
},
}
}
@@ -1979,7 +1983,7 @@ impl DocumentMethods for Document {
let (tx, rx) = ipc::channel().unwrap();
let _ = self.window.resource_task().send(GetCookiesForUrl((*url).clone(), tx, NonHTTP));
let cookies = rx.recv().unwrap();
- Ok(cookies.unwrap_or("".to_owned()))
+ Ok(DOMString(cookies.unwrap_or("".to_owned())))
}
// https://html.spec.whatwg.org/multipage/#dom-document-cookie
@@ -1989,7 +1993,7 @@ impl DocumentMethods for Document {
if !is_scheme_host_port_tuple(url) {
return Err(Error::Security);
}
- let _ = self.window.resource_task().send(SetCookiesForUrl((*url).clone(), cookie, NonHTTP));
+ let _ = self.window.resource_task().send(SetCookiesForUrl((*url).clone(), cookie.0, NonHTTP));
Ok(())
}
@@ -2139,7 +2143,7 @@ impl DocumentProgressHandler {
fn dispatch_load(&self) {
let document = self.addr.root();
let window = document.window();
- let event = Event::new(GlobalRef::Window(window), "load".to_owned(),
+ let event = Event::new(GlobalRef::Window(window), DOMString("load".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable);
let wintarget = window.upcast::<EventTarget>();
@@ -2151,7 +2155,7 @@ impl DocumentProgressHandler {
if let Some(frame_element) = browsing_context.frame_element() {
let frame_window = window_from_node(frame_element);
- let event = Event::new(GlobalRef::Window(frame_window.r()), "load".to_owned(),
+ let event = Event::new(GlobalRef::Window(frame_window.r()), DOMString("load".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable);
event.fire(frame_element.upcast());
diff --git a/components/script/dom/domexception.rs b/components/script/dom/domexception.rs
index 8bc3497f5c9..70b96e89325 100644
--- a/components/script/dom/domexception.rs
+++ b/components/script/dom/domexception.rs
@@ -70,7 +70,7 @@ impl DOMExceptionMethods for DOMException {
// https://heycam.github.io/webidl/#idl-DOMException-error-names
fn Name(&self) -> DOMString {
- format!("{:?}", self.code)
+ DOMString(format!("{:?}", self.code))
}
// https://heycam.github.io/webidl/#error-names
@@ -102,11 +102,11 @@ impl DOMExceptionMethods for DOMException {
DOMErrorName::EncodingError => "The encoding operation (either encoded or decoding) failed."
};
- message.to_owned()
+ DOMString(message.to_owned())
}
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-error.prototype.tostring
- fn Stringifier(&self) -> String {
- format!("{}: {}", self.Name(), self.Message())
+ fn Stringifier(&self) -> DOMString {
+ DOMString(format!("{}: {}", self.Name(), self.Message()))
}
}
diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs
index 80f0f89a654..8571584aea4 100644
--- a/components/script/dom/domimplementation.rs
+++ b/components/script/dom/domimplementation.rs
@@ -109,7 +109,7 @@ impl DOMImplementationMethods for DOMImplementation {
{
// Step 3.
let doc_node = doc.upcast::<Node>();
- let doc_type = DocumentType::new("html".to_owned(), None, None, doc.r());
+ let doc_type = DocumentType::new(DOMString("html".to_owned()), None, None, doc.r());
doc_node.AppendChild(doc_type.upcast()).unwrap();
}
@@ -117,13 +117,13 @@ impl DOMImplementationMethods for DOMImplementation {
// Step 4.
let doc_node = doc.upcast::<Node>();
let doc_html = Root::upcast::<Node>(
- HTMLHtmlElement::new("html".to_owned(), None, doc.r()));
+ HTMLHtmlElement::new(DOMString("html".to_owned()), None, doc.r()));
doc_node.AppendChild(&doc_html).expect("Appending failed");
{
// Step 5.
let doc_head = Root::upcast::<Node>(
- HTMLHeadElement::new("head".to_owned(), None, doc.r()));
+ HTMLHeadElement::new(DOMString("head".to_owned()), None, doc.r()));
doc_html.AppendChild(&doc_head).unwrap();
// Step 6.
@@ -132,7 +132,7 @@ impl DOMImplementationMethods for DOMImplementation {
Some(title_str) => {
// Step 6.1.
let doc_title = Root::upcast::<Node>(
- HTMLTitleElement::new("title".to_owned(), None, doc.r()));
+ HTMLTitleElement::new(DOMString("title".to_owned()), None, doc.r()));
doc_head.AppendChild(&doc_title).unwrap();
// Step 6.2.
@@ -143,7 +143,7 @@ impl DOMImplementationMethods for DOMImplementation {
}
// Step 7.
- let doc_body = HTMLBodyElement::new("body".to_owned(), None, doc.r());
+ let doc_body = HTMLBodyElement::new(DOMString("body".to_owned()), None, doc.r());
doc_html.AppendChild(doc_body.upcast()).unwrap();
}
diff --git a/components/script/dom/domparser.rs b/components/script/dom/domparser.rs
index b554c9082e3..386c2e1ab4a 100644
--- a/components/script/dom/domparser.rs
+++ b/components/script/dom/domparser.rs
@@ -50,7 +50,7 @@ impl DOMParserMethods for DOMParser {
ty: DOMParserBinding::SupportedType)
-> Fallible<Root<Document>> {
let url = self.window.get_url();
- let content_type = DOMParserBinding::SupportedTypeValues::strings[ty as usize].to_owned();
+ let content_type = DOMString(DOMParserBinding::SupportedTypeValues::strings[ty as usize].to_owned());
let doc = self.window.Document();
let doc = doc.r();
let loader = DocumentLoader::new(&*doc.loader());
diff --git a/components/script/dom/domtokenlist.rs b/components/script/dom/domtokenlist.rs
index 13210528905..65c1ca9f7f2 100644
--- a/components/script/dom/domtokenlist.rs
+++ b/components/script/dom/domtokenlist.rs
@@ -64,7 +64,7 @@ impl DOMTokenListMethods for DOMTokenList {
// https://dom.spec.whatwg.org/#dom-domtokenlist-item
fn Item(&self, index: u32) -> Option<DOMString> {
self.attribute().and_then(|attr| {
- attr.value().as_tokens().get(index as usize).map(|token| (**token).to_owned())
+ attr.value().as_tokens().get(index as usize).map(|token| DOMString((**token).to_owned()))
})
}
@@ -134,7 +134,7 @@ impl DOMTokenListMethods for DOMTokenList {
// https://dom.spec.whatwg.org/#stringification-behavior
fn Stringifier(&self) -> DOMString {
let tokenlist = self.element.get_tokenlist_attribute(&self.local_name);
- str_join(&tokenlist, "\x20")
+ DOMString(str_join(&tokenlist, "\x20"))
}
// check-tidy: no specs after this line
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 447658e4660..7d605ecd133 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -775,7 +775,7 @@ impl Element {
traversal_scope: traversal_scope,
.. Default::default()
}) {
- Ok(()) => Ok(String::from_utf8(writer).unwrap()),
+ Ok(()) => Ok(DOMString(String::from_utf8(writer).unwrap())),
Err(_) => panic!("Cannot serialize element"),
}
}
@@ -1030,10 +1030,10 @@ impl Element {
let base = doc.url();
// https://html.spec.whatwg.org/multipage/#reflect
// XXXManishearth this doesn't handle `javascript:` urls properly
- match UrlParser::new().base_url(&base).parse(&url) {
+ DOMString(match UrlParser::new().base_url(&base).parse(&url) {
Ok(parsed) => parsed.serialize(),
Err(_) => "".to_owned()
- }
+ })
}
pub fn set_url_attribute(&self, local_name: &Atom, value: DOMString) {
self.set_string_attribute(local_name, value);
@@ -1087,7 +1087,7 @@ impl Element {
}
pub fn set_uint_attribute(&self, local_name: &Atom, value: u32) {
assert!(&**local_name == local_name.to_ascii_lowercase());
- self.set_attribute(local_name, AttrValue::UInt(value.to_string(), value));
+ self.set_attribute(local_name, AttrValue::UInt(DOMString(value.to_string()), value));
}
}
@@ -1099,7 +1099,7 @@ impl ElementMethods for Element {
// https://dom.spec.whatwg.org/#dom-element-localname
fn LocalName(&self) -> DOMString {
- (*self.local_name).to_owned()
+ DOMString((*self.local_name).to_owned())
}
// https://dom.spec.whatwg.org/#dom-element-prefix
@@ -1115,11 +1115,11 @@ impl ElementMethods for Element {
},
None => Cow::Borrowed(&*self.local_name)
};
- if self.html_element_in_html_document() {
+ DOMString(if self.html_element_in_html_document() {
qualified_name.to_ascii_uppercase()
} else {
qualified_name.into_owned()
- }
+ })
}
// https://dom.spec.whatwg.org/#dom-element-id
diff --git a/components/script/dom/event.rs b/components/script/dom/event.rs
index 8f2cf49182c..0b0b3ce6028 100644
--- a/components/script/dom/event.rs
+++ b/components/script/dom/event.rs
@@ -169,7 +169,7 @@ impl EventMethods for Event {
// https://dom.spec.whatwg.org/#dom-event-type
fn Type(&self) -> DOMString {
- (*self.type_()).to_owned()
+ DOMString((*self.type_()).to_owned())
}
// https://dom.spec.whatwg.org/#dom-event-target
diff --git a/components/script/dom/filereader.rs b/components/script/dom/filereader.rs
index e01c91def32..55e49ec610f 100644
--- a/components/script/dom/filereader.rs
+++ b/components/script/dom/filereader.rs
@@ -228,7 +228,7 @@ impl FileReader {
let convert = blob_bytes;
// Step 7
let output = enc.decode(convert, DecoderTrap::Replace).unwrap();
- output
+ DOMString(output)
}
//https://w3c.github.io/FileAPI/#dfn-readAsDataURL
@@ -248,7 +248,7 @@ impl FileReader {
format!("data:{};base64,{}", data.blobtype, base64)
};
- output
+ DOMString(output)
}
}
@@ -319,11 +319,11 @@ impl FileReaderMethods for FileReader {
impl FileReader {
- fn dispatch_progress_event(&self, type_: DOMString, loaded: u64, total: Option<u64>) {
+ fn dispatch_progress_event(&self, type_: String, loaded: u64, total: Option<u64>) {
let global = self.global.root();
let progressevent = ProgressEvent::new(global.r(),
- type_, EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
+ DOMString(type_), EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
total.is_some(), loaded, total.unwrap_or(0));
progressevent.upcast::<Event>().fire(self.upcast());
}
diff --git a/components/script/dom/formdata.rs b/components/script/dom/formdata.rs
index d37bbbc738e..7736051fe16 100644
--- a/components/script/dom/formdata.rs
+++ b/components/script/dom/formdata.rs
@@ -117,7 +117,7 @@ impl FormData {
fn get_file_from_blob(&self, value: &Blob, filename: Option<DOMString>) -> Root<File> {
let global = self.global.root();
let f = value.downcast::<File>();
- let name = filename.unwrap_or(f.map(|inner| inner.name().clone()).unwrap_or("blob".to_owned()));
+ let name = filename.unwrap_or(f.map(|inner| inner.name().clone()).unwrap_or(DOMString("blob".to_owned())));
File::new(global.r(), value, name)
}
}
diff --git a/components/script/dom/htmlanchorelement.rs b/components/script/dom/htmlanchorelement.rs
index 5848428aec0..81c2ecb102f 100644
--- a/components/script/dom/htmlanchorelement.rs
+++ b/components/script/dom/htmlanchorelement.rs
@@ -170,7 +170,7 @@ impl Activatable for HTMLAnchorElement {
}
/// https://html.spec.whatwg.org/multipage/#following-hyperlinks-2
-fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<DOMString>) {
+fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<String>) {
// Step 1: replace.
// Step 2: source browsing context.
// Step 3: target browsing context.
@@ -182,7 +182,7 @@ fn follow_hyperlink(subject: &Element, hyperlink_suffix: Option<DOMString>) {
// Step 6.
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=28925
if let Some(suffix) = hyperlink_suffix {
- href.push_str(&suffix);
+ href.0.push_str(&suffix);
}
// Step 4-5.
diff --git a/components/script/dom/htmlbodyelement.rs b/components/script/dom/htmlbodyelement.rs
index 4ade3caf3ed..5e266646a1c 100644
--- a/components/script/dom/htmlbodyelement.rs
+++ b/components/script/dom/htmlbodyelement.rs
@@ -181,7 +181,7 @@ impl VirtualMethods for HTMLBodyElement {
};
evtarget.set_event_handler_uncompiled(cx, url, reflector,
&name[2..],
- (**attr.value()).to_owned());
+ DOMString((**attr.value()).to_owned()));
},
_ => {}
}
diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs
index 3bd97e01637..01161241a16 100644
--- a/components/script/dom/htmlbuttonelement.rs
+++ b/components/script/dom/htmlbuttonelement.rs
@@ -226,7 +226,7 @@ impl<'a> Activatable for &'a HTMLButtonElement {
if owner.is_none() || self.upcast::<Element>().click_in_progress() {
return;
}
- node.query_selector_iter("button[type=submit]".to_owned()).unwrap()
+ node.query_selector_iter(DOMString("button[type=submit]".to_owned())).unwrap()
.filter_map(Root::downcast::<HTMLButtonElement>)
.find(|r| r.form_owner() == owner)
.map(|s| s.r().synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey));
diff --git a/components/script/dom/htmlcanvaselement.rs b/components/script/dom/htmlcanvaselement.rs
index 786ce9eaa16..95e3476f757 100644
--- a/components/script/dom/htmlcanvaselement.rs
+++ b/components/script/dom/htmlcanvaselement.rs
@@ -264,7 +264,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
// Step 2.
if self.Width() == 0 || self.Height() == 0 {
- return Ok("data:,".to_owned());
+ return Ok(DOMString("data:,".to_owned()));
}
// Step 3.
@@ -285,7 +285,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
}
let encoded = encoded.to_base64(STANDARD);
- Ok(format!("data:{};base64,{}", mime_type, encoded))
+ Ok(DOMString(format!("data:{};base64,{}", mime_type, encoded)))
} else {
Err(Error::NotSupported)
}
diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs
index d2727b851f2..84198d29d95 100644
--- a/components/script/dom/htmlelement.rs
+++ b/components/script/dom/htmlelement.rs
@@ -274,7 +274,7 @@ fn to_snake_case(name: DOMString) -> DOMString {
attr_name.push(ch);
}
}
- attr_name
+ DOMString(attr_name)
}
@@ -313,7 +313,7 @@ fn to_camel_case(name: &str) -> Option<DOMString> {
result.push(curr_char);
}
}
- Some(result)
+ Some(DOMString(result))
}
impl HTMLElement {
@@ -329,7 +329,7 @@ impl HTMLElement {
pub fn get_custom_attr(&self, local_name: DOMString) -> Option<DOMString> {
let local_name = Atom::from_slice(&to_snake_case(local_name));
self.upcast::<Element>().get_attribute(&ns!(""), &local_name).map(|attr| {
- (**attr.value()).to_owned()
+ DOMString((**attr.value()).to_owned())
})
}
@@ -422,7 +422,7 @@ impl VirtualMethods for HTMLElement {
let evtarget = self.upcast::<EventTarget>();
evtarget.set_event_handler_uncompiled(cx, url, reflector,
&name[2..],
- (**attr.value()).to_owned());
+ DOMString((**attr.value()).to_owned()));
},
_ => {}
}
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index 0f28260d970..debf3e4b20e 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -159,7 +159,7 @@ impl HTMLFormElement {
// TODO: Handle browsing contexts
// TODO: Handle validation
let event = Event::new(GlobalRef::Window(win.r()),
- "submit".to_owned(),
+ DOMString("submit".to_owned()),
EventBubbles::Bubbles,
EventCancelable::Cancelable);
event.fire(self.upcast());
@@ -171,7 +171,7 @@ impl HTMLFormElement {
// Step 7-8
let mut action = submitter.action();
if action.is_empty() {
- action = base.serialize();
+ action = DOMString(base.serialize());
}
// TODO: Resolve the url relative to the submitter element
// Step 10-15
@@ -283,7 +283,7 @@ impl HTMLFormElement {
if prev == '\r' {
buf.push('\n');
}
- buf
+ DOMString(buf)
}
let mut ret = self.get_unclean_dataset(submitter);
@@ -311,7 +311,7 @@ impl HTMLFormElement {
let win = window_from_node(self);
let event = Event::new(GlobalRef::Window(win.r()),
- "reset".to_owned(),
+ DOMString("reset".to_owned()),
EventBubbles::Bubbles,
EventCancelable::Cancelable);
event.fire(self.upcast());
diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs
index 4c5d4c2b750..37564d22e54 100644
--- a/components/script/dom/htmliframeelement.rs
+++ b/components/script/dom/htmliframeelement.rs
@@ -144,7 +144,7 @@ impl HTMLIFrameElement {
let mut detail = RootedValue::new(cx, UndefinedValue());
event.detail().to_jsval(cx, detail.handle_mut());
let custom_event = CustomEvent::new(GlobalRef::Window(window.r()),
- event.name().to_owned(),
+ DOMString(event.name().to_owned()),
true,
true,
detail.handle());
diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs
index c446034a299..098938c8285 100644
--- a/components/script/dom/htmlimageelement.rs
+++ b/components/script/dom/htmlimageelement.rs
@@ -79,7 +79,7 @@ impl Runnable for ImageResponseHandlerRunnable {
// Fire image.onload
let window = window_from_node(document.r());
let event = Event::new(GlobalRef::Window(window.r()),
- "load".to_owned(),
+ DOMString("load".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable);
event.fire(element.upcast());
@@ -146,7 +146,7 @@ impl HTMLImageElement {
width: Option<u32>,
height: Option<u32>) -> Fallible<Root<HTMLImageElement>> {
let document = global.as_window().Document();
- let image = HTMLImageElement::new("img".to_owned(), None, document.r());
+ let image = HTMLImageElement::new(DOMString("img".to_owned()), None, document.r());
if let Some(w) = width {
image.SetWidth(w);
}
@@ -292,7 +292,7 @@ impl VirtualMethods for HTMLImageElement {
match attr.local_name() {
&atom!(src) => {
self.update_image(mutation.new_value(attr).map(|value| {
- ((**value).to_owned(), window_from_node(self).get_url())
+ (DOMString((**value).to_owned()), window_from_node(self).get_url())
}));
},
_ => {},
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index daa7fbde84b..640df12d01c 100644
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -131,7 +131,7 @@ impl HTMLInputElement {
pub trait LayoutHTMLInputElementHelpers {
#[allow(unsafe_code)]
- unsafe fn get_value_for_layout(self) -> String;
+ unsafe fn get_value_for_layout(self) -> DOMString;
#[allow(unsafe_code)]
unsafe fn get_size_for_layout(self) -> u32;
#[allow(unsafe_code)]
@@ -143,35 +143,37 @@ pub trait LayoutHTMLInputElementHelpers {
}
#[allow(unsafe_code)]
-unsafe fn get_raw_textinput_value(input: LayoutJS<HTMLInputElement>) -> String {
+unsafe fn get_raw_textinput_value(input: LayoutJS<HTMLInputElement>) -> DOMString {
let textinput = (*input.unsafe_get()).textinput.borrow_for_layout().get_content();
if !textinput.is_empty() {
textinput
} else {
- (*input.unsafe_get()).placeholder.borrow_for_layout().to_owned()
+ (*input.unsafe_get()).placeholder.borrow_for_layout().clone()
}
}
impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
#[allow(unsafe_code)]
- unsafe fn get_value_for_layout(self) -> String {
+ unsafe fn get_value_for_layout(self) -> DOMString {
#[allow(unsafe_code)]
- unsafe fn get_raw_attr_value(input: LayoutJS<HTMLInputElement>) -> Option<String> {
+ unsafe fn get_raw_attr_value(input: LayoutJS<HTMLInputElement>, default: &str) -> DOMString {
let elem = input.upcast::<Element>();
- (*elem.unsafe_get()).get_attr_val_for_layout(&ns!(""), &atom!("value"))
- .map(|s| s.to_owned())
+ let value = (*elem.unsafe_get())
+ .get_attr_val_for_layout(&ns!(""), &atom!("value"))
+ .unwrap_or(default);
+ DOMString(value.to_owned())
}
match (*self.unsafe_get()).input_type.get() {
- InputType::InputCheckbox | InputType::InputRadio => "".to_owned(),
- InputType::InputFile | InputType::InputImage => "".to_owned(),
- InputType::InputButton => get_raw_attr_value(self).unwrap_or_else(|| "".to_owned()),
- InputType::InputSubmit => get_raw_attr_value(self).unwrap_or_else(|| DEFAULT_SUBMIT_VALUE.to_owned()),
- InputType::InputReset => get_raw_attr_value(self).unwrap_or_else(|| DEFAULT_RESET_VALUE.to_owned()),
+ InputType::InputCheckbox | InputType::InputRadio => DOMString::new(),
+ InputType::InputFile | InputType::InputImage => DOMString::new(),
+ InputType::InputButton => get_raw_attr_value(self, ""),
+ InputType::InputSubmit => get_raw_attr_value(self, DEFAULT_SUBMIT_VALUE),
+ InputType::InputReset => get_raw_attr_value(self, DEFAULT_RESET_VALUE),
InputType::InputPassword => {
let raw = get_raw_textinput_value(self);
// The implementation of get_insertion_point_index_for_layout expects a 1:1 mapping of chars.
- raw.chars().map(|_| '●').collect()
+ DOMString(raw.chars().map(|_| '●').collect())
}
_ => get_raw_textinput_value(self),
}
@@ -363,7 +365,7 @@ fn broadcast_radio_checked(broadcaster: &HTMLInputElement, group: Option<&Atom>)
// This function is a workaround for lifetime constraint difficulties.
fn do_broadcast(doc_node: &Node, broadcaster: &HTMLInputElement,
owner: Option<&HTMLFormElement>, group: Option<&Atom>) {
- let iter = doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap()
+ let iter = doc_node.query_selector_iter(DOMString("input[type=radio]".to_owned())).unwrap()
.filter_map(Root::downcast::<HTMLInputElement>)
.filter(|r| in_same_group(r.r(), owner, group) && broadcaster != r.r());
for ref r in iter {
@@ -426,9 +428,9 @@ impl HTMLInputElement {
}
let mut value = self.Value();
- if ty == "radio" || ty == "checkbox" {
+ if &*ty == "radio" || &*ty == "checkbox" {
if value.is_empty() {
- value = "on".to_owned();
+ value = DOMString("on".to_owned());
}
}
Some(FormDatum {
@@ -560,8 +562,8 @@ impl VirtualMethods for HTMLInputElement {
},
&atom!(value) if !self.value_changed.get() => {
let value = mutation.new_value(attr).map(|value| (**value).to_owned());
- self.textinput.borrow_mut().set_content(
- value.unwrap_or_else(|| "".to_owned()));
+ self.textinput.borrow_mut().set_content(DOMString(
+ value.unwrap_or_else(|| "".to_owned())));
},
&atom!(name) if self.input_type.get() == InputType::InputRadio => {
self.radio_group_updated(
@@ -569,9 +571,9 @@ impl VirtualMethods for HTMLInputElement {
},
&atom!(placeholder) => {
let mut placeholder = self.placeholder.borrow_mut();
- placeholder.clear();
+ placeholder.0.clear();
if let AttributeMutation::Set(_) = mutation {
- placeholder.extend(
+ placeholder.0.extend(
attr.value().chars().filter(|&c| c != '\n' && c != '\r'));
}
},
@@ -708,7 +710,8 @@ impl Activatable for HTMLInputElement {
let group = self.get_radio_group_name();;
// Safe since we only manipulate the DOM tree after finding an element
- let checked_member = doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap()
+ let checked_member = doc_node.query_selector_iter(DOMString("input[type=radio]".to_owned()))
+ .unwrap()
.filter_map(Root::downcast::<HTMLInputElement>)
.find(|r| {
in_same_group(r.r(), owner.r(), group.as_ref()) &&
@@ -809,13 +812,13 @@ impl Activatable for HTMLInputElement {
let target = self.upcast();
let event = Event::new(GlobalRef::Window(win.r()),
- "input".to_owned(),
+ DOMString("input".to_owned()),
EventBubbles::Bubbles,
EventCancelable::NotCancelable);
event.fire(target);
let event = Event::new(GlobalRef::Window(win.r()),
- "change".to_owned(),
+ DOMString("change".to_owned()),
EventBubbles::Bubbles,
EventCancelable::NotCancelable);
event.fire(target);
@@ -840,7 +843,7 @@ impl Activatable for HTMLInputElement {
return;
}
let submit_button;
- submit_button = node.query_selector_iter("input[type=submit]".to_owned()).unwrap()
+ submit_button = node.query_selector_iter(DOMString("input[type=submit]".to_owned())).unwrap()
.filter_map(Root::downcast::<HTMLInputElement>)
.find(|r| r.form_owner() == owner);
match submit_button {
@@ -850,7 +853,7 @@ impl Activatable for HTMLInputElement {
}
}
None => {
- let inputs = node.query_selector_iter("input".to_owned()).unwrap()
+ let inputs = node.query_selector_iter(DOMString("input".to_owned())).unwrap()
.filter_map(Root::downcast::<HTMLInputElement>)
.filter(|input| {
input.form_owner() == owner && match &*input.Type() {
diff --git a/components/script/dom/htmllinkelement.rs b/components/script/dom/htmllinkelement.rs
index b3ab7d91f2f..6fd36f60074 100644
--- a/components/script/dom/htmllinkelement.rs
+++ b/components/script/dom/htmllinkelement.rs
@@ -261,7 +261,8 @@ impl StylesheetLoadResponder for StylesheetLoadDispatcher {
fn respond(self: Box<StylesheetLoadDispatcher>) {
let elem = self.elem.root();
let window = window_from_node(elem.r());
- let event = Event::new(GlobalRef::Window(window.r()), "load".to_owned(),
+ let event = Event::new(GlobalRef::Window(window.r()),
+ DOMString("load".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable);
event.fire(elem.upcast::<EventTarget>());
diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs
index 9db05875b91..39a153e6465 100644
--- a/components/script/dom/htmloptionelement.rs
+++ b/components/script/dom/htmloptionelement.rs
@@ -80,7 +80,7 @@ fn collect_text(element: &Element, value: &mut DOMString) {
for child in element.upcast::<Node>().children() {
if child.is::<Text>() {
let characterdata = child.downcast::<CharacterData>().unwrap();
- value.push_str(&characterdata.Data());
+ value.0.push_str(&characterdata.Data());
} else if let Some(element_child) = child.downcast() {
collect_text(element_child, value);
}
@@ -98,7 +98,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
fn Text(&self) -> DOMString {
let mut content = DOMString::new();
collect_text(self.upcast(), &mut content);
- str_join(split_html_space_chars(&content), " ")
+ DOMString(str_join(split_html_space_chars(&content), " "))
}
// https://html.spec.whatwg.org/multipage/#dom-option-text
diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs
index bd3fdc5fff7..7822fea99e9 100644
--- a/components/script/dom/htmlscriptelement.rs
+++ b/components/script/dom/htmlscriptelement.rs
@@ -120,7 +120,7 @@ static SCRIPT_JS_MIMES: StaticStringVec = &[
#[derive(HeapSizeOf, JSTraceable)]
pub enum ScriptOrigin {
- Internal(String, Url),
+ Internal(DOMString, Url),
External(Result<(Metadata, Vec<u8>), String>),
}
@@ -401,7 +401,8 @@ impl HTMLScriptElement {
// TODO: Otherwise, decode the file to Unicode, using character
// encoding as the fallback encoding.
- (UTF_8.decode(&*bytes, DecoderTrap::Replace).unwrap(), true,
+ (DOMString(UTF_8.decode(&*bytes, DecoderTrap::Replace).unwrap()),
+ true,
metadata.final_url)
},
@@ -542,13 +543,13 @@ impl HTMLScriptElement {
}
fn dispatch_event(&self,
- type_: DOMString,
+ type_: String,
bubbles: EventBubbles,
cancelable: EventCancelable) -> bool {
let window = window_from_node(self);
let window = window.r();
let event = Event::new(GlobalRef::Window(window),
- type_,
+ DOMString(type_),
bubbles,
cancelable);
event.fire(self.upcast())
diff --git a/components/script/dom/htmlselectelement.rs b/components/script/dom/htmlselectelement.rs
index faca0d999ad..f47e225f76c 100644
--- a/components/script/dom/htmlselectelement.rs
+++ b/components/script/dom/htmlselectelement.rs
@@ -153,11 +153,11 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
// https://html.spec.whatwg.org/multipage/#dom-select-type
fn Type(&self) -> DOMString {
- if self.Multiple() {
- "select-multiple".to_owned()
+ DOMString(if self.Multiple() {
+ "select-multiple"
} else {
- "select-one".to_owned()
- }
+ "select-one"
+ }.to_owned())
}
// https://html.spec.whatwg.org/multipage/#dom-lfe-labels
diff --git a/components/script/dom/htmltableelement.rs b/components/script/dom/htmltableelement.rs
index 2ad152c65ef..259104ae09c 100644
--- a/components/script/dom/htmltableelement.rs
+++ b/components/script/dom/htmltableelement.rs
@@ -73,7 +73,7 @@ impl HTMLTableElementMethods for HTMLTableElement {
let caption = match self.GetCaption() {
Some(caption) => caption,
None => {
- let caption = HTMLTableCaptionElement::new("caption".to_owned(),
+ let caption = HTMLTableCaptionElement::new(DOMString("caption".to_owned()),
None,
document_from_node(self).r());
self.SetCaption(Some(caption.r()));
@@ -92,7 +92,7 @@ impl HTMLTableElementMethods for HTMLTableElement {
// https://html.spec.whatwg.org/multipage/#dom-table-createtbody
fn CreateTBody(&self) -> Root<HTMLTableSectionElement> {
- let tbody = HTMLTableSectionElement::new("tbody".to_owned(),
+ let tbody = HTMLTableSectionElement::new(DOMString("tbody".to_owned()),
None,
document_from_node(self).r());
let node = self.upcast::<Node>();
diff --git a/components/script/dom/htmltablerowelement.rs b/components/script/dom/htmltablerowelement.rs
index 224252d3506..aa14c9064a0 100644
--- a/components/script/dom/htmltablerowelement.rs
+++ b/components/script/dom/htmltablerowelement.rs
@@ -82,7 +82,7 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
node.insert_cell_or_row(
index,
|| self.Cells(),
- || HTMLTableDataCellElement::new("td".to_owned(), None, node.owner_doc().r()))
+ || HTMLTableDataCellElement::new(DOMString("td".to_owned()), None, node.owner_doc().r()))
}
// https://html.spec.whatwg.org/multipage/#dom-tr-deletecell
diff --git a/components/script/dom/htmltablesectionelement.rs b/components/script/dom/htmltablesectionelement.rs
index af7bf7b9727..296d1c93dbe 100644
--- a/components/script/dom/htmltablesectionelement.rs
+++ b/components/script/dom/htmltablesectionelement.rs
@@ -67,7 +67,7 @@ impl HTMLTableSectionElementMethods for HTMLTableSectionElement {
node.insert_cell_or_row(
index,
|| self.Rows(),
- || HTMLTableRowElement::new("tr".to_owned(), None, node.owner_doc().r()))
+ || HTMLTableRowElement::new(DOMString("tr".to_owned()), None, node.owner_doc().r()))
}
// https://html.spec.whatwg.org/multipage/#dom-tbody-deleterow
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index fbb71031125..f9735e76c15 100644
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -63,7 +63,7 @@ impl LayoutHTMLTextAreaElementHelpers for LayoutJS<HTMLTextAreaElement> {
#[allow(unrooted_must_root)]
#[allow(unsafe_code)]
unsafe fn get_value_for_layout(self) -> String {
- (*self.unsafe_get()).textinput.borrow_for_layout().get_content()
+ (*self.unsafe_get()).textinput.borrow_for_layout().get_content().0
}
#[allow(unrooted_must_root)]
@@ -174,7 +174,7 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
// https://html.spec.whatwg.org/multipage/#dom-textarea-type
fn Type(&self) -> DOMString {
- "textarea".to_owned()
+ DOMString("textarea".to_owned())
}
// https://html.spec.whatwg.org/multipage/#dom-textarea-defaultvalue
@@ -238,7 +238,7 @@ impl HTMLTextAreaElement {
let window = window_from_node(self);
let window = window.r();
let event = Event::new(GlobalRef::Window(window),
- "input".to_owned(),
+ DOMString("input".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable);
diff --git a/components/script/dom/htmltitleelement.rs b/components/script/dom/htmltitleelement.rs
index f91a00ab739..98abf2e42a4 100644
--- a/components/script/dom/htmltitleelement.rs
+++ b/components/script/dom/htmltitleelement.rs
@@ -45,7 +45,7 @@ impl HTMLTitleElementMethods for HTMLTitleElement {
content.push_str(&text.upcast::<CharacterData>().data());
}
}
- content
+ DOMString(content)
}
// https://html.spec.whatwg.org/multipage/#dom-title-text
diff --git a/components/script/dom/location.rs b/components/script/dom/location.rs
index fa3cba5cf5c..6a4cc98543a 100644
--- a/components/script/dom/location.rs
+++ b/components/script/dom/location.rs
@@ -135,7 +135,7 @@ impl LocationMethods for Location {
// https://html.spec.whatwg.org/multipage/#dom-location-href
fn Stringifier(&self) -> DOMString {
- self.Href().0
+ DOMString(self.Href().0)
}
// https://html.spec.whatwg.org/multipage/#dom-location-search
diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs
index dd2842fe079..c41e100638c 100644
--- a/components/script/dom/macros.rs
+++ b/components/script/dom/macros.rs
@@ -84,7 +84,7 @@ macro_rules! make_url_or_base_getter(
let url = element.get_url_attribute(&Atom::from_slice($htmlname));
if url.is_empty() {
let window = window_from_node(self);
- window.get_url().serialize()
+ DOMString(window.get_url().serialize())
} else {
url
}
@@ -110,7 +110,7 @@ macro_rules! make_enumerated_getter(
// https://html.spec.whatwg.org/multipage/#attr-fs-method
match &*val {
$($choices)|+ => val,
- _ => $default.to_owned()
+ _ => DOMString($default.to_owned())
}
}
);
diff --git a/components/script/dom/messageevent.rs b/components/script/dom/messageevent.rs
index c418df4de3c..05acd3447ef 100644
--- a/components/script/dom/messageevent.rs
+++ b/components/script/dom/messageevent.rs
@@ -79,7 +79,7 @@ impl MessageEvent {
scope: GlobalRef,
message: HandleValue) {
let messageevent = MessageEvent::new(
- scope, "message".to_owned(), false, false, message,
+ scope, DOMString("message".to_owned()), false, false, message,
DOMString::new(), DOMString::new());
messageevent.upcast::<Event>().fire(target);
}
diff --git a/components/script/dom/namednodemap.rs b/components/script/dom/namednodemap.rs
index 3d6c3c4535c..8d9b3bb5627 100644
--- a/components/script/dom/namednodemap.rs
+++ b/components/script/dom/namednodemap.rs
@@ -89,7 +89,7 @@ impl NamedNodeMapMethods for NamedNodeMap {
// https://heycam.github.io/webidl/#dfn-supported-property-names
fn SupportedPropertyNames(&self) -> Vec<DOMString> {
self.owner.attrs().iter().map(|attr| {
- (**attr.name()).to_owned()
+ DOMString((**attr.name()).to_owned())
}).collect()
}
}
diff --git a/components/script/dom/navigatorinfo.rs b/components/script/dom/navigatorinfo.rs
index a4857c5ac39..324bda1cd11 100644
--- a/components/script/dom/navigatorinfo.rs
+++ b/components/script/dom/navigatorinfo.rs
@@ -7,7 +7,7 @@ use util::opts;
use util::str::DOMString;
pub fn Product() -> DOMString {
- "Gecko".to_owned()
+ DOMString("Gecko".to_owned())
}
pub fn TaintEnabled() -> bool {
@@ -15,32 +15,32 @@ pub fn TaintEnabled() -> bool {
}
pub fn AppName() -> DOMString {
- "Netscape".to_owned() // Like Gecko/Webkit
+ DOMString("Netscape".to_owned()) // Like Gecko/Webkit
}
pub fn AppCodeName() -> DOMString {
- "Mozilla".to_owned()
+ DOMString("Mozilla".to_owned())
}
#[cfg(target_os = "windows")]
pub fn Platform() -> DOMString {
- "Win32".to_owned()
+ DOMString("Win32".to_owned())
}
#[cfg(any(target_os = "android", target_os = "linux"))]
pub fn Platform() -> DOMString {
- "Linux".to_owned()
+ DOMString("Linux".to_owned())
}
#[cfg(target_os = "macos")]
pub fn Platform() -> DOMString {
- "Mac".to_owned()
+ DOMString("Mac".to_owned())
}
pub fn UserAgent() -> DOMString {
- opts::get().user_agent.clone()
+ DOMString(opts::get().user_agent.clone())
}
pub fn AppVersion() -> DOMString {
- "4.0".to_owned()
+ DOMString("4.0".to_owned())
}
diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs
index 6b5cf8be2f2..d65ce8bcba5 100644
--- a/components/script/dom/node.rs
+++ b/components/script/dom/node.rs
@@ -1676,7 +1676,7 @@ impl Node {
copy
}
- pub fn collect_text_contents<T: Iterator<Item=Root<Node>>>(iterator: T) -> String {
+ pub fn collect_text_contents<T: Iterator<Item=Root<Node>>>(iterator: T) -> DOMString {
let mut content = String::new();
for node in iterator {
match node.downcast::<Text>() {
@@ -1684,13 +1684,13 @@ impl Node {
None => (),
}
}
- content
+ DOMString(content)
}
pub fn namespace_to_string(namespace: Namespace) -> Option<DOMString> {
match namespace {
ns!("") => None,
- Namespace(ref ns) => Some((**ns).to_owned())
+ Namespace(ref ns) => Some(DOMString((**ns).to_owned()))
}
}
@@ -1786,16 +1786,16 @@ impl NodeMethods for Node {
NodeTypeId::Element(..) => {
self.downcast::<Element>().unwrap().TagName()
}
- NodeTypeId::CharacterData(CharacterDataTypeId::Text) => "#text".to_owned(),
+ NodeTypeId::CharacterData(CharacterDataTypeId::Text) => DOMString("#text".to_owned()),
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
self.downcast::<ProcessingInstruction>().unwrap().Target()
}
- NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => "#comment".to_owned(),
+ NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => DOMString("#comment".to_owned()),
NodeTypeId::DocumentType => {
self.downcast::<DocumentType>().unwrap().name().clone()
},
- NodeTypeId::DocumentFragment => "#document-fragment".to_owned(),
- NodeTypeId::Document => "#document".to_owned()
+ NodeTypeId::DocumentFragment => DOMString("#document-fragment".to_owned()),
+ NodeTypeId::Document => DOMString("#document".to_owned())
}
}
diff --git a/components/script/dom/servohtmlparser.rs b/components/script/dom/servohtmlparser.rs
index 6a0c89357c5..f1274108767 100644
--- a/components/script/dom/servohtmlparser.rs
+++ b/components/script/dom/servohtmlparser.rs
@@ -33,6 +33,7 @@ use script_task::{ScriptChan, ScriptTask};
use std::cell::Cell;
use std::default::Default;
use url::Url;
+use util::str::DOMString;
#[must_root]
#[derive(JSTraceable, HeapSizeOf)]
@@ -47,7 +48,7 @@ impl Sink {
match child {
NodeOrText::AppendNode(n) => Root::from_ref(&*n),
NodeOrText::AppendText(t) => {
- let text = Text::new(t.into(), &self.document);
+ let text = Text::new(DOMString(t.into()), &self.document);
Root::upcast(text)
}
}
diff --git a/components/script/dom/storage.rs b/components/script/dom/storage.rs
index 3bc14c44820..bfcc8fd067c 100644
--- a/components/script/dom/storage.rs
+++ b/components/script/dom/storage.rs
@@ -186,10 +186,10 @@ impl MainThreadRunnable for StorageEventRunnable {
let storage_event = StorageEvent::new(
global_ref,
- "storage".to_owned(),
+ DOMString("storage".to_owned()),
EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
this.key, this.old_value, this.new_value,
- ev_url.to_string(),
+ DOMString(ev_url.to_string()),
Some(storage)
);
diff --git a/components/script/dom/text.rs b/components/script/dom/text.rs
index 58b34f41b43..8fdf9dd8be6 100644
--- a/components/script/dom/text.rs
+++ b/components/script/dom/text.rs
@@ -86,7 +86,7 @@ impl TextMethods for Text {
let mut text = DOMString::new();
for ref node in nodes {
let cdata = node.downcast::<CharacterData>().unwrap();
- text.push_str(&cdata.data());
+ text.0.push_str(&cdata.data());
}
text
}
diff --git a/components/script/dom/textdecoder.rs b/components/script/dom/textdecoder.rs
index d4c49b490f8..899961963c5 100644
--- a/components/script/dom/textdecoder.rs
+++ b/components/script/dom/textdecoder.rs
@@ -72,7 +72,7 @@ impl TextDecoder {
impl TextDecoderMethods for TextDecoder {
// https://encoding.spec.whatwg.org/#dom-textdecoder-encoding
fn Encoding(&self) -> DOMString {
- self.encoding.whatwg_name().unwrap().to_owned()
+ DOMString(self.encoding.whatwg_name().unwrap().to_owned())
}
// https://encoding.spec.whatwg.org/#dom-textdecoder-fatal
diff --git a/components/script/dom/textencoder.rs b/components/script/dom/textencoder.rs
index 4e796699fc2..0181ec7c6e3 100644
--- a/components/script/dom/textencoder.rs
+++ b/components/script/dom/textencoder.rs
@@ -66,7 +66,7 @@ impl TextEncoder {
impl TextEncoderMethods for TextEncoder {
// https://encoding.spec.whatwg.org/#dom-textencoder-encoding
fn Encoding(&self) -> DOMString {
- self.encoder.name().to_owned()
+ DOMString(self.encoder.name().to_owned())
}
#[allow(unsafe_code)]
diff --git a/components/script/dom/url.rs b/components/script/dom/url.rs
index d4ed5b1bbed..b7a235dc741 100644
--- a/components/script/dom/url.rs
+++ b/components/script/dom/url.rs
@@ -188,7 +188,7 @@ impl URLMethods for URL {
// https://url.spec.whatwg.org/#dom-url-href
fn Stringifier(&self) -> DOMString {
- self.Href().0
+ DOMString(self.Href().0)
}
// https://url.spec.whatwg.org/#dom-url-username
diff --git a/components/script/dom/urlsearchparams.rs b/components/script/dom/urlsearchparams.rs
index ab5093f16fd..66591a6ffa1 100644
--- a/components/script/dom/urlsearchparams.rs
+++ b/components/script/dom/urlsearchparams.rs
@@ -119,7 +119,7 @@ impl URLSearchParamsMethods for URLSearchParams {
// https://url.spec.whatwg.org/#stringification-behavior
fn Stringifier(&self) -> DOMString {
- self.serialize(None)
+ DOMString(self.serialize(None))
}
}
diff --git a/components/script/dom/userscripts.rs b/components/script/dom/userscripts.rs
index ad03330bd7f..7a29b460840 100644
--- a/components/script/dom/userscripts.rs
+++ b/components/script/dom/userscripts.rs
@@ -13,6 +13,7 @@ use std::fs::read_dir;
use std::path::PathBuf;
use util::opts;
use util::resource_files::resources_dir_path;
+use util::str::DOMString;
pub fn load_script(head: &HTMLHeadElement) {
@@ -41,9 +42,9 @@ pub fn load_script(head: &HTMLHeadElement) {
Ok(ref s) if s.ends_with(".js") => "file://".to_owned() + &s[..],
_ => continue
};
- let new_script = doc.CreateElement("script".to_owned()).unwrap();
+ let new_script = doc.CreateElement(DOMString("script".to_owned())).unwrap();
let new_script = new_script.r();
- new_script.set_string_attribute(&atom!("src"), name);
+ new_script.set_string_attribute(&atom!("src"), DOMString(name));
node.InsertBefore(new_script.upcast(), first_child.r()).unwrap();
}
}
diff --git a/components/script/dom/webglactiveinfo.rs b/components/script/dom/webglactiveinfo.rs
index 3b069407f36..60597aee160 100644
--- a/components/script/dom/webglactiveinfo.rs
+++ b/components/script/dom/webglactiveinfo.rs
@@ -16,11 +16,11 @@ pub struct WebGLActiveInfo {
size: i32,
// NOTE: `ty` stands for `type`, which is a reserved keyword
ty: u32,
- name: String,
+ name: DOMString,
}
impl WebGLActiveInfo {
- fn new_inherited(size: i32, ty: u32, name: String) -> WebGLActiveInfo {
+ fn new_inherited(size: i32, ty: u32, name: DOMString) -> WebGLActiveInfo {
WebGLActiveInfo {
reflector_: Reflector::new(),
size: size,
@@ -29,7 +29,7 @@ impl WebGLActiveInfo {
}
}
- pub fn new(global: GlobalRef, size: i32, ty: u32, name: String) -> Root<WebGLActiveInfo> {
+ pub fn new(global: GlobalRef, size: i32, ty: u32, name: DOMString) -> Root<WebGLActiveInfo> {
reflect_dom_object(box WebGLActiveInfo::new_inherited(size, ty, name), global, WebGLActiveInfoBinding::Wrap)
}
}
diff --git a/components/script/dom/webglprogram.rs b/components/script/dom/webglprogram.rs
index 44958f358ba..2e8bc24e8b6 100644
--- a/components/script/dom/webglprogram.rs
+++ b/components/script/dom/webglprogram.rs
@@ -14,6 +14,7 @@ use dom::webglrenderingcontext::MAX_UNIFORM_AND_ATTRIBUTE_LEN;
use dom::webglshader::WebGLShader;
use ipc_channel::ipc::{self, IpcSender};
use std::cell::Cell;
+use util::str::DOMString;
#[dom_struct]
pub struct WebGLProgram {
@@ -94,7 +95,7 @@ impl WebGLProgram {
}
/// glGetAttribLocation
- pub fn get_attrib_location(&self, name: String) -> WebGLResult<Option<i32>> {
+ pub fn get_attrib_location(&self, name: DOMString) -> WebGLResult<Option<i32>> {
if name.len() > MAX_UNIFORM_AND_ATTRIBUTE_LEN {
return Err(WebGLError::InvalidValue);
}
@@ -105,12 +106,12 @@ impl WebGLProgram {
}
let (sender, receiver) = ipc::channel().unwrap();
- self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::GetAttribLocation(self.id, name, sender))).unwrap();
+ self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::GetAttribLocation(self.id, name.0, sender))).unwrap();
Ok(receiver.recv().unwrap())
}
/// glGetUniformLocation
- pub fn get_uniform_location(&self, name: String) -> WebGLResult<Option<i32>> {
+ pub fn get_uniform_location(&self, name: DOMString) -> WebGLResult<Option<i32>> {
if name.len() > MAX_UNIFORM_AND_ATTRIBUTE_LEN {
return Err(WebGLError::InvalidValue);
}
@@ -121,7 +122,7 @@ impl WebGLProgram {
}
let (sender, receiver) = ipc::channel().unwrap();
- self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::GetUniformLocation(self.id, name, sender))).unwrap();
+ self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::GetUniformLocation(self.id, name.0, sender))).unwrap();
Ok(receiver.recv().unwrap())
}
}
diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs
index d73e1185bb8..875f88628f4 100644
--- a/components/script/dom/webglrenderingcontext.rs
+++ b/components/script/dom/webglrenderingcontext.rs
@@ -118,10 +118,11 @@ impl WebGLRenderingContext {
WebGLRenderingContextBinding::Wrap)),
Err(msg) => {
error!("Couldn't create WebGLRenderingContext: {}", msg);
- let event = WebGLContextEvent::new(global, "webglcontextcreationerror".to_owned(),
+ let event = WebGLContextEvent::new(global,
+ DOMString("webglcontextcreationerror".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::Cancelable,
- msg);
+ DOMString(msg));
event.upcast::<Event>().fire(canvas.upcast());
None
}
@@ -622,7 +623,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
// https://www.khronos.org/registry/webgl/specs/latest/1.0/#5.14.9
fn GetShaderInfoLog(&self, shader: Option<&WebGLShader>) -> Option<DOMString> {
if let Some(shader) = shader {
- shader.info_log()
+ shader.info_log().map(DOMString)
} else {
None
}
diff --git a/components/script/dom/webglshader.rs b/components/script/dom/webglshader.rs
index 6a2e558974c..9d52030c56a 100644
--- a/components/script/dom/webglshader.rs
+++ b/components/script/dom/webglshader.rs
@@ -15,6 +15,7 @@ use dom::webglobject::WebGLObject;
use ipc_channel::ipc::{self, IpcSender};
use std::cell::Cell;
use std::sync::{ONCE_INIT, Once};
+use util::str::DOMString;
#[derive(Clone, Copy, PartialEq, Debug, JSTraceable, HeapSizeOf)]
pub enum ShaderCompilationStatus {
@@ -28,7 +29,7 @@ pub struct WebGLShader {
webgl_object: WebGLObject,
id: u32,
gl_type: u32,
- source: DOMRefCell<Option<String>>,
+ source: DOMRefCell<Option<DOMString>>,
info_log: DOMRefCell<Option<String>>,
is_deleted: Cell<bool>,
compilation_status: Cell<ShaderCompilationStatus>,
@@ -144,12 +145,12 @@ impl WebGLShader {
}
/// Get the shader source
- pub fn source(&self) -> Option<String> {
+ pub fn source(&self) -> Option<DOMString> {
self.source.borrow().clone()
}
/// glShaderSource
- pub fn set_source(&self, source: String) {
+ pub fn set_source(&self, source: DOMString) {
*self.source.borrow_mut() = Some(source);
}
}
diff --git a/components/script/dom/websocket.rs b/components/script/dom/websocket.rs
index 7c5101eaf75..eb010902b40 100644
--- a/components/script/dom/websocket.rs
+++ b/components/script/dom/websocket.rs
@@ -139,7 +139,7 @@ pub struct WebSocket {
full: Cell<bool>, //Flag to tell if websocket queue is full
clean_close: Cell<bool>, //Flag to tell if the websocket closed cleanly (not due to full or fail)
code: Cell<u16>, //Closing code
- reason: DOMRefCell<DOMString>, //Closing reason
+ reason: DOMRefCell<String>, //Closing reason
binary_type: Cell<BinaryType>,
}
@@ -309,7 +309,7 @@ impl WebSocketMethods for WebSocket {
// https://html.spec.whatwg.org/multipage/#dom-websocket-url
fn Url(&self) -> DOMString {
- self.url.serialize()
+ DOMString(self.url.serialize())
}
// https://html.spec.whatwg.org/multipage/#dom-websocket-readystate
@@ -452,7 +452,7 @@ impl Runnable for ConnectionEstablishedTask {
// Step 6.
let global = ws.global.root();
- let event = Event::new(global.r(), "open".to_owned(),
+ let event = Event::new(global.r(), DOMString("open".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable);
event.fire(ws.upcast());
@@ -494,23 +494,22 @@ impl Runnable for CloseTask {
//A Bad close
ws.clean_close.set(false);
let event = Event::new(global.r(),
- "error".to_owned(),
+ DOMString("error".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::Cancelable);
event.fire(ws.upcast());
}
- let rsn = ws.reason.borrow();
- let rsn_clone = rsn.clone();
+ let reason = ws.reason.borrow().clone();
/*In addition, we also have to fire a close even if error event fired
https://html.spec.whatwg.org/multipage/#closeWebSocket
*/
let close_event = CloseEvent::new(global.r(),
- "close".to_owned(),
+ DOMString("close".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable,
ws.clean_close.get(),
ws.code.get(),
- rsn_clone);
+ DOMString(reason));
close_event.upcast::<Event>().fire(ws.upcast());
}
}
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 69ddff9430a..a5b9fa4d0e1 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -300,7 +300,7 @@ pub fn base64_btoa(input: DOMString) -> Fallible<DOMString> {
// "and then must apply the base64 algorithm to that sequence of
// octets, and return the result. [RFC4648]"
- Ok(octets.to_base64(STANDARD))
+ Ok(DOMString(octets.to_base64(STANDARD)))
}
}
@@ -347,7 +347,7 @@ pub fn base64_atob(input: DOMString) -> Fallible<DOMString> {
}
match input.from_base64() {
- Ok(data) => Ok(data.iter().map(|&b| b as char).collect::<String>()),
+ Ok(data) => Ok(DOMString(data.iter().map(|&b| b as char).collect::<String>())),
Err(..) => Err(Error::InvalidCharacter)
}
}
@@ -986,12 +986,12 @@ impl Window {
pub fn resolved_style_query(&self,
element: TrustedNodeAddress,
pseudo: Option<PseudoElement>,
- property: &Atom) -> Option<String> {
+ property: &Atom) -> Option<DOMString> {
self.reflow(ReflowGoal::ForScriptQuery,
ReflowQueryType::ResolvedStyleQuery(element, pseudo, property.clone()),
ReflowReason::Query);
let ResolvedStyleResponse(resolved) = self.layout_rpc.resolved_style();
- resolved
+ resolved.map(DOMString)
}
pub fn offset_parent_query(&self, node: TrustedNodeAddress) -> (Option<Root<Element>>, Rect<Au>) {
diff --git a/components/script/dom/worker.rs b/components/script/dom/worker.rs
index 6441828185c..2102b9b6969 100644
--- a/components/script/dom/worker.rs
+++ b/components/script/dom/worker.rs
@@ -85,7 +85,7 @@ impl Worker {
let pipeline_id = global.pipeline();
let title = format!("Worker for {}", worker_url);
let page_info = DevtoolsPageInfo {
- title: title,
+ title: DOMString(title),
url: worker_url.clone(),
};
chan.send(ScriptToDevtoolsControlMsg::NewGlobal((pipeline_id, Some(worker_id)),
@@ -129,7 +129,7 @@ impl Worker {
let worker = address.root();
let global = worker.r().global.root();
let event = Event::new(global.r(),
- "error".to_owned(),
+ DOMString("error".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable);
event.fire(worker.upcast());
@@ -140,7 +140,7 @@ impl Worker {
let worker = address.root();
let global = worker.r().global.root();
let error = RootedValue::new(global.r().get_cx(), UndefinedValue());
- let errorevent = ErrorEvent::new(global.r(), "error".to_owned(),
+ let errorevent = ErrorEvent::new(global.r(), DOMString("error".to_owned()),
EventBubbles::Bubbles, EventCancelable::Cancelable,
message, filename, lineno, colno, error.handle());
errorevent.upcast::<Event>().fire(worker.upcast());
diff --git a/components/script/dom/workerglobalscope.rs b/components/script/dom/workerglobalscope.rs
index f775c335f8c..f6e75c53394 100644
--- a/components/script/dom/workerglobalscope.rs
+++ b/components/script/dom/workerglobalscope.rs
@@ -289,7 +289,7 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
impl WorkerGlobalScope {
pub fn execute_script(&self, source: DOMString) {
match self.runtime.evaluate_script(
- self.reflector().get_jsobject(), source, self.worker_url.serialize(), 1) {
+ self.reflector().get_jsobject(), source.0, self.worker_url.serialize(), 1) {
Ok(_) => (),
Err(_) => {
// TODO: An error needs to be dispatched to the parent.
diff --git a/components/script/dom/workerlocation.rs b/components/script/dom/workerlocation.rs
index 92b8b8492a3..9e26ca4a70e 100644
--- a/components/script/dom/workerlocation.rs
+++ b/components/script/dom/workerlocation.rs
@@ -78,6 +78,6 @@ impl WorkerLocationMethods for WorkerLocation {
// https://html.spec.whatwg.org/multipage/#dom-workerlocation-href
fn Stringifier(&self) -> DOMString {
- self.Href().0
+ DOMString(self.Href().0)
}
}
diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs
index aa617abcb0c..10bc4cd8d57 100644
--- a/components/script/dom/xmlhttprequest.rs
+++ b/components/script/dom/xmlhttprequest.rs
@@ -707,10 +707,10 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
fn GetResponseText(&self) -> Fallible<DOMString> {
match self.response_type.get() {
_empty | Text => {
- match self.ready_state.get() {
- XMLHttpRequestState::Loading | XMLHttpRequestState::Done => Ok(self.text_response()),
- _ => Ok("".to_owned())
- }
+ Ok(DOMString(match self.ready_state.get() {
+ XMLHttpRequestState::Loading | XMLHttpRequestState::Done => self.text_response(),
+ _ => "".to_owned()
+ }))
},
_ => Err(Error::InvalidState)
}
@@ -731,7 +731,7 @@ impl XMLHttpRequest {
self.ready_state.set(rs);
let global = self.global.root();
let event = Event::new(global.r(),
- "readystatechange".to_owned(),
+ DOMString("readystatechange".to_owned()),
EventBubbles::DoesNotBubble,
EventCancelable::Cancelable);
event.fire(self.upcast());
@@ -910,10 +910,12 @@ impl XMLHttpRequest {
self.request_headers.borrow_mut().set_raw(name, vec![value.into_bytes()]);
}
- fn dispatch_progress_event(&self, upload: bool, type_: DOMString, loaded: u64, total: Option<u64>) {
+ fn dispatch_progress_event(&self, upload: bool, type_: String, loaded: u64, total: Option<u64>) {
let global = self.global.root();
let progressevent = ProgressEvent::new(global.r(),
- type_, EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
+ DOMString(type_),
+ EventBubbles::DoesNotBubble,
+ EventCancelable::NotCancelable,
total.is_some(), loaded,
total.unwrap_or(0));
let target = if upload {
@@ -924,14 +926,14 @@ impl XMLHttpRequest {
progressevent.upcast::<Event>().fire(target);
}
- fn dispatch_upload_progress_event(&self, type_: DOMString, partial_load: Option<u64>) {
+ fn dispatch_upload_progress_event(&self, type_: String, partial_load: Option<u64>) {
// If partial_load is None, loading has completed and we can just use the value from the request body
let total = self.request_body_len.get() as u64;
self.dispatch_progress_event(true, type_, partial_load.unwrap_or(total), Some(total));
}
- fn dispatch_response_progress_event(&self, type_: DOMString) {
+ fn dispatch_response_progress_event(&self, type_: String) {
let len = self.response.borrow().len() as u64;
let total = self.response_headers.borrow().get::<ContentLength>().map(|x| { **x as u64 });
self.dispatch_progress_event(false, type_, len, total);
@@ -985,7 +987,7 @@ impl XMLHttpRequest {
}
}
- fn text_response(&self) -> DOMString {
+ fn text_response(&self) -> String {
let mut encoding = UTF_8 as EncodingRef;
match self.response_headers.borrow().get() {
Some(&ContentType(mime::Mime(_, _, ref params))) => {
diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs
index 36062208400..10115b9a235 100644
--- a/components/script/parse/html.rs
+++ b/components/script/parse/html.rs
@@ -71,14 +71,14 @@ impl<'a> TreeSink for servohtmlparser::Sink {
ElementCreator::ParserCreated);
for attr in attrs {
- elem.set_attribute_from_parser(attr.name, attr.value.into(), None);
+ elem.set_attribute_from_parser(attr.name, DOMString(attr.value.into()), None);
}
JS::from_ref(elem.upcast())
}
fn create_comment(&mut self, text: StrTendril) -> JS<Node> {
- let comment = Comment::new(text.into(), &*self.document);
+ let comment = Comment::new(DOMString(text.into()), &*self.document);
JS::from_ref(comment.upcast())
}
@@ -115,7 +115,8 @@ impl<'a> TreeSink for servohtmlparser::Sink {
system_id: StrTendril) {
let doc = &*self.document;
let doctype = DocumentType::new(
- name.into(), Some(public_id.into()), Some(system_id.into()), doc);
+ DOMString(name.into()), Some(DOMString(public_id.into())),
+ Some(DOMString(system_id.into())), doc);
doc.upcast::<Node>().AppendChild(doctype.upcast()).expect("Appending failed");
}
@@ -123,7 +124,7 @@ impl<'a> TreeSink for servohtmlparser::Sink {
let elem = target.downcast::<Element>()
.expect("tried to set attrs on non-Element in HTML parsing");
for attr in attrs {
- elem.set_attribute_from_parser(attr.name, attr.value.into(), None);
+ elem.set_attribute_from_parser(attr.name, DOMString(attr.value.into()), None);
}
}
@@ -237,7 +238,7 @@ pub enum ParseContext<'a> {
}
pub fn parse_html(document: &Document,
- input: String,
+ input: DOMString,
url: Url,
context: ParseContext) {
let parser = match context {
@@ -246,7 +247,7 @@ pub fn parse_html(document: &Document,
ParseContext::Fragment(fc) =>
ServoHTMLParser::new_for_fragment(Some(url), document, fc),
};
- parser.parse_chunk(input.into());
+ parser.parse_chunk(input.0.into());
}
// https://html.spec.whatwg.org/multipage/#parsing-html-fragments
diff --git a/components/script/script_task.rs b/components/script/script_task.rs
index 5455c5868fa..ac67e4a5996 100644
--- a/components/script/script_task.rs
+++ b/components/script/script_task.rs
@@ -1603,13 +1603,13 @@ impl ScriptTask {
incomplete.parent_info,
incomplete.window_size);
- let last_modified: Option<DOMString> = metadata.headers.as_ref().and_then(|headers| {
+ let last_modified = metadata.headers.as_ref().and_then(|headers| {
headers.get().map(|&LastModified(HttpDate(ref tm))| dom_last_modified(tm))
});
let content_type = match metadata.content_type {
Some(ContentType(Mime(TopLevel::Text, SubLevel::Plain, _))) => {
- Some("text/plain".to_owned())
+ Some(DOMString("text/plain".to_owned()))
}
_ => None
};
@@ -1640,8 +1640,8 @@ impl ScriptTask {
let evalstr = incomplete.url.non_relative_scheme_data().unwrap();
let mut jsval = RootedValue::new(self.get_cx(), UndefinedValue());
window.evaluate_js_on_global_with_result(evalstr, jsval.handle_mut());
- let strval = FromJSValConvertible::from_jsval(self.get_cx(), jsval.handle(),
- StringificationBehavior::Empty);
+ let strval = DOMString::from_jsval(self.get_cx(), jsval.handle(),
+ StringificationBehavior::Empty);
strval.unwrap_or(DOMString::new())
} else {
DOMString::new()
@@ -1877,7 +1877,7 @@ impl ScriptTask {
// http://dev.w3.org/csswg/cssom-view/#resizing-viewports
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#event-type-resize
let uievent = UIEvent::new(window.r(),
- "resize".to_owned(), EventBubbles::DoesNotBubble,
+ DOMString("resize".to_owned()), EventBubbles::DoesNotBubble,
EventCancelable::NotCancelable, Some(window.r()),
0i32);
uievent.upcast::<Event>().fire(window.upcast());
diff --git a/components/script/textinput.rs b/components/script/textinput.rs
index ce69139d5ab..98b080fd1b8 100644
--- a/components/script/textinput.rs
+++ b/components/script/textinput.rs
@@ -137,7 +137,7 @@ impl<T: ClipboardProvider> TextInput<T> {
if self.selection_begin.is_none() {
self.selection_begin = Some(self.edit_point);
}
- self.replace_selection(s.into());
+ self.replace_selection(DOMString(s.into()));
}
pub fn get_sorted_selection(&self) -> Option<(TextPoint, TextPoint)> {
@@ -170,7 +170,7 @@ impl<T: ClipboardProvider> TextInput<T> {
})
}
- pub fn replace_selection(&mut self, insert: String) {
+ pub fn replace_selection(&mut self, insert: DOMString) {
if let Some((begin, end)) = self.get_sorted_selection() {
self.clear_selection();
@@ -181,20 +181,20 @@ impl<T: ClipboardProvider> TextInput<T> {
let lines_suffix = &self.lines[end.line + 1..];
let mut insert_lines = if self.multiline {
- insert.split('\n').map(|s| s.to_owned()).collect()
+ insert.split('\n').map(|s| DOMString(s.to_owned())).collect()
} else {
vec!(insert)
};
let mut new_line = prefix.to_owned();
new_line.push_str(&insert_lines[0]);
- insert_lines[0] = new_line;
+ insert_lines[0] = DOMString(new_line);
let last_insert_lines_index = insert_lines.len() - 1;
self.edit_point.index = insert_lines[last_insert_lines_index].len();
self.edit_point.line = begin.line + last_insert_lines_index;
- insert_lines[last_insert_lines_index].push_str(suffix);
+ insert_lines[last_insert_lines_index].0.push_str(suffix);
let mut new_lines = vec!();
new_lines.push_all(lines_prefix);
@@ -441,14 +441,14 @@ impl<T: ClipboardProvider> TextInput<T> {
content.push('\n');
}
}
- content
+ DOMString(content)
}
/// Set the current contents of the text input. If this is control supports multiple lines,
/// any \n encountered will be stripped and force a new logical line.
pub fn set_content(&mut self, content: DOMString) {
self.lines = if self.multiline {
- content.split('\n').map(|s| s.to_owned()).collect()
+ content.split('\n').map(|s| DOMString(s.to_owned())).collect()
} else {
vec!(content)
};
diff --git a/components/script/webdriver_handlers.rs b/components/script/webdriver_handlers.rs
index 6c74825af2d..3fcd6ef1d0c 100644
--- a/components/script/webdriver_handlers.rs
+++ b/components/script/webdriver_handlers.rs
@@ -24,6 +24,7 @@ use page::Page;
use script_task::get_page;
use std::rc::Rc;
use url::Url;
+use util::str::DOMString;
fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Option<Root<Node>> {
let page = get_page(&*page, pipeline);
@@ -48,9 +49,8 @@ pub fn jsval_to_webdriver(cx: *mut JSContext, val: HandleValue) -> WebDriverJSRe
Ok(WebDriverJSValue::Number(FromJSValConvertible::from_jsval(cx, val, ()).unwrap()))
} else if val.get().is_string() {
//FIXME: use jsstring_to_str when jsval grows to_jsstring
- Ok(
- WebDriverJSValue::String(
- FromJSValConvertible::from_jsval(cx, val, StringificationBehavior::Default).unwrap()))
+ let string: DOMString = FromJSValConvertible::from_jsval(cx, val, StringificationBehavior::Default).unwrap();
+ Ok(WebDriverJSValue::String(string.0))
} else if val.get().is_null() {
Ok(WebDriverJSValue::Null)
} else {
@@ -115,7 +115,7 @@ pub fn handle_get_frame_id(page: &Rc<Page>,
pub fn handle_find_element_css(page: &Rc<Page>, _pipeline: PipelineId, selector: String,
reply: IpcSender<Result<Option<String>, ()>>) {
- reply.send(match page.document().QuerySelector(selector) {
+ reply.send(match page.document().QuerySelector(DOMString(selector)) {
Ok(node) => {
Ok(node.map(|x| x.upcast::<Node>().get_unique_id()))
}
@@ -127,7 +127,7 @@ pub fn handle_find_elements_css(page: &Rc<Page>,
_pipeline: PipelineId,
selector: String,
reply: IpcSender<Result<Vec<String>, ()>>) {
- reply.send(match page.document().QuerySelectorAll(selector) {
+ reply.send(match page.document().QuerySelectorAll(DOMString(selector)) {
Ok(ref nodes) => {
let mut result = Vec::with_capacity(nodes.Length() as usize);
for i in 0..nodes.Length() {
@@ -151,7 +151,7 @@ pub fn handle_get_active_element(page: &Rc<Page>,
}
pub fn handle_get_title(page: &Rc<Page>, _pipeline: PipelineId, reply: IpcSender<String>) {
- reply.send(page.document().Title()).unwrap();
+ reply.send(page.document().Title().0).unwrap();
}
pub fn handle_get_text(page: &Rc<Page>,
@@ -160,7 +160,7 @@ pub fn handle_get_text(page: &Rc<Page>,
reply: IpcSender<Result<String, ()>>) {
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
Some(ref node) => {
- Ok(node.GetTextContent().unwrap_or("".to_owned()))
+ Ok(node.GetTextContent().map(|x| x.0).unwrap_or("".to_owned()))
},
None => Err(())
}).unwrap();
@@ -172,7 +172,7 @@ pub fn handle_get_name(page: &Rc<Page>,
reply: IpcSender<Result<String, ()>>) {
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
Some(node) => {
- Ok(node.downcast::<Element>().unwrap().TagName())
+ Ok(node.downcast::<Element>().unwrap().TagName().0)
},
None => Err(())
}).unwrap();