mirror of
https://github.com/servo/servo
synced 2026-05-05 06:32:13 +02:00
Implement USVString.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
//! | float | `f32` |
|
||||
//! | double | `f64` |
|
||||
//! | DOMString | `DOMString` |
|
||||
//! | USVString | `USVString` |
|
||||
//! | ByteString | `ByteString` |
|
||||
//! | object | `*mut JSObject` |
|
||||
//! | interface types | `JSRef<T>` | `Temporary<T>` |
|
||||
@@ -31,7 +32,7 @@
|
||||
|
||||
use dom::bindings::codegen::PrototypeList;
|
||||
use dom::bindings::js::{JSRef, Root, Unrooted};
|
||||
use dom::bindings::str::ByteString;
|
||||
use dom::bindings::str::{ByteString, USVString};
|
||||
use dom::bindings::utils::{Reflectable, Reflector, DOMClass};
|
||||
use util::str::DOMString;
|
||||
|
||||
@@ -339,6 +340,31 @@ impl FromJSValConvertible for DOMString {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToJSValConvertible for USVString {
|
||||
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||
self.0.to_jsval(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromJSValConvertible for USVString {
|
||||
type Config = ();
|
||||
fn from_jsval(cx: *mut JSContext, value: JSVal, _: ())
|
||||
-> Result<USVString, ()> {
|
||||
let jsstr = unsafe { JS_ValueToString(cx, value) };
|
||||
if jsstr.is_null() {
|
||||
debug!("JS_ValueToString failed");
|
||||
Err(())
|
||||
} else {
|
||||
unsafe {
|
||||
let mut length = 0;
|
||||
let chars = JS_GetStringCharsAndLength(cx, jsstr, &mut length);
|
||||
let char_vec = slice::from_raw_parts(chars, length as usize);
|
||||
Ok(USVString(String::from_utf16_lossy(char_vec)))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToJSValConvertible for ByteString {
|
||||
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||
unsafe {
|
||||
|
||||
Reference in New Issue
Block a user