@@ -138,6 +138,16 @@ namespace jni
138
138
return UniqueGlobalRef<T>(reinterpret_cast <T*>(obj), GlobalRefDeleter (env));
139
139
}
140
140
141
+ // Attempt to promote a weak reference to a strong one. Returns an empty result
142
+ // if the weak reference has expired.
143
+ template < class T >
144
+ UniqueGlobalRef<T> NewGlobalRef (JNIEnv& env, const UniqueWeakGlobalRef<T>& t)
145
+ {
146
+ jobject* obj = Wrap<jobject*>(env.NewGlobalRef (Unwrap (t)));
147
+ CheckJavaException (env);
148
+ return UniqueGlobalRef<T>(reinterpret_cast <T*>(obj), GlobalRefDeleter (env));
149
+ }
150
+
141
151
inline void DeleteGlobalRef (JNIEnv& env, UniqueGlobalRef<jobject>&& ref)
142
152
{
143
153
env.DeleteGlobalRef (Unwrap (ref.release ()));
@@ -155,6 +165,16 @@ namespace jni
155
165
return UniqueLocalRef<T>(reinterpret_cast <T*>(obj), LocalRefDeleter (env));
156
166
}
157
167
168
+ // Attempt to promote a weak reference to a strong one. Returns an empty result
169
+ // if the weak reference has expired.
170
+ template < class T >
171
+ UniqueLocalRef<T> NewLocalRef (JNIEnv& env, const UniqueWeakGlobalRef<T>& t)
172
+ {
173
+ jobject* obj = Wrap<jobject*>(env.NewLocalRef (Unwrap (t)));
174
+ CheckJavaException (env);
175
+ return UniqueLocalRef<T>(reinterpret_cast <T*>(obj), LocalRefDeleter (env));
176
+ }
177
+
158
178
inline void DeleteLocalRef (JNIEnv& env, UniqueLocalRef<jobject>&& ref)
159
179
{
160
180
env.DeleteLocalRef (Unwrap (ref.release ()));
0 commit comments