From 21df6dd5cf15941c7c7e23dc0dcc6c63834dd4e9 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 5 Dec 2013 11:39:50 -0500 Subject: [PATCH] Bug 945788. Add support for dictionary return values to example codegen and js-implemented codegen. r=smaug --- dom/bindings/Codegen.py | 27 +++++++++++++++++++++--- dom/bindings/parser/WebIDL.py | 2 +- dom/bindings/test/TestBindingHeader.h | 1 + dom/bindings/test/TestCodeGen.webidl | 2 ++ dom/bindings/test/TestExampleGen.webidl | 9 ++++---- dom/bindings/test/TestJSImplGen.webidl | 11 +++++----- dom/webidl/PeerConnectionObserver.webidl | 5 +---- 7 files changed, 40 insertions(+), 17 deletions(-) diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index dec307571ccd..aefc789eb894 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -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" diff --git a/dom/bindings/parser/WebIDL.py b/dom/bindings/parser/WebIDL.py index 944faed6ffa0..dc0e0f00ea36 100644 --- a/dom/bindings/parser/WebIDL.py +++ b/dom/bindings/parser/WebIDL.py @@ -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]) diff --git a/dom/bindings/test/TestBindingHeader.h b/dom/bindings/test/TestBindingHeader.h index 034dc30b497b..305cdb7a9b04 100644 --- a/dom/bindings/test/TestBindingHeader.h +++ b/dom/bindings/test/TestBindingHeader.h @@ -341,6 +341,7 @@ public: // Sequence types void GetReadonlySequence(nsTArray&); + void GetReadonlySequenceOfDictionaries(JSContext*, nsTArray&); void ReceiveSequence(nsTArray&); void ReceiveNullableSequence(Nullable< nsTArray >&); void ReceiveSequenceOfNullableInts(nsTArray< Nullable >&); diff --git a/dom/bindings/test/TestCodeGen.webidl b/dom/bindings/test/TestCodeGen.webidl index 152046722ab7..a2c0f99b6af0 100644 --- a/dom/bindings/test/TestCodeGen.webidl +++ b/dom/bindings/test/TestCodeGen.webidl @@ -297,6 +297,8 @@ interface TestInterface { // Sequence types [Cached, Pure] readonly attribute sequence readonlySequence; + [Cached, Pure] + readonly attribute sequence readonlySequenceOfDictionaries; sequence receiveSequence(); sequence? receiveNullableSequence(); sequence receiveSequenceOfNullableInts(); diff --git a/dom/bindings/test/TestExampleGen.webidl b/dom/bindings/test/TestExampleGen.webidl index 6910b7124d72..63777e4c26a5 100644 --- a/dom/bindings/test/TestExampleGen.webidl +++ b/dom/bindings/test/TestExampleGen.webidl @@ -193,6 +193,8 @@ interface TestExampleInterface { // Sequence types [Cached, Pure] readonly attribute sequence readonlySequence; + [Cached, Pure] + readonly attribute sequence readonlySequenceOfDictionaries; sequence receiveSequence(); sequence? receiveNullableSequence(); sequence 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 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); diff --git a/dom/bindings/test/TestJSImplGen.webidl b/dom/bindings/test/TestJSImplGen.webidl index 208cf1ac41df..6135630c82e7 100644 --- a/dom/bindings/test/TestJSImplGen.webidl +++ b/dom/bindings/test/TestJSImplGen.webidl @@ -214,6 +214,8 @@ interface TestJSImplInterface { // Sequence types [Cached, Pure] readonly attribute sequence readonlySequence; + [Cached, Pure] + readonly attribute sequence readonlySequenceOfDictionaries; sequence receiveSequence(); sequence? receiveNullableSequence(); sequence 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 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); diff --git a/dom/webidl/PeerConnectionObserver.webidl b/dom/webidl/PeerConnectionObserver.webidl index dd9dfd2e8acb..23564499fba1 100644 --- a/dom/webidl/PeerConnectionObserver.webidl +++ b/dom/webidl/PeerConnectionObserver.webidl @@ -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); };