Skip to content

Commit f5d38d4

Browse files
committed
jni: implement IsInstanceOf
1 parent f59be13 commit f5d38d4

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

jni/src/env/object.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ impl super::JniEnv {
5151
}
5252

5353
// TODO: GetObjectClass
54-
// TODO: IsInstanceOf
54+
/// Tests whether an object is an instance of a class.
55+
///
56+
/// ## PARAMETERS
57+
///
58+
/// `obj`: a Java object.
59+
/// `class`: a Java class object.
60+
pub fn is_instance_of(&self, obj: JObject, class: JClass) -> bool {
61+
let ret;
62+
unsafe {
63+
let invoke_interface = self.as_native_interface();
64+
ret = ((*invoke_interface).IsInstanceOf)(
65+
self.0.cast::<jni_sys::JNIEnv>(),
66+
obj.raw(),
67+
class.raw(),
68+
);
69+
}
70+
71+
ret
72+
}
5573
// TODO: GetObjectRefType
5674
}

runtime/src/native/jni/object.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,17 @@ pub unsafe extern "system" fn IsInstanceOf(
7979
obj: jobject,
8080
clazz: jclass,
8181
) -> jboolean {
82-
unimplemented!("jni::IsInstanceOf");
82+
let obj = unsafe { reference_from_jobject(obj) };
83+
let Some(obj) = obj else {
84+
return false;
85+
};
86+
87+
let class_obj = unsafe { reference_from_jobject(clazz) };
88+
let Some(class_obj) = class_obj else {
89+
return false;
90+
};
91+
92+
obj.is_instance_of(class_obj.extract_instance_class())
8393
}
8494

8595
pub unsafe extern "system" fn GetObjectRefType(env: *mut JNIEnv, obj: jobject) -> jobjectRefType {

0 commit comments

Comments
 (0)