/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ #pragma once #include #include #include #include #include #include #include #include namespace facebook::react { struct CallableModule { explicit CallableModule(jsi::Function factory) : factory(std::move(factory)) {} jsi::Function factory; }; class ReactInstance final { public: using BindingsInstallFunc = std::function; ReactInstance( std::unique_ptr runtime, std::shared_ptr jsMessageQueueThread, std::shared_ptr timerManager, JsErrorHandler::JsErrorHandlingFunc JsErrorHandlingFunc); RuntimeExecutor getUnbufferedRuntimeExecutor() noexcept; RuntimeExecutor getBufferedRuntimeExecutor() noexcept; std::shared_ptr getRuntimeScheduler() noexcept; struct JSRuntimeFlags { bool isProfiling = false; const std::string runtimeDiagnosticFlags = ""; }; void initializeRuntime( JSRuntimeFlags options, BindingsInstallFunc bindingsInstallFunc) noexcept; void loadScript( std::unique_ptr script, const std::string& sourceURL); void registerSegment(uint32_t segmentId, const std::string& segmentPath); void callFunctionOnModule( const std::string& moduleName, const std::string& methodName, const folly::dynamic& args); void handleMemoryPressureJs(int pressureLevel); private: std::shared_ptr runtime_; std::shared_ptr jsMessageQueueThread_; std::shared_ptr bufferedRuntimeExecutor_; std::shared_ptr timerManager_; std::unordered_map> modules_; std::shared_ptr runtimeScheduler_; JsErrorHandler jsErrorHandler_; // Whether there are errors caught during bundle loading std::shared_ptr hasFatalJsError_; }; } // namespace facebook::react