Bug 1500926 - Part 2: Support a test-only edgecase in Codegen.py, r=bzbarsky
authorNika Layzell <nika@thelayzells.com>
Mon, 22 Oct 2018 00:57:24 -0400
changeset 491207 3d9631fca868cb87b172f0b615aea84042084356
parent 491206 80b71708f7ca5d177b3ffb46b518d69d45540310
child 491208 8b0b407e053f4bbde1b14abc8b3d28d6251c908b
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersbzbarsky
bugs1500926
milestone65.0a1
Bug 1500926 - Part 2: Support a test-only edgecase in Codegen.py, r=bzbarsky When running tests, we can build a WebIDL environment with no interfaces exposed on the primary global. Unfortunately, due to the perfecthash.py logic not handling empty tables, this causes an assertion to be raised. We can work around this by generating some dummy code for that situation, as we will never try to build it. Differential Revision: https://phabricator.services.mozilla.com/D9407
dom/bindings/Codegen.py
--- a/dom/bindings/Codegen.py
+++ b/dom/bindings/Codegen.py
@@ -13725,16 +13725,25 @@ class CGGlobalNames(CGGeneric):
                 nameLength=len(name),
                 name=name,
                 realname=desc.name,
                 enabled=("%s_Binding::ConstructorEnabled" % desc.name
                          if desc.isExposedConditionally() else "nullptr"))
 
             entries.append((name, nativeEntry))
 
+        # Unfortunately, when running tests, we may have no entries.
+        # PerfectHash will assert if we give it an empty set of entries, so we
+        # just generate a dummy value.
+        if len(entries) == 0:
+            CGGeneric.__init__(self, define=dedent('''
+                static_assert(false, "No WebIDL global name entries!");
+                '''))
+            return
+
         # Build the perfect hash function.
         phf = PerfectHash(entries, GLOBAL_NAMES_PHF_SIZE)
 
         # Generate code for the PHF
         phfCodegen = phf.codegen('WebIDLGlobalNameHash::sEntries',
                                  'WebIDLNameTableEntry')
         entries = phfCodegen.gen_entries(lambda e: e[1])
         getter = phfCodegen.gen_jsflatstr_getter(