More miscellaneous script splitting changes (#36220)

* script: Move HasParent to script_bindings and update imports for InheritTypes.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make principal creation generic over DOM interface.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move a bunch of proxy-related code to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make some proxy-related code generic over the DOM interface.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move DomSlice to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move some utility bindings code to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make enumerating and resolving globals generic over the DOM interface.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make realm helpers generic over the DOM interface.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move implementations on concrete DOM types to concrete bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make additional codegen helpers generic over the DOM interface.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make iterator creation generic over the DOM interface.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Make reporting an exception a generic operation.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* script: Move AsCCharPtrPtr to script_bindings.

Signed-off-by: Josh Matthews <josh@joshmatthews.net>

* Formatting.

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-30 07:06:30 -04:00 committed by GitHub
parent 971490084e
commit b445053a7c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 806 additions and 628 deletions

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use std::ffi::CString;
use std::os::raw::c_void;
use std::os::raw::{c_char, c_void};
use std::ptr::{self, NonNull};
use js::conversions::ToJSValConvertible;
@ -13,9 +13,9 @@ use js::glue::{
};
use js::jsapi::{
AtomToLinearString, CallArgs, ExceptionStackBehavior, GetLinearStringCharAt,
GetLinearStringLength, GetNonCCWObjectGlobal, HandleObject as RawHandleObject,
GetLinearStringLength, GetNonCCWObjectGlobal, HandleObject as RawHandleObject, Heap,
JS_ClearPendingException, JS_IsExceptionPending, JSAtom, JSContext, JSJitInfo, JSObject,
MutableHandleValue as RawMutableHandleValue, ObjectOpResult, StringIsArrayIndex,
JSTracer, MutableHandleValue as RawMutableHandleValue, ObjectOpResult, StringIsArrayIndex,
};
use js::jsval::{JSVal, UndefinedValue};
use js::rust::wrappers::{
@ -36,6 +36,7 @@ use crate::conversions::{PrototypeCheck, jsstring_to_str, private_from_proto_che
use crate::error::throw_invalid_this;
use crate::script_runtime::{CanGc, JSContext as SafeJSContext};
use crate::str::DOMString;
use crate::trace::trace_object;
/// The struct that holds inheritance information for DOM object reflectors.
#[derive(Clone, Copy)]
@ -526,3 +527,42 @@ pub unsafe fn exception_to_promise(
false
}
}
/// Trace the resources held by reserved slots of a global object
///
/// # Safety
/// `tracer` must point to a valid, non-null JSTracer.
/// `obj` must point to a valid, non-null JSObject.
pub unsafe fn trace_global(tracer: *mut JSTracer, obj: *mut JSObject) {
let array = get_proto_or_iface_array(obj);
for proto in (*array).iter() {
if !proto.is_null() {
trace_object(
tracer,
"prototype",
&*(proto as *const *mut JSObject as *const Heap<*mut JSObject>),
);
}
}
}
// Generic method for returning libc::c_void from caller
pub trait AsVoidPtr {
fn as_void_ptr(&self) -> *const libc::c_void;
}
impl<T> AsVoidPtr for T {
fn as_void_ptr(&self) -> *const libc::c_void {
self as *const T as *const libc::c_void
}
}
// Generic method for returning c_char from caller
pub trait AsCCharPtrPtr {
fn as_c_char_ptr(&self) -> *const c_char;
}
impl AsCCharPtrPtr for [u8] {
fn as_c_char_ptr(&self) -> *const c_char {
self as *const [u8] as *const c_char
}
}