mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
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:
parent
971490084e
commit
b445053a7c
33 changed files with 806 additions and 628 deletions
|
@ -2279,8 +2279,6 @@ class CGImports(CGWrapper):
|
|||
if t.isInterface() or t.isNamespace():
|
||||
name = getIdentifier(t).name
|
||||
descriptor = descriptorProvider.getDescriptor(name)
|
||||
if name != 'GlobalScope':
|
||||
extras += [descriptor.path]
|
||||
parentName = descriptor.getParentName()
|
||||
while parentName:
|
||||
descriptor = descriptorProvider.getDescriptor(parentName)
|
||||
|
@ -2289,7 +2287,7 @@ class CGImports(CGWrapper):
|
|||
elif t.isType() and t.isRecord():
|
||||
extras += ['script_bindings::record::Record']
|
||||
elif isinstance(t, IDLPromiseType):
|
||||
extras += ['crate::dom::promise::Promise']
|
||||
pass
|
||||
else:
|
||||
if t.isEnum():
|
||||
extras += [f'{getModuleFromObject(t)}::{getIdentifier(t).name}Values']
|
||||
|
@ -2339,15 +2337,15 @@ def DOMClassTypeId(desc):
|
|||
inner = ""
|
||||
if desc.hasDescendants():
|
||||
if desc.interface.getExtendedAttribute("Abstract"):
|
||||
return "crate::dom::bindings::codegen::InheritTypes::TopTypeId { abstract_: () }"
|
||||
return "script_bindings::codegen::InheritTypes::TopTypeId { abstract_: () }"
|
||||
name = desc.interface.identifier.name
|
||||
inner = f"(crate::dom::bindings::codegen::InheritTypes::{name}TypeId::{name})"
|
||||
inner = f"(script_bindings::codegen::InheritTypes::{name}TypeId::{name})"
|
||||
elif len(protochain) == 1:
|
||||
return "crate::dom::bindings::codegen::InheritTypes::TopTypeId { alone: () }"
|
||||
return "script_bindings::codegen::InheritTypes::TopTypeId { alone: () }"
|
||||
reversed_protochain = list(reversed(protochain))
|
||||
for (child, parent) in zip(reversed_protochain, reversed_protochain[1:]):
|
||||
inner = f"(crate::dom::bindings::codegen::InheritTypes::{parent}TypeId::{child}{inner})"
|
||||
return f"crate::dom::bindings::codegen::InheritTypes::TopTypeId {{ {protochain[0].lower()}: {inner} }}"
|
||||
inner = f"(script_bindings::codegen::InheritTypes::{parent}TypeId::{child}{inner})"
|
||||
return f"script_bindings::codegen::InheritTypes::TopTypeId {{ {protochain[0].lower()}: {inner} }}"
|
||||
|
||||
|
||||
def DOMClass(descriptor):
|
||||
|
@ -2398,10 +2396,10 @@ class CGDOMJSClass(CGThing):
|
|||
}
|
||||
if self.descriptor.isGlobal():
|
||||
assert not self.descriptor.weakReferenceable
|
||||
args["enumerateHook"] = "Some(enumerate_global)"
|
||||
args["enumerateHook"] = "Some(enumerate_global::<D>)"
|
||||
args["flags"] = "JSCLASS_IS_GLOBAL | JSCLASS_DOM_GLOBAL | JSCLASS_FOREGROUND_FINALIZE"
|
||||
args["slots"] = "JSCLASS_GLOBAL_SLOT_COUNT + 1"
|
||||
args["resolveHook"] = "Some(resolve_global)"
|
||||
args["resolveHook"] = "Some(resolve_global::<D>)"
|
||||
args["traceHook"] = "js::jsapi::JS_GlobalObjectTraceHook"
|
||||
elif self.descriptor.weakReferenceable:
|
||||
args["slots"] = "2"
|
||||
|
@ -2423,7 +2421,7 @@ pub(crate) fn init_class_ops<D: DomTypes>() {{
|
|||
}});
|
||||
}}
|
||||
|
||||
static Class: ThreadUnsafeOnceLock<DOMJSClass> = ThreadUnsafeOnceLock::new();
|
||||
pub(crate) static Class: ThreadUnsafeOnceLock<DOMJSClass> = ThreadUnsafeOnceLock::new();
|
||||
|
||||
pub(crate) fn init_domjs_class<D: DomTypes>() {{
|
||||
init_class_ops::<D>();
|
||||
|
@ -3185,7 +3183,7 @@ let raw = Root::new(MaybeUnreflectedDom::from_box(object));
|
|||
let origin = (*raw.as_ptr()).upcast::<D::GlobalScope>().origin();
|
||||
|
||||
rooted!(in(*cx) let mut obj = ptr::null_mut::<JSObject>());
|
||||
create_global_object(
|
||||
create_global_object::<D>(
|
||||
cx,
|
||||
&Class.get().base,
|
||||
raw.as_ptr() as *const libc::c_void,
|
||||
|
@ -3229,14 +3227,15 @@ class CGIDLInterface(CGThing):
|
|||
def define(self):
|
||||
interface = self.descriptor.interface
|
||||
name = interface.identifier.name
|
||||
bindingModule = f"crate::dom::bindings::codegen::GenericBindings::{toBindingPath(self.descriptor)}"
|
||||
if (interface.getUserData("hasConcreteDescendant", False)
|
||||
or interface.getUserData("hasProxyDescendant", False)):
|
||||
depth = self.descriptor.prototypeDepth
|
||||
check = f"class.interface_chain[{depth}] == PrototypeList::ID::{name}"
|
||||
elif self.descriptor.proxy:
|
||||
check = "ptr::eq(class, unsafe { Class.get() })"
|
||||
check = f"ptr::eq(class, unsafe {{ {bindingModule}::Class.get() }})"
|
||||
else:
|
||||
check = "ptr::eq(class, unsafe { &Class.get().dom_class })"
|
||||
check = f"ptr::eq(class, unsafe {{ &{bindingModule}::Class.get().dom_class }})"
|
||||
return f"""
|
||||
impl IDLInterface for {name} {{
|
||||
#[inline]
|
||||
|
@ -3279,6 +3278,7 @@ class CGDomObjectWrap(CGThing):
|
|||
|
||||
def define(self):
|
||||
ifaceName = self.descriptor.interface.identifier.name
|
||||
bindingModule = f"crate::dom::bindings::codegen::GenericBindings::{toBindingPath(self.descriptor)}"
|
||||
return f"""
|
||||
impl DomObjectWrap<crate::DomTypeHolder> for {firstCap(ifaceName)} {{
|
||||
const WRAP: unsafe fn(
|
||||
|
@ -3287,7 +3287,7 @@ impl DomObjectWrap<crate::DomTypeHolder> for {firstCap(ifaceName)} {{
|
|||
Option<HandleObject>,
|
||||
Box<Self>,
|
||||
CanGc,
|
||||
) -> Root<Dom<Self>> = Wrap::<crate::DomTypeHolder>;
|
||||
) -> Root<Dom<Self>> = {bindingModule}::Wrap::<crate::DomTypeHolder>;
|
||||
}}
|
||||
"""
|
||||
|
||||
|
@ -3303,6 +3303,7 @@ class CGDomObjectIteratorWrap(CGThing):
|
|||
def define(self):
|
||||
assert self.descriptor.interface.isIteratorInterface()
|
||||
name = self.descriptor.interface.iterableInterface.identifier.name
|
||||
bindingModule = f"crate::dom::bindings::codegen::GenericBindings::{toBindingPath(self.descriptor)}"
|
||||
return f"""
|
||||
impl DomObjectIteratorWrap<crate::DomTypeHolder> for {name} {{
|
||||
const ITER_WRAP: unsafe fn(
|
||||
|
@ -3311,7 +3312,7 @@ impl DomObjectIteratorWrap<crate::DomTypeHolder> for {name} {{
|
|||
Option<HandleObject>,
|
||||
Box<IterableIterator<crate::DomTypeHolder, Self>>,
|
||||
CanGc,
|
||||
) -> Root<Dom<IterableIterator<crate::DomTypeHolder, Self>>> = Wrap::<crate::DomTypeHolder>;
|
||||
) -> Root<Dom<IterableIterator<crate::DomTypeHolder, Self>>> = {bindingModule}::Wrap::<crate::DomTypeHolder>;
|
||||
}}
|
||||
"""
|
||||
|
||||
|
@ -3516,7 +3517,7 @@ assert!(!prototype_proto.is_null());""")]
|
|||
assert not self.haveUnscopables
|
||||
code.append(CGGeneric(f"""
|
||||
rooted!(in(*cx) let mut prototype_proto_proto = prototype_proto.get());
|
||||
dom::types::{name}::create_named_properties_object(cx, prototype_proto_proto.handle(), prototype_proto.handle_mut());
|
||||
D::{name}::create_named_properties_object(cx, prototype_proto_proto.handle(), prototype_proto.handle_mut());
|
||||
assert!(!prototype_proto.is_null());"""))
|
||||
|
||||
properties = {
|
||||
|
@ -3797,7 +3798,7 @@ class CGDefineProxyHandler(CGAbstractMethod):
|
|||
# `[[Set]]` (https://heycam.github.io/webidl/#legacy-platform-object-set) (yet).
|
||||
assert not self.descriptor.operations['IndexedGetter']
|
||||
assert not self.descriptor.operations['NamedGetter']
|
||||
customSet = 'Some(proxyhandler::maybe_cross_origin_set_rawcx)'
|
||||
customSet = 'Some(proxyhandler::maybe_cross_origin_set_rawcx::<D>)'
|
||||
|
||||
getOwnEnumerablePropertyKeys = "own_property_keys::<D>"
|
||||
if self.descriptor.interface.getExtendedAttribute("LegacyUnenumerableNamedProperties") or \
|
||||
|
@ -3944,7 +3945,7 @@ class CGCallGenerator(CGThing):
|
|||
call = CGList([call, CGWrapper(args, pre="(", post=")")])
|
||||
|
||||
if hasCEReactions:
|
||||
self.cgRoot.append(CGGeneric("push_new_element_queue();\n"))
|
||||
self.cgRoot.append(CGGeneric("<D as DomHelpers<D>>::push_new_element_queue();\n"))
|
||||
|
||||
self.cgRoot.append(CGList([
|
||||
CGGeneric("let result: "),
|
||||
|
@ -3955,7 +3956,7 @@ class CGCallGenerator(CGThing):
|
|||
]))
|
||||
|
||||
if hasCEReactions:
|
||||
self.cgRoot.append(CGGeneric("pop_current_element_queue(CanGc::note());\n"))
|
||||
self.cgRoot.append(CGGeneric("<D as DomHelpers<D>>::pop_current_element_queue(CanGc::note());\n"))
|
||||
|
||||
if isFallible:
|
||||
if static:
|
||||
|
@ -3967,7 +3968,7 @@ class CGCallGenerator(CGThing):
|
|||
"let result = match result {\n"
|
||||
" Ok(result) => result,\n"
|
||||
" Err(e) => {\n"
|
||||
f" <D as DomHelpers<D>>::throw_dom_exception(cx, {glob}, e);\n"
|
||||
f" <D as DomHelpers<D>>::throw_dom_exception(cx, {glob}, e, CanGc::note());\n"
|
||||
f" return{errorResult};\n"
|
||||
" },\n"
|
||||
"};"))
|
||||
|
@ -5911,14 +5912,14 @@ class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
|
|||
if self.descriptor.isMaybeCrossOriginObject():
|
||||
get += dedent(
|
||||
"""
|
||||
if !proxyhandler::is_platform_object_same_origin(cx, proxy) {
|
||||
if !<D as DomHelpers<D>>::is_platform_object_same_origin(cx, proxy) {
|
||||
if !proxyhandler::cross_origin_get_own_property_helper(
|
||||
cx, proxy, CROSS_ORIGIN_PROPERTIES.get(), id, desc, &mut *is_none
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
if *is_none {
|
||||
return proxyhandler::cross_origin_property_fallback(cx, proxy, id, desc, &mut *is_none);
|
||||
return proxyhandler::cross_origin_property_fallback::<D>(cx, proxy, id, desc, &mut *is_none);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -6033,8 +6034,8 @@ class CGDOMJSProxyHandler_defineProperty(CGAbstractExternMethod):
|
|||
if self.descriptor.isMaybeCrossOriginObject():
|
||||
set += dedent(
|
||||
"""
|
||||
if !proxyhandler::is_platform_object_same_origin(cx, proxy) {
|
||||
return proxyhandler::report_cross_origin_denial(cx, id, "define");
|
||||
if !<D as DomHelpers<D>>::is_platform_object_same_origin(cx, proxy) {
|
||||
return proxyhandler::report_cross_origin_denial::<D>(cx, id, "define");
|
||||
}
|
||||
|
||||
// Safe to enter the Realm of proxy now.
|
||||
|
@ -6092,8 +6093,8 @@ class CGDOMJSProxyHandler_delete(CGAbstractExternMethod):
|
|||
if self.descriptor.isMaybeCrossOriginObject():
|
||||
set += dedent(
|
||||
"""
|
||||
if !proxyhandler::is_platform_object_same_origin(cx, proxy) {
|
||||
return proxyhandler::report_cross_origin_denial(cx, id, "delete");
|
||||
if !<D as DomHelpers<D>>::is_platform_object_same_origin(cx, proxy) {
|
||||
return proxyhandler::report_cross_origin_denial::<D>(cx, id, "delete");
|
||||
}
|
||||
|
||||
// Safe to enter the Realm of proxy now.
|
||||
|
@ -6131,7 +6132,7 @@ class CGDOMJSProxyHandler_ownPropertyKeys(CGAbstractExternMethod):
|
|||
if self.descriptor.isMaybeCrossOriginObject():
|
||||
body += dedent(
|
||||
"""
|
||||
if !proxyhandler::is_platform_object_same_origin(cx, proxy) {
|
||||
if !<D as DomHelpers<D>>::is_platform_object_same_origin(cx, proxy) {
|
||||
return proxyhandler::cross_origin_own_property_keys(
|
||||
cx, proxy, CROSS_ORIGIN_PROPERTIES.get(), props
|
||||
);
|
||||
|
@ -6204,7 +6205,7 @@ class CGDOMJSProxyHandler_getOwnEnumerablePropertyKeys(CGAbstractExternMethod):
|
|||
if self.descriptor.isMaybeCrossOriginObject():
|
||||
body += dedent(
|
||||
"""
|
||||
if !proxyhandler::is_platform_object_same_origin(cx, proxy) {
|
||||
if !<D as DomHelpers<D>>::is_platform_object_same_origin(cx, proxy) {
|
||||
// There are no enumerable cross-origin props, so we're done.
|
||||
return true;
|
||||
}
|
||||
|
@ -6255,7 +6256,7 @@ class CGDOMJSProxyHandler_hasOwn(CGAbstractExternMethod):
|
|||
if self.descriptor.isMaybeCrossOriginObject():
|
||||
indexed += dedent(
|
||||
"""
|
||||
if !proxyhandler::is_platform_object_same_origin(cx, proxy) {
|
||||
if !<D as DomHelpers<D>>::is_platform_object_same_origin(cx, proxy) {
|
||||
return proxyhandler::cross_origin_has_own(
|
||||
cx, proxy, CROSS_ORIGIN_PROPERTIES.get(), id, bp
|
||||
);
|
||||
|
@ -6328,8 +6329,8 @@ class CGDOMJSProxyHandler_get(CGAbstractExternMethod):
|
|||
if self.descriptor.isMaybeCrossOriginObject():
|
||||
maybeCrossOriginGet = dedent(
|
||||
"""
|
||||
if !proxyhandler::is_platform_object_same_origin(cx, proxy) {
|
||||
return proxyhandler::cross_origin_get(cx, proxy, receiver, id, vp);
|
||||
if !<D as DomHelpers<D>>::is_platform_object_same_origin(cx, proxy) {
|
||||
return proxyhandler::cross_origin_get::<D>(cx, proxy, receiver, id, vp);
|
||||
}
|
||||
|
||||
// Safe to enter the Realm of proxy now.
|
||||
|
@ -6589,7 +6590,7 @@ class CGDOMJSProxyHandlerDOMClass(CGThing):
|
|||
|
||||
def define(self):
|
||||
return f"""
|
||||
static Class: ThreadUnsafeOnceLock<DOMClass> = ThreadUnsafeOnceLock::new();
|
||||
pub(crate) static Class: ThreadUnsafeOnceLock<DOMClass> = ThreadUnsafeOnceLock::new();
|
||||
|
||||
pub(crate) fn init_proxy_handler_dom_class<D: DomTypes>() {{
|
||||
Class.set({DOMClass(self.descriptor)});
|
||||
|
@ -6990,18 +6991,11 @@ class CGDescriptor(CGThing):
|
|||
pass
|
||||
else:
|
||||
cgThings.append(CGDOMJSClass(descriptor))
|
||||
if not descriptor.interface.isIteratorInterface():
|
||||
cgThings.append(CGAssertInheritance(descriptor))
|
||||
pass
|
||||
|
||||
if descriptor.isGlobal():
|
||||
cgThings.append(CGWrapGlobalMethod(descriptor, properties))
|
||||
else:
|
||||
cgThings.append(CGWrapMethod(descriptor))
|
||||
if descriptor.interface.isIteratorInterface():
|
||||
cgThings.append(CGDomObjectIteratorWrap(descriptor))
|
||||
else:
|
||||
cgThings.append(CGDomObjectWrap(descriptor))
|
||||
reexports.append('Wrap')
|
||||
|
||||
haveUnscopables = False
|
||||
|
@ -7013,16 +7007,6 @@ class CGDescriptor(CGThing):
|
|||
CGIndenter(CGList([CGGeneric(str_to_cstr(name)) for
|
||||
name in unscopableNames], ",\n")),
|
||||
CGGeneric("];\n")], "\n"))
|
||||
if (
|
||||
(descriptor.concrete or descriptor.hasDescendants())
|
||||
and not descriptor.interface.isIteratorInterface()
|
||||
):
|
||||
cgThings.append(CGIDLInterface(descriptor))
|
||||
if descriptor.interface.isIteratorInterface():
|
||||
cgThings.append(CGIteratorDerives(descriptor))
|
||||
|
||||
if descriptor.weakReferenceable:
|
||||
cgThings.append(CGWeakReferenceableTrait(descriptor))
|
||||
|
||||
if not descriptor.interface.isCallback():
|
||||
interfaceTrait = CGInterfaceTrait(descriptor, config.getDescriptorProvider())
|
||||
|
@ -7590,6 +7574,27 @@ class CGConcreteBindingRoot(CGThing):
|
|||
f"pub(crate) use {originalBinding}::{firstCap(ifaceName)}_Binding as {firstCap(ifaceName)}_Binding;"
|
||||
),
|
||||
]
|
||||
|
||||
if d.concrete:
|
||||
if not d.interface.isIteratorInterface():
|
||||
cgthings.append(CGAssertInheritance(d))
|
||||
else:
|
||||
cgthings.append(CGIteratorDerives(d))
|
||||
|
||||
if (
|
||||
(d.concrete or d.hasDescendants())
|
||||
and not d.interface.isIteratorInterface()
|
||||
):
|
||||
cgthings.append(CGIDLInterface(d))
|
||||
|
||||
if d.interface.isIteratorInterface():
|
||||
cgthings.append(CGDomObjectIteratorWrap(d))
|
||||
elif d.concrete and not d.isGlobal():
|
||||
cgthings.append(CGDomObjectWrap(d))
|
||||
|
||||
if d.weakReferenceable:
|
||||
cgthings.append(CGWeakReferenceableTrait(d))
|
||||
|
||||
if not d.interface.isCallback():
|
||||
traitName = f"{ifaceName}Methods"
|
||||
cgthings += [
|
||||
|
@ -7625,7 +7630,7 @@ pub(crate) fn GetConstructorObject(
|
|||
curr = CGImports(curr, descriptors=[], callbacks=[],
|
||||
dictionaries=[], enums=[], typedefs=[],
|
||||
imports=[
|
||||
'crate::dom::bindings::import::base::*',
|
||||
'crate::dom::bindings::import::module::*',
|
||||
'crate::dom::types::*'],
|
||||
config=config)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue