mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
e04d1b47b6
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42434 Changelog: [internal] The flags for the event loop were set up using different mechanisms due to the limitations of the previous feature flags systems. Now we can centralize on the new system and use them consistently on Android and iOS. Reviewed By: RSNara Differential Revision: D52819137 fbshipit-source-id: e30a6f2e12b4a027a906502b80a70dd48bb657b6
80 lines
2.4 KiB
C++
80 lines
2.4 KiB
C++
/*
|
|
* 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 <ReactCommon/RuntimeExecutor.h>
|
|
#include <cxxreact/MessageQueueThread.h>
|
|
#include <jserrorhandler/JsErrorHandler.h>
|
|
#include <jsi/jsi.h>
|
|
#include <jsireact/JSIExecutor.h>
|
|
#include <react/renderer/runtimescheduler/RuntimeScheduler.h>
|
|
#include <react/runtime/BufferedRuntimeExecutor.h>
|
|
#include <react/runtime/JSRuntimeFactory.h>
|
|
#include <react/runtime/TimerManager.h>
|
|
|
|
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<void(jsi::Runtime& runtime)>;
|
|
|
|
ReactInstance(
|
|
std::unique_ptr<JSRuntime> runtime,
|
|
std::shared_ptr<MessageQueueThread> jsMessageQueueThread,
|
|
std::shared_ptr<TimerManager> timerManager,
|
|
JsErrorHandler::JsErrorHandlingFunc JsErrorHandlingFunc);
|
|
|
|
RuntimeExecutor getUnbufferedRuntimeExecutor() noexcept;
|
|
|
|
RuntimeExecutor getBufferedRuntimeExecutor() noexcept;
|
|
|
|
std::shared_ptr<RuntimeScheduler> getRuntimeScheduler() noexcept;
|
|
|
|
struct JSRuntimeFlags {
|
|
bool isProfiling = false;
|
|
const std::string runtimeDiagnosticFlags = "";
|
|
};
|
|
|
|
void initializeRuntime(
|
|
JSRuntimeFlags options,
|
|
BindingsInstallFunc bindingsInstallFunc) noexcept;
|
|
|
|
void loadScript(
|
|
std::unique_ptr<const JSBigString> 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<JSRuntime> runtime_;
|
|
std::shared_ptr<MessageQueueThread> jsMessageQueueThread_;
|
|
std::shared_ptr<BufferedRuntimeExecutor> bufferedRuntimeExecutor_;
|
|
std::shared_ptr<TimerManager> timerManager_;
|
|
std::unordered_map<std::string, std::shared_ptr<CallableModule>> modules_;
|
|
std::shared_ptr<RuntimeScheduler> runtimeScheduler_;
|
|
JsErrorHandler jsErrorHandler_;
|
|
|
|
// Whether there are errors caught during bundle loading
|
|
std::shared_ptr<bool> hasFatalJsError_;
|
|
};
|
|
|
|
} // namespace facebook::react
|