// Copyright © 2021-present 650 Industries, Inc. (aka Expo) #pragma once #include "JSIObjectWrapper.h" #include "WeakRuntimeHolder.h" #include "JavaScriptTypedArray.h" #include "JNIDeallocator.h" #include #include #include namespace jni = facebook::jni; namespace jsi = facebook::jsi; namespace expo { class JavaScriptRuntime; class JavaScriptObject; class JavaScriptTypedArray; class JavaScriptFunction; /** * Represents any JavaScript value. Its purpose is to expose the `jsi::Value` API back to Kotlin. */ class JavaScriptValue : public jni::HybridClass, JSIValueWrapper { public: static auto constexpr kJavaDescriptor = "Lexpo/modules/kotlin/jni/JavaScriptValue;"; static auto constexpr TAG = "JavaScriptValue"; static void registerNatives(); static jni::local_ref newInstance( JSIInteropModuleRegistry *jsiInteropModuleRegistry, std::weak_ptr runtime, std::shared_ptr jsValue ); JavaScriptValue( std::weak_ptr runtime, std::shared_ptr jsValue ); JavaScriptValue( WeakRuntimeHolder runtime, std::shared_ptr jsValue ); std::shared_ptr get() override; std::string kind(); bool isNull(); bool isUndefined(); bool isBool(); bool isNumber(); bool isString(); bool isSymbol(); bool isFunction(); bool isArray(); bool isObject(); bool isTypedArray(); bool getBool(); double getDouble(); std::string getString(); jni::local_ref::javaobject> getObject(); jni::local_ref> getArray(); jni::local_ref getTypedArray(); jni::local_ref::javaobject> jniGetFunction(); private: friend HybridBase; WeakRuntimeHolder runtimeHolder; std::shared_ptr jsValue; jni::local_ref jniKind(); jni::local_ref jniGetString(); }; } // namespace expo