Update webidl-parser snapshot to pick up bug 742145.
authorKyle Huey <khuey@kylehuey.com>
Thu, 24 May 2012 21:41:33 -0700
changeset 94811 7a9a2341db114df56f6581308940eeadfd0ee8b4
parent 94810 bd4201e13a9f4a5b8fbf88d2204f8143ef264b36
child 94812 faa1929dc2471759a90409ce4b478e57c18403e5
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
bugs742145
milestone15.0a1
Update webidl-parser snapshot to pick up bug 742145.
dom/bindings/parser/WebIDL.py
dom/bindings/parser/tests/test_arraybuffer.py
dom/bindings/parser/tests/test_incomplete_types.py
--- a/dom/bindings/parser/WebIDL.py
+++ b/dom/bindings/parser/WebIDL.py
@@ -605,16 +605,37 @@ class IDLType(IDLObject):
         return False
 
     def isArray(self):
         return False
 
     def isArrayBuffer(self):
         return False
 
+    def isArrayBufferView(self):
+        return False
+
+    def isTypedArray(self):
+        return False
+
+    def isGeckoInterface(self):
+        """ Returns a boolean indicating whether this type is an 'interface'
+            type that is implemented in Gecko. At the moment, this returns
+            true for all interface types that are not types from the TypedArray
+            spec."""
+        return self.isInterface() and not self.isSpiderMonkeyInterface()
+
+    def isSpiderMonkeyInterface(self):
+        """ Returns a boolean indicating whether this type is an 'interface'
+            type that is implemented in Spidermonkey.  At the moment, this
+            only returns true for the types from the TypedArray spec. """
+        return self.isInterface() and (self.isArrayBuffer() or \
+                                       self.isArrayBufferView() or \
+                                       self.isTypedArray())
+
     def isDictionary(self):
         return False
 
     def isInterface(self):
         return False
 
     def isAny(self):
         return self.tag() == IDLType.Tags.any
@@ -725,16 +746,22 @@ class IDLNullableType(IDLType):
         return self.inner.isSequence()
 
     def isArray(self):
         return self.inner.isArray()
 
     def isArrayBuffer(self):
         return self.inner.isArrayBuffer()
 
+    def isArrayBufferView(self):
+        return self.inner.isArrayBufferView()
+
+    def isTypedArray(self):
+        return self.inner.isTypedArray()
+
     def isDictionary(self):
         return self.inner.isDictionary()
 
     def isInterface(self):
         return self.inner.isInterface()
 
     def isEnum(self):
         return self.inner.isEnum()
@@ -935,16 +962,25 @@ class IDLTypedefType(IDLType, IDLObjectW
         return self.inner.isSequence()
 
     def isArray(self):
         return self.inner.isArray()
 
     def isDictionary(self):
         return self.inner.isDictionary()
 
+    def isArrayBuffer(self):
+        return self.inner.isArrayBuffer()
+
+    def isArrayBufferView(self):
+        return self.inner.isArrayBufferView()
+
+    def isTypedArray(self):
+        return self.inner.isTypedArray()
+
     def isInterface(self):
         return self.inner.isInterface()
 
     def resolve(self, parentScope):
         assert isinstance(parentScope, IDLScope)
         IDLObjectWithIdentifier.resolve(self, parentScope)
 
     def tag(self):
@@ -955,24 +991,25 @@ class IDLTypedefType(IDLType, IDLObjectW
 
     def isDistinguishableFrom(self, other):
         return self.inner.isDistinguishableFrom(other)
 
 class IDLWrapperType(IDLType):
     def __init__(self, location, inner):
         IDLType.__init__(self, location, inner.identifier.name)
         self.inner = inner
-        self.name = inner.identifier
+        self._identifier = inner.identifier
         self.builtin = False
 
     def __eq__(self, other):
-        return other and self.name == other.name and self.builtin == other.builtin
+        return other and self._identifier == other._identifier and \
+               self.builtin == other.builtin
 
     def __str__(self):
-        return str(self.name.name) + " (Wrapper)"
+        return str(self.name) + " (Wrapper)"
 
     def nullable(self):
         return False
 
     def isPrimitive(self):
         return False
 
     def isString(self):
@@ -1049,17 +1086,27 @@ class IDLBuiltinType(IDLType):
         'double',
         # Other types
         'any',
         'domstring',
         'object',
         'date',
         'void',
         # Funny stuff
-        'ArrayBuffer'
+        'ArrayBuffer',
+        'ArrayBufferView',
+        'Int8Array',
+        'Uint8Array',
+        'Uint8ClampedArray',
+        'Int16Array',
+        'Uint16Array',
+        'Int32Array',
+        'Uint32Array',
+        'Float32Array',
+        'Float64Array'
         )
 
     TagLookup = {
             Types.byte: IDLType.Tags.int8,
             Types.octet: IDLType.Tags.uint8,
             Types.short: IDLType.Tags.int16,
             Types.unsigned_short: IDLType.Tags.uint16,
             Types.long: IDLType.Tags.int32,
@@ -1069,17 +1116,27 @@ class IDLBuiltinType(IDLType):
             Types.boolean: IDLType.Tags.bool,
             Types.float: IDLType.Tags.float,
             Types.double: IDLType.Tags.double,
             Types.any: IDLType.Tags.any,
             Types.domstring: IDLType.Tags.domstring,
             Types.object: IDLType.Tags.object,
             Types.date: IDLType.Tags.date,
             Types.void: IDLType.Tags.void,
-            Types.ArrayBuffer: IDLType.Tags.interface
+            Types.ArrayBuffer: IDLType.Tags.interface,
+            Types.ArrayBufferView: IDLType.Tags.interface,
+            Types.Int8Array: IDLType.Tags.interface,
+            Types.Uint8Array: IDLType.Tags.interface,
+            Types.Uint8ClampedArray: IDLType.Tags.interface,
+            Types.Int16Array: IDLType.Tags.interface,
+            Types.Uint16Array: IDLType.Tags.interface,
+            Types.Int32Array: IDLType.Tags.interface,
+            Types.Uint32Array: IDLType.Tags.interface,
+            Types.Float32Array: IDLType.Tags.interface,
+            Types.Float64Array: IDLType.Tags.interface
         }
 
     def __init__(self, location, name, type):
         IDLType.__init__(self, location, name)
         self.builtin = True
         self._typeTag = type
 
     def isPrimitive(self):
@@ -1089,21 +1146,30 @@ class IDLBuiltinType(IDLType):
         return self._typeTag == IDLBuiltinType.Types.domstring
 
     def isInteger(self):
         return self._typeTag <= IDLBuiltinType.Types.unsigned_long_long
 
     def isArrayBuffer(self):
         return self._typeTag == IDLBuiltinType.Types.ArrayBuffer
 
+    def isArrayBufferView(self):
+        return self._typeTag == IDLBuiltinType.Types.ArrayBufferView
+
+    def isTypedArray(self):
+        return self._typeTag >= IDLBuiltinType.Types.Int8Array and \
+               self._typeTag <= IDLBuiltinType.Types.Float64Array
+
     def isInterface(self):
-        # ArrayBuffers are interface types per the TypedArray spec,
+        # TypedArray things are interface types per the TypedArray spec,
         # but we handle them as builtins because SpiderMonkey implements
-        # ArrayBuffers.
-        return self._typeTag == IDLBuiltinType.Types.ArrayBuffer
+        # all of it internally.
+        return self.isArrayBuffer() or \
+               self.isArrayBufferView() or \
+               self.isTypedArray()
 
     def isFloat(self):
         return self._typeTag == IDLBuiltinType.Types.float or \
                self._typeTag == IDLBuiltinType.Types.double
 
     def tag(self):
         return IDLBuiltinType.TagLookup[self._typeTag]
 
@@ -1121,22 +1187,34 @@ class IDLBuiltinType(IDLType):
         if self.isDate():
             return (other.isPrimitive() or other.isString() or other.isEnum() or
                     other.isInterface() or other.isCallback() or
                     other.isDictionary() or other.isSequence() or
                     other.isArray())
         if self.isVoid():
             return not other.isVoid()
         # Not much else we could be!
-        assert self.isArrayBuffer()
+        assert self.isSpiderMonkeyInterface()
         # Like interfaces, but we know we're not a callback
         return (other.isPrimitive() or other.isString() or other.isEnum() or
                 other.isCallback() or other.isDictionary() or
                 other.isSequence() or other.isArray() or other.isDate() or
-                (other.isInterface() and not other.isArrayBuffer()))
+                (other.isInterface() and (
+                 # ArrayBuffer is distinguishable from everything
+                 # that's not an ArrayBuffer
+                 (self.isArrayBuffer() and not other.isArrayBuffer()) or
+                 # ArrayBufferView is distinguishable from everything
+                 # that's not an ArrayBufferView or typed array.
+                 (self.isArrayBufferView() and not other.isArrayBufferView() and
+                  not other.isTypedArray()) or
+                 # Typed arrays are distinguishable from everything
+                 # except ArrayBufferView and the same type of typed
+                 # array
+                 (self.isTypedArray() and not other.isArrayBufferView() and not
+                  (other.isTypedArray() and other.name == self.name)))))
 
 BuiltinTypes = {
       IDLBuiltinType.Types.byte:
           IDLBuiltinType(BuiltinLocation("<builtin type>"), "Byte",
                          IDLBuiltinType.Types.byte),
       IDLBuiltinType.Types.octet:
           IDLBuiltinType(BuiltinLocation("<builtin type>"), "Octet",
                          IDLBuiltinType.Types.octet),
@@ -1179,17 +1257,47 @@ BuiltinTypes = {
       IDLBuiltinType.Types.date:
           IDLBuiltinType(BuiltinLocation("<builtin type>"), "Date",
                          IDLBuiltinType.Types.date),
       IDLBuiltinType.Types.void:
           IDLBuiltinType(BuiltinLocation("<builtin type>"), "Void",
                          IDLBuiltinType.Types.void),
       IDLBuiltinType.Types.ArrayBuffer:
           IDLBuiltinType(BuiltinLocation("<builtin type>"), "ArrayBuffer",
-                         IDLBuiltinType.Types.ArrayBuffer)
+                         IDLBuiltinType.Types.ArrayBuffer),
+      IDLBuiltinType.Types.ArrayBufferView:
+          IDLBuiltinType(BuiltinLocation("<builtin type>"), "ArrayBufferView",
+                         IDLBuiltinType.Types.ArrayBufferView),
+      IDLBuiltinType.Types.Int8Array:
+          IDLBuiltinType(BuiltinLocation("<builtin type>"), "Int8Array",
+                         IDLBuiltinType.Types.Int8Array),
+      IDLBuiltinType.Types.Uint8Array:
+          IDLBuiltinType(BuiltinLocation("<builtin type>"), "Uint8Array",
+                         IDLBuiltinType.Types.Uint8Array),
+      IDLBuiltinType.Types.Uint8ClampedArray:
+          IDLBuiltinType(BuiltinLocation("<builtin type>"), "Uint8ClampedArray",
+                         IDLBuiltinType.Types.Uint8ClampedArray),
+      IDLBuiltinType.Types.Int16Array:
+          IDLBuiltinType(BuiltinLocation("<builtin type>"), "Int16Array",
+                         IDLBuiltinType.Types.Int16Array),
+      IDLBuiltinType.Types.Uint16Array:
+          IDLBuiltinType(BuiltinLocation("<builtin type>"), "Uint16Array",
+                         IDLBuiltinType.Types.Uint16Array),
+      IDLBuiltinType.Types.Int32Array:
+          IDLBuiltinType(BuiltinLocation("<builtin type>"), "Int32Array",
+                         IDLBuiltinType.Types.Int32Array),
+      IDLBuiltinType.Types.Uint32Array:
+          IDLBuiltinType(BuiltinLocation("<builtin type>"), "Uint32Array",
+                         IDLBuiltinType.Types.Uint32Array),
+      IDLBuiltinType.Types.Float32Array:
+          IDLBuiltinType(BuiltinLocation("<builtin type>"), "Float32Array",
+                         IDLBuiltinType.Types.Float32Array),
+      IDLBuiltinType.Types.Float64Array:
+          IDLBuiltinType(BuiltinLocation("<builtin type>"), "Float64Array",
+                         IDLBuiltinType.Types.Float64Array)
     }
 
 
 integerTypeSizes = {
         IDLBuiltinType.Types.byte: (-128, 127),
         IDLBuiltinType.Types.octet:  (0, 255),
         IDLBuiltinType.Types.short: (-32768, 32767),
         IDLBuiltinType.Types.unsigned_short: (0, 65535),
@@ -2795,24 +2903,36 @@ class Parser(Tokenizer):
             raise WebIDLError("invalid syntax", Location(self.lexer, p.lineno, p.lexpos, self._filename))
 
     def __init__(self, outputdir=''):
         Tokenizer.__init__(self, outputdir)
         self.parser = yacc.yacc(module=self,
                                 outputdir=outputdir,
                                 tabmodule='webidlyacc')
         self._globalScope = IDLScope(BuiltinLocation("<Global Scope>"), None, None)
+        self._installBuiltins(self._globalScope)
         self._productions = []
 
         self._filename = "<builtin>"
         self.lexer.input(Parser._builtins)
         self._filename = None
 
         self.parser.parse(lexer=self.lexer)
 
+    def _installBuiltins(self, scope):
+        assert isinstance(scope, IDLScope)
+
+        # xrange omits the last value.
+        for x in xrange(IDLBuiltinType.Types.ArrayBuffer, IDLBuiltinType.Types.Float64Array + 1):
+            builtin = BuiltinTypes[x]
+            name = builtin.name
+
+            typedef = IDLTypedefType(BuiltinLocation("<builtin type>"), builtin, name)
+            typedef.resolve(scope)
+
     def parse(self, t, filename=None):
         self.lexer.input(t)
 
         #for tok in iter(self.lexer.token, None):
         #    print tok
 
         self._filename = filename
         self._productions.extend(self.parser.parse(lexer=self.lexer))
--- a/dom/bindings/parser/tests/test_arraybuffer.py
+++ b/dom/bindings/parser/tests/test_arraybuffer.py
@@ -1,25 +1,85 @@
 import WebIDL
 
 def WebIDLTest(parser, harness):
     parser.parse("""
         interface TestArrayBuffer {
-          attribute ArrayBuffer attr;
-          void method(ArrayBuffer arg1, ArrayBuffer? arg2, ArrayBuffer[] arg3, sequence<ArrayBuffer> arg4);
+          attribute ArrayBuffer bufferAttr;
+          void bufferMethod(ArrayBuffer arg1, ArrayBuffer? arg2, ArrayBuffer[] arg3, sequence<ArrayBuffer> arg4);
+
+          attribute ArrayBufferView viewAttr;
+          void viewMethod(ArrayBufferView arg1, ArrayBufferView? arg2, ArrayBufferView[] arg3, sequence<ArrayBufferView> arg4);
+
+          attribute Int8Array int8ArrayAttr;
+          void int8ArrayMethod(Int8Array arg1, Int8Array? arg2, Int8Array[] arg3, sequence<Int8Array> arg4);
+
+          attribute Uint8Array uint8ArrayAttr;
+          void uint8ArrayMethod(Uint8Array arg1, Uint8Array? arg2, Uint8Array[] arg3, sequence<Uint8Array> arg4);
+
+          attribute Uint8ClampedArray uint8ClampedArrayAttr;
+          void uint8ClampedArrayMethod(Uint8ClampedArray arg1, Uint8ClampedArray? arg2, Uint8ClampedArray[] arg3, sequence<Uint8ClampedArray> arg4);
+
+          attribute Int16Array int16ArrayAttr;
+          void int16ArrayMethod(Int16Array arg1, Int16Array? arg2, Int16Array[] arg3, sequence<Int16Array> arg4);
+
+          attribute Uint16Array uint16ArrayAttr;
+          void uint16ArrayMethod(Uint16Array arg1, Uint16Array? arg2, Uint16Array[] arg3, sequence<Uint16Array> arg4);
+
+          attribute Int32Array int32ArrayAttr;
+          void int32ArrayMethod(Int32Array arg1, Int32Array? arg2, Int32Array[] arg3, sequence<Int32Array> arg4);
+
+          attribute Uint32Array uint32ArrayAttr;
+          void uint32ArrayMethod(Uint32Array arg1, Uint32Array? arg2, Uint32Array[] arg3, sequence<Uint32Array> arg4);
+
+          attribute Float32Array float32ArrayAttr;
+          void float32ArrayMethod(Float32Array arg1, Float32Array? arg2, Float32Array[] arg3, sequence<Float32Array> arg4);
+
+          attribute Float64Array float64ArrayAttr;
+          void float64ArrayMethod(Float64Array arg1, Float64Array? arg2, Float64Array[] arg3, sequence<Float64Array> arg4);
         };
     """)
 
     results = parser.finish()
 
     iface = results[0]
 
     harness.ok(True, "TestArrayBuffer interface parsed without error")
-    harness.check(len(iface.members), 2, "Interface should have two members")
+    harness.check(len(iface.members), 22, "Interface should have twenty two members")
+
+    members = iface.members
+
+    def checkStuff(attr, method, t):
+        harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Expect an IDLAttribute")
+        harness.ok(isinstance(method, WebIDL.IDLMethod), "Expect an IDLMethod")
 
-    attr = iface.members[0]
-    method = iface.members[1]
+        harness.check(str(attr.type), t, "Expect an ArrayBuffer type")
+        print type(attr.type)
+        harness.ok(attr.type.isSpiderMonkeyInterface(), "Should test as a js interface")
+
+        (retType, arguments) = method.signatures()[0]
+        harness.ok(retType.isVoid(), "Should have a void return type")
+        harness.check(len(arguments), 4, "Expect 4 arguments")
+
+        harness.check(str(arguments[0].type), t,  "Expect an ArrayBuffer type")
+        harness.ok(arguments[0].type.isSpiderMonkeyInterface(), "Should test as a js interface")
 
-    harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Expect an IDLAttribute")
-    harness.ok(isinstance(method, WebIDL.IDLMethod), "Expect an IDLMethod")
+        harness.check(str(arguments[1].type), t + "OrNull",  "Expect an ArrayBuffer type")
+        harness.ok(arguments[1].type.inner.isSpiderMonkeyInterface(), "Should test as a js interface")
+
+        harness.check(str(arguments[2].type), t + "Array",  "Expect an ArrayBuffer type")
+        harness.ok(arguments[2].type.inner.isSpiderMonkeyInterface(), "Should test as a js interface")
+
+        harness.check(str(arguments[3].type), t + "Sequence",  "Expect an ArrayBuffer type")
+        harness.ok(arguments[3].type.inner.isSpiderMonkeyInterface(), "Should test as a js interface")
+
 
-    harness.check(str(attr.type), "ArrayBuffer", "Expect an ArrayBuffer type")
-    harness.ok(attr.type.isArrayBuffer(), "Expect an ArrayBuffer type")
+    checkStuff(members[0],  members[1],  "ArrayBuffer")
+    checkStuff(members[2],  members[3],  "ArrayBufferView")
+    checkStuff(members[4],  members[5],  "Int8Array")
+    checkStuff(members[6],  members[7],  "Uint8Array")
+    checkStuff(members[8],  members[9],  "Uint8ClampedArray")
+    checkStuff(members[10], members[11], "Int16Array")
+    checkStuff(members[12], members[13], "Uint16Array")
+    checkStuff(members[14], members[15], "Int32Array")
+    checkStuff(members[16], members[17], "Uint32Array")
+    checkStuff(members[18], members[19], "Float32Array")
+    checkStuff(members[20], members[21], "Float64Array")
--- a/dom/bindings/parser/tests/test_incomplete_types.py
+++ b/dom/bindings/parser/tests/test_incomplete_types.py
@@ -27,18 +27,18 @@ def WebIDLTest(parser, harness):
     harness.ok(isinstance(attr, WebIDL.IDLAttribute),
                "Should be an IDLAttribute")
     method = iface.members[1]
     harness.ok(isinstance(method, WebIDL.IDLMethod),
                "Should be an IDLMethod")
 
     harness.check(attr.identifier.QName(), "::TestIncompleteTypes::attr1",
                   "Attribute has the right QName")
-    harness.check(attr.type.name.QName(), "::FooInterface",
+    harness.check(attr.type.name, "FooInterface",
                   "Previously unresolved type has the right name")
 
     harness.check(method.identifier.QName(), "::TestIncompleteTypes::method1",
                   "Attribute has the right QName")
     (returnType, args) = method.signatures()[0]
-    harness.check(returnType.name.QName(), "::FooInterface",
+    harness.check(returnType.name, "FooInterface",
                   "Previously unresolved type has the right name")
-    harness.check(args[0].type.name.QName(), "::FooInterface",
+    harness.check(args[0].type.name, "FooInterface",
                   "Previously unresolved type has the right name")