зеркало из https://github.com/mozilla/pjs.git
Bug 705386 - Allow AutoLocalJNIFrame callers to specify the JNIEnv. r=mwu
This commit is contained in:
Родитель
f30b4e424f
Коммит
a77e0383f1
|
@ -233,30 +233,50 @@ public:
|
|||
|
||||
bool GetAccessibilityEnabled();
|
||||
|
||||
struct AutoLocalJNIFrame {
|
||||
AutoLocalJNIFrame(int nEntries = 128) : mEntries(nEntries) {
|
||||
// Make sure there is enough space to store a local ref to the
|
||||
// exception. I am not completely sure this is needed, but does
|
||||
// not hurt.
|
||||
AndroidBridge::Bridge()->JNI()->PushLocalFrame(mEntries + 1);
|
||||
class AutoLocalJNIFrame {
|
||||
public:
|
||||
AutoLocalJNIFrame(int nEntries = 128)
|
||||
: mEntries(nEntries)
|
||||
, mJNIEnv(JNI())
|
||||
{
|
||||
Push();
|
||||
}
|
||||
|
||||
AutoLocalJNIFrame(JNIEnv* aJNIEnv, int nEntries = 128)
|
||||
: mEntries(nEntries)
|
||||
, mJNIEnv(aJNIEnv ? aJNIEnv : JNI())
|
||||
{
|
||||
Push();
|
||||
}
|
||||
|
||||
// Note! Calling Purge makes all previous local refs created in
|
||||
// the AutoLocalJNIFrame's scope INVALID; be sure that you locked down
|
||||
// any local refs that you need to keep around in global refs!
|
||||
void Purge() {
|
||||
AndroidBridge::Bridge()->JNI()->PopLocalFrame(NULL);
|
||||
AndroidBridge::Bridge()->JNI()->PushLocalFrame(mEntries);
|
||||
mJNIEnv->PopLocalFrame(NULL);
|
||||
Push();
|
||||
}
|
||||
|
||||
~AutoLocalJNIFrame() {
|
||||
jthrowable exception =
|
||||
AndroidBridge::Bridge()->JNI()->ExceptionOccurred();
|
||||
jthrowable exception = mJNIEnv->ExceptionOccurred();
|
||||
if (exception) {
|
||||
AndroidBridge::Bridge()->JNI()->ExceptionDescribe();
|
||||
AndroidBridge::Bridge()->JNI()->ExceptionClear();
|
||||
mJNIEnv->ExceptionDescribe();
|
||||
mJNIEnv->ExceptionClear();
|
||||
}
|
||||
AndroidBridge::Bridge()->JNI()->PopLocalFrame(NULL);
|
||||
|
||||
mJNIEnv->PopLocalFrame(NULL);
|
||||
}
|
||||
|
||||
private:
|
||||
void Push() {
|
||||
// Make sure there is enough space to store a local ref to the
|
||||
// exception. I am not completely sure this is needed, but does
|
||||
// not hurt.
|
||||
mJNIEnv->PushLocalFrame(mEntries + 1);
|
||||
}
|
||||
|
||||
int mEntries;
|
||||
JNIEnv* mJNIEnv;
|
||||
};
|
||||
|
||||
/* See GLHelpers.java as to why this is needed */
|
||||
|
|
Загрузка…
Ссылка в новой задаче