Skip to content

Commit 2abcd6c

Browse files
committed
chore: migrate to JSBigString from BigStringBuffer
1 parent 6a3e47e commit 2abcd6c

8 files changed

Lines changed: 29 additions & 22 deletions

File tree

packages/react-native/React/Base/RCTBundleProvider.h

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

88
#import <Foundation/Foundation.h>
9+
10+
#ifdef __cplusplus
911
#import <jsireact/JSIExecutor.h>
12+
#endif // __cplusplus
1013

1114
@class NSBundleWrapper;
1215

@@ -15,7 +18,11 @@
1518
*/
1619
@interface RCTBundleProvider : NSObject
1720

18-
- (std::shared_ptr<const facebook::react::BigStringBuffer>)getBundle;
21+
#ifdef __cplusplus
22+
23+
- (std::shared_ptr<const facebook::react::JSBigString>)getBundle;
1924
- (NSString *)getSourceURL;
2025

26+
#endif // __cplusplus
27+
2128
@end

packages/react-native/React/Base/RCTBundleProvider.mm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@
1010
using namespace facebook::react;
1111

1212
@implementation RCTBundleProvider{
13-
std::shared_ptr<const BigStringBuffer> _bundleBuffer;
13+
std::shared_ptr<const JSBigString> _bundle;
1414
NSString *_sourceURL;
1515
}
1616

17-
- (std::shared_ptr<const BigStringBuffer>)getBundle {
18-
return _bundleBuffer;
17+
- (std::shared_ptr<const JSBigString>)getBundle {
18+
return _bundle;
1919
}
2020

21-
- (void)setBundle:(std::shared_ptr<const BigStringBuffer>)bundle {
22-
_bundleBuffer = bundle;
21+
- (void)setBundle:(std::shared_ptr<const JSBigString>)bundle {
22+
_bundle = bundle;
2323
}
2424

2525
- (NSString *)getSourceURL {

packages/react-native/ReactAndroid/src/main/jni/react/fabric/BundleWrapper.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ jni::local_ref<BundleWrapper::jhybriddata> BundleWrapper::initHybridFromFile(
1818
std::unique_ptr<const JSBigFileString> script;
1919
RecoverableError::runRethrowingAsRecoverable<std::system_error>(
2020
[&fileName, &script]() { script = JSBigFileString::fromPath(fileName); });
21-
auto bundle = std::make_shared<BigStringBuffer>(std::move(script));
22-
return makeCxxInstance(bundle);
21+
return makeCxxInstance(std::move(script));
2322
}
2423

2524
jni::local_ref<BundleWrapper::jhybriddata> BundleWrapper::initHybridFromAssets(
@@ -28,15 +27,14 @@ jni::local_ref<BundleWrapper::jhybriddata> BundleWrapper::initHybridFromAssets(
2827
const std::string& sourceURL) {
2928
auto manager = extractAssetManager(assetManager);
3029
auto script = loadScriptFromAssets(manager, sourceURL);
31-
auto bundle = std::make_shared<BigStringBuffer>(std::move(script));
32-
return makeCxxInstance(bundle);
30+
return makeCxxInstance(std::move(script));
3331
}
3432

3533
BundleWrapper::BundleWrapper(
36-
const std::shared_ptr<const BigStringBuffer>& bundle)
34+
const std::shared_ptr<const JSBigString>& bundle)
3735
: bundle_(bundle) {}
3836

39-
const std::shared_ptr<const BigStringBuffer> BundleWrapper::getBundle() const {
37+
std::shared_ptr<const JSBigString> BundleWrapper::getBundle() const {
4038
return bundle_;
4139
}
4240

packages/react-native/ReactAndroid/src/main/jni/react/fabric/BundleWrapper.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class BundleWrapper : public jni::HybridClass<BundleWrapper> {
2323

2424
static void registerNatives();
2525

26-
[[nodiscard]] const std::shared_ptr<const BigStringBuffer> getBundle() const;
26+
[[nodiscard]] std::shared_ptr<const JSBigString> getBundle() const;
2727

2828
private:
2929
static jni::local_ref<BundleWrapper::jhybriddata> initHybridFromFile(
@@ -37,9 +37,9 @@ class BundleWrapper : public jni::HybridClass<BundleWrapper> {
3737

3838
friend HybridBase;
3939

40-
explicit BundleWrapper(const std::shared_ptr<const BigStringBuffer>& bundle);
40+
explicit BundleWrapper(const std::shared_ptr<const JSBigString>& bundle);
4141

42-
const std::shared_ptr<const BigStringBuffer> bundle_;
42+
const std::shared_ptr<const JSBigString> bundle_;
4343
};
4444

4545
} // namespace facebook::react

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ std::string simpleBasename(const std::string& path) {
228228
* JSThread, preferably via the runtimeExecutor_.
229229
*/
230230
void ReactInstance::loadScript(
231-
const std::shared_ptr<const BigStringBuffer>& script,
231+
const std::shared_ptr<const JSBigString>& script,
232232
const std::string& sourceURL,
233233
std::function<void(jsi::Runtime& runtime)>&& beforeLoad,
234234
std::function<void(jsi::Runtime& runtime)>&& afterLoad) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class ReactInstance final : private jsinspector_modern::InstanceTargetDelegate {
5050
void initializeRuntime(JSRuntimeFlags options, BindingsInstallFunc bindingsInstallFunc) noexcept;
5151

5252
void loadScript(
53-
const std::shared_ptr<const BigStringBuffer>& script,
53+
const std::shared_ptr<const JSBigString>& script,
5454
const std::string& sourceURL,
5555
std::function<void(jsi::Runtime& runtime)>&& beforeLoad = nullptr,
5656
std::function<void(jsi::Runtime& runtime)>&& afterLoad = nullptr);

packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ RCT_EXTERN void RCTInstanceSetRuntimeDiagnosticFlags(NSString *_Nullable flags);
7979
- (instancetype)initWithDelegate:(id<RCTInstanceDelegate>)delegate
8080
jsRuntimeFactory:(std::shared_ptr<facebook::react::JSRuntimeFactory>)jsRuntimeFactory
8181
bundleManager:(RCTBundleManager *)bundleManager
82+
bundleProvider:(RCTBundleProvider *)bundleProvider
8283
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)turboModuleManagerDelegate
8384
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
8485
parentInspectorTarget:(facebook::react::jsinspector_modern::HostTarget *)parentInspectorTarget

packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags)
7373
}
7474

7575
@interface RCTBundleProvider : NSObject
76-
- (void)setBundle:(std::shared_ptr<const BigStringBuffer>)bundleBuffer;
76+
- (void)setBundle:(std::shared_ptr<const JSBigString>)bundleBuffer;
7777
- (void)setSourceURL:(NSString *)sourceURL;
7878
@end
7979

@@ -146,6 +146,7 @@ - (instancetype)initWithDelegate:(id<RCTInstanceDelegate>)delegate
146146
return [self initWithDelegate:delegate
147147
jsRuntimeFactory:jsRuntimeFactory
148148
bundleManager:bundleManager
149+
bundleProvider:bundleProvider
149150
turboModuleManagerDelegate:tmmDelegate
150151
moduleRegistry:moduleRegistry
151152
parentInspectorTarget:parentInspectorTarget
@@ -156,6 +157,7 @@ - (instancetype)initWithDelegate:(id<RCTInstanceDelegate>)delegate
156157
- (instancetype)initWithDelegate:(id<RCTInstanceDelegate>)delegate
157158
jsRuntimeFactory:(std::shared_ptr<facebook::react::JSRuntimeFactory>)jsRuntimeFactory
158159
bundleManager:(RCTBundleManager *)bundleManager
160+
bundleProvider:(RCTBundleProvider *)bundleProvider
159161
turboModuleManagerDelegate:(id<RCTTurboModuleManagerDelegate>)tmmDelegate
160162
moduleRegistry:(RCTModuleRegistry *)moduleRegistry
161163
parentInspectorTarget:(jsinspector_modern::HostTarget *)parentInspectorTarget
@@ -610,11 +612,10 @@ - (void)_loadScriptFromSource:(RCTSource *)source
610612
return;
611613
}
612614

613-
auto script = std::make_unique<NSDataBigString>(source.data);
614-
const auto scriptBuffer = std::make_shared<const BigStringBuffer>(std::move(script));
615+
auto script = std::make_shared<NSDataBigString>(source.data);
615616
const auto *url = deriveSourceURL(source.url).UTF8String;
616617

617-
[_bundleProvider setBundle:scriptBuffer];
618+
[_bundleProvider setBundle:script];
618619
[_bundleProvider setSourceURL:@(url)];
619620

620621
auto beforeLoad = [waitUntilModuleSetupComplete = self->_waitUntilModuleSetupComplete](jsi::Runtime &_) {
@@ -625,7 +626,7 @@ - (void)_loadScriptFromSource:(RCTSource *)source
625626
auto afterLoad = [](jsi::Runtime &_) {
626627
[[NSNotificationCenter defaultCenter] postNotificationName:@"RCTInstanceDidLoadBundle" object:nil];
627628
};
628-
_reactInstance->loadScript(scriptBuffer, url, beforeLoad, afterLoad);
629+
_reactInstance->loadScript(script, url, beforeLoad, afterLoad);
629630
}
630631

631632
- (void)_handleJSError:(const JsErrorHandler::ProcessedError &)error withRuntime:(jsi::Runtime &)runtime

0 commit comments

Comments
 (0)