mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Move CustomTraceable to script_bindings. (#35988)
* script: Move CustomTraceable to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Move record binding support to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Address clippy warnings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
d35da38a2f
commit
c8d8787959
15 changed files with 340 additions and 277 deletions
|
@ -18,8 +18,8 @@ use js::jsapi::{
|
|||
};
|
||||
use js::jsval::{ObjectValue, StringValue, UndefinedValue};
|
||||
use js::rust::{
|
||||
HandleValue, MutableHandleValue, ToString, get_object_class, is_dom_class, is_dom_object,
|
||||
maybe_wrap_value,
|
||||
HandleId, HandleValue, MutableHandleValue, ToString, get_object_class, is_dom_class,
|
||||
is_dom_object, maybe_wrap_value,
|
||||
};
|
||||
|
||||
use crate::inheritance::Castable;
|
||||
|
@ -387,3 +387,24 @@ where
|
|||
}
|
||||
root_from_object(v.get().to_object(), cx)
|
||||
}
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// # Safety
|
||||
/// - cx must point to a non-null, valid JSContext instance.
|
||||
pub unsafe fn jsid_to_string(cx: *mut JSContext, id: HandleId) -> Option<DOMString> {
|
||||
let id_raw = *id;
|
||||
if id_raw.is_string() {
|
||||
let jsstr = std::ptr::NonNull::new(id_raw.to_string()).unwrap();
|
||||
return Some(jsstring_to_str(cx, jsstr));
|
||||
}
|
||||
|
||||
if id_raw.is_int() {
|
||||
return Some(id_raw.to_int().to_string().into());
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue