Bug 1187552 - Support direct ownership of C++ objects by Java objects; r=snorp

Add a direct ownership model where the Java object owns the
corresponding C++ object directly, in addition to the WeakPtr model
where the Java object owns a WeakPtr to the C++ object. The WeakPtr
model is chosen when the implementing C++ class inherits from
SupportsWeakPtr. Otherwise, the direct ownership model is chosen. Under
the direct ownership model, a UniquePtr object must be used to attach
the containing C++ object to a Java object, to ensure ownership is
passed on to the Java object.
This commit is contained in:
Jim Chen
2015-08-04 17:47:28 -04:00
parent 2986b3f565
commit b4d1d1173f
2 changed files with 178 additions and 56 deletions

View File

@@ -111,14 +111,8 @@ uintptr_t GetNativeHandle(JNIEnv* env, jobject instance)
return 0;
}
auto handle = static_cast<uintptr_t>(
return static_cast<uintptr_t>(
env->GetLongField(instance, sJNIObjectHandleField));
if (!handle && !env->ExceptionCheck()) {
ThrowException(env, "java/lang/NullPointerException",
"Null native pointer");
}
return handle;
}
void SetNativeHandle(JNIEnv* env, jobject instance, uintptr_t handle)