mirror of
https://github.com/servo/servo.git
synced 2025-07-22 14:53:49 +01:00
Make generated bindings generic over DOM types (#35169)
* bindings: Start making generated bindings methods generic over DOM trait. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * bindings: Make binding initialization generic over the DOM types trait. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * bindings: Start making proxyhandler code generic over DOM types. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
8748071329
commit
d5d7b0d34f
6 changed files with 72 additions and 52 deletions
|
@ -42,7 +42,7 @@ use crate::dom::bindings::principals::ServoJSPrincipalsRef;
|
|||
use crate::dom::bindings::reflector::DomObject;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::bindings::utils::delete_property_by_id;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::globalscope::{GlobalScope, GlobalScopeHelpers};
|
||||
use crate::realms::{AlreadyInRealm, InRealm};
|
||||
use crate::script_runtime::JSContext as SafeJSContext;
|
||||
|
||||
|
@ -376,7 +376,7 @@ pub(crate) unsafe extern "C" fn maybe_cross_origin_get_prototype_if_ordinary_raw
|
|||
/// Implementation of `[[GetPrototypeOf]]` for [`Location`].
|
||||
///
|
||||
/// [`Location`]: https://html.spec.whatwg.org/multipage/#location-getprototypeof
|
||||
pub(crate) unsafe fn maybe_cross_origin_get_prototype(
|
||||
pub(crate) unsafe fn maybe_cross_origin_get_prototype<D: crate::DomTypes>(
|
||||
cx: SafeJSContext,
|
||||
proxy: RawHandleObject,
|
||||
get_proto_object: unsafe fn(cx: SafeJSContext, global: HandleObject, rval: MutableHandleObject),
|
||||
|
@ -385,7 +385,7 @@ pub(crate) unsafe fn maybe_cross_origin_get_prototype(
|
|||
// > 1. If ! IsPlatformObjectSameOrigin(this) is true, then return ! OrdinaryGetPrototypeOf(this).
|
||||
if is_platform_object_same_origin(cx, proxy) {
|
||||
let ac = JSAutoRealm::new(*cx, proxy.get());
|
||||
let global = GlobalScope::from_context(*cx, InRealm::Entered(&ac));
|
||||
let global = D::GlobalScope::from_context(*cx, InRealm::Entered(&ac));
|
||||
get_proto_object(
|
||||
cx,
|
||||
global.reflector().get_jsobject(),
|
||||
|
|
|
@ -3272,3 +3272,15 @@ unsafe fn global_scope_from_global_static(global: *mut JSObject) -> DomRoot<Glob
|
|||
);
|
||||
root_from_object_static(global).unwrap()
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
pub(crate) trait GlobalScopeHelpers<D: crate::DomTypes> {
|
||||
unsafe fn from_context(cx: *mut JSContext, realm: InRealm) -> DomRoot<D::GlobalScope>;
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
impl GlobalScopeHelpers<crate::DomTypeHolder> for GlobalScope {
|
||||
unsafe fn from_context(cx: *mut JSContext, realm: InRealm) -> DomRoot<Self> {
|
||||
GlobalScope::from_context(cx, realm)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,8 +69,8 @@ pub fn init() -> JSEngineSetup {
|
|||
|
||||
// Create the global vtables used by the (generated) DOM
|
||||
// bindings to implement JS proxies.
|
||||
RegisterBindings::RegisterProxyHandlers();
|
||||
RegisterBindings::InitAllStatics();
|
||||
RegisterBindings::RegisterProxyHandlers::<crate::DomTypeHolder>();
|
||||
RegisterBindings::InitAllStatics::<crate::DomTypeHolder>();
|
||||
|
||||
js::glue::InitializeMemoryReporter(Some(is_dom_object));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue