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:
Josh Matthews 2025-03-16 10:08:22 -04:00 committed by GitHub
parent d35da38a2f
commit c8d8787959
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 340 additions and 277 deletions

View file

@ -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
}