Bug 1144397. Disallow using fill when dedent would do. r=peterv
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 30 Mar 2015 23:43:24 -0400
changeset 236793 b182c5d8d0dffa07d69f35b2d307ac2cf72cdeb6
parent 236792 1f5a169f04763eb5f4cc514119d9b2d2a5e5bfe3
child 236794 538a0b9c118c8ff08066013be4c4adc701c03647
push id57776
push userbzbarsky@mozilla.com
push dateTue, 31 Mar 2015 17:11:44 +0000
treeherdermozilla-inbound@c39ec40cb4e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspeterv
bugs1144397
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1144397. Disallow using fill when dedent would do. r=peterv
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -129,16 +129,19 @@ def dedent(s):
     return textwrap.dedent(s)
 
 
 # This works by transforming the fill()-template to an equivalent
 # string.Template.
 fill_multiline_substitution_re = re.compile(r"( *)\$\*{(\w+)}(\n)?")
 
 
+find_substitutions = re.compile(r"\${")
+
+
 @memoize
 def compile_fill_template(template):
     """
     Helper function for fill().  Given the template string passed to fill(),
     do the reusable part of template processing and return a pair (t,
     argModList) that can be used every time fill() is called with that
     template argument.
 
@@ -168,16 +171,18 @@ def compile_fill_template(template):
             raise ValueError("Invalid fill() template: $*{%s} must appear by itself on a line" % name)
 
         # Now replace this whole line of template with the indented equivalent.
         modified_name = name + "_" + str(depth)
         argModList.append((name, modified_name, depth))
         return "${" + modified_name + "}"
 
     t = re.sub(fill_multiline_substitution_re, replace, t)
+    if not re.search(find_substitutions, t):
+        raise TypeError("Using fill() when dedent() would do.")
     return (string.Template(t), argModList)
 
 
 def fill(template, **args):
     """
     Convenience function for filling in a multiline template.
 
     `fill(template, name1=v1, name2=v2)` is a lot like
@@ -2761,24 +2766,23 @@ class CGCreateInterfaceObjectsMethod(CGA
             namedConstructors=namedConstructors,
             interfaceCache=interfaceCache,
             properties=properties,
             chromeProperties=chromeProperties,
             name='"' + self.descriptor.interface.identifier.name + '"' if needInterfaceObject else "nullptr")
 
         if self.descriptor.hasUnforgeableMembers:
             assert needInterfacePrototypeObject
-            setUnforgeableHolder = CGGeneric(fill(
+            setUnforgeableHolder = CGGeneric(dedent(
                 """
                 if (*protoCache) {
                   js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
                                       JS::ObjectValue(*unforgeableHolder));
                 }
-                """,
-                name=self.descriptor.name))
+                """))
         else:
             setUnforgeableHolder = None
 
         aliasedMembers = [m for m in self.descriptor.interface.members if m.isMethod() and m.aliases]
         if aliasedMembers:
             assert needInterfacePrototypeObject
 
             def defineAlias(alias):
@@ -11509,17 +11513,17 @@ class CGDictionary(CGThing):
                 if (!${dictName}::Init(cx, val)) {
                   return false;
                 }
                 MOZ_ASSERT(IsConvertibleToDictionary(cx, val));
 
                 """,
                 dictName=self.makeClassName(self.dictionary.parent))
         else:
-            body += fill(
+            body += dedent(
                 """
                 if (!IsConvertibleToDictionary(cx, val)) {
                   return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
                 }
 
                 """)
 
         memberInits = [self.getMemberConversion(m).define()
@@ -11595,17 +11599,17 @@ class CGDictionary(CGThing):
                 if (!${dictName}::ToObjectInternal(cx, rval)) {
                   return false;
                 }
                 JS::Rooted<JSObject*> obj(cx, &rval.toObject());
 
                 """,
                 dictName=self.makeClassName(self.dictionary.parent))
         else:
-            body += fill(
+            body += dedent(
                 """
                 JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
                 if (!obj) {
                   return false;
                 }
                 rval.set(JS::ObjectValue(*obj));
 
                 """)