Bug 1286548 - SecureContext makes sense for interface with NoInterfaceObject, since it is also propagated to interface members; r=bz
authorEdgar Chen <echen@mozilla.com>
Thu, 14 Jul 2016 17:48:20 +0800
changeset 330324 4cefce05d01dd194c47090e51f9796a109674352
parent 330323 93b1deb435f2683e713904edd792b15381f2ef89
child 330325 5de877ba2a5d04088d3f62bcb38c84e04f082046
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1286548
milestone50.0a1
Bug 1286548 - SecureContext makes sense for interface with NoInterfaceObject, since it is also propagated to interface members; r=bz MozReview-Commit-ID: K7Z3r2YRt7M
dom/bindings/parser/WebIDL.py
dom/bindings/parser/tests/test_securecontext_extended_attribute.py
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -1290,17 +1290,19 @@ class IDLInterfaceOrNamespace(IDLObjectW
         if (self.getExtendedAttribute("Pref") and
             self._exposureGlobalNames != set([self.parentScope.primaryGlobalName])):
             raise WebIDLError("[Pref] used on an interface that is not %s-only" %
                               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
@@ -1528,18 +1530,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")