// Copyright 2023-present 650 Industries. All rights reserved. #import #import @implementation EXRawJavaScriptFunction { /** Pointer to the `EXJavaScriptRuntime` wrapper. \note It must be weak because only then the original runtime can be safely deallocated when the JS engine wants to without unsetting it on each created object. */ __weak EXJavaScriptRuntime *_runtime; /** Shared pointer to the underlying JSI function. */ std::shared_ptr _function; } - (nonnull instancetype)initWith:(std::shared_ptr)function runtime:(nonnull EXJavaScriptRuntime *)runtime { if (self = [super init]) { _runtime = runtime; _function = function; } return self; } - (nonnull EXJavaScriptValue *)callWithArguments:(nonnull NSArray *)arguments thisObject:(nullable EXJavaScriptObject *)thisObject asConstructor:(BOOL)asConstructor { jsi::Runtime *runtime = [_runtime get]; std::vector vector = expo::convertNSArrayToStdVector(*runtime, arguments); const jsi::Value *data = vector.data(); jsi::Value result; if (asConstructor) { result = _function->callAsConstructor(*runtime, data, arguments.count); } else if (thisObject) { result = _function->callWithThis(*runtime, *[thisObject get], data, arguments.count); } else { result = _function->call(*runtime, data, arguments.count); } std::shared_ptr resultPtr = std::make_shared(*runtime, result); return [[EXJavaScriptValue alloc] initWithRuntime:_runtime value:resultPtr]; } @end