Bug 960653 - part 1 - assert that we don't overflow JSJitInfo fields in bindings codegen; r=bz
authorNathan Froyd <froydnj@mozilla.com>
Thu, 16 Jan 2014 11:20:51 -0500
changeset 163880 2da6a47736c54505c67cef95e77e0a2897f71526
parent 163879 1e77fda6a5e092faebae0b72e2d0c94defa2ee60
child 163881 4b70796946456df101de34d7b4ef84619fe58f08
push id38579
push usernfroyd@mozilla.com
push dateFri, 17 Jan 2014 02:06:03 +0000
treeherdermozilla-inbound@4b7079694645 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs960653
milestone29.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 960653 - part 1 - assert that we don't overflow JSJitInfo fields in bindings codegen; r=bz
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -11501,26 +11501,37 @@ class GlobalGenRoots():
                               post=") \\\n")
             macroContent = CGIndenter(CGList(supplied + remaining, ", \\\n"))
             macroContent = CGIndenter(CGWrapper(macroContent, pre="{ \\\n",
                                                 post=" \\\n}"))
             return CGWrapper(CGList([macro, macroContent]), post="\n\n")
 
         idEnum.append(ifaceChainMacro(1))
 
+        def fieldSizeAssert(amount, jitInfoField, message):
+            maxFieldValue = "(uint64_t(1) << (sizeof(((JSJitInfo*)nullptr)->%s) * 8))" % jitInfoField
+            return CGGeneric(declare="static_assert(%s < %s, \"%s\");\n\n"
+                             % (amount, maxFieldValue, message))
+
+        idEnum.append(fieldSizeAssert("id::_ID_Count", "protoID",
+                                      "Too many prototypes!"));
+
         # Wrap all of that in our namespaces.
         idEnum = CGNamespace.build(['mozilla', 'dom', 'prototypes'],
                                    CGWrapper(idEnum, pre='\n'))
         idEnum = CGWrapper(idEnum, post='\n')
 
         curr = CGList([idEnum])
 
         # Let things know the maximum length of the prototype chain.
-        maxMacro = CGGeneric(declare="#define MAX_PROTOTYPE_CHAIN_LENGTH " + str(config.maxProtoChainLength))
+        maxMacroName = "MAX_PROTOTYPE_CHAIN_LENGTH"
+        maxMacro = CGGeneric(declare="#define " + maxMacroName + " " + str(config.maxProtoChainLength))
         curr.append(CGWrapper(maxMacro, post='\n\n'))
+        curr.append(fieldSizeAssert(maxMacroName, "depth",
+                                    "Some inheritance chain is too long!"));
 
         # Constructor ID enum.
         constructors = [d.name for d in config.getDescriptors(hasInterfaceObject=True)]
         idEnum = CGNamespacedEnum('id', 'ID', ['_ID_Start'] + constructors,
                                   ['prototypes::id::_ID_Count', '_ID_Start'])
 
         # Wrap all of that in our namespaces.
         idEnum = CGNamespace.build(['mozilla', 'dom', 'constructors'],