Bug 963388. Add support for nullable dictionary return values in callbacks and js-implemented bindings. r=peterv

This commit is contained in:
Boris Zbarsky 2014-02-05 13:38:16 -05:00
parent da001d4b79
commit 4d16883304
3 changed files with 23 additions and 12 deletions

View File

@ -3844,12 +3844,15 @@ for (uint32_t i = 0; i < length; ++i) {
if type.isDictionary():
# There are no nullable dictionaries
assert not type.nullable()
assert not type.nullable() or isCallbackReturnValue
# All optional dictionaries always have default values, so we
# should be able to assume not isOptional here.
assert not isOptional
# In the callback return value case we never have to worry
# about a default value; we always have a value.
assert not isCallbackReturnValue or defaultValue is None
typeName = CGDictionary.makeDictionaryName(type.inner)
typeName = CGDictionary.makeDictionaryName(type.unroll().inner)
if not isMember and not isCallbackReturnValue:
# Since we're not a member and not nullable or optional, no one will
# see our real type, so we can do the fast version of the dictionary
@ -3883,11 +3886,21 @@ for (uint32_t i = 0; i < length; ++i) {
else:
template = ""
template += ('if (!${declName}.Init(cx, %s, "%s")) {\n'
dictLoc = "${declName}"
if type.nullable():
dictLoc += ".SetValue()"
template += ('if (!%s.Init(cx, %s, "%s")) {\n'
"%s\n"
"}" % (val, firstCap(sourceDescription),
"}" % (dictLoc, val, firstCap(sourceDescription),
exceptionCodeIndented.define()))
if type.nullable():
declType = CGTemplatedType("Nullable", declType)
template = CGIfElseWrapper("${val}.isNullOrUndefined()",
CGGeneric("${declName}.SetNull();"),
CGGeneric(template)).define()
# Dictionary arguments that might contain traceable things need to get
# traced
if not isMember and isCallbackReturnValue:

View File

@ -29,6 +29,7 @@ callback interface TestCallbackInterface {
sequence<TestCallbackInterface>? getNullableSequenceOfCallbackInterfaces();
sequence<TestCallbackInterface?> getSequenceOfNullableCallbackInterfaces();
sequence<TestCallbackInterface?>? getNullableSequenceOfNullableCallbackInterfaces();
Dict? getDictionary();
};
callback interface TestSingleOperationCallbackInterface {

View File

@ -469,21 +469,18 @@ interface TestJSImplInterface {
void passDictionary(optional Dict x);
[Cached, Pure]
readonly attribute Dict readonlyDictionary;
// No support for nullable dictionary return values here yet
// [Cached, Pure]
// readonly attribute Dict? readonlyNullableDictionary;
[Cached, Pure]
readonly attribute Dict? readonlyNullableDictionary;
[Cached, Pure]
attribute Dict writableDictionary;
[Cached, Pure, Frozen]
readonly attribute Dict readonlyFrozenDictionary;
// No support for nullable dictionary return values here yet
// [Cached, Pure, Frozen]
// readonly attribute Dict? readonlyFrozenNullableDictionary;
[Cached, Pure, Frozen]
readonly attribute Dict? readonlyFrozenNullableDictionary;
[Cached, Pure, Frozen]
attribute Dict writableFrozenDictionary;
Dict receiveDictionary();
// No support for nullable dictionary return values here yet
// Dict? receiveNullableDictionary();
Dict? receiveNullableDictionary();
void passOtherDictionary(optional GrandparentDict x);
void passSequenceOfDictionaries(sequence<Dict> x);
// No support for nullable dictionaries inside a sequence (nor should there be)