mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Move more bindings code to script_bindings (#35578)
* Move JSContext wrapper to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Move webidl constant bindings to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Move CanGc to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Move Dom<T> and Root<T> types to script_bindings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Extra docs for new traits. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix clippy warnings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
54286229ea
commit
35f21e426b
23 changed files with 788 additions and 641 deletions
|
@ -931,27 +931,21 @@ unsafe fn set_gc_zeal_options(cx: *mut RawJSContext) {
|
|||
#[cfg(not(feature = "debugmozjs"))]
|
||||
unsafe fn set_gc_zeal_options(_: *mut RawJSContext) {}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[repr(transparent)]
|
||||
pub(crate) struct JSContext(*mut RawJSContext);
|
||||
pub(crate) use script_bindings::script_runtime::JSContext;
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
impl JSContext {
|
||||
/// Create a new [`JSContext`] object from the given raw pointer.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The `RawJSContext` argument must point to a valid `RawJSContext` in memory.
|
||||
pub(crate) unsafe fn from_ptr(raw_js_context: *mut RawJSContext) -> Self {
|
||||
JSContext(raw_js_context)
|
||||
}
|
||||
/// Extra methods for the JSContext type defined in script_bindings, when
|
||||
/// the methods are only called by code in the script crate.
|
||||
pub(crate) trait JSContextHelper {
|
||||
fn get_reports(&self, path_seg: String) -> Vec<Report>;
|
||||
}
|
||||
|
||||
impl JSContextHelper for JSContext {
|
||||
#[allow(unsafe_code)]
|
||||
pub(crate) fn get_reports(&self, path_seg: String) -> Vec<Report> {
|
||||
fn get_reports(&self, path_seg: String) -> Vec<Report> {
|
||||
SEEN_POINTERS.with(|pointers| pointers.borrow_mut().clear());
|
||||
let stats = unsafe {
|
||||
let mut stats = ::std::mem::zeroed();
|
||||
if !CollectServoSizes(self.0, &mut stats, Some(get_size)) {
|
||||
if !CollectServoSizes(**self, &mut stats, Some(get_size)) {
|
||||
return vec![];
|
||||
}
|
||||
stats
|
||||
|
@ -1007,15 +1001,6 @@ impl JSContext {
|
|||
}
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
impl Deref for JSContext {
|
||||
type Target = *mut RawJSContext;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct StreamConsumer(*mut JSStreamConsumer);
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
|
@ -1171,18 +1156,4 @@ impl Runnable {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
/// A compile-time marker that there are operations that could trigger a JS garbage collection
|
||||
/// operation within the current stack frame. It is trivially copyable, so it should be passed
|
||||
/// as a function argument and reused when calling other functions whenever possible. Since it
|
||||
/// is only meaningful within the current stack frame, it is impossible to move it to a different
|
||||
/// thread or into a task that will execute asynchronously.
|
||||
pub(crate) struct CanGc(std::marker::PhantomData<*mut ()>);
|
||||
|
||||
impl CanGc {
|
||||
/// Create a new CanGc value, representing that a GC operation is possible within the
|
||||
/// current stack frame.
|
||||
pub(crate) fn note() -> CanGc {
|
||||
CanGc(std::marker::PhantomData)
|
||||
}
|
||||
}
|
||||
pub(crate) use script_bindings::script_runtime::CanGc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue