aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/reflector.rs
diff options
context:
space:
mode:
authorJosh Matthews <josh@joshmatthews.net>2025-04-04 02:45:08 -0400
committerGitHub <noreply@github.com>2025-04-04 06:45:08 +0000
commitb4079b3ff33a3f7e2b35ac3aacc4467f8da42242 (patch)
treeaf6ae87af10c1383a3a3fcdb28b1d2544bc2fc45 /components/script/dom/bindings/reflector.rs
parent277c0b82dd4411798b461a4e3a782e7869ae5740 (diff)
downloadservo-b4079b3ff33a3f7e2b35ac3aacc4467f8da42242.tar.gz
servo-b4079b3ff33a3f7e2b35ac3aacc4467f8da42242.zip
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>
Diffstat (limited to 'components/script/dom/bindings/reflector.rs')
-rw-r--r--components/script/dom/bindings/reflector.rs69
1 files changed, 6 insertions, 63 deletions
diff --git a/components/script/dom/bindings/reflector.rs b/components/script/dom/bindings/reflector.rs
index 3593578a66f..0a5afbce487 100644
--- a/components/script/dom/bindings/reflector.rs
+++ b/components/script/dom/bindings/reflector.rs
@@ -5,15 +5,14 @@
//! The `Reflector` struct.
use js::rust::HandleObject;
+use script_bindings::interfaces::GlobalScopeHelpers;
use crate::DomTypes;
use crate::dom::bindings::conversions::DerivedFrom;
-use crate::dom::bindings::iterable::{Iterable, IterableIterator};
-use crate::dom::bindings::root::{Dom, DomRoot, Root};
-use crate::dom::bindings::trace::JSTraceable;
-use crate::dom::globalscope::{GlobalScope, GlobalScopeHelpers};
-use crate::realms::{AlreadyInRealm, InRealm};
-use crate::script_runtime::{CanGc, JSContext};
+use crate::dom::bindings::root::DomRoot;
+use crate::dom::globalscope::GlobalScope;
+use crate::realms::InRealm;
+use crate::script_runtime::CanGc;
/// Create the reflector for a new DOM object and yield ownership to the
/// reflector.
@@ -42,31 +41,6 @@ where
unsafe { T::WRAP(D::GlobalScope::get_cx(), global_scope, proto, obj, can_gc) }
}
-pub(crate) trait DomGlobalGeneric<D: DomTypes>: DomObject {
- /// Returns the [`GlobalScope`] of the realm that the [`DomObject`] was created in. If this
- /// object is a `Node`, this will be different from it's owning `Document` if adopted by. For
- /// `Node`s it's almost always better to use `NodeTraits::owning_global`.
- fn global_(&self, realm: InRealm) -> DomRoot<D::GlobalScope>
- where
- Self: Sized,
- {
- D::GlobalScope::from_reflector(self, realm)
- }
-
- /// Returns the [`GlobalScope`] of the realm that the [`DomObject`] was created in. If this
- /// object is a `Node`, this will be different from it's owning `Document` if adopted by. For
- /// `Node`s it's almost always better to use `NodeTraits::owning_global`.
- fn global(&self) -> DomRoot<D::GlobalScope>
- where
- Self: Sized,
- {
- let realm = AlreadyInRealm::assert_for_cx(D::GlobalScope::get_cx());
- D::GlobalScope::from_reflector(self, InRealm::already(&realm))
- }
-}
-
-impl<D: DomTypes, T: DomObject> DomGlobalGeneric<D> for T {}
-
pub(crate) trait DomGlobal {
fn global_(&self, realm: InRealm) -> DomRoot<GlobalScope>;
fn global(&self) -> DomRoot<GlobalScope>;
@@ -81,35 +55,4 @@ impl<T: DomGlobalGeneric<crate::DomTypeHolder>> DomGlobal for T {
}
}
-pub(crate) use script_bindings::reflector::{DomObject, MutDomObject, Reflector};
-
-/// A trait to provide a function pointer to wrap function for DOM objects.
-pub(crate) trait DomObjectWrap<D: DomTypes>:
- Sized + DomObject + DomGlobalGeneric<D>
-{
- /// Function pointer to the general wrap function type
- #[allow(clippy::type_complexity)]
- const WRAP: unsafe fn(
- JSContext,
- &D::GlobalScope,
- Option<HandleObject>,
- Box<Self>,
- CanGc,
- ) -> Root<Dom<Self>>;
-}
-
-/// A trait to provide a function pointer to wrap function for
-/// DOM iterator interfaces.
-pub(crate) trait DomObjectIteratorWrap<D: DomTypes>:
- DomObjectWrap<D> + JSTraceable + Iterable
-{
- /// Function pointer to the wrap function for `IterableIterator<T>`
- #[allow(clippy::type_complexity)]
- const ITER_WRAP: unsafe fn(
- JSContext,
- &D::GlobalScope,
- Option<HandleObject>,
- Box<IterableIterator<D, Self>>,
- CanGc,
- ) -> Root<Dom<IterableIterator<D, Self>>>;
-}
+pub(crate) use script_bindings::reflector::*;