Bug 895728 part 2. Make booleans, numerics, and strings/enums all be distinguishable from each other. r=khuey
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 30 Jul 2013 10:39:34 -0700
changeset 152868 7cc767d92af6b96798c0e49b31da9f00b410f8ad
parent 152867 11874cb8656063fa6b32d5427d013d233955308d
child 152869 c4e3b826d3f323f2922c5b5acdb0deddd4deaa99
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskhuey
bugs895728
milestone25.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 895728 part 2. Make booleans, numerics, and strings/enums all be distinguishable from each other. r=khuey
dom/bindings/parser/WebIDL.py
dom/bindings/parser/tests/test_distinguishability.py
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -1968,17 +1968,17 @@ class IDLWrapperType(IDLType):
             assert False
 
     def isDistinguishableFrom(self, other):
         if other.isUnion():
             # Just forward to the union; it'll deal
             return other.isDistinguishableFrom(self)
         assert self.isInterface() or self.isEnum() or self.isDictionary()
         if self.isEnum():
-            return (other.isInterface() or other.isObject() or
+            return (other.isPrimitive() or other.isInterface() or other.isObject() or
                     other.isCallback() or other.isDictionary() or
                     other.isSequence() or other.isArray() or
                     other.isDate())
         if self.isDictionary() and other.nullable():
             return False
         if other.isPrimitive() or other.isString() or other.isEnum() or other.isDate():
             return True
         if self.isDictionary():
@@ -2159,18 +2159,31 @@ class IDLBuiltinType(IDLType):
 
     def tag(self):
         return IDLBuiltinType.TagLookup[self._typeTag]
 
     def isDistinguishableFrom(self, other):
         if other.isUnion():
             # Just forward to the union; it'll deal
             return other.isDistinguishableFrom(self)
-        if self.isPrimitive() or self.isString():
-            return (other.isInterface() or other.isObject() or
+        if self.isBoolean():
+            return (other.isNumeric() or other.isString() or other.isEnum() or
+                    other.isInterface() or other.isObject() or
+                    other.isCallback() or other.isDictionary() or
+                    other.isSequence() or other.isArray() or
+                    other.isDate())
+        if self.isNumeric():
+            return (other.isBoolean() or other.isString() or other.isEnum() or
+                    other.isInterface() or other.isObject() or
+                    other.isCallback() or other.isDictionary() or
+                    other.isSequence() or other.isArray() or
+                    other.isDate())
+        if self.isString():
+            return (other.isPrimitive() or other.isInterface() or
+                    other.isObject() or
                     other.isCallback() or other.isDictionary() or
                     other.isSequence() or other.isArray() or
                     other.isDate())
         if self.isAny():
             # Can't tell "any" apart from anything
             return False
         if self.isObject():
             return other.isPrimitive() or other.isString() or other.isEnum()
--- a/dom/bindings/parser/tests/test_distinguishability.py
+++ b/dom/bindings/parser/tests/test_distinguishability.py
@@ -145,77 +145,90 @@ def WebIDLTest(parser, harness):
         """)
         results = parser.finish()
     except:
         threw = True
 
     harness.ok(threw, "Should throw when there is no distinguishing index")
 
     # Now let's test our whole distinguishability table
-    argTypes = [ "long", "short", "long?", "short?", "DOMString", "Enum",
-                 "Enum2", "Interface", "Interface?",
+    argTypes = [ "long", "short", "long?", "short?", "boolean",
+                 "boolean?", "DOMString", "ByteString", "Enum", "Enum2",
+                 "Interface", "Interface?",
                  "AncestorInterface", "UnrelatedInterface",
                  "ImplementedInterface", "CallbackInterface",
                  "CallbackInterface?", "CallbackInterface2",
                  "object", "Callback", "Callback2", "optional Dict",
                  "optional Dict2", "sequence<long>", "sequence<short>",
-                 "long[]", "short[]", "Date", "Date?" ]
+                 "long[]", "short[]", "Date", "Date?", "any" ]
     # When we can parse Date and RegExp, we need to add them here.
 
     # Try to categorize things a bit to keep list lengths down
     def allBut(list1, list2):
-        return [a for a in list1 if a not in list2]
-    primitives = [ "long", "short", "long?", "short?", "DOMString",
-                   "Enum", "Enum2" ]
-    nonPrimitives = allBut(argTypes, primitives)
+        return [a for a in list1 if a not in list2 and a != "any"]
+    numerics = [ "long", "short", "long?", "short?" ]
+    booleans = [ "boolean", "boolean?" ]
+    primitives = numerics + booleans
+    nonNumerics = allBut(argTypes, numerics)
+    nonBooleans = allBut(argTypes, booleans)
+    strings = [ "DOMString", "ByteString", "Enum", "Enum2" ]
+    nonStrings = allBut(argTypes, strings)
+    nonObjects = primitives + strings
+    objects = allBut(argTypes, nonObjects )
     interfaces = [ "Interface", "Interface?", "AncestorInterface",
                    "UnrelatedInterface", "ImplementedInterface" ]
-    nullables = ["long?", "short?", "Interface?", "CallbackInterface?",
-                 "optional Dict", "optional Dict2", "Date?"]
+    nullables = ["long?", "short?", "boolean?", "Interface?",
+                 "CallbackInterface?", "optional Dict", "optional Dict2",
+                 "Date?", "any"]
     dates = [ "Date", "Date?" ]
-    nonUserObjects = primitives + interfaces + dates
+    nonUserObjects = nonObjects + interfaces + dates
     otherObjects = allBut(argTypes, nonUserObjects + ["object"])
-    notRelatedInterfaces = primitives + ["UnrelatedInterface"] + otherObjects + dates
+    notRelatedInterfaces = (nonObjects + ["UnrelatedInterface"] +
+                            otherObjects + dates)
 
     # Build a representation of the distinguishability table as a dict
     # of dicts, holding True values where needed, holes elsewhere.
     data = dict();
     for type in argTypes:
         data[type] = dict()
     def setDistinguishable(type, types):
         for other in types:
             data[type][other] = True
 
-    setDistinguishable("long", nonPrimitives)
-    setDistinguishable("short", nonPrimitives)
-    setDistinguishable("long?", allBut(nonPrimitives, nullables))
-    setDistinguishable("short?", allBut(nonPrimitives, nullables))
-    setDistinguishable("DOMString", nonPrimitives)
-    setDistinguishable("Enum", nonPrimitives)
-    setDistinguishable("Enum2", nonPrimitives)
+    setDistinguishable("long", nonNumerics)
+    setDistinguishable("short", nonNumerics)
+    setDistinguishable("long?", allBut(nonNumerics, nullables))
+    setDistinguishable("short?", allBut(nonNumerics, nullables))
+    setDistinguishable("boolean", nonBooleans)
+    setDistinguishable("boolean?", allBut(nonBooleans, nullables))
+    setDistinguishable("DOMString", nonStrings)
+    setDistinguishable("ByteString", nonStrings)
+    setDistinguishable("Enum", nonStrings)
+    setDistinguishable("Enum2", nonStrings)
     setDistinguishable("Interface", notRelatedInterfaces)
     setDistinguishable("Interface?", allBut(notRelatedInterfaces, nullables))
     setDistinguishable("AncestorInterface", notRelatedInterfaces)
     setDistinguishable("UnrelatedInterface",
                        allBut(argTypes, ["object", "UnrelatedInterface"]))
     setDistinguishable("ImplementedInterface", notRelatedInterfaces)
     setDistinguishable("CallbackInterface", nonUserObjects)
     setDistinguishable("CallbackInterface?", allBut(nonUserObjects, nullables))
     setDistinguishable("CallbackInterface2", nonUserObjects)
-    setDistinguishable("object", primitives)
+    setDistinguishable("object", nonObjects)
     setDistinguishable("Callback", nonUserObjects)
     setDistinguishable("Callback2", nonUserObjects)
     setDistinguishable("optional Dict", allBut(nonUserObjects, nullables))
     setDistinguishable("optional Dict2", allBut(nonUserObjects, nullables))
     setDistinguishable("sequence<long>", nonUserObjects)
     setDistinguishable("sequence<short>", nonUserObjects)
     setDistinguishable("long[]", nonUserObjects)
     setDistinguishable("short[]", nonUserObjects)
     setDistinguishable("Date", allBut(argTypes, dates + ["object"]))
     setDistinguishable("Date?", allBut(argTypes, dates + nullables + ["object"]))
+    setDistinguishable("any", [])
 
     def areDistinguishable(type1, type2):
         return data[type1].get(type2, False)
 
     def checkDistinguishability(parser, type1, type2):
         idlTemplate = """
           enum Enum { "a", "b" };
           enum Enum2 { "c", "d" };