Skip to content

Commit

Permalink
Add support for attributes to the inCompartments binding parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Eijebong committed May 25, 2019
1 parent 7dbff6e commit 0b29caa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
6 changes: 5 additions & 1 deletion components/script/dom/bindings/codegen/Bindings.conf
Expand Up @@ -48,6 +48,10 @@ DOMInterfaces = {

'WorkerGlobalScope': {
'inCompartments': ['Fetch'],
}
},

'TestBinding': {
'inCompartments': ['PromiseAttribute'],
},

}
9 changes: 6 additions & 3 deletions components/script/dom/bindings/codegen/CodegenRust.py
Expand Up @@ -5627,13 +5627,16 @@ class CGInterfaceTrait(CGThing):
def __init__(self, descriptor):
CGThing.__init__(self)

def attribute_arguments(needCx, argument=None):
def attribute_arguments(needCx, argument=None, inCompartment=False):
if needCx:
yield "cx", "*mut JSContext"

if argument:
yield "value", argument_type(descriptor, argument)

if inCompartment:
yield "_comp", "InCompartment"

def members():
for m in descriptor.interface.members:
if (m.isMethod() and not m.isStatic() and
Expand All @@ -5649,7 +5652,7 @@ def members():
name = CGSpecializedGetter.makeNativeName(descriptor, m)
infallible = 'infallible' in descriptor.getExtendedAttributes(m, getter=True)
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))

if not m.readonly:
Expand All @@ -5659,7 +5662,7 @@ def members():
rettype = "()"
else:
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:
for name, operation in descriptor.operations.iteritems():
Expand Down
5 changes: 2 additions & 3 deletions components/script/dom/testbinding.rs
Expand Up @@ -1048,11 +1048,10 @@ impl TestBindingMethods for TestBinding {
}
}

fn PromiseAttribute(&self) -> Rc<Promise> {
let in_compartment_proof = AlreadyInCompartment::assert(&self.global());
fn PromiseAttribute(&self, comp: InCompartment) -> Rc<Promise> {
Promise::new_in_current_compartment(
&self.global(),
InCompartment::Already(&in_compartment_proof),
comp
)
}

Expand Down

0 comments on commit 0b29caa

Please sign in to comment.