diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index 48041abafb35..50fdd8c6c8eb 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -610,6 +610,27 @@ class IDLType(IDLObject): 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 @@ -730,6 +751,12 @@ class IDLNullableType(IDLType): 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() @@ -940,6 +967,15 @@ class IDLTypedefType(IDLType, IDLObjectWithIdentifier): 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() @@ -960,14 +996,15 @@ 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 @@ -1054,7 +1091,17 @@ class IDLBuiltinType(IDLType): 'date', 'void', # Funny stuff - 'ArrayBuffer' + 'ArrayBuffer', + 'ArrayBufferView', + 'Int8Array', + 'Uint8Array', + 'Uint8ClampedArray', + 'Int16Array', + 'Uint16Array', + 'Int32Array', + 'Uint32Array', + 'Float32Array', + 'Float64Array' ) TagLookup = { @@ -1074,7 +1121,17 @@ class IDLBuiltinType(IDLType): 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): @@ -1094,11 +1151,20 @@ class IDLBuiltinType(IDLType): 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 \ @@ -1126,12 +1192,24 @@ class IDLBuiltinType(IDLType): 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: @@ -1184,7 +1262,37 @@ BuiltinTypes = { IDLBuiltinType.Types.void), IDLBuiltinType.Types.ArrayBuffer: IDLBuiltinType(BuiltinLocation(""), "ArrayBuffer", - IDLBuiltinType.Types.ArrayBuffer) + IDLBuiltinType.Types.ArrayBuffer), + IDLBuiltinType.Types.ArrayBufferView: + IDLBuiltinType(BuiltinLocation(""), "ArrayBufferView", + IDLBuiltinType.Types.ArrayBufferView), + IDLBuiltinType.Types.Int8Array: + IDLBuiltinType(BuiltinLocation(""), "Int8Array", + IDLBuiltinType.Types.Int8Array), + IDLBuiltinType.Types.Uint8Array: + IDLBuiltinType(BuiltinLocation(""), "Uint8Array", + IDLBuiltinType.Types.Uint8Array), + IDLBuiltinType.Types.Uint8ClampedArray: + IDLBuiltinType(BuiltinLocation(""), "Uint8ClampedArray", + IDLBuiltinType.Types.Uint8ClampedArray), + IDLBuiltinType.Types.Int16Array: + IDLBuiltinType(BuiltinLocation(""), "Int16Array", + IDLBuiltinType.Types.Int16Array), + IDLBuiltinType.Types.Uint16Array: + IDLBuiltinType(BuiltinLocation(""), "Uint16Array", + IDLBuiltinType.Types.Uint16Array), + IDLBuiltinType.Types.Int32Array: + IDLBuiltinType(BuiltinLocation(""), "Int32Array", + IDLBuiltinType.Types.Int32Array), + IDLBuiltinType.Types.Uint32Array: + IDLBuiltinType(BuiltinLocation(""), "Uint32Array", + IDLBuiltinType.Types.Uint32Array), + IDLBuiltinType.Types.Float32Array: + IDLBuiltinType(BuiltinLocation(""), "Float32Array", + IDLBuiltinType.Types.Float32Array), + IDLBuiltinType.Types.Float64Array: + IDLBuiltinType(BuiltinLocation(""), "Float64Array", + IDLBuiltinType.Types.Float64Array) } @@ -2800,6 +2908,7 @@ class Parser(Tokenizer): outputdir=outputdir, tabmodule='webidlyacc') self._globalScope = IDLScope(BuiltinLocation(""), None, None) + self._installBuiltins(self._globalScope) self._productions = [] self._filename = "" @@ -2808,6 +2917,17 @@ class Parser(Tokenizer): 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, name) + typedef.resolve(scope) + def parse(self, t, filename=None): self.lexer.input(t) diff --git a/dom/bindings/parser/tests/test_arraybuffer.py b/dom/bindings/parser/tests/test_arraybuffer.py index 7504b38012d0..fe4d8bbfeaaf 100644 --- a/dom/bindings/parser/tests/test_arraybuffer.py +++ b/dom/bindings/parser/tests/test_arraybuffer.py @@ -3,8 +3,38 @@ import WebIDL def WebIDLTest(parser, harness): parser.parse(""" interface TestArrayBuffer { - attribute ArrayBuffer attr; - void method(ArrayBuffer arg1, ArrayBuffer? arg2, ArrayBuffer[] arg3, sequence arg4); + attribute ArrayBuffer bufferAttr; + void bufferMethod(ArrayBuffer arg1, ArrayBuffer? arg2, ArrayBuffer[] arg3, sequence arg4); + + attribute ArrayBufferView viewAttr; + void viewMethod(ArrayBufferView arg1, ArrayBufferView? arg2, ArrayBufferView[] arg3, sequence arg4); + + attribute Int8Array int8ArrayAttr; + void int8ArrayMethod(Int8Array arg1, Int8Array? arg2, Int8Array[] arg3, sequence arg4); + + attribute Uint8Array uint8ArrayAttr; + void uint8ArrayMethod(Uint8Array arg1, Uint8Array? arg2, Uint8Array[] arg3, sequence arg4); + + attribute Uint8ClampedArray uint8ClampedArrayAttr; + void uint8ClampedArrayMethod(Uint8ClampedArray arg1, Uint8ClampedArray? arg2, Uint8ClampedArray[] arg3, sequence arg4); + + attribute Int16Array int16ArrayAttr; + void int16ArrayMethod(Int16Array arg1, Int16Array? arg2, Int16Array[] arg3, sequence arg4); + + attribute Uint16Array uint16ArrayAttr; + void uint16ArrayMethod(Uint16Array arg1, Uint16Array? arg2, Uint16Array[] arg3, sequence arg4); + + attribute Int32Array int32ArrayAttr; + void int32ArrayMethod(Int32Array arg1, Int32Array? arg2, Int32Array[] arg3, sequence arg4); + + attribute Uint32Array uint32ArrayAttr; + void uint32ArrayMethod(Uint32Array arg1, Uint32Array? arg2, Uint32Array[] arg3, sequence arg4); + + attribute Float32Array float32ArrayAttr; + void float32ArrayMethod(Float32Array arg1, Float32Array? arg2, Float32Array[] arg3, sequence arg4); + + attribute Float64Array float64ArrayAttr; + void float64ArrayMethod(Float64Array arg1, Float64Array? arg2, Float64Array[] arg3, sequence arg4); }; """) @@ -13,13 +43,43 @@ def WebIDLTest(parser, harness): 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") - attr = iface.members[0] - method = iface.members[1] + members = iface.members - harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Expect an IDLAttribute") - harness.ok(isinstance(method, WebIDL.IDLMethod), "Expect an IDLMethod") + def checkStuff(attr, method, t): + harness.ok(isinstance(attr, WebIDL.IDLAttribute), "Expect an IDLAttribute") + harness.ok(isinstance(method, WebIDL.IDLMethod), "Expect an IDLMethod") - harness.check(str(attr.type), "ArrayBuffer", "Expect an ArrayBuffer type") - harness.ok(attr.type.isArrayBuffer(), "Expect an ArrayBuffer type") + 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.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") + + + 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") diff --git a/dom/bindings/parser/tests/test_incomplete_types.py b/dom/bindings/parser/tests/test_incomplete_types.py index d4e014b040f9..fdc396040709 100644 --- a/dom/bindings/parser/tests/test_incomplete_types.py +++ b/dom/bindings/parser/tests/test_incomplete_types.py @@ -32,13 +32,13 @@ def WebIDLTest(parser, harness): 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")