mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add an inCompartments config for bindings
This commit is contained in:
parent
2181872973
commit
7dbff6efb7
7 changed files with 37 additions and 10 deletions
|
@ -40,6 +40,14 @@ DOMInterfaces = {
|
|||
'WindowProxy' : {
|
||||
'path': 'crate::dom::windowproxy::WindowProxy',
|
||||
'register': False,
|
||||
},
|
||||
|
||||
'Window': {
|
||||
'inCompartments': ['Fetch'],
|
||||
},
|
||||
|
||||
'WorkerGlobalScope': {
|
||||
'inCompartments': ['Fetch'],
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3316,6 +3316,8 @@ class CGCallGenerator(CGThing):
|
|||
|
||||
if "cx" not in argsPre and needsCx:
|
||||
args.prepend(CGGeneric("cx"))
|
||||
if nativeMethodName in descriptor.inCompartmentMethods:
|
||||
args.append(CGGeneric("InCompartment::in_compartment(&AlreadyInCompartment::assert_for_cx(cx))"));
|
||||
|
||||
# Build up our actual call
|
||||
self.cgRoot = CGList([], "\n")
|
||||
|
@ -5640,7 +5642,7 @@ class CGInterfaceTrait(CGThing):
|
|||
name = CGSpecializedMethod.makeNativeName(descriptor, m)
|
||||
infallible = 'infallible' in descriptor.getExtendedAttributes(m)
|
||||
for idx, (rettype, arguments) in enumerate(m.signatures()):
|
||||
arguments = method_arguments(descriptor, rettype, arguments)
|
||||
arguments = method_arguments(descriptor, rettype, arguments, inCompartment=name in descriptor.inCompartmentMethods)
|
||||
rettype = return_type(descriptor, rettype, infallible)
|
||||
yield name + ('_' * idx), arguments, rettype
|
||||
elif m.isAttr() and not m.isStatic():
|
||||
|
@ -5671,7 +5673,7 @@ class CGInterfaceTrait(CGThing):
|
|||
if operation.isGetter():
|
||||
if not rettype.nullable():
|
||||
rettype = IDLNullableType(rettype.location, rettype)
|
||||
arguments = method_arguments(descriptor, rettype, arguments)
|
||||
arguments = method_arguments(descriptor, rettype, arguments, inCompartment=name in descriptor.inCompartmentMethods)
|
||||
|
||||
# If this interface 'supports named properties', then we
|
||||
# should be able to access 'supported property names'
|
||||
|
@ -5681,7 +5683,7 @@ class CGInterfaceTrait(CGThing):
|
|||
if operation.isNamed():
|
||||
yield "SupportedPropertyNames", [], "Vec<DOMString>"
|
||||
else:
|
||||
arguments = method_arguments(descriptor, rettype, arguments)
|
||||
arguments = method_arguments(descriptor, rettype, arguments, inCompartment=name in descriptor.inCompartmentMethods)
|
||||
rettype = return_type(descriptor, rettype, infallible)
|
||||
yield name, arguments, rettype
|
||||
|
||||
|
@ -5975,6 +5977,8 @@ def generate_imports(config, cgthings, descriptors, callbacks=None, dictionaries
|
|||
'crate::dom::windowproxy::WindowProxy',
|
||||
'crate::dom::globalscope::GlobalScope',
|
||||
'crate::mem::malloc_size_of_including_raw_self',
|
||||
'crate::compartments::InCompartment',
|
||||
'crate::compartments::AlreadyInCompartment',
|
||||
'libc',
|
||||
'servo_config::pref',
|
||||
'servo_config::prefs',
|
||||
|
@ -6676,7 +6680,7 @@ def argument_type(descriptorProvider, ty, optional=False, defaultValue=None, var
|
|||
return declType.define()
|
||||
|
||||
|
||||
def method_arguments(descriptorProvider, returnType, arguments, passJSBits=True, trailing=None):
|
||||
def method_arguments(descriptorProvider, returnType, arguments, passJSBits=True, trailing=None, inCompartment=False):
|
||||
if needCx(returnType, arguments, passJSBits):
|
||||
yield "cx", "*mut JSContext"
|
||||
|
||||
|
@ -6688,6 +6692,9 @@ def method_arguments(descriptorProvider, returnType, arguments, passJSBits=True,
|
|||
if trailing:
|
||||
yield trailing
|
||||
|
||||
if inCompartment:
|
||||
yield "_comp", "InCompartment"
|
||||
|
||||
|
||||
def return_type(descriptorProvider, rettype, infallible):
|
||||
result = getRetvalDeclarationForType(rettype, descriptorProvider)
|
||||
|
|
|
@ -223,6 +223,7 @@ class Descriptor(DescriptorProvider):
|
|||
self.concreteType = typeName
|
||||
self.register = desc.get('register', True)
|
||||
self.path = desc.get('path', pathDefault)
|
||||
self.inCompartmentMethods = [name for name in desc.get('inCompartments', [])]
|
||||
self.bindingPath = 'crate::dom::bindings::codegen::Bindings::%s' % ('::'.join([ifaceName + 'Binding'] * 2))
|
||||
self.outerObjectHook = desc.get('outerObjectHook', 'None')
|
||||
self.proxy = False
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::compartments::InCompartment;
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::DocumentBinding::{
|
||||
DocumentMethods, DocumentReadyState,
|
||||
|
@ -1144,8 +1145,9 @@ impl WindowMethods for Window {
|
|||
&self,
|
||||
input: RequestOrUSVString,
|
||||
init: RootedTraceableBox<RequestInit>,
|
||||
comp: InCompartment,
|
||||
) -> Rc<Promise> {
|
||||
fetch::Fetch(&self.upcast(), input, init)
|
||||
fetch::Fetch(&self.upcast(), input, init, comp)
|
||||
}
|
||||
|
||||
fn TestRunner(&self) -> DomRoot<TestRunner> {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::compartments::InCompartment;
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||
use crate::dom::bindings::codegen::Bindings::RequestBinding::RequestInit;
|
||||
|
@ -368,8 +369,9 @@ impl WorkerGlobalScopeMethods for WorkerGlobalScope {
|
|||
&self,
|
||||
input: RequestOrUSVString,
|
||||
init: RootedTraceableBox<RequestInit>,
|
||||
comp: InCompartment,
|
||||
) -> Rc<Promise> {
|
||||
fetch::Fetch(self.upcast(), input, init)
|
||||
fetch::Fetch(self.upcast(), input, init, comp)
|
||||
}
|
||||
|
||||
// https://w3c.github.io/hr-time/#the-performance-attribute
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue