Bug 895009. Don't pass in NonNull/OwningNonNull arguments to WebIDL binding consumers. r=peterv

This commit is contained in:
Boris Zbarsky 2013-07-22 08:15:43 -04:00
parent 240fa2dbbd
commit 12fbb7f6ba
10 changed files with 72 additions and 50 deletions

View File

@ -522,7 +522,8 @@ public:
template<class ElementType> template<class ElementType>
void TexImage2D(WebGLenum target, WebGLint level, void TexImage2D(WebGLenum target, WebGLint level,
WebGLenum internalformat, WebGLenum format, WebGLenum type, WebGLenum internalformat, WebGLenum format, WebGLenum type,
const ElementType& elt, ErrorResult& rv) { ElementType& elt, ErrorResult& rv)
{
if (!IsContextStable()) if (!IsContextStable())
return; return;
nsRefPtr<gfxImageSurface> isurf; nsRefPtr<gfxImageSurface> isurf;
@ -559,7 +560,8 @@ public:
template<class ElementType> template<class ElementType>
void TexSubImage2D(WebGLenum target, WebGLint level, void TexSubImage2D(WebGLenum target, WebGLint level,
WebGLint xoffset, WebGLint yoffset, WebGLenum format, WebGLint xoffset, WebGLint yoffset, WebGLenum format,
WebGLenum type, const ElementType& elt, ErrorResult& rv) { WebGLenum type, ElementType& elt, ErrorResult& rv)
{
if (!IsContextStable()) if (!IsContextStable())
return; return;
nsRefPtr<gfxImageSurface> isurf; nsRefPtr<gfxImageSurface> isurf;
@ -976,8 +978,9 @@ protected:
return nsLayoutUtils::SurfaceFromElement(aElement, flags); return nsLayoutUtils::SurfaceFromElement(aElement, flags);
} }
template<class ElementType> template<class ElementType>
nsLayoutUtils::SurfaceFromElementResult SurfaceFromElement(const dom::NonNull<ElementType>& aElement) { nsLayoutUtils::SurfaceFromElementResult SurfaceFromElement(ElementType& aElement)
return SurfaceFromElement(aElement.get()); {
return SurfaceFromElement(&aElement);
} }
nsresult SurfaceFromElementResultToImageSurface(nsLayoutUtils::SurfaceFromElementResult& res, nsresult SurfaceFromElementResultToImageSurface(nsLayoutUtils::SurfaceFromElementResult& res,

View File

@ -2022,6 +2022,37 @@ const T& Constify(T& arg)
return arg; return arg;
} }
// Helper for turning (Owning)NonNull<T> into T&
template<typename T>
T& NonNullHelper(T& aArg)
{
return aArg;
}
template<typename T>
T& NonNullHelper(NonNull<T>& aArg)
{
return aArg;
}
template<typename T>
const T& NonNullHelper(const NonNull<T>& aArg)
{
return aArg;
}
template<typename T>
T& NonNullHelper(OwningNonNull<T>& aArg)
{
return aArg;
}
template<typename T>
const T& NonNullHelper(const OwningNonNull<T>& aArg)
{
return aArg;
}
// Reparent the wrapper of aObj to whatever its native now thinks its // Reparent the wrapper of aObj to whatever its native now thinks its
// parent should be. // parent should be.
nsresult nsresult

View File

@ -4420,6 +4420,11 @@ class CGCallGenerator(CGThing):
return False return False
if needsConst(a): if needsConst(a):
arg = CGWrapper(arg, pre="Constify(", post=")") arg = CGWrapper(arg, pre="Constify(", post=")")
# And convert NonNull<T> to T&
if (((a.type.isInterface() or a.type.isCallback()) and
not a.type.nullable()) or
a.type.isDOMString()):
arg = CGWrapper(arg, pre="NonNullHelper(", post=")")
args.append(arg) args.append(arg)
# Return values that go in outparams go here # Return values that go in outparams go here

View File

@ -275,7 +275,6 @@ public:
TestInterface* ReceiveWeakSelf(); TestInterface* ReceiveWeakSelf();
TestInterface* ReceiveWeakNullableSelf(); TestInterface* ReceiveWeakNullableSelf();
void PassSelf(TestInterface&); void PassSelf(TestInterface&);
void PassSelf2(NonNull<TestInterface>&);
void PassNullableSelf(TestInterface*); void PassNullableSelf(TestInterface*);
already_AddRefed<TestInterface> NonNullSelf(); already_AddRefed<TestInterface> NonNullSelf();
void SetNonNullSelf(TestInterface&); void SetNonNullSelf(TestInterface&);
@ -297,7 +296,6 @@ public:
IndirectlyImplementedInterface* ReceiveWeakOther(); IndirectlyImplementedInterface* ReceiveWeakOther();
IndirectlyImplementedInterface* ReceiveWeakNullableOther(); IndirectlyImplementedInterface* ReceiveWeakNullableOther();
void PassOther(IndirectlyImplementedInterface&); void PassOther(IndirectlyImplementedInterface&);
void PassOther2(NonNull<IndirectlyImplementedInterface>&);
void PassNullableOther(IndirectlyImplementedInterface*); void PassNullableOther(IndirectlyImplementedInterface*);
already_AddRefed<IndirectlyImplementedInterface> NonNullOther(); already_AddRefed<IndirectlyImplementedInterface> NonNullOther();
void SetNonNullOther(IndirectlyImplementedInterface&); void SetNonNullOther(IndirectlyImplementedInterface&);
@ -312,7 +310,6 @@ public:
TestExternalInterface* ReceiveWeakExternal(); TestExternalInterface* ReceiveWeakExternal();
TestExternalInterface* ReceiveWeakNullableExternal(); TestExternalInterface* ReceiveWeakNullableExternal();
void PassExternal(TestExternalInterface*); void PassExternal(TestExternalInterface*);
void PassExternal2(TestExternalInterface*);
void PassNullableExternal(TestExternalInterface*); void PassNullableExternal(TestExternalInterface*);
already_AddRefed<TestExternalInterface> NonNullExternal(); already_AddRefed<TestExternalInterface> NonNullExternal();
void SetNonNullExternal(TestExternalInterface*); void SetNonNullExternal(TestExternalInterface*);
@ -327,7 +324,6 @@ public:
TestCallbackInterface* ReceiveWeakCallbackInterface(); TestCallbackInterface* ReceiveWeakCallbackInterface();
TestCallbackInterface* ReceiveWeakNullableCallbackInterface(); TestCallbackInterface* ReceiveWeakNullableCallbackInterface();
void PassCallbackInterface(TestCallbackInterface&); void PassCallbackInterface(TestCallbackInterface&);
void PassCallbackInterface2(OwningNonNull<TestCallbackInterface>);
void PassNullableCallbackInterface(TestCallbackInterface*); void PassNullableCallbackInterface(TestCallbackInterface*);
already_AddRefed<TestCallbackInterface> NonNullCallbackInterface(); already_AddRefed<TestCallbackInterface> NonNullCallbackInterface();
void SetNonNullCallbackInterface(TestCallbackInterface&); void SetNonNullCallbackInterface(TestCallbackInterface&);
@ -808,6 +804,28 @@ private:
void PassVariadicAny(JSContext*, Sequence<JS::Value>&) MOZ_DELETE; void PassVariadicAny(JSContext*, Sequence<JS::Value>&) MOZ_DELETE;
void PassVariadicObject(JSContext*, Sequence<JSObject*>&) MOZ_DELETE; void PassVariadicObject(JSContext*, Sequence<JSObject*>&) MOZ_DELETE;
void PassVariadicNullableObject(JSContext*, Sequence<JSObject*>&) MOZ_DELETE; void PassVariadicNullableObject(JSContext*, Sequence<JSObject*>&) MOZ_DELETE;
// Ensure NonNull does not leak in
void PassSelf(NonNull<TestInterface>&) MOZ_DELETE;
void PassSelf(OwningNonNull<TestInterface>&) MOZ_DELETE;
void PassSelf(const NonNull<TestInterface>&) MOZ_DELETE;
void PassSelf(const OwningNonNull<TestInterface>&) MOZ_DELETE;
void PassOther(NonNull<IndirectlyImplementedInterface>&) MOZ_DELETE;
void PassOther(const NonNull<IndirectlyImplementedInterface>&) MOZ_DELETE;
void PassOther(OwningNonNull<IndirectlyImplementedInterface>&) MOZ_DELETE;
void PassOther(const OwningNonNull<IndirectlyImplementedInterface>&) MOZ_DELETE;
void PassCallbackInterface(OwningNonNull<TestCallbackInterface>&) MOZ_DELETE;
void PassCallbackInterface(const OwningNonNull<TestCallbackInterface>&) MOZ_DELETE;
void PassCallbackInterface(NonNull<TestCallbackInterface>&) MOZ_DELETE;
void PassCallbackInterface(const NonNull<TestCallbackInterface>&) MOZ_DELETE;
void PassCallback(OwningNonNull<TestCallback>&) MOZ_DELETE;
void PassCallback(const OwningNonNull<TestCallback>&) MOZ_DELETE;
void PassCallback(NonNull<TestCallback>&) MOZ_DELETE;
void PassCallback(const NonNull<TestCallback>&) MOZ_DELETE;
void PassString(const NonNull<nsAString>&) MOZ_DELETE;
void PassString(NonNull<nsAString>&) MOZ_DELETE;
void PassString(const OwningNonNull<nsAString>&) MOZ_DELETE;
void PassString(OwningNonNull<nsAString>&) MOZ_DELETE;
}; };
class TestIndexedGetterInterface : public nsISupports, class TestIndexedGetterInterface : public nsISupports,

View File

@ -223,10 +223,7 @@ interface TestInterface {
TestInterface? receiveNullableSelf(); TestInterface? receiveNullableSelf();
TestInterface receiveWeakSelf(); TestInterface receiveWeakSelf();
TestInterface? receiveWeakNullableSelf(); TestInterface? receiveWeakNullableSelf();
// A verstion to test for casting to TestInterface&
void passSelf(TestInterface arg); void passSelf(TestInterface arg);
// A version we can use to test for the exact type passed in
void passSelf2(TestInterface arg);
void passNullableSelf(TestInterface? arg); void passNullableSelf(TestInterface? arg);
attribute TestInterface nonNullSelf; attribute TestInterface nonNullSelf;
attribute TestInterface? nullableSelf; attribute TestInterface? nullableSelf;
@ -254,10 +251,7 @@ interface TestInterface {
IndirectlyImplementedInterface? receiveNullableOther(); IndirectlyImplementedInterface? receiveNullableOther();
IndirectlyImplementedInterface receiveWeakOther(); IndirectlyImplementedInterface receiveWeakOther();
IndirectlyImplementedInterface? receiveWeakNullableOther(); IndirectlyImplementedInterface? receiveWeakNullableOther();
// A verstion to test for casting to IndirectlyImplementedInterface&
void passOther(IndirectlyImplementedInterface arg); void passOther(IndirectlyImplementedInterface arg);
// A version we can use to test for the exact type passed in
void passOther2(IndirectlyImplementedInterface arg);
void passNullableOther(IndirectlyImplementedInterface? arg); void passNullableOther(IndirectlyImplementedInterface? arg);
attribute IndirectlyImplementedInterface nonNullOther; attribute IndirectlyImplementedInterface nonNullOther;
attribute IndirectlyImplementedInterface? nullableOther; attribute IndirectlyImplementedInterface? nullableOther;
@ -271,10 +265,7 @@ interface TestInterface {
TestExternalInterface? receiveNullableExternal(); TestExternalInterface? receiveNullableExternal();
TestExternalInterface receiveWeakExternal(); TestExternalInterface receiveWeakExternal();
TestExternalInterface? receiveWeakNullableExternal(); TestExternalInterface? receiveWeakNullableExternal();
// A verstion to test for casting to TestExternalInterface&
void passExternal(TestExternalInterface arg); void passExternal(TestExternalInterface arg);
// A version we can use to test for the exact type passed in
void passExternal2(TestExternalInterface arg);
void passNullableExternal(TestExternalInterface? arg); void passNullableExternal(TestExternalInterface? arg);
attribute TestExternalInterface nonNullExternal; attribute TestExternalInterface nonNullExternal;
attribute TestExternalInterface? nullableExternal; attribute TestExternalInterface? nullableExternal;
@ -288,10 +279,7 @@ interface TestInterface {
TestCallbackInterface? receiveNullableCallbackInterface(); TestCallbackInterface? receiveNullableCallbackInterface();
TestCallbackInterface receiveWeakCallbackInterface(); TestCallbackInterface receiveWeakCallbackInterface();
TestCallbackInterface? receiveWeakNullableCallbackInterface(); TestCallbackInterface? receiveWeakNullableCallbackInterface();
// A verstion to test for casting to TestCallbackInterface&
void passCallbackInterface(TestCallbackInterface arg); void passCallbackInterface(TestCallbackInterface arg);
// A version we can use to test for the exact type passed in
void passCallbackInterface2(TestCallbackInterface arg);
void passNullableCallbackInterface(TestCallbackInterface? arg); void passNullableCallbackInterface(TestCallbackInterface? arg);
attribute TestCallbackInterface nonNullCallbackInterface; attribute TestCallbackInterface nonNullCallbackInterface;
attribute TestCallbackInterface? nullableCallbackInterface; attribute TestCallbackInterface? nullableCallbackInterface;

View File

@ -119,10 +119,7 @@ interface TestExampleInterface {
TestInterface? receiveNullableSelf(); TestInterface? receiveNullableSelf();
TestInterface receiveWeakSelf(); TestInterface receiveWeakSelf();
TestInterface? receiveWeakNullableSelf(); TestInterface? receiveWeakNullableSelf();
// A verstion to test for casting to TestInterface&
void passSelf(TestInterface arg); void passSelf(TestInterface arg);
// A version we can use to test for the exact type passed in
void passSelf2(TestInterface arg);
void passNullableSelf(TestInterface? arg); void passNullableSelf(TestInterface? arg);
attribute TestInterface nonNullSelf; attribute TestInterface nonNullSelf;
attribute TestInterface? nullableSelf; attribute TestInterface? nullableSelf;
@ -150,10 +147,7 @@ interface TestExampleInterface {
IndirectlyImplementedInterface? receiveNullableOther(); IndirectlyImplementedInterface? receiveNullableOther();
IndirectlyImplementedInterface receiveWeakOther(); IndirectlyImplementedInterface receiveWeakOther();
IndirectlyImplementedInterface? receiveWeakNullableOther(); IndirectlyImplementedInterface? receiveWeakNullableOther();
// A verstion to test for casting to IndirectlyImplementedInterface&
void passOther(IndirectlyImplementedInterface arg); void passOther(IndirectlyImplementedInterface arg);
// A version we can use to test for the exact type passed in
void passOther2(IndirectlyImplementedInterface arg);
void passNullableOther(IndirectlyImplementedInterface? arg); void passNullableOther(IndirectlyImplementedInterface? arg);
attribute IndirectlyImplementedInterface nonNullOther; attribute IndirectlyImplementedInterface nonNullOther;
attribute IndirectlyImplementedInterface? nullableOther; attribute IndirectlyImplementedInterface? nullableOther;
@ -167,10 +161,7 @@ interface TestExampleInterface {
TestExternalInterface? receiveNullableExternal(); TestExternalInterface? receiveNullableExternal();
TestExternalInterface receiveWeakExternal(); TestExternalInterface receiveWeakExternal();
TestExternalInterface? receiveWeakNullableExternal(); TestExternalInterface? receiveWeakNullableExternal();
// A verstion to test for casting to TestExternalInterface&
void passExternal(TestExternalInterface arg); void passExternal(TestExternalInterface arg);
// A version we can use to test for the exact type passed in
void passExternal2(TestExternalInterface arg);
void passNullableExternal(TestExternalInterface? arg); void passNullableExternal(TestExternalInterface? arg);
attribute TestExternalInterface nonNullExternal; attribute TestExternalInterface nonNullExternal;
attribute TestExternalInterface? nullableExternal; attribute TestExternalInterface? nullableExternal;
@ -184,10 +175,7 @@ interface TestExampleInterface {
TestCallbackInterface? receiveNullableCallbackInterface(); TestCallbackInterface? receiveNullableCallbackInterface();
TestCallbackInterface receiveWeakCallbackInterface(); TestCallbackInterface receiveWeakCallbackInterface();
TestCallbackInterface? receiveWeakNullableCallbackInterface(); TestCallbackInterface? receiveWeakNullableCallbackInterface();
// A verstion to test for casting to TestCallbackInterface&
void passCallbackInterface(TestCallbackInterface arg); void passCallbackInterface(TestCallbackInterface arg);
// A version we can use to test for the exact type passed in
void passCallbackInterface2(TestCallbackInterface arg);
void passNullableCallbackInterface(TestCallbackInterface? arg); void passNullableCallbackInterface(TestCallbackInterface? arg);
attribute TestCallbackInterface nonNullCallbackInterface; attribute TestCallbackInterface nonNullCallbackInterface;
attribute TestCallbackInterface? nullableCallbackInterface; attribute TestCallbackInterface? nullableCallbackInterface;

View File

@ -136,8 +136,6 @@ interface TestJSImplInterface {
// A version to test for casting to TestJSImplInterface& // A version to test for casting to TestJSImplInterface&
void passSelf(TestJSImplInterface arg); void passSelf(TestJSImplInterface arg);
// A version we can use to test for the exact type passed in
void passSelf2(TestJSImplInterface arg);
void passNullableSelf(TestJSImplInterface? arg); void passNullableSelf(TestJSImplInterface? arg);
attribute TestJSImplInterface nonNullSelf; attribute TestJSImplInterface nonNullSelf;
attribute TestJSImplInterface? nullableSelf; attribute TestJSImplInterface? nullableSelf;
@ -168,10 +166,7 @@ interface TestJSImplInterface {
//IndirectlyImplementedInterface receiveWeakOther(); //IndirectlyImplementedInterface receiveWeakOther();
//IndirectlyImplementedInterface? receiveWeakNullableOther(); //IndirectlyImplementedInterface? receiveWeakNullableOther();
// A verstion to test for casting to IndirectlyImplementedInterface&
void passOther(IndirectlyImplementedInterface arg); void passOther(IndirectlyImplementedInterface arg);
// A version we can use to test for the exact type passed in
void passOther2(IndirectlyImplementedInterface arg);
void passNullableOther(IndirectlyImplementedInterface? arg); void passNullableOther(IndirectlyImplementedInterface? arg);
attribute IndirectlyImplementedInterface nonNullOther; attribute IndirectlyImplementedInterface nonNullOther;
attribute IndirectlyImplementedInterface? nullableOther; attribute IndirectlyImplementedInterface? nullableOther;
@ -186,10 +181,7 @@ interface TestJSImplInterface {
// Callback interface ignores 'resultNotAddRefed'. See bug 843272. // Callback interface ignores 'resultNotAddRefed'. See bug 843272.
//TestExternalInterface receiveWeakExternal(); //TestExternalInterface receiveWeakExternal();
//TestExternalInterface? receiveWeakNullableExternal(); //TestExternalInterface? receiveWeakNullableExternal();
// A verstion to test for casting to TestExternalInterface&
void passExternal(TestExternalInterface arg); void passExternal(TestExternalInterface arg);
// A version we can use to test for the exact type passed in
void passExternal2(TestExternalInterface arg);
void passNullableExternal(TestExternalInterface? arg); void passNullableExternal(TestExternalInterface? arg);
attribute TestExternalInterface nonNullExternal; attribute TestExternalInterface nonNullExternal;
attribute TestExternalInterface? nullableExternal; attribute TestExternalInterface? nullableExternal;
@ -204,10 +196,7 @@ interface TestJSImplInterface {
// Callback interface ignores 'resultNotAddRefed'. See bug 843272. // Callback interface ignores 'resultNotAddRefed'. See bug 843272.
//TestCallbackInterface receiveWeakCallbackInterface(); //TestCallbackInterface receiveWeakCallbackInterface();
//TestCallbackInterface? receiveWeakNullableCallbackInterface(); //TestCallbackInterface? receiveWeakNullableCallbackInterface();
// A verstion to test for casting to TestCallbackInterface&
void passCallbackInterface(TestCallbackInterface arg); void passCallbackInterface(TestCallbackInterface arg);
// A version we can use to test for the exact type passed in
void passCallbackInterface2(TestCallbackInterface arg);
void passNullableCallbackInterface(TestCallbackInterface? arg); void passNullableCallbackInterface(TestCallbackInterface? arg);
attribute TestCallbackInterface nonNullCallbackInterface; attribute TestCallbackInterface nonNullCallbackInterface;
attribute TestCallbackInterface? nullableCallbackInterface; attribute TestCallbackInterface? nullableCallbackInterface;

View File

@ -61,7 +61,7 @@ public:
static already_AddRefed<IDBVersionChangeEvent> static already_AddRefed<IDBVersionChangeEvent>
Constructor(const GlobalObject& aGlobal, Constructor(const GlobalObject& aGlobal,
const NonNull<nsAString>& aType, const nsAString& aType,
const IDBVersionChangeEventInit& aOptions, const IDBVersionChangeEventInit& aOptions,
ErrorResult& aRv) ErrorResult& aRv)
{ {

View File

@ -647,7 +647,7 @@ IDBFactory::Cmp(JSContext* aCx, JS::Handle<JS::Value> aFirst,
already_AddRefed<nsIIDBOpenDBRequest> already_AddRefed<nsIIDBOpenDBRequest>
IDBFactory::OpenForPrincipal(nsIPrincipal* aPrincipal, IDBFactory::OpenForPrincipal(nsIPrincipal* aPrincipal,
const NonNull<nsAString>& aName, const nsAString& aName,
const Optional<uint64_t>& aVersion, const Optional<uint64_t>& aVersion,
ErrorResult& aRv) ErrorResult& aRv)
{ {
@ -661,7 +661,7 @@ IDBFactory::OpenForPrincipal(nsIPrincipal* aPrincipal,
already_AddRefed<nsIIDBOpenDBRequest> already_AddRefed<nsIIDBOpenDBRequest>
IDBFactory::DeleteForPrincipal(nsIPrincipal* aPrincipal, IDBFactory::DeleteForPrincipal(nsIPrincipal* aPrincipal,
const NonNull<nsAString>& aName, const nsAString& aName,
ErrorResult& aRv) ErrorResult& aRv)
{ {
// Just to be on the extra-safe side // Just to be on the extra-safe side

View File

@ -141,14 +141,14 @@ public:
// WebIDL // WebIDL
already_AddRefed<nsIIDBOpenDBRequest> already_AddRefed<nsIIDBOpenDBRequest>
Open(const NonNull<nsAString>& aName, const Optional<uint64_t>& aVersion, Open(const nsAString& aName, const Optional<uint64_t>& aVersion,
ErrorResult& aRv) ErrorResult& aRv)
{ {
return Open(nullptr, aName, aVersion, false, aRv); return Open(nullptr, aName, aVersion, false, aRv);
} }
already_AddRefed<nsIIDBOpenDBRequest> already_AddRefed<nsIIDBOpenDBRequest>
DeleteDatabase(const NonNull<nsAString>& aName, ErrorResult& aRv) DeleteDatabase(const nsAString& aName, ErrorResult& aRv)
{ {
return Open(nullptr, aName, Optional<uint64_t>(), true, aRv); return Open(nullptr, aName, Optional<uint64_t>(), true, aRv);
} }
@ -158,11 +158,11 @@ public:
JS::Handle<JS::Value> aSecond, ErrorResult& aRv); JS::Handle<JS::Value> aSecond, ErrorResult& aRv);
already_AddRefed<nsIIDBOpenDBRequest> already_AddRefed<nsIIDBOpenDBRequest>
OpenForPrincipal(nsIPrincipal* aPrincipal, const NonNull<nsAString>& aName, OpenForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName,
const Optional<uint64_t>& aVersion, ErrorResult& aRv); const Optional<uint64_t>& aVersion, ErrorResult& aRv);
already_AddRefed<nsIIDBOpenDBRequest> already_AddRefed<nsIIDBOpenDBRequest>
DeleteForPrincipal(nsIPrincipal* aPrincipal, const NonNull<nsAString>& aName, DeleteForPrincipal(nsIPrincipal* aPrincipal, const nsAString& aName,
ErrorResult& aRv); ErrorResult& aRv);
private: private: