mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Move generated bindings to script_bindings (#36323)
This is the final step of #1799, where the majority of the generated code for the JS bindings is now compiled as part of the script_bindings build step. The remaining pieces in script must live there because they refer to concrete DOM types; all code in script_bindings is generic over the [DomTypes](https://doc.servo.org/script/dom/bindings/codegen/DomTypes/trait.DomTypes.html) trait. My testing with incremental builds shows me a 12 second reduction in build times on my 2024 M4 Macbook Pro when modifying code in the script crate after these changes. Before this PR those changes took 20 seconds to rebuild Servo, and now they take 8 seconds. Testing: Existing WPT tests ensure no regressions. Fixes: #1799 --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
277c0b82dd
commit
b4079b3ff3
44 changed files with 1932 additions and 1829 deletions
|
@ -3,36 +3,20 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::marker::PhantomData;
|
||||
use std::thread;
|
||||
|
||||
use js::jsapi::{GetScriptedCallerGlobal, HideScriptedCaller, JSTracer, UnhideScriptedCaller};
|
||||
use js::jsapi::{GetScriptedCallerGlobal, JSTracer};
|
||||
use js::rust::Runtime;
|
||||
use script_bindings::settings_stack::*;
|
||||
|
||||
use crate::DomTypes;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
//use script_bindings::interfaces::{DomHelpers, GlobalScopeHelpers};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::trace::JSTraceable;
|
||||
use crate::dom::bindings::utils::DomHelpers;
|
||||
use crate::dom::globalscope::{GlobalScope, GlobalScopeHelpers};
|
||||
use crate::script_runtime::CanGc;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
|
||||
thread_local!(pub(super) static STACK: RefCell<Vec<StackEntry<crate::DomTypeHolder>>> = const {
|
||||
RefCell::new(Vec::new())
|
||||
});
|
||||
|
||||
#[derive(Debug, Eq, JSTraceable, PartialEq)]
|
||||
enum StackEntryKind {
|
||||
Incumbent,
|
||||
Entry,
|
||||
}
|
||||
|
||||
#[cfg_attr(crown, allow(crown::unrooted_must_root))]
|
||||
#[derive(JSTraceable)]
|
||||
pub(crate) struct StackEntry<D: DomTypes> {
|
||||
global: Dom<D::GlobalScope>,
|
||||
kind: StackEntryKind,
|
||||
}
|
||||
|
||||
/// Traces the script settings stack.
|
||||
pub(crate) unsafe fn trace(tracer: *mut JSTracer) {
|
||||
STACK.with(|stack| {
|
||||
|
@ -46,61 +30,6 @@ pub(crate) fn is_execution_stack_empty() -> bool {
|
|||
|
||||
pub(crate) type AutoEntryScript = GenericAutoEntryScript<crate::DomTypeHolder>;
|
||||
|
||||
/// RAII struct that pushes and pops entries from the script settings stack.
|
||||
pub(crate) struct GenericAutoEntryScript<D: DomTypes> {
|
||||
global: DomRoot<D::GlobalScope>,
|
||||
#[cfg(feature = "tracing")]
|
||||
#[allow(dead_code)]
|
||||
span: tracing::span::EnteredSpan,
|
||||
}
|
||||
|
||||
impl<D: DomTypes> GenericAutoEntryScript<D> {
|
||||
/// <https://html.spec.whatwg.org/multipage/#prepare-to-run-script>
|
||||
pub(crate) fn new(global: &D::GlobalScope) -> Self {
|
||||
let settings_stack = <D as DomHelpers<D>>::settings_stack();
|
||||
settings_stack.with(|stack| {
|
||||
trace!("Prepare to run script with {:p}", global);
|
||||
let mut stack = stack.borrow_mut();
|
||||
stack.push(StackEntry {
|
||||
global: Dom::from_ref(global),
|
||||
kind: StackEntryKind::Entry,
|
||||
});
|
||||
Self {
|
||||
global: DomRoot::from_ref(global),
|
||||
#[cfg(feature = "tracing")]
|
||||
span: tracing::info_span!(
|
||||
"ScriptEvaluate",
|
||||
servo_profiling = true,
|
||||
url = global.get_url().to_string(),
|
||||
)
|
||||
.entered(),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DomTypes> Drop for GenericAutoEntryScript<D> {
|
||||
/// <https://html.spec.whatwg.org/multipage/#clean-up-after-running-script>
|
||||
fn drop(&mut self) {
|
||||
let settings_stack = <D as DomHelpers<D>>::settings_stack();
|
||||
settings_stack.with(|stack| {
|
||||
let mut stack = stack.borrow_mut();
|
||||
let entry = stack.pop().unwrap();
|
||||
assert_eq!(
|
||||
&*entry.global as *const D::GlobalScope, &*self.global as *const D::GlobalScope,
|
||||
"Dropped AutoEntryScript out of order."
|
||||
);
|
||||
assert_eq!(entry.kind, StackEntryKind::Entry);
|
||||
trace!("Clean up after running script with {:p}", &*entry.global);
|
||||
});
|
||||
|
||||
// Step 5
|
||||
if !thread::panicking() && incumbent_global().is_none() {
|
||||
self.global.perform_a_microtask_checkpoint(CanGc::note());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the ["entry"] global object.
|
||||
///
|
||||
/// ["entry"]: https://html.spec.whatwg.org/multipage/#entry
|
||||
|
@ -117,67 +46,7 @@ pub(crate) fn entry_global() -> DomRoot<GlobalScope> {
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
/// RAII struct that pushes and pops entries from the script settings stack.
|
||||
pub(crate) struct GenericAutoIncumbentScript<D: DomTypes> {
|
||||
global: usize,
|
||||
_marker: PhantomData<D>,
|
||||
}
|
||||
|
||||
pub(crate) type AutoIncumbentScript = GenericAutoIncumbentScript<crate::DomTypeHolder>;
|
||||
|
||||
impl<D: DomTypes> GenericAutoIncumbentScript<D> {
|
||||
/// <https://html.spec.whatwg.org/multipage/#prepare-to-run-a-callback>
|
||||
pub(crate) fn new(global: &D::GlobalScope) -> Self {
|
||||
// Step 2-3.
|
||||
unsafe {
|
||||
let cx =
|
||||
Runtime::get().expect("Creating a new incumbent script after runtime shutdown");
|
||||
HideScriptedCaller(cx.as_ptr());
|
||||
}
|
||||
let settings_stack = <D as DomHelpers<D>>::settings_stack();
|
||||
settings_stack.with(|stack| {
|
||||
trace!("Prepare to run a callback with {:p}", global);
|
||||
// Step 1.
|
||||
let mut stack = stack.borrow_mut();
|
||||
stack.push(StackEntry {
|
||||
global: Dom::from_ref(global),
|
||||
kind: StackEntryKind::Incumbent,
|
||||
});
|
||||
Self {
|
||||
global: global as *const _ as usize,
|
||||
_marker: PhantomData,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<D: DomTypes> Drop for GenericAutoIncumbentScript<D> {
|
||||
/// <https://html.spec.whatwg.org/multipage/#clean-up-after-running-a-callback>
|
||||
fn drop(&mut self) {
|
||||
let settings_stack = <D as DomHelpers<D>>::settings_stack();
|
||||
settings_stack.with(|stack| {
|
||||
// Step 4.
|
||||
let mut stack = stack.borrow_mut();
|
||||
let entry = stack.pop().unwrap();
|
||||
// Step 3.
|
||||
assert_eq!(
|
||||
&*entry.global as *const D::GlobalScope as usize, self.global,
|
||||
"Dropped AutoIncumbentScript out of order."
|
||||
);
|
||||
assert_eq!(entry.kind, StackEntryKind::Incumbent);
|
||||
trace!(
|
||||
"Clean up after running a callback with {:p}",
|
||||
&*entry.global
|
||||
);
|
||||
});
|
||||
unsafe {
|
||||
// Step 1-2.
|
||||
if let Some(cx) = Runtime::get() {
|
||||
UnhideScriptedCaller(cx.as_ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub type AutoIncumbentScript = GenericAutoIncumbentScript<crate::DomTypeHolder>;
|
||||
|
||||
/// Returns the ["incumbent"] global object.
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue