зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1343027 - 1. Add jni::Ref::Cast function; r=snorp
Add a Cast function to jni::Ref to cast a reference to a different type (e.g. if ref is a jni::Object::Ref referring to a String instance, use | ref.Cast<jni::String>()->Length() | to get the length of the string). In MOZ_CHECK_JNI builds, Cast() checks that an instance of the source class can indeed be cast to the target class.
This commit is contained in:
Родитель
fd2114caa6
Коммит
0d3d8e6fd1
|
@ -106,6 +106,17 @@ public:
|
||||||
mInstance, typename T::Context().ClassRef());
|
mInstance, typename T::Context().ClassRef());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
typename T::Ref Cast() const
|
||||||
|
{
|
||||||
|
#ifdef MOZ_CHECK_JNI
|
||||||
|
MOZ_RELEASE_ASSERT(FindEnv()->IsAssignableFrom(
|
||||||
|
Context<Cls, Type>().ClassRef(),
|
||||||
|
typename T::Context().ClassRef()));
|
||||||
|
#endif
|
||||||
|
return T::Ref::From(*this);
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const Ref& other) const
|
bool operator==(const Ref& other) const
|
||||||
{
|
{
|
||||||
// Treat two references of the same object as being the same.
|
// Treat two references of the same object as being the same.
|
||||||
|
|
Загрузка…
Ссылка в новой задаче