Bug 945788. Add support for dictionary return values to example codegen and js-implemented codegen. r=smaug

This commit is contained in:
Boris Zbarsky 2013-12-05 11:39:50 -05:00
Родитель 27592060c0
Коммит 21df6dd5cf
7 изменённых файлов: 40 добавлений и 17 удалений

Просмотреть файл

@ -3743,7 +3743,7 @@ for (uint32_t i = 0; i < length; ++i) {
assert not isOptional
typeName = CGDictionary.makeDictionaryName(type.inner)
if not isMember:
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
# that doesn't pre-initialize members.
@ -3783,7 +3783,11 @@ for (uint32_t i = 0; i < length; ++i) {
# Dictionary arguments that might contain traceable things need to get
# traced
if not isMember and typeNeedsRooting(type):
if not isMember and isCallbackReturnValue:
# Go ahead and just convert directly into our actual return value
declType = CGWrapper(declType, post="&")
declArgs = "retval"
elif not isMember and typeNeedsRooting(type):
declType = CGTemplatedType("RootedDictionary", declType);
declArgs = "cx"
else:
@ -9708,6 +9712,15 @@ class CGNativeMember(ClassMethod):
result = CGTemplatedType("Nullable", result)
return (result.define(), "%s()" % result.define(),
"return ${declName};")
if type.isDictionary():
if isMember:
# Only the first member of the tuple matters here, but return
# bogus values for the others in case someone decides to use
# them.
return CGDictionary.makeDictionaryName(type.inner), None, None
# In this case we convert directly into our outparam to start with
return "void", "", ""
raise TypeError("Don't know how to declare return value for %s" %
type)
@ -9716,7 +9729,7 @@ class CGNativeMember(ClassMethod):
# Now the outparams
if returnType.isDOMString():
args.append(Argument("nsString&", "retval"))
if returnType.isByteString():
elif returnType.isByteString():
args.append(Argument("nsCString&", "retval"))
elif returnType.isSequence():
nullable = returnType.nullable()
@ -9728,6 +9741,14 @@ class CGNativeMember(ClassMethod):
if nullable:
type = CGTemplatedType("Nullable", type)
args.append(Argument("%s&" % type.define(), "retval"))
elif returnType.isDictionary():
nullable = returnType.nullable()
if nullable:
returnType = returnType.inner
dictType = CGGeneric(CGDictionary.makeDictionaryName(returnType.inner))
if nullable:
dictType = CGTemplatedType("Nullable", dictType)
args.append(Argument("%s&" % dictType.define(), "retval"))
# And the ErrorResult
if not 'infallible' in self.extendedAttrs:
# Use aRv so it won't conflict with local vars named "rv"

Просмотреть файл

@ -2032,7 +2032,7 @@ class IDLWrapperType(IDLType):
elif self.isEnum():
return True
elif self.isDictionary():
return all(m.isSerializable() for m in self.inner.members)
return all(m.type.isSerializable() for m in self.inner.members)
else:
raise WebIDLError("IDLWrapperType wraps type %s that we don't know if "
"is serializable" % type(self.inner), [self.location])

Просмотреть файл

@ -341,6 +341,7 @@ public:
// Sequence types
void GetReadonlySequence(nsTArray<int32_t>&);
void GetReadonlySequenceOfDictionaries(JSContext*, nsTArray<Dict>&);
void ReceiveSequence(nsTArray<int32_t>&);
void ReceiveNullableSequence(Nullable< nsTArray<int32_t> >&);
void ReceiveSequenceOfNullableInts(nsTArray< Nullable<int32_t> >&);

Просмотреть файл

@ -297,6 +297,8 @@ interface TestInterface {
// Sequence types
[Cached, Pure]
readonly attribute sequence<long> readonlySequence;
[Cached, Pure]
readonly attribute sequence<Dict> readonlySequenceOfDictionaries;
sequence<long> receiveSequence();
sequence<long>? receiveNullableSequence();
sequence<long?> receiveSequenceOfNullableInts();

Просмотреть файл

@ -193,6 +193,8 @@ interface TestExampleInterface {
// Sequence types
[Cached, Pure]
readonly attribute sequence<long> readonlySequence;
[Cached, Pure]
readonly attribute sequence<Dict> readonlySequenceOfDictionaries;
sequence<long> receiveSequence();
sequence<long>? receiveNullableSequence();
sequence<long?> receiveSequenceOfNullableInts();
@ -427,9 +429,8 @@ interface TestExampleInterface {
attribute byte attributeRenamedFrom;
void passDictionary(optional Dict x);
// FIXME: Bug 863949 no dictionary return values in callbacks
// Dict receiveDictionary();
// Dict? receiveNullableDictionary();
Dict receiveDictionary();
Dict? receiveNullableDictionary();
void passOtherDictionary(optional GrandparentDict x);
void passSequenceOfDictionaries(sequence<Dict> x);
// No support for nullable dictionaries inside a sequence (nor should there be)
@ -439,7 +440,7 @@ interface TestExampleInterface {
void passDictContainingDict(optional DictContainingDict arg);
void passDictContainingSequence(optional DictContainingSequence arg);
//UNSUPPORTED DictContainingSequence receiveDictContainingSequence();
DictContainingSequence receiveDictContainingSequence();
// EnforceRange/Clamp tests
void dontEnforceRangeOrClamp(byte arg);

Просмотреть файл

@ -214,6 +214,8 @@ interface TestJSImplInterface {
// Sequence types
[Cached, Pure]
readonly attribute sequence<long> readonlySequence;
[Cached, Pure]
readonly attribute sequence<Dict> readonlySequenceOfDictionaries;
sequence<long> receiveSequence();
sequence<long>? receiveNullableSequence();
sequence<long?> receiveSequenceOfNullableInts();
@ -451,9 +453,9 @@ interface TestJSImplInterface {
attribute byte attributeRenamedFrom;
void passDictionary(optional Dict x);
// FIXME: Bug 863949 no dictionary return values
// Dict receiveDictionary();
// Dict? receiveNullableDictionary();
Dict receiveDictionary();
// No support for nullable dictionary return values here yet
// Dict? receiveNullableDictionary();
void passOtherDictionary(optional GrandparentDict x);
void passSequenceOfDictionaries(sequence<Dict> x);
// No support for nullable dictionaries inside a sequence (nor should there be)
@ -463,8 +465,7 @@ interface TestJSImplInterface {
void passDictContainingDict(optional DictContainingDict arg);
void passDictContainingSequence(optional DictContainingSequence arg);
// FIXME: Bug 863949 no dictionary return values
// DictContainingSequence receiveDictContainingSequence();
DictContainingSequence receiveDictContainingSequence();
// EnforceRange/Clamp tests
void dontEnforceRangeOrClamp(byte arg);

Просмотреть файл

@ -49,8 +49,5 @@ interface PeerConnectionObserver
/* Helper function to access supported constraints defined in webidl. Needs to
* be in a separate webidl object we hold, so putting it here was convenient.
*/
// TODO: Bug 863949
// MediaConstraintSet getSupportedConstraints(optional
object getSupportedConstraints(optional
MediaConstraintSet constraints);
MediaConstraintSet getSupportedConstraints(optional MediaConstraintSet constraints);
};