1 // Copyright 2018-present 650 Industries. All rights reserved. 2 3 #import <ExpoModulesCore/EXJavaScriptObject.h> 4 5 #ifdef __cplusplus 6 #import <ReactCommon/CallInvoker.h> 7 8 namespace jsi = facebook::jsi; 9 namespace react = facebook::react; 10 #endif // __cplusplus 11 12 NS_SWIFT_NAME(JavaScriptRuntime) 13 @interface EXJavaScriptRuntime : NSObject 14 15 #ifdef __cplusplus 16 typedef jsi::Value (^JSHostFunctionBlock)(jsi::Runtime &runtime, std::shared_ptr<react::CallInvoker> callInvoker, NSArray * _Nonnull arguments); 17 18 - (nonnull instancetype)initWithRuntime:(jsi::Runtime &)runtime 19 callInvoker:(std::shared_ptr<react::CallInvoker>)callInvoker; 20 21 /** 22 Returns the underlying runtime object. 23 */ 24 - (nonnull jsi::Runtime *)get; 25 26 /** 27 Returns the call invoker the runtime was initialized with. 28 */ 29 - (std::shared_ptr<react::CallInvoker>)callInvoker; 30 31 /** 32 Wraps given host object to `EXJavaScriptObject`. 33 */ 34 - (nonnull EXJavaScriptObject *)createHostObject:(std::shared_ptr<jsi::HostObject>)jsiHostObjectPtr; 35 36 - (jsi::Function)createSyncFunction:(nonnull NSString *)name 37 argsCount:(NSInteger)argsCount 38 block:(nonnull JSSyncFunctionBlock)block; 39 40 - (jsi::Function)createAsyncFunction:(nonnull NSString *)name 41 argsCount:(NSInteger)argsCount 42 block:(nonnull JSAsyncFunctionBlock)block; 43 #endif // __cplusplus 44 45 /** 46 Returns the runtime global object for use in Swift. 47 */ 48 - (nonnull EXJavaScriptObject *)global; 49 50 /** 51 Creates a new object for use in Swift. 52 */ 53 - (nonnull EXJavaScriptObject *)createObject; 54 55 @end 56