Skip to content

Commit d838489

Browse files
javachefacebook-github-bot
authored andcommitted
Move common JSI binding utils to jsitooling (#54406)
Summary: Refactor some dependencies to avoid pulling in `jsireact` (which is deprecated) in new environments which are binary-size constrained. Changelog: [Internal] Differential Revision: D86200983
1 parent 1033dbd commit d838489

File tree

15 files changed

+103
-68
lines changed

15 files changed

+103
-68
lines changed

packages/react-native/Package.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,20 @@ let reactCxxReact = RNTarget(
199199
searchPaths: [CallInvokerPath],
200200
excludedPaths: ["tests"],
201201
dependencies: [.reactNativeDependencies, .jsi, .reactPerfLogger, .logger, .reactDebug, .reactJsInspector]
202+
)
202203

204+
/// React-jsitooling.podspec
205+
let reactJsiTooling = RNTarget(
206+
name: .reactJsiTooling,
207+
path: "ReactCommon/jsitooling",
208+
dependencies: [.reactNativeDependencies, .jsi, .reactJsInspector, .reactJsInspectorTracing, .reactCxxReact, .reactJsiTooling]
203209
)
204210

205211
/// React-jsiexecutor.podspec
206212
let reactJsiExecutor = RNTarget(
207213
name: .reactJsiExecutor,
208214
path: "ReactCommon/jsiexecutor",
209-
dependencies: [.reactNativeDependencies, .jsi, .reactPerfLogger, .reactCxxReact, .reactJsInspector]
210-
)
211-
212-
/// React-jsitooling.podspec
213-
let reactJsiTooling = RNTarget(
214-
name: .reactJsiTooling,
215-
path: "ReactCommon/jsitooling",
216-
dependencies: [.reactNativeDependencies, .reactJsInspector, .reactJsInspectorTracing, .reactCxxReact, .jsi, .reactRuntimeExecutor]
215+
dependencies: [.reactNativeDependencies, .jsi, .reactCxxReact]
217216
)
218217

219218
/// React-hermes.podspec

packages/react-native/ReactAndroid/src/main/jni/react/runtime/jni/JReactInstance.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
#include <glog/logging.h>
1414
#include <jni.h>
1515
#include <jsi/jsi.h>
16-
#include <jsireact/JSIExecutor.h>
1716
#include <react/jni/JRuntimeExecutor.h>
1817
#include <react/jni/JSLogging.h>
1918
#include <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
2019
#include <react/runtime/BridgelessNativeMethodCallInvoker.h>
20+
#include <react/runtime/JSRuntimeBindings.h>
21+
2122
#include "JavaTimerRegistry.h"
2223

2324
namespace facebook::react {

packages/react-native/ReactCommon/cxxreact/ReactMarker.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77

88
#include "ReactMarker.h"
9-
#include <cxxreact/JSExecutor.h>
109

1110
namespace facebook::react::ReactMarker {
1211

packages/react-native/ReactCommon/jsiexecutor/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ target_link_libraries(jsireact
2020
reactperflogger
2121
folly_runtime
2222
glog
23-
jsi)
23+
jserrorhandler
24+
jsi
25+
jsitooling)
2426

2527
target_compile_reactnative_options(jsireact PRIVATE)
2628
target_compile_options(jsireact PRIVATE -O3)

packages/react-native/ReactCommon/jsiexecutor/React-jsiexecutor.podspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ Pod::Spec.new do |s|
3030
s.header_dir = "jsireact"
3131

3232
s.dependency "React-cxxreact"
33+
s.dependency "React-jserrorhandler"
3334
s.dependency "React-jsi"
35+
s.dependency "React-jsitooling"
3436
s.dependency "React-perflogger"
3537
add_dependency(s, "React-debug")
3638
add_dependency(s, "React-runtimeexecutor", :additional_framework_paths => ["platform/ios"])

packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -576,44 +576,4 @@ void JSIExecutor::flush() {}
576576

577577
#endif // RCT_REMOVE_LEGACY_ARCH
578578

579-
void bindNativeLogger(Runtime& runtime, Logger logger) {
580-
runtime.global().setProperty(
581-
runtime,
582-
"nativeLoggingHook",
583-
Function::createFromHostFunction(
584-
runtime,
585-
PropNameID::forAscii(runtime, "nativeLoggingHook"),
586-
2,
587-
[logger = std::move(logger)](
588-
jsi::Runtime& runtime,
589-
const jsi::Value&,
590-
const jsi::Value* args,
591-
size_t count) {
592-
if (count != 2) {
593-
throw std::invalid_argument(
594-
"nativeLoggingHook takes 2 arguments");
595-
}
596-
logger(
597-
args[0].asString(runtime).utf8(runtime),
598-
static_cast<unsigned int>(args[1].asNumber()));
599-
return Value::undefined();
600-
}));
601-
}
602-
603-
void bindNativePerformanceNow(Runtime& runtime) {
604-
runtime.global().setProperty(
605-
runtime,
606-
"nativePerformanceNow",
607-
Function::createFromHostFunction(
608-
runtime,
609-
PropNameID::forAscii(runtime, "nativePerformanceNow"),
610-
0,
611-
[](jsi::Runtime& runtime,
612-
const jsi::Value&,
613-
const jsi::Value* args,
614-
size_t /*count*/) {
615-
return HighResTimeStamp::now().toDOMHighResTimeStamp();
616-
}));
617-
}
618-
619579
} // namespace facebook::react

packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <cxxreact/RAMBundleRegistry.h>
1313
#include <jsi/jsi.h>
1414
#include <jsireact/JSINativeModules.h>
15+
#include <react/runtime/JSRuntimeBindings.h>
1516
#include <functional>
1617
#include <mutex>
1718
#include <optional>
@@ -127,10 +128,4 @@ class [[deprecated("This API will be removed along with the legacy architecture.
127128
#endif // RCT_REMOVE_LEGACY_ARCH
128129
};
129130

130-
using Logger = std::function<void(const std::string &message, unsigned int logLevel)>;
131-
void bindNativeLogger(jsi::Runtime &runtime, Logger logger);
132-
133-
void bindNativePerformanceNow(jsi::Runtime &runtime);
134-
135-
double performanceNow();
136131
} // namespace facebook::react

packages/react-native/ReactCommon/jsinspector-modern/tests/ReactInstanceIntegrationTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <glog/logging.h>
1515
#include <jsinspector-modern/InspectorFlags.h>
1616
#include <react/featureflags/ReactNativeFeatureFlags.h>
17+
#include <react/runtime/JSRuntimeBindings.h>
1718
#include <react/runtime/hermes/HermesInstance.h>
1819

1920
using namespace ::testing;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "JSRuntimeBindings.h"
9+
10+
#include <react/timing/primitives.h>
11+
12+
namespace facebook::react {
13+
14+
void bindNativeLogger(jsi::Runtime& runtime, Logger logger) {
15+
runtime.global().setProperty(
16+
runtime,
17+
"nativeLoggingHook",
18+
jsi::Function::createFromHostFunction(
19+
runtime,
20+
jsi::PropNameID::forAscii(runtime, "nativeLoggingHook"),
21+
2,
22+
[logger = std::move(logger)](
23+
jsi::Runtime& runtime,
24+
const jsi::Value& /* this */,
25+
const jsi::Value* args,
26+
size_t count) {
27+
if (count != 2) {
28+
throw std::invalid_argument(
29+
"nativeLoggingHook takes 2 arguments");
30+
}
31+
logger(
32+
args[0].asString(runtime).utf8(runtime),
33+
static_cast<unsigned int>(args[1].asNumber()));
34+
return jsi::Value::undefined();
35+
}));
36+
}
37+
38+
void bindNativePerformanceNow(jsi::Runtime& runtime) {
39+
runtime.global().setProperty(
40+
runtime,
41+
"nativePerformanceNow",
42+
jsi::Function::createFromHostFunction(
43+
runtime,
44+
jsi::PropNameID::forAscii(runtime, "nativePerformanceNow"),
45+
0,
46+
[](jsi::Runtime& /* runtime */,
47+
const jsi::Value& /* this */,
48+
const jsi::Value* /* args */,
49+
size_t /*count*/) {
50+
return HighResTimeStamp::now().toDOMHighResTimeStamp();
51+
}));
52+
}
53+
54+
} // namespace facebook::react
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <jsi/jsi.h>
11+
#include <string>
12+
13+
namespace facebook::react {
14+
15+
using Logger = std::function<void(const std::string &message, unsigned int logLevel)>;
16+
void bindNativeLogger(jsi::Runtime &runtime, Logger logger);
17+
18+
void bindNativePerformanceNow(jsi::Runtime &runtime);
19+
20+
} // namespace facebook::react

0 commit comments

Comments
 (0)