From b8013723d55a1bc95043b7c7ae149c5f49652717 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Tue, 25 Aug 2015 14:52:16 -0400 Subject: [PATCH] Bug 1192043 - Fix compile errors in Natives.h; r=snorp This patch fixes a compile error when using WeakPtr, where Impl* was expected but SupportsWeakPtr* was given. This patch also fixes a compile error when using the DisposeNative implementation provided by the autogenerated Natives class. e.g., > struct Foo : Bar::Natives { > using Bar::Natives::DisposeNative; > }; This uses a default implementation of DisposeNative instead of a custom implementation, and resulted in a compile error that this patch fixes. --- widget/android/jni/Natives.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/widget/android/jni/Natives.h b/widget/android/jni/Natives.h index e7d85cc3f284..ca52094c43f0 100644 --- a/widget/android/jni/Natives.h +++ b/widget/android/jni/Natives.h @@ -147,7 +147,7 @@ struct NativePtr } template - static void Set(const LocalRef& instance, SupportsWeakPtr* ptr) + static void Set(const LocalRef& instance, Impl* ptr) { Clear(instance); SetNativeHandle(instance.Env(), instance.Get(), @@ -172,6 +172,8 @@ struct NativePtr } // namespace +template class NativeImpl; + namespace detail { // Wrapper methods that convert arguments from the JNI types to the native @@ -259,6 +261,19 @@ public: (impl->*Method)(self, TypeAdapter::ToNative(env, args)...); self.Forget(); } + + // Overload for DisposeNative + template::*Method) (const typename Owner::LocalRef&)> + static void Wrap(JNIEnv* env, jobject instance) + { + Impl* const impl = NativePtr::Get(env, instance); + if (!impl) { + return; + } + auto self = Owner::LocalRef::Adopt(env, instance); + (impl->*Method)(self); + self.Forget(); + } }; // Specialization for static methods with non-void return type @@ -369,7 +384,7 @@ protected: { static_assert(mozilla::IsBaseOf, Impl>::value, "Attach with UniquePtr&& when not using WeakPtr"); - return NativePtr::Set(instance, ptr); + return NativePtr::Set(instance, static_cast(ptr)); } static void AttachNative(const typename Cls::LocalRef& instance,