aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/codegen/CodegenRust.py
diff options
context:
space:
mode:
authorBastien Orivel <eijebong@bananium.fr>2019-05-24 22:24:41 +0200
committerBastien Orivel <eijebong@bananium.fr>2019-05-24 23:02:38 +0200
commit7dbff6efb7ce93ecfb04883cd1dffa24a03ed0ad (patch)
tree6cecd1c857227a6d61188689c143d7bf99a50d0b /components/script/dom/bindings/codegen/CodegenRust.py
parent2181872973ce49b50ed2dd077c4fdde6f4c5d019 (diff)
downloadservo-7dbff6efb7ce93ecfb04883cd1dffa24a03ed0ad.tar.gz
servo-7dbff6efb7ce93ecfb04883cd1dffa24a03ed0ad.zip
Add an inCompartments config for bindings
Diffstat (limited to 'components/script/dom/bindings/codegen/CodegenRust.py')
-rw-r--r--components/script/dom/bindings/codegen/CodegenRust.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py
index 27bfdce71b4..9032012dea7 100644
--- a/components/script/dom/bindings/codegen/CodegenRust.py
+++ b/components/script/dom/bindings/codegen/CodegenRust.py
@@ -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)