Bug 1531623. Fix webidl identifier conflicts involving typedefs to produce saner exceptions. r=qdot
authorBoris Zbarsky <bzbarsky@mit.edu>
Fri, 01 Mar 2019 20:38:39 +0000
changeset 519885 5ab896c5a05d166321bc8e71424d94bb004f7153
parent 519884 2b32f21ec0dc870475a73ac52cd53706ff023657
child 519886 ac3747e1e5da4dc7564eef9a96668208b9910772
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersqdot
bugs1531623
milestone67.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 1531623. Fix webidl identifier conflicts involving typedefs to produce saner exceptions. r=qdot Differential Revision: https://phabricator.services.mozilla.com/D21647
dom/bindings/parser/WebIDL.py
dom/bindings/parser/tests/test_typedef_identifier_conflict.py
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -2784,19 +2784,21 @@ class IDLTypedefType(IDLType):
         return self.inner.isDistinguishableFrom(other)
 
     def _getDependentObjects(self):
         return self.inner._getDependentObjects()
 
 
 class IDLTypedef(IDLObjectWithIdentifier):
     def __init__(self, location, parentScope, innerType, name):
+        # Set self.innerType first, because IDLObjectWithIdentifier.__init__
+        # will call our __str__, which wants to use it.
+        self.innerType = innerType
         identifier = IDLUnresolvedIdentifier(location, name)
         IDLObjectWithIdentifier.__init__(self, location, parentScope, identifier)
-        self.innerType = innerType
 
     def __str__(self):
         return "Typedef %s %s" % (self.identifier.name, self.innerType)
 
     def finish(self, parentScope):
         if not self.innerType.isComplete():
             self.innerType = self.innerType.complete(parentScope)
 
new file mode 100644
--- /dev/null
+++ b/dom/bindings/parser/tests/test_typedef_identifier_conflict.py
@@ -0,0 +1,16 @@
+def WebIDLTest(parser, harness):
+    exception = None
+    try:
+        parser.parse(
+            """
+            typedef long foo;
+            typedef long foo;
+            """)
+
+        results = parser.finish()
+    except Exception as e:
+        exception = e
+
+    harness.ok(exception, "Should have thrown.")
+    harness.ok("Multiple unresolvable definitions of identifier 'foo'" in str(exception),
+               "Should have a sane exception message")