1 // Copyright © 2021-present 650 Industries, Inc. (aka Expo) 2 3 #pragma once 4 5 #include "JSIObjectWrapper.h" 6 7 #include <fbjni/fbjni.h> 8 #include <jsi/jsi.h> 9 10 #include <memory> 11 12 namespace jni = facebook::jni; 13 namespace jsi = facebook::jsi; 14 15 namespace expo { 16 class JavaScriptRuntime; 17 18 class JavaScriptObject; 19 20 /** 21 * Represents any JavaScript value. Its purpose is to expose the `jsi::Value` API back to Kotlin. 22 */ 23 class JavaScriptValue : public jni::HybridClass<JavaScriptValue>, JSIValueWrapper { 24 public: 25 static auto constexpr 26 kJavaDescriptor = "Lexpo/modules/kotlin/jni/JavaScriptValue;"; 27 static auto constexpr TAG = "JavaScriptValue"; 28 29 static void registerNatives(); 30 31 JavaScriptValue( 32 std::weak_ptr<JavaScriptRuntime> runtime, 33 std::shared_ptr<jsi::Value> jsValue 34 ); 35 36 std::shared_ptr<jsi::Value> get() override; 37 38 std::string kind(); 39 40 bool isNull(); 41 42 bool isUndefined(); 43 44 bool isBool(); 45 46 bool isNumber(); 47 48 bool isString(); 49 50 bool isSymbol(); 51 52 bool isFunction(); 53 54 bool isObject(); 55 56 bool getBool(); 57 58 double getDouble(); 59 60 std::string getString(); 61 62 jni::local_ref<jni::HybridClass<JavaScriptObject>::javaobject> getObject(); 63 64 private: 65 friend HybridBase; 66 67 std::weak_ptr<JavaScriptRuntime> runtimeHolder; 68 std::shared_ptr<jsi::Value> jsValue; 69 70 jni::local_ref<jstring> jniKind(); 71 72 jni::local_ref<jstring> jniGetString(); 73 }; 74 } // namespace expo 75