Skip to content

Commit 196ca80

Browse files
javachefacebook-github-bot
authored andcommitted
Move common JSI binding utils to jsitooling (facebook#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 8123f31 commit 196ca80

File tree

12 files changed

+91
-59
lines changed

12 files changed

+91
-59
lines changed

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/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

packages/react-native/ReactCommon/react/renderer/core/EventDispatcher.cpp

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

88
#include "EventDispatcher.h"
9-
#include <cxxreact/JSExecutor.h>
9+
1010
#include <react/renderer/core/StateUpdate.h>
1111

1212
#include "EventQueue.h"

packages/react-native/ReactCommon/react/renderer/core/EventQueueProcessor.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#include <cxxreact/JSExecutor.h>
8+
#include "EventQueueProcessor.h"
9+
910
#include <logger/react_native_log.h>
1011
#include <react/featureflags/ReactNativeFeatureFlags.h>
12+
1113
#include "EventEmitter.h"
1214
#include "EventLogger.h"
13-
#include "EventQueue.h"
14-
#include "ShadowNodeFamily.h"
1515

1616
namespace facebook::react {
1717

packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
#include <jsi/hermes.h>
1919
#include <jsi/instrumentation.h>
2020
#include <jsinspector-modern/HostTarget.h>
21-
#include <jsireact/JSIExecutor.h>
2221
#include <react/featureflags/ReactNativeFeatureFlags.h>
2322
#include <react/renderer/core/ShadowNode.h>
2423
#include <react/renderer/runtimescheduler/RuntimeSchedulerBinding.h>
24+
#include <react/runtime/JSRuntimeBindings.h>
2525
#include <react/timing/primitives.h>
2626
#include <react/utils/jsi-utils.h>
2727
#include <iostream>
@@ -48,6 +48,12 @@ std::shared_ptr<RuntimeScheduler> createRuntimeScheduler(
4848
return scheduler;
4949
}
5050

51+
std::string getSyntheticBundlePath(uint32_t bundleId) {
52+
std::array<char, 32> buffer{};
53+
std::snprintf(buffer.data(), buffer.size(), "seg-%u.js", bundleId);
54+
return buffer.data();
55+
}
56+
5157
} // namespace
5258

5359
ReactInstance::ReactInstance(
@@ -365,12 +371,8 @@ void ReactInstance::registerSegment(
365371
}
366372
LOG(WARNING) << "Starting to evaluate segment " << segmentId
367373
<< " in ReactInstance::registerSegment";
368-
#pragma clang diagnostic push
369-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
370374
runtime.evaluateJavaScript(
371-
std::move(script),
372-
JSExecutor::getSyntheticBundlePath(segmentId, segmentPath));
373-
#pragma clang diagnostic pop
375+
std::move(script), getSyntheticBundlePath(segmentId));
374376
LOG(WARNING) << "Finished evaluating segment " << segmentId
375377
<< " in ReactInstance::registerSegment";
376378
if (hasLogger) {

0 commit comments

Comments
 (0)