mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Move jni files to OSS folders (#36825)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/36825 Move Bridgeless Android jni files from > fbandroid/java/com/facebook/venice to > xplat/js/react-native-github/packages/react-native/ReactAndroid/src/main/jni/react/bridgeless Changelog: [Android][Changed] - Move Bridgeless Android jni code to OSS folders Reviewed By: cortinico Differential Revision: D44501428 fbshipit-source-id: 442276a56f35bccd24c2fd425abc0e68479ad379
This commit is contained in:
committed by
Facebook GitHub Bot
parent
6f94cd272f
commit
9bd68a54d1
+26
@@ -0,0 +1,26 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ReactCommon/RuntimeExecutor.h>
|
||||
#include <react/bridgeless/ReactInstance.h>
|
||||
|
||||
#include <qpljsibindings/QuickPerformanceLoggerJSIBindings.h>
|
||||
#include <qpljsibindings/UserFlowJSIBindings.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class BindingsInstaller {
|
||||
public:
|
||||
ReactInstance::BindingsInstallFunc getBindingsInstallFunc() {
|
||||
auto installBindings = [](jsi::Runtime &runtime) {
|
||||
jsi::installQPLBindings(runtime);
|
||||
jsi::installUserFlowBindings(runtime);
|
||||
};
|
||||
return installBindings;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
---
|
||||
Checks: '
|
||||
*,
|
||||
-cert-err60-cpp,
|
||||
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||
-cppcoreguidelines-special-member-functions,
|
||||
-cppcoreguidelines-pro-type-const-cast,
|
||||
-fuchsia-default-arguments-calls,
|
||||
-fuchsia-multiple-inheritance,
|
||||
-google-readability-casting,
|
||||
-google-runtime-int,
|
||||
-google-runtime-references,
|
||||
-hicpp-special-member-functions,
|
||||
-llvm-header-guard,
|
||||
-misc-non-private-member-variables-in-classes,
|
||||
-misc-unused-parameters,
|
||||
-modernize-use-trailing-return-type,
|
||||
-performance-unnecessary-value-param
|
||||
'
|
||||
...
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#include "JHermesInstance.h"
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
jni::local_ref<JHermesInstance::jhybriddata> JHermesInstance::initHybrid(
|
||||
jni::alias_ref<jhybridobject>) {
|
||||
return makeCxxInstance();
|
||||
}
|
||||
|
||||
void JHermesInstance::registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", JHermesInstance::initHybrid),
|
||||
});
|
||||
}
|
||||
|
||||
std::unique_ptr<jsi::Runtime> JHermesInstance::createJSRuntime() noexcept {
|
||||
// TODO T105438175 Pass ReactNativeConfig to init Hermes with MobileConfig
|
||||
return HermesInstance::createJSRuntime();
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
#include <jni.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <react/bridgeless/JSEngineInstance.h>
|
||||
#include <react/bridgeless/hermes/HermesInstance.h>
|
||||
#include "../../jni/JJSEngineInstance.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class JHermesInstance
|
||||
: public jni::HybridClass<JHermesInstance, JJSEngineInstance> {
|
||||
public:
|
||||
static constexpr auto kJavaDescriptor =
|
||||
"Lcom/facebook/venice/hermes/HermesInstance;";
|
||||
|
||||
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject>);
|
||||
|
||||
static void registerNatives();
|
||||
|
||||
std::unique_ptr<jsi::Runtime> createJSRuntime() noexcept;
|
||||
|
||||
~JHermesInstance() {}
|
||||
|
||||
private:
|
||||
friend HybridBase;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
#include <fb/xplat_init.h>
|
||||
|
||||
#include "JHermesInstance.h"
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
|
||||
return facebook::xplat::initialize(
|
||||
vm, [] { facebook::react::JHermesInstance::registerNatives(); });
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
Checks: '
|
||||
*,
|
||||
-cert-err60-cpp,
|
||||
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
|
||||
-cppcoreguidelines-special-member-functions,
|
||||
-cppcoreguidelines-pro-type-const-cast,
|
||||
-fuchsia-default-arguments-calls,
|
||||
-fuchsia-multiple-inheritance,
|
||||
-google-readability-casting,
|
||||
-google-runtime-int,
|
||||
-google-runtime-references,
|
||||
-hicpp-special-member-functions,
|
||||
-llvm-header-guard,
|
||||
-misc-non-private-member-variables-in-classes,
|
||||
-misc-unused-parameters,
|
||||
-modernize-use-trailing-return-type,
|
||||
-performance-unnecessary-value-param
|
||||
'
|
||||
...
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#include "BridgelessJSCallInvoker.h"
|
||||
|
||||
#include <exception>
|
||||
#include <utility>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
BridgelessJSCallInvoker::BridgelessJSCallInvoker(
|
||||
RuntimeExecutor runtimeExecutor)
|
||||
: runtimeExecutor_(std::move(runtimeExecutor)) {}
|
||||
|
||||
void BridgelessJSCallInvoker::invokeAsync(std::function<void()> &&func) {
|
||||
runtimeExecutor_([func = std::move(func)](jsi::Runtime &runtime) { func(); });
|
||||
}
|
||||
|
||||
void BridgelessJSCallInvoker::invokeSync(std::function<void()> &&func) {
|
||||
// TODO: Replace JS Callinvoker with RuntimeExecutor.
|
||||
throw std::runtime_error(
|
||||
"Synchronous native -> JS calls are currently not supported.");
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include <ReactCommon/CallInvoker.h>
|
||||
#include <ReactCommon/RuntimeExecutor.h>
|
||||
#include <fb/fbjni.h>
|
||||
#include <jsi/jsi.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class BridgelessJSCallInvoker : public CallInvoker {
|
||||
public:
|
||||
explicit BridgelessJSCallInvoker(RuntimeExecutor runtimeExecutor);
|
||||
void invokeAsync(std::function<void()> &&func) override;
|
||||
void invokeSync(std::function<void()> &&func) override;
|
||||
|
||||
private:
|
||||
RuntimeExecutor runtimeExecutor_;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#include "BridgelessNativeCallInvoker.h"
|
||||
|
||||
#include <exception>
|
||||
#include <utility>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
BridgelessNativeCallInvoker::BridgelessNativeCallInvoker(
|
||||
std::shared_ptr<JMessageQueueThread> messageQueueThread)
|
||||
: messageQueueThread_(std::move(messageQueueThread)) {}
|
||||
|
||||
void BridgelessNativeCallInvoker::invokeAsync(std::function<void()> &&func) {
|
||||
messageQueueThread_->runOnQueue(std::move(func));
|
||||
}
|
||||
|
||||
void BridgelessNativeCallInvoker::invokeSync(std::function<void()> &&func) {
|
||||
messageQueueThread_->runOnQueueSync(std::move(func));
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include <ReactCommon/CallInvoker.h>
|
||||
#include <ReactCommon/RuntimeExecutor.h>
|
||||
#include <fb/fbjni.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <react/jni/JMessageQueueThread.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class BridgelessNativeCallInvoker : public CallInvoker {
|
||||
public:
|
||||
explicit BridgelessNativeCallInvoker(
|
||||
std::shared_ptr<JMessageQueueThread> messageQueueThread);
|
||||
void invokeAsync(std::function<void()> &&func) override;
|
||||
void invokeSync(std::function<void()> &&func) override;
|
||||
|
||||
private:
|
||||
std::shared_ptr<JMessageQueueThread> messageQueueThread_;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
#include <jni.h>
|
||||
#include <react/bridgeless/JSEngineInstance.h>
|
||||
|
||||
namespace facebook {
|
||||
|
||||
namespace react {
|
||||
|
||||
class JJSEngineInstance : public jni::HybridClass<JJSEngineInstance>,
|
||||
public JSEngineInstance {
|
||||
public:
|
||||
static auto constexpr kJavaDescriptor =
|
||||
"Lcom/facebook/venice/JSEngineInstance;";
|
||||
|
||||
private:
|
||||
friend HybridBase;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#include "JJSTimerExecutor.h"
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
#include <jni.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
void JJSTimerExecutor::setTimerManager(
|
||||
std::weak_ptr<TimerManager> timerManager) {
|
||||
assert(timerManager && "`timerManager` must not be `nullptr`.");
|
||||
timerManager_ = timerManager;
|
||||
}
|
||||
|
||||
void JJSTimerExecutor::callTimers(WritableNativeArray *timerIDs) {
|
||||
if (auto timerManager = timerManager_.lock()) {
|
||||
for (const auto &timerID : timerIDs->consume()) {
|
||||
timerManager->callTimer((uint32_t)timerID.asInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JJSTimerExecutor::registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("callTimers", JJSTimerExecutor::callTimers),
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ReactCommon/RuntimeExecutor.h>
|
||||
#include <fb/fbjni.h>
|
||||
#include <jni.h>
|
||||
#include <react/bridgeless/TimerManager.h>
|
||||
#include <react/jni/WritableNativeArray.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class JJSTimerExecutor : public jni::HybridClass<JJSTimerExecutor> {
|
||||
public:
|
||||
JJSTimerExecutor() = default;
|
||||
|
||||
constexpr static auto kJavaDescriptor =
|
||||
"Lcom/facebook/venice/JSTimerExecutor;";
|
||||
|
||||
static void registerNatives();
|
||||
|
||||
void setTimerManager(std::weak_ptr<TimerManager> timerManager);
|
||||
|
||||
void callTimers(WritableNativeArray *timerIDs);
|
||||
|
||||
private:
|
||||
friend HybridBase;
|
||||
|
||||
std::weak_ptr<TimerManager> timerManager_;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#include "JJavaTimerManager.h"
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
#include <jni.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
void JJavaTimerManager::createTimer(
|
||||
uint32_t timerID,
|
||||
double duration,
|
||||
bool repeat) {
|
||||
static const auto method =
|
||||
javaClassStatic()->getMethod<void(jint, jlong, jboolean)>("createTimer");
|
||||
method(self(), timerID, (long)duration, static_cast<unsigned char>(repeat));
|
||||
}
|
||||
|
||||
void JJavaTimerManager::deleteTimer(uint32_t timerID) {
|
||||
static const auto method =
|
||||
javaClassStatic()->getMethod<void(jint)>("deleteTimer");
|
||||
method(self(), timerID);
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
#include <jni.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
struct JJavaTimerManager : jni::JavaClass<JJavaTimerManager> {
|
||||
static auto constexpr kJavaDescriptor =
|
||||
"Lcom/facebook/react/modules/core/JavaTimerManager;";
|
||||
|
||||
void createTimer(uint32_t timerID, double duration, bool repeat);
|
||||
|
||||
void deleteTimer(uint32_t timerID);
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#include "JReactExceptionManager.h"
|
||||
#include <fb/fbjni.h>
|
||||
#include <glog/logging.h>
|
||||
#include <jni.h>
|
||||
#include <iostream>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
void JReactExceptionManager::reportJsException(
|
||||
const JReadableMapBuffer::javaobject errorMapBuffer) {
|
||||
static const auto method =
|
||||
javaClassStatic()->getMethod<void(JReadableMapBuffer::javaobject)>(
|
||||
"reportJsException");
|
||||
if (self() != nullptr) {
|
||||
method(self(), errorMapBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
#include <jni.h>
|
||||
#include <react/common/mapbuffer/JReadableMapBuffer.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class JReactExceptionManager
|
||||
: public facebook::jni::JavaClass<JReactExceptionManager> {
|
||||
public:
|
||||
static auto constexpr kJavaDescriptor =
|
||||
"Lcom/facebook/venice/exceptionmanager/ReactJsExceptionHandler;";
|
||||
|
||||
void reportJsException(const JReadableMapBuffer::javaobject errorMapBuffer);
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#include "JReactInstance.h"
|
||||
|
||||
#ifdef WITH_FBSYSTRACE
|
||||
#include <fbsystrace.h>
|
||||
#endif
|
||||
|
||||
#include <BindingsInstaller.h>
|
||||
#include <cxxreact/JSBigString.h>
|
||||
#include <cxxreact/RecoverableError.h>
|
||||
#include <fb/fbjni.h>
|
||||
#include <glog/logging.h>
|
||||
#include <jni.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <jsireact/JSIExecutor.h>
|
||||
#include <react/common/mapbuffer/JReadableMapBuffer.h>
|
||||
#include <react/jni/JRuntimeExecutor.h>
|
||||
#include <react/jni/JSLogging.h>
|
||||
#include <react/renderer/mapbuffer/MapBuffer.h>
|
||||
#include "BridgelessJSCallInvoker.h"
|
||||
#include "BridgelessNativeCallInvoker.h"
|
||||
#include "JavaTimerRegistry.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
JReactInstance::JReactInstance(
|
||||
jni::alias_ref<JJSEngineInstance::javaobject> jsEngineInstance,
|
||||
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
|
||||
jni::alias_ref<JavaMessageQueueThread::javaobject> nativeMessageQueueThread,
|
||||
jni::alias_ref<JJavaTimerManager::javaobject> javaTimerManager,
|
||||
jni::alias_ref<JJSTimerExecutor::javaobject> jsTimerExecutor,
|
||||
jni::alias_ref<JReactExceptionManager::javaobject> jReactExceptionManager,
|
||||
bool isProfiling) noexcept {
|
||||
// TODO(janzer): Lazily create runtime
|
||||
auto sharedJSMessageQueueThread =
|
||||
std::make_shared<JMessageQueueThread>(jsMessageQueueThread);
|
||||
auto sharedNativeMessageQueueThread =
|
||||
std::make_shared<JMessageQueueThread>(nativeMessageQueueThread);
|
||||
|
||||
// Create the timer manager (for JS timers)
|
||||
auto timerRegistry =
|
||||
std::make_unique<JavaTimerRegistry>(jni::make_global(javaTimerManager));
|
||||
auto timerManager = std::make_shared<TimerManager>(std::move(timerRegistry));
|
||||
jsTimerExecutor->cthis()->setTimerManager(timerManager);
|
||||
|
||||
// Create the instance
|
||||
std::unique_ptr<BindingsInstaller> bindingsInstaller =
|
||||
std::make_unique<BindingsInstaller>();
|
||||
|
||||
jReactExceptionManager_ = jni::make_global(jReactExceptionManager);
|
||||
auto jsErrorHandlingFunc = [this](MapBuffer errorMap) noexcept {
|
||||
if (jReactExceptionManager_ != nullptr) {
|
||||
auto jErrorMap =
|
||||
JReadableMapBuffer::createWithContents(std::move(errorMap));
|
||||
jReactExceptionManager_->reportJsException(jErrorMap.get());
|
||||
}
|
||||
};
|
||||
|
||||
instance_ = std::make_unique<ReactInstance>(
|
||||
jsEngineInstance->cthis()->createJSRuntime(),
|
||||
sharedJSMessageQueueThread,
|
||||
timerManager,
|
||||
std::move(jsErrorHandlingFunc));
|
||||
auto appBindingInstaller = bindingsInstaller->getBindingsInstallFunc();
|
||||
|
||||
auto bufferedRuntimeExecutor = instance_->getBufferedRuntimeExecutor();
|
||||
timerManager->setRuntimeExecutor(bufferedRuntimeExecutor);
|
||||
|
||||
ReactInstance::JSRuntimeFlags options = {.isProfiling = isProfiling};
|
||||
instance_->initializeRuntime(
|
||||
options,
|
||||
[appBindingInstaller, instance = instance_.get()](jsi::Runtime &runtime) {
|
||||
react::Logger androidLogger =
|
||||
static_cast<void (*)(const std::string &, unsigned int)>(
|
||||
&reactAndroidLoggingHook);
|
||||
react::bindNativeLogger(runtime, androidLogger);
|
||||
appBindingInstaller(runtime);
|
||||
});
|
||||
|
||||
auto unbufferedRuntimeExecutor = instance_->getUnbufferedRuntimeExecutor();
|
||||
// Set up the JS and native modules call invokers (for TurboModules)
|
||||
auto jsInvoker =
|
||||
std::make_unique<BridgelessJSCallInvoker>(unbufferedRuntimeExecutor);
|
||||
jsCallInvokerHolder_ = jni::make_global(
|
||||
CallInvokerHolder::newObjectCxxArgs(std::move(jsInvoker)));
|
||||
auto nativeInvoker = std::make_unique<BridgelessNativeCallInvoker>(
|
||||
sharedNativeMessageQueueThread);
|
||||
nativeCallInvokerHolder_ = jni::make_global(
|
||||
CallInvokerHolder::newObjectCxxArgs(std::move(nativeInvoker)));
|
||||
|
||||
// Storing this here to make sure the Java reference doesn't get destroyed
|
||||
unbufferedRuntimeExecutor_ = jni::make_global(
|
||||
JRuntimeExecutor::newObjectCxxArgs(unbufferedRuntimeExecutor));
|
||||
bufferedRuntimeExecutor_ = jni::make_global(
|
||||
JRuntimeExecutor::newObjectCxxArgs(bufferedRuntimeExecutor));
|
||||
runtimeScheduler_ = jni::make_global(
|
||||
JRuntimeScheduler::newObjectCxxArgs(instance_->getRuntimeScheduler()));
|
||||
}
|
||||
|
||||
jni::local_ref<JReactInstance::jhybriddata> JReactInstance::initHybrid(
|
||||
jni::alias_ref<jhybridobject> /* unused */,
|
||||
jni::alias_ref<JJSEngineInstance::javaobject> jsEngineInstance,
|
||||
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
|
||||
jni::alias_ref<JavaMessageQueueThread::javaobject> nativeMessageQueueThread,
|
||||
jni::alias_ref<JJavaTimerManager::javaobject> javaTimerManager,
|
||||
jni::alias_ref<JJSTimerExecutor::javaobject> jsTimerExecutor,
|
||||
jni::alias_ref<JReactExceptionManager::javaobject> jReactExceptionManager,
|
||||
bool isProfiling) {
|
||||
return makeCxxInstance(
|
||||
jsEngineInstance,
|
||||
jsMessageQueueThread,
|
||||
nativeMessageQueueThread,
|
||||
javaTimerManager,
|
||||
jsTimerExecutor,
|
||||
jReactExceptionManager,
|
||||
isProfiling);
|
||||
}
|
||||
|
||||
void JReactInstance::loadJSBundleFromAssets(
|
||||
jni::alias_ref<JAssetManager::javaobject> assetManager,
|
||||
const std::string &assetURL) {
|
||||
const int kAssetsLength = 9; // strlen("assets://");
|
||||
auto sourceURL = assetURL.substr(kAssetsLength);
|
||||
|
||||
auto manager = extractAssetManager(assetManager);
|
||||
auto script = loadScriptFromAssets(manager, sourceURL);
|
||||
instance_->loadScript(std::move(script), sourceURL);
|
||||
}
|
||||
|
||||
void JReactInstance::loadJSBundleFromFile(
|
||||
const std::string &fileName,
|
||||
const std::string &sourceURL) {
|
||||
std::unique_ptr<const JSBigFileString> script;
|
||||
RecoverableError::runRethrowingAsRecoverable<std::system_error>(
|
||||
[&fileName, &script]() { script = JSBigFileString::fromPath(fileName); });
|
||||
instance_->loadScript(std::move(script), sourceURL);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is needed to initialize TurboModules; in the future this will be
|
||||
* replaced with something similar to runtimeExecutor, which we'll use for
|
||||
* Fabric as well.
|
||||
* TODO T44251068 Replace with runtimeExecutor
|
||||
*/
|
||||
jni::alias_ref<CallInvokerHolder::javaobject>
|
||||
JReactInstance::getJSCallInvokerHolder() {
|
||||
return jsCallInvokerHolder_;
|
||||
}
|
||||
|
||||
jni::alias_ref<CallInvokerHolder::javaobject>
|
||||
JReactInstance::getNativeCallInvokerHolder() {
|
||||
return nativeCallInvokerHolder_;
|
||||
}
|
||||
|
||||
jni::global_ref<JJSTimerExecutor::javaobject>
|
||||
JReactInstance::createJSTimerExecutor(
|
||||
jni::alias_ref<jhybridobject> /* unused */) {
|
||||
return jni::make_global(JJSTimerExecutor::newObjectCxxArgs());
|
||||
}
|
||||
|
||||
void JReactInstance::callFunctionOnModule(
|
||||
const std::string &moduleName,
|
||||
const std::string &methodName,
|
||||
NativeArray *args) {
|
||||
instance_->callFunctionOnModule(moduleName, methodName, args->consume());
|
||||
}
|
||||
|
||||
jni::alias_ref<JRuntimeExecutor::javaobject>
|
||||
JReactInstance::getUnbufferedRuntimeExecutor() noexcept {
|
||||
return unbufferedRuntimeExecutor_;
|
||||
}
|
||||
|
||||
jni::alias_ref<JRuntimeExecutor::javaobject>
|
||||
JReactInstance::getBufferedRuntimeExecutor() noexcept {
|
||||
return bufferedRuntimeExecutor_;
|
||||
}
|
||||
|
||||
jni::alias_ref<JRuntimeScheduler::javaobject>
|
||||
JReactInstance::getRuntimeScheduler() noexcept {
|
||||
return runtimeScheduler_;
|
||||
}
|
||||
|
||||
void JReactInstance::registerSegment(
|
||||
int segmentId,
|
||||
const std::string &segmentPath) noexcept {
|
||||
instance_->registerSegment((uint32_t)segmentId, segmentPath);
|
||||
}
|
||||
|
||||
void JReactInstance::handleMemoryPressureJs(jint level) {
|
||||
instance_->handleMemoryPressureJs(level);
|
||||
}
|
||||
|
||||
void JReactInstance::registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", JReactInstance::initHybrid),
|
||||
makeNativeMethod(
|
||||
"createJSTimerExecutor", JReactInstance::createJSTimerExecutor),
|
||||
makeNativeMethod(
|
||||
"loadJSBundleFromAssets", JReactInstance::loadJSBundleFromAssets),
|
||||
makeNativeMethod(
|
||||
"loadJSBundleFromFile", JReactInstance::loadJSBundleFromFile),
|
||||
makeNativeMethod(
|
||||
"getJSCallInvokerHolder", JReactInstance::getJSCallInvokerHolder),
|
||||
makeNativeMethod(
|
||||
"getNativeCallInvokerHolder",
|
||||
JReactInstance::getNativeCallInvokerHolder),
|
||||
makeNativeMethod(
|
||||
"callFunctionOnModule", JReactInstance::callFunctionOnModule),
|
||||
makeNativeMethod(
|
||||
"getUnbufferedRuntimeExecutor",
|
||||
JReactInstance::getUnbufferedRuntimeExecutor),
|
||||
makeNativeMethod(
|
||||
"getBufferedRuntimeExecutor",
|
||||
JReactInstance::getBufferedRuntimeExecutor),
|
||||
makeNativeMethod(
|
||||
"getRuntimeScheduler", JReactInstance::getRuntimeScheduler),
|
||||
|
||||
makeNativeMethod(
|
||||
"registerSegmentNative", JReactInstance::registerSegment),
|
||||
makeNativeMethod(
|
||||
"handleMemoryPressureJs", JReactInstance::handleMemoryPressureJs),
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -0,0 +1,99 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <ReactCommon/CallInvokerHolder.h>
|
||||
#include <ReactCommon/RuntimeExecutor.h>
|
||||
#include <fb/fbjni.h>
|
||||
#include <jni.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <react/bridgeless/JSEngineInstance.h>
|
||||
#include <react/bridgeless/PlatformTimerRegistry.h>
|
||||
#include <react/bridgeless/ReactInstance.h>
|
||||
#include <react/jni/JMessageQueueThread.h>
|
||||
#include <react/jni/JRuntimeExecutor.h>
|
||||
#include <react/jni/JRuntimeScheduler.h>
|
||||
#include <react/jni/JSLoader.h>
|
||||
#include <react/jni/ReadableNativeMap.h>
|
||||
|
||||
#include "JJSEngineInstance.h"
|
||||
#include "JJSTimerExecutor.h"
|
||||
#include "JJavaTimerManager.h"
|
||||
#include "JReactExceptionManager.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class JReactInstance : public jni::HybridClass<JReactInstance> {
|
||||
public:
|
||||
constexpr static auto kJavaDescriptor = "Lcom/facebook/venice/ReactInstance;";
|
||||
|
||||
static jni::local_ref<jhybriddata> initHybrid(
|
||||
jni::alias_ref<jhybridobject>,
|
||||
jni::alias_ref<JJSEngineInstance::javaobject> jsEngineInstance,
|
||||
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
|
||||
jni::alias_ref<JavaMessageQueueThread::javaobject>
|
||||
nativeMessageQueueThread,
|
||||
jni::alias_ref<JJavaTimerManager::javaobject> javaTimerManager,
|
||||
jni::alias_ref<JJSTimerExecutor::javaobject> jsTimerExecutor,
|
||||
jni::alias_ref<JReactExceptionManager::javaobject> jReactExceptionManager,
|
||||
bool isProfiling);
|
||||
|
||||
/*
|
||||
* Instantiates and returns an instance of `JSTimerExecutor`.
|
||||
*/
|
||||
static jni::global_ref<JJSTimerExecutor::javaobject> createJSTimerExecutor(
|
||||
jni::alias_ref<jhybridobject> /* unused */);
|
||||
|
||||
static void registerNatives();
|
||||
|
||||
void loadJSBundleFromAssets(
|
||||
jni::alias_ref<JAssetManager::javaobject> assetManager,
|
||||
const std::string &assetURL);
|
||||
|
||||
void loadJSBundleFromFile(
|
||||
const std::string &fileName,
|
||||
const std::string &sourceURL);
|
||||
|
||||
void callFunctionOnModule(
|
||||
const std::string &moduleName,
|
||||
const std::string &methodName,
|
||||
NativeArray *args);
|
||||
|
||||
jni::alias_ref<JRuntimeExecutor::javaobject>
|
||||
getUnbufferedRuntimeExecutor() noexcept;
|
||||
jni::alias_ref<JRuntimeExecutor::javaobject>
|
||||
getBufferedRuntimeExecutor() noexcept;
|
||||
jni::alias_ref<JRuntimeScheduler::javaobject> getRuntimeScheduler() noexcept;
|
||||
|
||||
void registerSegment(int segmentId, const std::string &segmentPath) noexcept;
|
||||
|
||||
void handleMemoryPressureJs(jint level);
|
||||
|
||||
private:
|
||||
friend HybridBase;
|
||||
|
||||
explicit JReactInstance(
|
||||
jni::alias_ref<JJSEngineInstance::javaobject> jsEngineInstance,
|
||||
jni::alias_ref<JavaMessageQueueThread::javaobject> jsMessageQueueThread,
|
||||
jni::alias_ref<JavaMessageQueueThread::javaobject>
|
||||
nativeMessageQueueThread,
|
||||
jni::alias_ref<JJavaTimerManager::javaobject> javaTimerManager,
|
||||
jni::alias_ref<JJSTimerExecutor::javaobject> jsTimerExecutor,
|
||||
jni::alias_ref<JReactExceptionManager::javaobject> jReactExceptionManager,
|
||||
bool isProfiling) noexcept;
|
||||
|
||||
jni::alias_ref<CallInvokerHolder::javaobject> getJSCallInvokerHolder();
|
||||
jni::alias_ref<CallInvokerHolder::javaobject> getNativeCallInvokerHolder();
|
||||
|
||||
std::unique_ptr<ReactInstance> instance_;
|
||||
jni::global_ref<JRuntimeExecutor::javaobject> unbufferedRuntimeExecutor_;
|
||||
jni::global_ref<JRuntimeExecutor::javaobject> bufferedRuntimeExecutor_;
|
||||
jni::global_ref<JRuntimeScheduler::javaobject> runtimeScheduler_;
|
||||
jni::global_ref<CallInvokerHolder::javaobject> jsCallInvokerHolder_;
|
||||
jni::global_ref<CallInvokerHolder::javaobject> nativeCallInvokerHolder_;
|
||||
jni::global_ref<JReactExceptionManager::javaobject> jReactExceptionManager_;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#include "JavaTimerRegistry.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
JavaTimerRegistry::JavaTimerRegistry(
|
||||
jni::global_ref<JJavaTimerManager::javaobject> javaTimerManager)
|
||||
: javaTimerManager_(javaTimerManager) {}
|
||||
|
||||
void JavaTimerRegistry::createTimer(uint32_t timerID, double delayMS) {
|
||||
javaTimerManager_->createTimer(timerID, delayMS, /* repeat */ false);
|
||||
}
|
||||
|
||||
void JavaTimerRegistry::createRecurringTimer(uint32_t timerID, double delayMS) {
|
||||
javaTimerManager_->createTimer(timerID, delayMS, /* repeat */ true);
|
||||
}
|
||||
|
||||
void JavaTimerRegistry::deleteTimer(uint32_t timerID) {
|
||||
javaTimerManager_->deleteTimer(timerID);
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
#include <react/bridgeless/PlatformTimerRegistry.h>
|
||||
|
||||
#include "JJavaTimerManager.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
/**
|
||||
* Call into JavaTimerManager.java to schedule and delete timers
|
||||
* with the Platform.
|
||||
*/
|
||||
class JavaTimerRegistry : public PlatformTimerRegistry {
|
||||
public:
|
||||
JavaTimerRegistry(
|
||||
jni::global_ref<JJavaTimerManager::javaobject> javaTimerManager);
|
||||
|
||||
#pragma mark - PlatformTimerRegistry
|
||||
|
||||
void createTimer(uint32_t timerID, double delayMS) override;
|
||||
void createRecurringTimer(uint32_t timerID, double delayMS) override;
|
||||
void deleteTimer(uint32_t timerID) override;
|
||||
|
||||
private:
|
||||
jni::global_ref<JJavaTimerManager::javaobject> javaTimerManager_;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
@@ -0,0 +1,16 @@
|
||||
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
#include <fb/xplat_init.h>
|
||||
#include <react/jni/JReactMarker.h>
|
||||
|
||||
#include "JJSTimerExecutor.h"
|
||||
#include "JReactInstance.h"
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void * /*unused*/) {
|
||||
return facebook::xplat::initialize(vm, [] {
|
||||
facebook::react::JReactMarker::setLogPerfMarkerIfNeeded();
|
||||
facebook::react::JReactInstance::registerNatives();
|
||||
facebook::react::JJSTimerExecutor::registerNatives();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user