Bug 1063889. Fix the handling of sequences of wrapper types in unions. r=khuey

This commit is contained in:
Boris Zbarsky 2014-09-08 11:28:57 -04:00
parent cd088d907b
commit 5f46861110
6 changed files with 40 additions and 12 deletions

View File

@ -1216,6 +1216,7 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
def addHeadersForType(f): def addHeadersForType(f):
if f.nullable(): if f.nullable():
headers.add("mozilla/dom/Nullable.h") headers.add("mozilla/dom/Nullable.h")
isSequence = f.isSequence()
f = f.unroll() f = f.unroll()
if f.isInterface(): if f.isInterface():
if f.isSpiderMonkeyInterface(): if f.isSpiderMonkeyInterface():
@ -1227,10 +1228,14 @@ def UnionTypes(descriptors, dictionaries, callbacks, config):
typeDesc = p.getDescriptor(f.inner.identifier.name) typeDesc = p.getDescriptor(f.inner.identifier.name)
except NoSuchDescriptorError: except NoSuchDescriptorError:
continue continue
if typeDesc.interface.isCallback(): if typeDesc.interface.isCallback() or isSequence:
# Callback interfaces always use strong refs, so # Callback interfaces always use strong refs, so
# we need to include the right header to be able # we need to include the right header to be able
# to Release() in our inlined code. # to Release() in our inlined code.
#
# Similarly, sequences always contain strong
# refs, so we'll need the header to handler
# those.
headers.add(typeDesc.headerFile) headers.add(typeDesc.headerFile)
else: else:
declarations.add((typeDesc.nativeType, False)) declarations.add((typeDesc.nativeType, False))
@ -4651,7 +4656,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if type.isSpiderMonkeyInterface(): if type.isSpiderMonkeyInterface():
assert not isEnforceRange and not isClamp assert not isEnforceRange and not isClamp
name = type.name name = type.unroll().name # unroll() because it may be nullable
arrayType = CGGeneric(name) arrayType = CGGeneric(name)
declType = arrayType declType = arrayType
if type.nullable(): if type.nullable():
@ -6202,8 +6207,6 @@ def getUnionMemberName(type):
return type.inner.identifier.name return type.inner.identifier.name
if type.isEnum(): if type.isEnum():
return type.inner.identifier.name return type.inner.identifier.name
if type.isArray() or type.isSequence() or type.isMozMap():
return str(type)
return type.name return type.name
@ -12448,7 +12451,8 @@ class CGNativeMember(ClassMethod):
if not self.typedArraysAreStructs: if not self.typedArraysAreStructs:
return "JS::Handle<JSObject*>", False, False return "JS::Handle<JSObject*>", False, False
return type.name, True, True # Unroll for the name, in case we're nullable.
return type.unroll().name, True, True
if type.isDOMString() or type.isScalarValueString(): if type.isDOMString() or type.isScalarValueString():
if isMember: if isMember:

View File

@ -1764,7 +1764,10 @@ class IDLNullableType(IDLType):
assert not innerType.isVoid() assert not innerType.isVoid()
assert not innerType == BuiltinTypes[IDLBuiltinType.Types.any] assert not innerType == BuiltinTypes[IDLBuiltinType.Types.any]
IDLType.__init__(self, location, innerType.name) name = innerType.name
if innerType.isComplete():
name += "OrNull"
IDLType.__init__(self, location, name)
self.inner = innerType self.inner = innerType
self.builtin = False self.builtin = False
@ -1877,7 +1880,7 @@ class IDLNullableType(IDLType):
"be a union type that itself has a nullable " "be a union type that itself has a nullable "
"type as a member type", [self.location]) "type as a member type", [self.location])
self.name = self.inner.name self.name = self.inner.name + "OrNull"
return self return self
def unroll(self): def unroll(self):
@ -1900,6 +1903,10 @@ class IDLSequenceType(IDLType):
IDLType.__init__(self, location, parameterType.name) IDLType.__init__(self, location, parameterType.name)
self.inner = parameterType self.inner = parameterType
self.builtin = False self.builtin = False
# Need to set self.name up front if our inner type is already complete,
# since in that case our .complete() won't be called.
if self.inner.isComplete():
self.name = self.inner.name + "Sequence"
def __eq__(self, other): def __eq__(self, other):
return isinstance(other, IDLSequenceType) and self.inner == other.inner return isinstance(other, IDLSequenceType) and self.inner == other.inner
@ -1961,7 +1968,7 @@ class IDLSequenceType(IDLType):
def complete(self, scope): def complete(self, scope):
self.inner = self.inner.complete(scope) self.inner = self.inner.complete(scope)
self.name = self.inner.name self.name = self.inner.name + "Sequence"
return self return self
def unroll(self): def unroll(self):
@ -1987,6 +1994,10 @@ class IDLMozMapType(IDLType):
IDLType.__init__(self, location, parameterType.name) IDLType.__init__(self, location, parameterType.name)
self.inner = parameterType self.inner = parameterType
self.builtin = False self.builtin = False
# Need to set self.name up front if our inner type is already complete,
# since in that case our .complete() won't be called.
if self.inner.isComplete():
self.name = self.inner.name + "MozMap"
def __eq__(self, other): def __eq__(self, other):
return isinstance(other, IDLMozMapType) and self.inner == other.inner return isinstance(other, IDLMozMapType) and self.inner == other.inner
@ -2012,7 +2023,7 @@ class IDLMozMapType(IDLType):
def complete(self, scope): def complete(self, scope):
self.inner = self.inner.complete(scope) self.inner = self.inner.complete(scope)
self.name = self.inner.name self.name = self.inner.name + "MozMap"
return self return self
def unroll(self): def unroll(self):
@ -2077,9 +2088,6 @@ class IDLUnionType(IDLType):
return typeName(type._identifier.object()) return typeName(type._identifier.object())
if isinstance(type, IDLObjectWithIdentifier): if isinstance(type, IDLObjectWithIdentifier):
return typeName(type.identifier) return typeName(type.identifier)
if (isinstance(type, IDLType) and
(type.isArray() or type.isSequence() or type.isMozMap)):
return str(type)
return type.name return type.name
for (i, type) in enumerate(self.memberTypes): for (i, type) in enumerate(self.memberTypes):

View File

@ -603,6 +603,10 @@ public:
void PassUnion20(JSContext*, const ObjectSequenceOrLong&); void PassUnion20(JSContext*, const ObjectSequenceOrLong&);
void PassUnion21(const LongMozMapOrLong&); void PassUnion21(const LongMozMapOrLong&);
void PassUnion22(JSContext*, const ObjectMozMapOrLong&); void PassUnion22(JSContext*, const ObjectMozMapOrLong&);
void PassUnion23(const NodeSequenceOrLong&);
void PassUnion24(const NodeOrNullSequenceOrLong&);
void PassUnion25(const NodeSequenceSequenceOrLong&);
void PassUnion26(const NodeOrNullSequenceSequenceOrLong&);
void PassUnionWithCallback(const EventHandlerNonNullOrNullOrLong& arg); void PassUnionWithCallback(const EventHandlerNonNullOrNullOrLong& arg);
void PassUnionWithByteString(const ByteStringOrLong&); void PassUnionWithByteString(const ByteStringOrLong&);
void PassUnionWithMozMap(const StringMozMapOrString&); void PassUnionWithMozMap(const StringMozMapOrString&);

View File

@ -567,6 +567,10 @@ interface TestInterface {
void passUnion20(optional (sequence<object> or long) arg = []); void passUnion20(optional (sequence<object> or long) arg = []);
void passUnion21((MozMap<long> or long) arg); void passUnion21((MozMap<long> or long) arg);
void passUnion22((MozMap<object> or long) arg); void passUnion22((MozMap<object> or long) arg);
void passUnion23((sequence<Node> or long) arg);
void passUnion24((sequence<Node?> or long) arg);
void passUnion25((sequence<sequence<Node>> or long) arg);
void passUnion26((sequence<sequence<Node?>> or long) arg);
void passUnionWithCallback((EventHandler or long) arg); void passUnionWithCallback((EventHandler or long) arg);
void passUnionWithByteString((ByteString or long) arg); void passUnionWithByteString((ByteString or long) arg);
void passUnionWithMozMap((MozMap<DOMString> or DOMString) arg); void passUnionWithMozMap((MozMap<DOMString> or DOMString) arg);

View File

@ -431,6 +431,10 @@ interface TestExampleInterface {
void passUnion20(optional (sequence<object> or long) arg = []); void passUnion20(optional (sequence<object> or long) arg = []);
void passUnion21((MozMap<long> or long) arg); void passUnion21((MozMap<long> or long) arg);
void passUnion22((MozMap<object> or long) arg); void passUnion22((MozMap<object> or long) arg);
void passUnion23((sequence<Node> or long) arg);
void passUnion24((sequence<Node?> or long) arg);
void passUnion25((sequence<sequence<Node>> or long) arg);
void passUnion26((sequence<sequence<Node?>> or long) arg);
void passUnionWithCallback((EventHandler or long) arg); void passUnionWithCallback((EventHandler or long) arg);
void passUnionWithByteString((ByteString or long) arg); void passUnionWithByteString((ByteString or long) arg);
void passUnionWithMozMap((MozMap<DOMString> or DOMString) arg); void passUnionWithMozMap((MozMap<DOMString> or DOMString) arg);

View File

@ -451,6 +451,10 @@ interface TestJSImplInterface {
void passUnion20(optional (sequence<object> or long) arg = []); void passUnion20(optional (sequence<object> or long) arg = []);
void passUnion21((MozMap<long> or long) arg); void passUnion21((MozMap<long> or long) arg);
void passUnion22((MozMap<object> or long) arg); void passUnion22((MozMap<object> or long) arg);
void passUnion23((sequence<Node> or long) arg);
void passUnion24((sequence<Node?> or long) arg);
void passUnion25((sequence<sequence<Node>> or long) arg);
void passUnion26((sequence<sequence<Node?>> or long) arg);
void passUnionWithCallback((EventHandler or long) arg); void passUnionWithCallback((EventHandler or long) arg);
void passUnionWithByteString((ByteString or long) arg); void passUnionWithByteString((ByteString or long) arg);
void passUnionWithMozMap((MozMap<DOMString> or DOMString) arg); void passUnionWithMozMap((MozMap<DOMString> or DOMString) arg);