mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
parent
9a9ca45084
commit
2d83e5a788
6 changed files with 207 additions and 7 deletions
|
@ -44,6 +44,7 @@ pub use js::conversions::ConversionBehavior;
|
|||
use js::conversions::latin1_to_string;
|
||||
use js::error::throw_type_error;
|
||||
use js::glue::{GetProxyPrivate, IsWrapper};
|
||||
use js::glue::{RUST_JSID_IS_INT, RUST_JSID_TO_INT};
|
||||
use js::glue::{RUST_JSID_IS_STRING, RUST_JSID_TO_STRING, UnwrapObject};
|
||||
use js::jsapi::{HandleId, HandleObject, HandleValue, JSClass, JSContext};
|
||||
use js::jsapi::{JSObject, JSString, JS_GetArrayBufferViewType, JS_GetClass};
|
||||
|
@ -129,6 +130,22 @@ pub fn string_jsid_to_string(cx: *mut JSContext, id: HandleId) -> DOMString {
|
|||
}
|
||||
}
|
||||
|
||||
/// Convert `id` to a `DOMString`. Returns `None` if `id` is not a string or
|
||||
/// integer.
|
||||
///
|
||||
/// Handling of invalid UTF-16 in strings depends on the relevant option.
|
||||
pub unsafe fn jsid_to_string(cx: *mut JSContext, id: HandleId) -> Option<DOMString> {
|
||||
if RUST_JSID_IS_STRING(id) {
|
||||
return Some(jsstring_to_str(cx, RUST_JSID_TO_STRING(id)));
|
||||
}
|
||||
|
||||
if RUST_JSID_IS_INT(id) {
|
||||
return Some(RUST_JSID_TO_INT(id).to_string().into());
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
// http://heycam.github.io/webidl/#es-USVString
|
||||
impl ToJSValConvertible for USVString {
|
||||
unsafe fn to_jsval(&self, cx: *mut JSContext, rval: MutableHandleValue) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue