// Copyright © 2021-present 650 Industries, Inc. (aka Expo) #pragma once #include "JSIObjectWrapper.h" #include "JavaScriptRuntime.h" #include "WeakRuntimeHolder.h" #include "types/ExpectedType.h" #include #include namespace jni = facebook::jni; namespace jsi = facebook::jsi; namespace expo { /** * Represents any JavaScript function. Its purpose is to expose the `jsi::Function` API back to Kotlin. */ class JavaScriptFunction : public jni::HybridClass, JSIFunctionWrapper { public: static auto constexpr kJavaDescriptor = "Lexpo/modules/kotlin/jni/JavaScriptFunction;"; static auto constexpr TAG = "JavaScriptFunction"; static void registerNatives(); static jni::local_ref newInstance( JSIInteropModuleRegistry *jsiInteropModuleRegistry, std::weak_ptr runtime, std::shared_ptr jsFunction ); JavaScriptFunction( std::weak_ptr runtime, std::shared_ptr jsFunction ); JavaScriptFunction( WeakRuntimeHolder runtime, std::shared_ptr jsFunction ); std::shared_ptr get() override; private: friend HybridBase; WeakRuntimeHolder runtimeHolder; std::shared_ptr jsFunction; jobject invoke( jni::alias_ref> args, jni::alias_ref expectedReturnType ); }; } // namespace expo