mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
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.
This commit is contained in:
parent
e6aa976462
commit
6b75078503
83 changed files with 393 additions and 297 deletions
|
@ -430,6 +430,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) {
|
||||
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue