Add support for attributes to the inCompartments binding parameter

This commit is contained in:
Bastien Orivel 2019-05-25 14:43:44 +02:00
parent 7dbff6efb7
commit 0b29caa554
3 changed files with 13 additions and 7 deletions

View file

@ -48,6 +48,10 @@ DOMInterfaces = {
'WorkerGlobalScope': { 'WorkerGlobalScope': {
'inCompartments': ['Fetch'], 'inCompartments': ['Fetch'],
} },
'TestBinding': {
'inCompartments': ['PromiseAttribute'],
},
} }

View file

@ -5627,13 +5627,16 @@ class CGInterfaceTrait(CGThing):
def __init__(self, descriptor): def __init__(self, descriptor):
CGThing.__init__(self) CGThing.__init__(self)
def attribute_arguments(needCx, argument=None): def attribute_arguments(needCx, argument=None, inCompartment=False):
if needCx: if needCx:
yield "cx", "*mut JSContext" yield "cx", "*mut JSContext"
if argument: if argument:
yield "value", argument_type(descriptor, argument) yield "value", argument_type(descriptor, argument)
if inCompartment:
yield "_comp", "InCompartment"
def members(): def members():
for m in descriptor.interface.members: for m in descriptor.interface.members:
if (m.isMethod() and not m.isStatic() and if (m.isMethod() and not m.isStatic() and
@ -5649,7 +5652,7 @@ class CGInterfaceTrait(CGThing):
name = CGSpecializedGetter.makeNativeName(descriptor, m) name = CGSpecializedGetter.makeNativeName(descriptor, m)
infallible = 'infallible' in descriptor.getExtendedAttributes(m, getter=True) infallible = 'infallible' in descriptor.getExtendedAttributes(m, getter=True)
yield (name, yield (name,
attribute_arguments(typeNeedsCx(m.type, True)), attribute_arguments(typeNeedsCx(m.type, True), inCompartment=name in descriptor.inCompartmentMethods),
return_type(descriptor, m.type, infallible)) return_type(descriptor, m.type, infallible))
if not m.readonly: if not m.readonly:
@ -5659,7 +5662,7 @@ class CGInterfaceTrait(CGThing):
rettype = "()" rettype = "()"
else: else:
rettype = "ErrorResult" rettype = "ErrorResult"
yield name, attribute_arguments(typeNeedsCx(m.type, False), m.type), rettype yield name, attribute_arguments(typeNeedsCx(m.type, False), m.type, inCompartment=name in descriptor.inCompartmentMethods), rettype
if descriptor.proxy: if descriptor.proxy:
for name, operation in descriptor.operations.iteritems(): for name, operation in descriptor.operations.iteritems():

View file

@ -1048,11 +1048,10 @@ impl TestBindingMethods for TestBinding {
} }
} }
fn PromiseAttribute(&self) -> Rc<Promise> { fn PromiseAttribute(&self, comp: InCompartment) -> Rc<Promise> {
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
Promise::new_in_current_compartment( Promise::new_in_current_compartment(
&self.global(), &self.global(),
InCompartment::Already(&in_compartment_proof), comp
) )
} }