Bug 1286548 - SecureContext makes sense for interface with NoInterfaceObject, since it is also propagated to interface members; r?bz
MozReview-Commit-ID: K7Z3r2YRt7M
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -1301,17 +1301,19 @@ class IDLInterfaceOrNamespace(IDLObjectW
self._exposureGlobalNames != set([self.parentScope.primaryGlobalName])):
raise WebIDLError("[%s] used on an interface that is "
"not %s-only" %
(attribute, self.parentScope.primaryGlobalName),
[self.location])
# Conditional exposure makes no sense for interfaces with no
# interface object, unless they're navigator properties.
- if (self.isExposedConditionally() and
+ # And SecureContext makes sense for interfaces with no interface object,
+ # since it is also propagated to interface members.
+ if (self.isExposedConditionally(exclusions=["SecureContext"]) and
not self.hasInterfaceObject() and
not self.isNavigatorProperty()):
raise WebIDLError("Interface with no interface object is "
"exposed conditionally",
[self.location])
# Value iterators are only allowed on interfaces with indexed getters,
# and pair iterators are only allowed on interfaces without indexed
@@ -1539,18 +1541,18 @@ class IDLInterfaceOrNamespace(IDLObjectW
def hasMembersInSlots(self):
return self._ownMembersInSlots != 0
conditionExtendedAttributes = [ "Pref", "ChromeOnly", "Func", "AvailableIn",
"SecureContext",
"CheckAnyPermissions",
"CheckAllPermissions" ]
- def isExposedConditionally(self):
- return any(self.getExtendedAttribute(a) for a in self.conditionExtendedAttributes)
+ def isExposedConditionally(self, exclusions=[]):
+ return any(((not a in exclusions) and self.getExtendedAttribute(a)) for a in self.conditionExtendedAttributes)
class IDLInterface(IDLInterfaceOrNamespace):
def __init__(self, location, parentScope, name, parent, members,
isKnownNonPartial):
IDLInterfaceOrNamespace.__init__(self, location, parentScope, name,
parent, members, isKnownNonPartial)
def __str__(self):
--- a/dom/bindings/parser/tests/test_securecontext_extended_attribute.py
+++ b/dom/bindings/parser/tests/test_securecontext_extended_attribute.py
@@ -311,8 +311,22 @@ def WebIDLTest(parser, harness):
"[SecureContext] should propagate from interface to constant members even when other members are copied from a non-[SecureContext] interface")
harness.ok(results[0].members[1].getExtendedAttribute("SecureContext") is None,
"Constants copied from non-[SecureContext] interface should not be [SecureContext]")
harness.ok(results[0].members[2].getExtendedAttribute("SecureContext") is None,
"Attributes copied from non-[SecureContext] interface should not be [SecureContext]")
harness.ok(results[0].members[3].getExtendedAttribute("SecureContext") is None,
"Methods copied from non-[SecureContext] interface should not be [SecureContext]")
+ # Test SecureContext and NoInterfaceObject
+ parser = parser.reset()
+ parser.parse("""
+ [NoInterfaceObject, SecureContext]
+ interface TestSecureContextNoInterfaceObject {
+ void testSecureMethod(byte foo);
+ };
+ """)
+ results = parser.finish()
+ harness.check(len(results[0].members), 1, "TestSecureContextNoInterfaceObject should have only one member")
+ harness.ok(results[0].getExtendedAttribute("SecureContext"),
+ "Interface should have [SecureContext] extended attribute")
+ harness.ok(results[0].members[0].getExtendedAttribute("SecureContext"),
+ "Interface member should have [SecureContext] extended attribute")