1 // Copyright © 2021-present 650 Industries, Inc. (aka Expo)
2 
3 #include "JNIFunctionBody.h"
4 
5 namespace jni = facebook::jni;
6 namespace react = facebook::react;
7 
8 namespace expo {
9 jni::local_ref<react::ReadableNativeArray::javaobject>
10 JNIFunctionBody::invoke(jni::local_ref<jni::JArrayClass<jobject>> &&args) {
11   // Do NOT use getClass here!
12   // Method obtained from `getClass` will point to the overridden version of the method.
13   // Because of that, it can't be cached - we will try to invoke the nonexistent method
14   // if we receive an object of a different class than the one used to obtain the method id.
15   // The only cacheable method id can be obtain from the base class.
16   static const auto method = jni::findClassLocal("expo/modules/kotlin/jni/JNIFunctionBody")
17     ->getMethod<
18       react::ReadableNativeArray::javaobject(jni::local_ref<jni::JArrayClass<jobject>>)
19     >(
20       "invoke"
21     );
22 
23   return method(this->self(), args);
24 }
25 
26 void JNIAsyncFunctionBody::invoke(
27   jni::local_ref<jni::JArrayClass<jobject>> &&args,
28   jobject promise
29 ) {
30   // Do NOT use getClass here!
31   // Method obtained from `getClass` will point to the overridden version of the method.
32   // Because of that, it can't be cached - we will try to invoke the nonexistent method
33   // if we receive an object of a different class than the one used to obtain the method id.
34   // The only cacheable method id can be obtain from the base class.
35   static const auto method = jni::findClassLocal("expo/modules/kotlin/jni/JNIAsyncFunctionBody")
36     ->getMethod<
37       void(jni::local_ref<jni::JArrayClass<jobject>>, jobject)
38     >(
39       "invoke"
40     );
41 
42   method(this->self(), args, promise);
43 }
44 } // namespace expo
45