Bug 1277401 part 5. Change dictionary codegen to output Func stuff as needed. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 07 Jun 2016 10:34:54 -0400
changeset 300915 44182df669827908761c819bdb2cba1c15ce39e5
parent 300914 759fdef36b82043a3a95a830d686d0903f4a28fc
child 300916 8eabc0613ebc8b6a625234bece4a924ad91c0aa2
push id19599
push usercbook@mozilla.com
push dateWed, 08 Jun 2016 10:16:21 +0000
treeherderfx-team@81f4cc3f6f4c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1277401
milestone50.0a1
Bug 1277401 part 5. Change dictionary codegen to output Func stuff as needed. r=peterv
dom/bindings/Codegen.py
dom/bindings/test/TestCodeGen.webidl
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -12777,28 +12777,29 @@ class CGDictionary(CGThing):
             "prop": self.makeMemberName(member.identifier.name),
             "convert": string.Template(conversionInfo.template).substitute(replacements),
             "propGet": propGet
         }
         # The conversion code will only run where a default value or a value passed
         # by the author needs to get converted, so we can remember if we have any
         # members present here.
         conversionReplacements["convert"] += "mIsAnyMemberPresent = true;\n"
-        if isChromeOnly(member):
-            conversion = ("if (!isNull) {\n"
-                          "  if (!nsContentUtils::ThreadsafeIsCallerChrome()) {\n"
-                          "    temp->setUndefined();\n"
-                          "  } else if (!${propGet}) {\n"
-                          "    return false;\n"
-                          "  }\n"
-                          "}\n")
-        else:
-            conversion = ("if (!isNull && !${propGet}) {\n"
-                          "  return false;\n"
-                          "}\n")
+        setTempValue = CGGeneric(dedent(
+            """
+            if (!${propGet}) {
+              return false;
+            }
+            """))
+        conditions = getConditionList(member, "cx", "*object")
+        if len(conditions) != 0:
+            setTempValue = CGIfElseWrapper(conditions.define(),
+                                           setTempValue,
+                                           CGGeneric("temp->setUndefined();\n"))
+        setTempValue = CGIfWrapper(setTempValue, "!isNull")
+        conversion = setTempValue.define()
         if member.defaultValue:
             if (member.type.isUnion() and
                 (not member.type.nullable() or
                  not isinstance(member.defaultValue, IDLNullValue))):
                 # Since this has a default value, it might have been initialized
                 # already.  Go ahead and uninit it before we try to init it
                 # again.
                 memberName = self.makeMemberName(member.identifier.name)
@@ -12898,18 +12899,19 @@ class CGDictionary(CGThing):
         conversion = CGWrapper(
             CGIndenter(conversion),
             pre=("do {\n"
                  "  // block for our 'break' successCode and scope for 'temp' and 'currentValue'\n"),
             post="} while(0);\n")
         if member.canHaveMissingValue():
             # Only do the conversion if we have a value
             conversion = CGIfWrapper(conversion, "%s.WasPassed()" % memberLoc)
-        if isChromeOnly(member):
-            conversion = CGIfWrapper(conversion, "nsContentUtils::ThreadsafeIsCallerChrome()")
+        conditions = getConditionList(member, "cx", "obj")
+        if len(conditions) != 0:
+            conversion = CGIfWrapper(conversion, conditions.define())
         return conversion
 
     def getMemberTrace(self, member):
         type = member.type
         assert typeNeedsRooting(type)
         memberLoc = self.makeMemberName(member.identifier.name)
         if not member.canHaveMissingValue():
             memberData = memberLoc
--- a/dom/bindings/test/TestCodeGen.webidl
+++ b/dom/bindings/test/TestCodeGen.webidl
@@ -1124,16 +1124,25 @@ dictionary DictForConstructor {
   sequence<any> seq4;
   sequence<any> seq5;
   sequence<DictContainingSequence> seq6;
   object obj1;
   object? obj2;
   any any1 = null;
 };
 
+dictionary DictWithConditionalMembers {
+  [ChromeOnly]
+  long chromeOnlyMember;
+  [Func="TestFuncControlledMember"]
+  long funcControlledMember;
+  [ChromeOnly, Func="nsGenericHTMLElement::TouchEventsEnabled"]
+  long chromeOnlyFuncControlledMember;
+};
+
 interface TestIndexedGetterInterface {
   getter long item(unsigned long idx);
   readonly attribute unsigned long length;
   legacycaller void();
 };
 
 interface TestNamedGetterInterface {
   getter DOMString (DOMString name);