mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor JSIExecutor to use runtimeInstaller for injecting the logger instance
Summary: This is based on the work done in D8686586. Removed the logger instance from JSIExecutor constructor and installed it into the runtimeInstaller at all call sites. Reviewed By: mhorowitz Differential Revision: D14444120 fbshipit-source-id: 0476fda4230c467573ea04102a12101bcdf36c53
This commit is contained in:
committed by
Facebook Github Bot
parent
9db347fabc
commit
64f3a87c9d
@@ -1,15 +1,15 @@
|
||||
// Copyright (c) Facebook, Inc. and its affiliates.
|
||||
//
|
||||
// This source code is licensed under the MIT license found in the
|
||||
// LICENSE file in the root directory of this source tree.
|
||||
// LICENSE file in the root directory of this source tree.
|
||||
|
||||
#include <fb/fbjni.h>
|
||||
#include <folly/Memory.h>
|
||||
#include <jsi/JSCRuntime.h>
|
||||
#include <jsireact/JSIExecutor.h>
|
||||
#include <react/jni/JavaScriptExecutorHolder.h>
|
||||
#include <react/jni/JReactMarker.h>
|
||||
#include <react/jni/JSLogging.h>
|
||||
#include <react/jni/JavaScriptExecutorHolder.h>
|
||||
#include <react/jni/ReadableNativeMap.h>
|
||||
|
||||
namespace facebook {
|
||||
@@ -18,32 +18,37 @@ namespace react {
|
||||
namespace {
|
||||
|
||||
class JSCExecutorFactory : public JSExecutorFactory {
|
||||
public:
|
||||
public:
|
||||
std::unique_ptr<JSExecutor> createJSExecutor(
|
||||
std::shared_ptr<ExecutorDelegate> delegate,
|
||||
std::shared_ptr<MessageQueueThread> jsQueue) override {
|
||||
auto installBindings = [](jsi::Runtime &runtime) {
|
||||
react::Logger androidLogger =
|
||||
static_cast<void (*)(const std::string &, unsigned int)>(
|
||||
&reactAndroidLoggingHook);
|
||||
react::bindNativeLogger(runtime, androidLogger);
|
||||
};
|
||||
return folly::make_unique<JSIExecutor>(
|
||||
jsc::makeJSCRuntime(),
|
||||
delegate,
|
||||
[](const std::string& message, unsigned int logLevel) {
|
||||
reactAndroidLoggingHook(message, logLevel);
|
||||
},
|
||||
JSIExecutor::defaultTimeoutInvoker,
|
||||
nullptr);
|
||||
jsc::makeJSCRuntime(),
|
||||
delegate,
|
||||
JSIExecutor::defaultTimeoutInvoker,
|
||||
installBindings);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// This is not like JSCJavaScriptExecutor, which calls JSC directly. This uses
|
||||
// JSIExecutor with JSCRuntime.
|
||||
class JSCExecutorHolder
|
||||
: public jni::HybridClass<JSCExecutorHolder, JavaScriptExecutorHolder> {
|
||||
public:
|
||||
static constexpr auto kJavaDescriptor = "Lcom/facebook/react/jscexecutor/JSCExecutor;";
|
||||
static constexpr auto kJavaDescriptor =
|
||||
"Lcom/facebook/react/jscexecutor/JSCExecutor;";
|
||||
|
||||
static jni::local_ref<jhybriddata> initHybrid(
|
||||
jni::alias_ref<jclass>, ReadableNativeMap*) {
|
||||
jni::alias_ref<jclass>,
|
||||
ReadableNativeMap *) {
|
||||
// This is kind of a weird place for stuff, but there's no other
|
||||
// good place for initialization which is specific to JSC on
|
||||
// Android.
|
||||
@@ -54,7 +59,7 @@ class JSCExecutorHolder
|
||||
|
||||
static void registerNatives() {
|
||||
registerHybrid({
|
||||
makeNativeMethod("initHybrid", JSCExecutorHolder::initHybrid),
|
||||
makeNativeMethod("initHybrid", JSCExecutorHolder::initHybrid),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -66,8 +71,7 @@ class JSCExecutorHolder
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
return facebook::jni::initialize(vm, [] {
|
||||
facebook::react::JSCExecutorHolder::registerNatives();
|
||||
});
|
||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
|
||||
return facebook::jni::initialize(
|
||||
vm, [] { facebook::react::JSCExecutorHolder::registerNatives(); });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user