Bug 1134112 part 2. When doing dictionary init, if we have a non-optional union member just go ahead and uninit it before we try initing it. That way even if it's already been initialized (e.g. because we default-initialized at some point) things will still work correctly. r=peterv

This commit is contained in:
Boris Zbarsky 2015-02-19 14:36:35 -05:00
parent fc8317f7a4
commit b864faa155
2 changed files with 32 additions and 3 deletions

View File

@ -4570,13 +4570,15 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
if tag in numericSuffixes or tag is IDLType.Tags.bool:
defaultStr = getHandleDefault(defaultValue)
value = declLoc + (".Value()" if nullable else "")
# Make sure we actually construct the thing inside the nullable.
value = declLoc + (".SetValue()" if nullable else "")
name = getUnionMemberName(defaultValue.type)
default = CGGeneric("%s.RawSetAs%s() = %s;\n" %
(value, name, defaultStr))
elif isinstance(defaultValue, IDLEmptySequenceValue):
name = getUnionMemberName(defaultValue.type)
value = declLoc + (".Value()" if nullable else "")
# Make sure we actually construct the thing inside the nullable.
value = declLoc + (".SetValue()" if nullable else "")
# It's enough to set us to the right type; that will
# create an empty array, which is all we need here.
default = CGGeneric("%s.RawSetAs%s();\n" %
@ -8852,7 +8854,7 @@ class CGUnionStruct(CGThing):
dtor = CGSwitch("mType", destructorCases).define()
methods.append(ClassMethod("Uninit", "void", [],
visibility="private", body=dtor,
visibility="public", body=dtor,
bodyInHeader=not self.ownsMembers,
inline=not self.ownsMembers))
@ -11743,6 +11745,23 @@ class CGDictionary(CGThing):
" return false;\n"
"}\n")
if member.defaultValue:
if (member.type.isUnion() and
(not member.type.nullable() or
not isinstance(member.defaultValue, IDLNullValue))):
# Since this has a default value, it might have been initialized
# already. Go ahead and uninit it before we try to init it
# again.
memberName = self.makeMemberName(member.identifier.name)
if member.type.nullable():
conversion += fill(
"""
if (!${memberName}.IsNull()) {
${memberName}.Value().Uninit();
}
""",
memberName=memberName)
else:
conversion += "%s.Uninit();\n" % memberName
conversion += "${convert}"
elif not conversionInfo.dealWithOptional:
# We're required, but have no default value. Make sure

View File

@ -960,6 +960,7 @@ dictionary Dict : ParentDict {
unrestricted double nanUrDouble = NaN;
(float or DOMString) floatOrString = "str";
(float or DOMString)? nullableFloatOrString = "str";
(object or long) objectOrLong;
#ifdef DEBUG
(EventInit or long) eventInitOrLong;
@ -972,7 +973,16 @@ dictionary Dict : ParentDict {
(CustomEventInit or long) eventInitOrLongWithDefaultValue2 = null;
(EventInit or long) eventInitOrLongWithDefaultValue3 = 5;
(CustomEventInit or long) eventInitOrLongWithDefaultValue4 = 5;
(EventInit or long)? nullableEventInitOrLongWithDefaultValue = null;
(CustomEventInit or long)? nullableEventInitOrLongWithDefaultValue2 = null;
(EventInit or long)? nullableEventInitOrLongWithDefaultValue3 = 5;
(CustomEventInit or long)? nullableEventInitOrLongWithDefaultValue4 = 5;
(sequence<object> or long) objectSequenceOrLong;
(sequence<object> or long) objectSequenceOrLongWithDefaultValue1 = 1;
(sequence<object> or long) objectSequenceOrLongWithDefaultValue2 = [];
(sequence<object> or long)? nullableObjectSequenceOrLong;
(sequence<object> or long)? nullableObjectSequenceOrLongWithDefaultValue1 = 1;
(sequence<object> or long)? nullableObjectSequenceOrLongWithDefaultValue2 = [];
#endif
ArrayBuffer arrayBuffer;