react-native-windows 0.82.1 → 0.83.0-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.flowconfig +2 -7
- package/Libraries/Animated/components/AnimatedFlatList.js +5 -3
- package/Libraries/Animated/components/AnimatedImage.js +4 -3
- package/Libraries/Animated/components/AnimatedSectionList.js +2 -2
- package/Libraries/Animated/components/AnimatedText.js +7 -3
- package/Libraries/Animated/components/AnimatedView.js +3 -2
- package/Libraries/Animated/createAnimatedComponent.js +24 -12
- package/Libraries/Animated/nodes/AnimatedColor.js +26 -10
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +43 -15
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.windows.js +43 -15
- package/Libraries/Components/ActivityIndicator/ActivityIndicator.d.ts +2 -2
- package/Libraries/Components/DrawerAndroid/DrawerLayoutAndroid.d.ts +2 -2
- package/Libraries/Components/Glyph/Glyph.js +4 -1
- package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroid.d.ts +2 -2
- package/Libraries/Components/RefreshControl/RefreshControl.d.ts +3 -3
- package/Libraries/Components/SafeAreaView/SafeAreaView.d.ts +2 -2
- package/Libraries/Components/ScrollView/ScrollView.js +1 -0
- package/Libraries/Components/ScrollView/ScrollView.windows.js +1 -0
- package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +6 -6
- package/Libraries/Components/Switch/Switch.d.ts +2 -2
- package/Libraries/Components/Switch/Switch.windows.js +1 -1
- package/Libraries/Components/TextInput/TextInput.d.ts +2 -5
- package/Libraries/Components/TextInput/TextInput.js +6 -0
- package/Libraries/Components/TextInput/TextInput.windows.js +6 -0
- package/Libraries/Components/Touchable/TouchableBounce.js +7 -7
- package/Libraries/Components/Touchable/TouchableBounce.windows.js +7 -7
- package/Libraries/Components/Touchable/TouchableWithoutFeedback.windows.js +1 -1
- package/Libraries/Components/View/ReactNativeStyleAttributes.js +19 -1
- package/Libraries/Components/View/View.d.ts +2 -2
- package/Libraries/Components/View/View.windows.js +0 -1
- package/Libraries/Components/View/ViewNativeComponent.js +13 -1
- package/Libraries/Core/ReactNativeVersion.js +3 -3
- package/Libraries/Core/setUpPerformance.js +2 -0
- package/Libraries/Debugging/DebuggingOverlay.js +14 -14
- package/Libraries/Debugging/DebuggingOverlayRegistry.js +8 -2
- package/Libraries/EventEmitter/RCTDeviceEventEmitter.js +5 -2
- package/Libraries/Image/Image.d.ts +3 -3
- package/Libraries/Image/ImageInjection.js +3 -6
- package/Libraries/Image/ImageTypes.flow.js +3 -7
- package/Libraries/Lists/FlatList.js +8 -8
- package/Libraries/Lists/SectionList.d.ts +5 -1
- package/Libraries/Lists/ViewabilityHelper.js +1 -1
- package/Libraries/Lists/VirtualizedList.js +1 -0
- package/Libraries/LogBox/UI/AnsiHighlight.js +4 -1
- package/Libraries/NativeComponent/BaseViewConfig.android.js +11 -2
- package/Libraries/NativeComponent/NativeComponentRegistry.d.ts +98 -0
- package/Libraries/NativeComponent/NativeComponentRegistry.js +2 -0
- package/Libraries/NativeComponent/NativeComponentRegistryUnstable.js +3 -1
- package/Libraries/NativeComponent/ViewConfigIgnore.windows.js +45 -0
- package/Libraries/Network/RCTNetworking.android.js +3 -1
- package/Libraries/Network/RCTNetworking.ios.js +3 -0
- package/Libraries/Network/RCTNetworking.windows.js +3 -0
- package/Libraries/Network/XMLHttpRequest.js +1 -41
- package/Libraries/Pressability/usePressability.js +14 -3
- package/Libraries/ReactNative/PaperUIManager.windows.js +3 -3
- package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +20 -82
- package/Libraries/ReactNative/getNativeComponentAttributes.js +12 -0
- package/Libraries/Renderer/implementations/ReactFabric-dev.js +6759 -4478
- package/Libraries/Renderer/implementations/ReactFabric-prod.js +3169 -3119
- package/Libraries/Renderer/implementations/ReactFabric-profiling.js +4732 -3535
- package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +6646 -4070
- package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +3136 -2825
- package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +4761 -3312
- package/Libraries/Renderer/shims/ReactNative.js +3 -1
- package/Libraries/Renderer/shims/ReactNativeTypes.js +2 -1
- package/Libraries/Renderer/shims/ReactNativeTypes.windows.js +2 -1
- package/Libraries/StyleSheet/StyleSheetTypes.d.ts +1 -1
- package/Libraries/StyleSheet/StyleSheetTypes.js +44 -0
- package/Libraries/StyleSheet/processBackgroundPosition.js +284 -0
- package/Libraries/StyleSheet/processBackgroundRepeat.js +105 -0
- package/Libraries/StyleSheet/processBackgroundSize.js +104 -0
- package/Libraries/Text/Text.d.ts +2 -2
- package/Libraries/Text/TextNativeComponent.js +10 -0
- package/Libraries/TurboModule/TurboModuleRegistry.js +3 -9
- package/Libraries/Utilities/DevLoadingView.js +14 -6
- package/Libraries/Utilities/HMRClient.js +13 -5
- package/Microsoft.ReactNative/Base/CxxReactIncludes.h +11 -0
- package/Microsoft.ReactNative/CompositionComponentView.idl +2 -0
- package/Microsoft.ReactNative/CompositionHwndHost.idl +1 -0
- package/Microsoft.ReactNative/Fabric/ComponentView.cpp +1 -1
- package/Microsoft.ReactNative/Fabric/ComponentView.h +1 -1
- package/Microsoft.ReactNative/Fabric/Composition/CompositionHwndHost.cpp +10 -40
- package/Microsoft.ReactNative/Fabric/Composition/CompositionViewComponentView.cpp +3 -80
- package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.cpp +45 -12
- package/Microsoft.ReactNative/Fabric/Composition/ContentIslandComponentView.h +8 -0
- package/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp +61 -74
- package/Microsoft.ReactNative/Fabric/Composition/ParagraphComponentView.h +4 -0
- package/Microsoft.ReactNative/Fabric/Composition/ReactCompositionViewComponentBuilder.h +1 -0
- package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp +4 -3
- package/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.h +2 -1
- package/Microsoft.ReactNative/Fabric/Composition/ReactNativeWindow.cpp +245 -0
- package/Microsoft.ReactNative/Fabric/Composition/ReactNativeWindow.h +80 -0
- package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentDescriptor.h +20 -36
- package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.cpp +70 -49
- package/Microsoft.ReactNative/Fabric/Composition/TextInput/WindowsTextInputComponentView.h +4 -1
- package/Microsoft.ReactNative/Fabric/Composition/UriImageManager.cpp +5 -0
- package/Microsoft.ReactNative/Fabric/platform/react/renderer/textlayoutmanager/WindowsTextLayoutManager.cpp +7 -2
- package/Microsoft.ReactNative/IReactCompositionViewComponentBuilder.idl +1 -0
- package/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +1 -1
- package/Microsoft.ReactNative/Modules/ImageViewManagerModule.cpp +1 -1
- package/Microsoft.ReactNative/Modules/LogBoxModule.cpp +20 -94
- package/Microsoft.ReactNative/Modules/LogBoxModule.h +1 -3
- package/Microsoft.ReactNative/Pch/pch.h +2 -0
- package/Microsoft.ReactNative/ReactHost/CrashManager.cpp +5 -0
- package/Microsoft.ReactNative/ReactHost/ReactNativeHeaders.h +1 -0
- package/Microsoft.ReactNative/ReactNativeAppBuilder.cpp +0 -41
- package/Microsoft.ReactNative/ReactNativeAppBuilder.idl +0 -11
- package/Microsoft.ReactNative/ReactNativeIsland.idl +2 -3
- package/Microsoft.ReactNative/ReactNativeWin32App.cpp +31 -101
- package/Microsoft.ReactNative/ReactNativeWin32App.h +2 -13
- package/Microsoft.ReactNative/ReactNativeWindow.idl +44 -0
- package/Microsoft.ReactNative.Cxx/AutoDraw.h +9 -1
- package/Microsoft.ReactNative.Cxx/ReactCommon/CallInvoker.h +13 -16
- package/Microsoft.ReactNative.Cxx/ReactCommon/TurboModule.h +24 -36
- package/Microsoft.ReactNative.Cxx/ReactCommon/TurboModuleUtils.h +5 -8
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/AString.h +8 -6
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Array.h +32 -49
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Base.h +27 -76
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Bool.h +4 -2
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/CallbackWrapper.h +19 -18
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Class.h +25 -48
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Convert.h +38 -31
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Error.h +11 -6
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/EventEmitter.h +47 -45
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Function.h +69 -89
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/HighResTimeStamp.h +8 -8
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/LongLivedObject.h +6 -6
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Number.h +16 -8
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Object.h +17 -24
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Promise.h +17 -17
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/bridging/Value.h +20 -29
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/debug/react_native_assert.h +2 -7
- package/Microsoft.ReactNative.Cxx/ReactCommon/react/timing/primitives.h +127 -115
- package/PropertySheets/External/Microsoft.ReactNative.Composition.CppLib.props +10 -0
- package/PropertySheets/External/Microsoft.ReactNative.Uwp.CppLib.props +10 -0
- package/PropertySheets/Generated/PackageVersion.g.props +5 -5
- package/PropertySheets/Warnings.props +2 -1
- package/ReactCommon/ReactCommon.vcxproj +21 -12
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/CxxNativeModule.cpp +2 -2
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/Instance.cpp +381 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +49 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSIndexedRAMBundle.cpp +145 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/MethodCall.cpp +100 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/ModuleRegistry.cpp +256 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/NativeToJsBridge.cpp +13 -4
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/RAMBundleRegistry.cpp +93 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/ReactMarker.cpp +149 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/TraceSection.h +25 -35
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsi/jsi/test/testlib.cpp +86 -67
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsiexecutor/jsireact/JSIExecutor.cpp +629 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsiexecutor/jsireact/JSINativeModules.cpp +123 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/NetworkIOAgent.cpp +84 -68
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/NetworkIOAgent.h +31 -35
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/Utf8.h +4 -5
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsinspector-modern/network/HttpUtils.cpp +2 -1
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/core/ReactCommon/TurboModule.h +24 -36
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/dom/NativeDOM.h +28 -66
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/nativemodule/webperformance/NativePerformance.cpp +414 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp +3 -3
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/image/conversions.h +8 -4
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/text/ParagraphShadowNode.cpp +19 -16
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/text/platform/android/react/renderer/components/text/ParagraphState.h +8 -9
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/AccessibilityPrimitives.h +25 -95
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/accessibilityPropsConversions.h +85 -42
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/EventDispatcher.cpp +81 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/EventQueueProcessor.cpp +140 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/imagemanager/primitives.h +25 -31
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/uimanager/UIManager.cpp +746 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +702 -0
- package/Scripts/Tfs/Layout-Desktop-Headers.ps1 +1 -15
- package/Scripts/creaternwapp.cmd +1 -1
- package/Scripts/perf/compare-results.js +357 -0
- package/Scripts/perf/create-perf-test.js +343 -0
- package/Scripts/perf/post-pr-comment.js +210 -0
- package/Shared/Hermes/HermesRuntimeTargetDelegate.cpp +8 -0
- package/Shared/Hermes/HermesRuntimeTargetDelegate.h +3 -0
- package/Shared/Shared.vcxitems +24 -12
- package/Shared/Shared.vcxitems.filters +11 -3
- package/codegen/NativeIntersectionObserverSpec.g.h +2 -0
- package/codegen/NativeNetworkingIOSSpec.g.h +2 -0
- package/codegen/NativePerformanceSpec.g.h +6 -0
- package/codegen/NativeReactNativeFeatureFlagsSpec.g.h +229 -139
- package/codegen/react/components/rnwcore/ActivityIndicatorView.g.h +2 -1
- package/codegen/react/components/rnwcore/AndroidDrawerLayout.g.h +42 -25
- package/codegen/react/components/rnwcore/AndroidHorizontalScrollContentView.g.h +2 -1
- package/codegen/react/components/rnwcore/AndroidProgressBar.g.h +2 -1
- package/codegen/react/components/rnwcore/AndroidSwipeRefreshLayout.g.h +11 -6
- package/codegen/react/components/rnwcore/AndroidSwitch.g.h +11 -6
- package/codegen/react/components/rnwcore/DebuggingOverlay.g.h +1 -0
- package/codegen/react/components/rnwcore/InputAccessory.g.h +2 -1
- package/codegen/react/components/rnwcore/ModalHostView.g.h +40 -23
- package/codegen/react/components/rnwcore/Props.cpp +6 -1
- package/codegen/react/components/rnwcore/Props.h +1 -0
- package/codegen/react/components/rnwcore/PullToRefreshView.g.h +11 -6
- package/codegen/react/components/rnwcore/SafeAreaView.g.h +1 -0
- package/codegen/react/components/rnwcore/Switch.g.h +11 -6
- package/codegen/react/components/rnwcore/UnimplementedNativeView.g.h +2 -1
- package/codegen/react/components/rnwcore/VirtualView.g.h +41 -8
- package/codegen/react/components/rnwcore/VirtualViewExperimental.g.h +45 -8
- package/codegen/rnwcoreJSI.h +3973 -6059
- package/index.js +6 -0
- package/index.windows.js +6 -0
- package/jest/mockComponent.js +6 -6
- package/jest/setup.js +15 -10
- package/package.json +27 -27
- package/src/private/components/virtualview/VirtualView.js +22 -27
- package/src/private/components/virtualview/VirtualViewExperimentalNativeComponent.js +6 -0
- package/src/private/featureflags/ReactNativeFeatureFlags.js +100 -19
- package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +18 -3
- package/src/private/setup/setUpDefaultReactNativeEnvironment.js +6 -0
- package/src/private/specs_DEPRECATED/components/SwitchNativeComponent.js +1 -1
- package/src/private/specs_DEPRECATED/modules/NativeNetworkingIOS.js +1 -0
- package/src/private/webapis/dom/nodes/ReactNativeElement.js +12 -2
- package/src/private/webapis/intersectionobserver/IntersectionObserver.js +76 -15
- package/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js +1 -0
- package/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +1 -0
- package/src/private/webapis/performance/ResourceTiming.js +31 -4
- package/src/private/webapis/performance/internals/RawPerformanceEntry.js +4 -1
- package/src/private/webapis/performance/specs/NativePerformance.js +3 -0
- package/stubs/double-conversion/double-conversion.h +5 -0
- package/templates/cpp-app/template.config.js +1 -1
- package/templates/cpp-app/windows/MyApp/MyApp.vcxproj +3 -1
- package/templates/cpp-lib/template.config.js +1 -1
- package/templates/cpp-lib/windows/MyLib/MyLib.vcxproj +1 -1
- package/types/index.d.ts +1 -0
- package/types/public/ReactNativeTypes.d.ts +115 -2
- package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +0 -152
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/components/view/conversions.h +0 -1574
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/ShadowNode.cpp +0 -528
- package/Scripts/OpenSSL.nuspec +0 -39
- package/Scripts/OpenSSL.targets +0 -36
- package/codegen/rnwcoreJSI-generated.cpp +0 -3470
|
@@ -0,0 +1,381 @@
|
|
|
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
|
+
|
|
9
|
+
#if _MSC_VER
|
|
10
|
+
#pragma warning(push)
|
|
11
|
+
#pragma warning(disable : 4996) // deprecated APIs
|
|
12
|
+
#endif
|
|
13
|
+
#include "Instance.h"
|
|
14
|
+
|
|
15
|
+
#ifndef RCT_REMOVE_LEGACY_ARCH
|
|
16
|
+
|
|
17
|
+
#include "ErrorUtils.h"
|
|
18
|
+
#include "JSBigString.h"
|
|
19
|
+
#include "JSBundleType.h"
|
|
20
|
+
#include "JSExecutor.h"
|
|
21
|
+
#include "MessageQueueThread.h"
|
|
22
|
+
#include "MethodCall.h"
|
|
23
|
+
#include "NativeToJsBridge.h"
|
|
24
|
+
#include "RAMBundleRegistry.h"
|
|
25
|
+
#include "RecoverableError.h"
|
|
26
|
+
#include "TraceSection.h"
|
|
27
|
+
|
|
28
|
+
#include <cxxreact/JSIndexedRAMBundle.h>
|
|
29
|
+
#include <folly/json.h>
|
|
30
|
+
#include <react/debug/react_native_assert.h>
|
|
31
|
+
|
|
32
|
+
#include <glog/logging.h>
|
|
33
|
+
|
|
34
|
+
#include <condition_variable>
|
|
35
|
+
#include <exception>
|
|
36
|
+
#include <memory>
|
|
37
|
+
#include <mutex>
|
|
38
|
+
#include <string>
|
|
39
|
+
|
|
40
|
+
namespace facebook::react {
|
|
41
|
+
|
|
42
|
+
Instance::~Instance() {
|
|
43
|
+
if (nativeToJsBridge_) {
|
|
44
|
+
nativeToJsBridge_->destroy();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
void Instance::unregisterFromInspector() {
|
|
49
|
+
if (inspectorTarget_ != nullptr) {
|
|
50
|
+
assert(runtimeInspectorTarget_);
|
|
51
|
+
inspectorTarget_->unregisterRuntime(*runtimeInspectorTarget_);
|
|
52
|
+
assert(parentInspectorTarget_);
|
|
53
|
+
parentInspectorTarget_->unregisterInstance(*inspectorTarget_);
|
|
54
|
+
parentInspectorTarget_ = nullptr;
|
|
55
|
+
inspectorTarget_ = nullptr;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
void Instance::initializeBridge(
|
|
60
|
+
std::unique_ptr<InstanceCallback> callback,
|
|
61
|
+
std::shared_ptr<JSExecutorFactory> jsef,
|
|
62
|
+
std::shared_ptr<MessageQueueThread> jsQueue,
|
|
63
|
+
std::shared_ptr<ModuleRegistry> moduleRegistry,
|
|
64
|
+
jsinspector_modern::HostTarget* parentInspectorTarget) {
|
|
65
|
+
callback_ = std::move(callback);
|
|
66
|
+
moduleRegistry_ = std::move(moduleRegistry);
|
|
67
|
+
parentInspectorTarget_ = parentInspectorTarget;
|
|
68
|
+
|
|
69
|
+
jsQueue->runOnQueueSync([this, &jsef, jsQueue]() mutable {
|
|
70
|
+
nativeToJsBridge_ = std::make_shared<NativeToJsBridge>(
|
|
71
|
+
jsef.get(), moduleRegistry_, jsQueue, callback_);
|
|
72
|
+
|
|
73
|
+
// If a parent inspector HostTarget is provided, perform inspector
|
|
74
|
+
// initialization synchronously.
|
|
75
|
+
if (parentInspectorTarget_ != nullptr) {
|
|
76
|
+
auto inspectorExecutor = parentInspectorTarget_->executorFromThis();
|
|
77
|
+
std::mutex inspectorInitializedMutex;
|
|
78
|
+
std::condition_variable inspectorInitializedCv;
|
|
79
|
+
bool inspectorInitialized = false;
|
|
80
|
+
|
|
81
|
+
// Schedule work on the inspector thread. NOTE: We expect this callback
|
|
82
|
+
// to always execute, given the invariant that `initializeBridge` (this
|
|
83
|
+
// method) completes before `unregisterFromInspector` is called.
|
|
84
|
+
// - On iOS, instance creation and invalidation both run on the main
|
|
85
|
+
// queue (`RCTCxxBridge::start,invalidate` use `RCTAssertMainQueue`).
|
|
86
|
+
// - On Android, `ReactContext` must be initialized with a constructed
|
|
87
|
+
// `CatalystInstance` (in which `Instance::initializeBridge` has
|
|
88
|
+
// completed) before `destroy` can be called.
|
|
89
|
+
inspectorExecutor([this,
|
|
90
|
+
&inspectorInitialized,
|
|
91
|
+
&inspectorInitializedMutex,
|
|
92
|
+
&inspectorInitializedCv](
|
|
93
|
+
jsinspector_modern::HostTarget& hostTarget) {
|
|
94
|
+
// NOTE: By passing *this, we strongly assume the Instance will still
|
|
95
|
+
// be alive by the time this executes.
|
|
96
|
+
// - On iOS, instance creation is done synchronously
|
|
97
|
+
// (`RCTCxxBridge::_initializeBridgeLocked`).
|
|
98
|
+
// - On Android, we explicitly wait for instance creation before
|
|
99
|
+
// destruction (`ReactInstanceManager::mReactContextLock`).
|
|
100
|
+
inspectorTarget_ = &hostTarget.registerInstance(*this);
|
|
101
|
+
RuntimeExecutor runtimeExecutorIfJsi = getRuntimeExecutor();
|
|
102
|
+
runtimeInspectorTarget_ = &inspectorTarget_->registerRuntime(
|
|
103
|
+
nativeToJsBridge_->getInspectorTargetDelegate(),
|
|
104
|
+
runtimeExecutorIfJsi ? runtimeExecutorIfJsi : [](auto) {});
|
|
105
|
+
|
|
106
|
+
// Signal that initialization is complete
|
|
107
|
+
{
|
|
108
|
+
std::lock_guard lock(inspectorInitializedMutex);
|
|
109
|
+
inspectorInitialized = true;
|
|
110
|
+
}
|
|
111
|
+
inspectorInitializedCv.notify_one();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Wait for the initialization work to complete
|
|
115
|
+
{
|
|
116
|
+
std::unique_lock lock(inspectorInitializedMutex);
|
|
117
|
+
inspectorInitializedCv.wait(
|
|
118
|
+
lock, [&inspectorInitialized] { return inspectorInitialized; });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Initialize the JavaScript runtime after we've initialized the inspector
|
|
123
|
+
nativeToJsBridge_->initializeRuntime();
|
|
124
|
+
|
|
125
|
+
// After NativeToJsBridge is created, the jsi::Runtime should exist. Also,
|
|
126
|
+
// the JS message queue thread exists. So, it's safe to schedule all queued
|
|
127
|
+
// up JS calls.
|
|
128
|
+
jsCallInvoker_->setNativeToJsBridgeAndFlushCalls(nativeToJsBridge_);
|
|
129
|
+
|
|
130
|
+
std::scoped_lock lock(m_syncMutex);
|
|
131
|
+
m_syncReady = true;
|
|
132
|
+
m_syncCV.notify_all();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
CHECK(nativeToJsBridge_);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
void Instance::loadBundle(
|
|
139
|
+
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
|
140
|
+
std::unique_ptr<const JSBigString> startupScript,
|
|
141
|
+
std::string sourceURL) {
|
|
142
|
+
callback_->incrementPendingJSCalls();
|
|
143
|
+
TraceSection s("Instance::loadBundle", "sourceURL", sourceURL);
|
|
144
|
+
nativeToJsBridge_->loadBundle(
|
|
145
|
+
std::move(bundleRegistry),
|
|
146
|
+
std::move(startupScript),
|
|
147
|
+
std::move(sourceURL));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
void Instance::loadBundleSync(
|
|
151
|
+
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
|
152
|
+
std::unique_ptr<const JSBigString> startupScript,
|
|
153
|
+
std::string sourceURL) {
|
|
154
|
+
std::unique_lock<std::mutex> lock(m_syncMutex);
|
|
155
|
+
m_syncCV.wait(lock, [this] { return m_syncReady; });
|
|
156
|
+
|
|
157
|
+
TraceSection s("Instance::loadBundleSync", "sourceURL", sourceURL);
|
|
158
|
+
nativeToJsBridge_->loadBundleSync(
|
|
159
|
+
std::move(bundleRegistry),
|
|
160
|
+
std::move(startupScript),
|
|
161
|
+
std::move(sourceURL));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
void Instance::setSourceURL(std::string sourceURL) {
|
|
165
|
+
callback_->incrementPendingJSCalls();
|
|
166
|
+
TraceSection s("Instance::setSourceURL", "sourceURL", sourceURL);
|
|
167
|
+
|
|
168
|
+
nativeToJsBridge_->loadBundle(nullptr, nullptr, std::move(sourceURL));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
void Instance::loadScriptFromString(
|
|
172
|
+
std::unique_ptr<const JSBigString> string,
|
|
173
|
+
std::string sourceURL,
|
|
174
|
+
bool loadSynchronously) {
|
|
175
|
+
TraceSection s("Instance::loadScriptFromString", "sourceURL", sourceURL);
|
|
176
|
+
if (loadSynchronously) {
|
|
177
|
+
loadBundleSync(nullptr, std::move(string), std::move(sourceURL));
|
|
178
|
+
} else {
|
|
179
|
+
loadBundle(nullptr, std::move(string), std::move(sourceURL));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
void Instance::loadRAMBundleFromString(
|
|
184
|
+
std::unique_ptr<const JSBigString> script,
|
|
185
|
+
const std::string& sourceURL) {
|
|
186
|
+
auto bundle = std::make_unique<JSIndexedRAMBundle>(std::move(script));
|
|
187
|
+
auto startupScript = bundle->getStartupCode();
|
|
188
|
+
auto registry = RAMBundleRegistry::singleBundleRegistry(std::move(bundle));
|
|
189
|
+
loadRAMBundle(std::move(registry), std::move(startupScript), sourceURL, true);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
void Instance::loadRAMBundleFromFile(
|
|
193
|
+
const std::string& sourcePath,
|
|
194
|
+
const std::string& sourceURL,
|
|
195
|
+
bool loadSynchronously) {
|
|
196
|
+
auto bundle = std::make_unique<JSIndexedRAMBundle>(sourcePath.c_str());
|
|
197
|
+
auto startupScript = bundle->getStartupCode();
|
|
198
|
+
auto registry = RAMBundleRegistry::multipleBundlesRegistry(
|
|
199
|
+
std::move(bundle), JSIndexedRAMBundle::buildFactory());
|
|
200
|
+
loadRAMBundle(
|
|
201
|
+
std::move(registry),
|
|
202
|
+
std::move(startupScript),
|
|
203
|
+
sourceURL,
|
|
204
|
+
loadSynchronously);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
void Instance::loadRAMBundle(
|
|
208
|
+
std::unique_ptr<RAMBundleRegistry> bundleRegistry,
|
|
209
|
+
std::unique_ptr<const JSBigString> startupScript,
|
|
210
|
+
std::string startupScriptSourceURL,
|
|
211
|
+
bool loadSynchronously) {
|
|
212
|
+
if (loadSynchronously) {
|
|
213
|
+
loadBundleSync(
|
|
214
|
+
std::move(bundleRegistry),
|
|
215
|
+
std::move(startupScript),
|
|
216
|
+
std::move(startupScriptSourceURL));
|
|
217
|
+
} else {
|
|
218
|
+
loadBundle(
|
|
219
|
+
std::move(bundleRegistry),
|
|
220
|
+
std::move(startupScript),
|
|
221
|
+
std::move(startupScriptSourceURL));
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
void Instance::setGlobalVariable(
|
|
226
|
+
std::string propName,
|
|
227
|
+
std::unique_ptr<const JSBigString> jsonValue) {
|
|
228
|
+
nativeToJsBridge_->setGlobalVariable(
|
|
229
|
+
std::move(propName), std::move(jsonValue));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
void* Instance::getJavaScriptContext() {
|
|
233
|
+
return nativeToJsBridge_ ? nativeToJsBridge_->getJavaScriptContext()
|
|
234
|
+
: nullptr;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
bool Instance::isInspectable() {
|
|
238
|
+
return nativeToJsBridge_ ? nativeToJsBridge_->isInspectable() : false;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
bool Instance::isBatchActive() {
|
|
242
|
+
return nativeToJsBridge_ ? nativeToJsBridge_->isBatchActive() : false;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
void Instance::callJSFunction(
|
|
246
|
+
std::string&& module,
|
|
247
|
+
std::string&& method,
|
|
248
|
+
folly::dynamic&& params) {
|
|
249
|
+
callback_->incrementPendingJSCalls();
|
|
250
|
+
nativeToJsBridge_->callFunction(
|
|
251
|
+
std::move(module), std::move(method), std::move(params));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
void Instance::callJSCallback(uint64_t callbackId, folly::dynamic&& params) {
|
|
255
|
+
TraceSection s("Instance::callJSCallback");
|
|
256
|
+
callback_->incrementPendingJSCalls();
|
|
257
|
+
nativeToJsBridge_->invokeCallback((double)callbackId, std::move(params));
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
void Instance::registerBundle(
|
|
261
|
+
uint32_t bundleId,
|
|
262
|
+
const std::string& bundlePath) {
|
|
263
|
+
nativeToJsBridge_->registerBundle(bundleId, bundlePath);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const ModuleRegistry& Instance::getModuleRegistry() const {
|
|
267
|
+
return *moduleRegistry_;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
ModuleRegistry& Instance::getModuleRegistry() {
|
|
271
|
+
return *moduleRegistry_;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
void Instance::handleMemoryPressure(int pressureLevel) {
|
|
275
|
+
if (nativeToJsBridge_) {
|
|
276
|
+
// This class resets `nativeToJsBridge_` only in the destructor,
|
|
277
|
+
// hence a race is not possible there.
|
|
278
|
+
nativeToJsBridge_->handleMemoryPressure(pressureLevel);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
std::shared_ptr<CallInvoker> Instance::getJSCallInvoker() {
|
|
283
|
+
return std::static_pointer_cast<CallInvoker>(jsCallInvoker_);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
RuntimeExecutor Instance::getRuntimeExecutor() {
|
|
287
|
+
// HACK: RuntimeExecutor is not compatible with non-JSIExecutor, we return
|
|
288
|
+
// a null callback, which the caller should handle.
|
|
289
|
+
if (getJavaScriptContext() == nullptr) {
|
|
290
|
+
return nullptr;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
std::weak_ptr<NativeToJsBridge> weakNativeToJsBridge = nativeToJsBridge_;
|
|
294
|
+
return [weakNativeToJsBridge](
|
|
295
|
+
std::function<void(jsi::Runtime & runtime)>&& callback) {
|
|
296
|
+
if (auto strongNativeToJsBridge = weakNativeToJsBridge.lock()) {
|
|
297
|
+
strongNativeToJsBridge->runOnExecutorQueue(
|
|
298
|
+
[callback = std::move(callback)](JSExecutor* executor) {
|
|
299
|
+
// Assumes the underlying executor is a JSIExecutor
|
|
300
|
+
auto* runtime =
|
|
301
|
+
static_cast<jsi::Runtime*>(executor->getJavaScriptContext());
|
|
302
|
+
try {
|
|
303
|
+
react_native_assert(runtime != nullptr);
|
|
304
|
+
callback(*runtime);
|
|
305
|
+
executor->flush();
|
|
306
|
+
} catch (jsi::JSError& originalError) {
|
|
307
|
+
handleJSError(*runtime, originalError, true);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
std::shared_ptr<NativeMethodCallInvoker>
|
|
315
|
+
Instance::getDecoratedNativeMethodCallInvoker(
|
|
316
|
+
std::shared_ptr<NativeMethodCallInvoker> nativeMethodCallInvoker) {
|
|
317
|
+
return nativeToJsBridge_->getDecoratedNativeMethodCallInvoker(
|
|
318
|
+
nativeMethodCallInvoker);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
void Instance::JSCallInvoker::setNativeToJsBridgeAndFlushCalls(
|
|
322
|
+
std::weak_ptr<NativeToJsBridge> nativeToJsBridge) {
|
|
323
|
+
std::scoped_lock guard(m_mutex);
|
|
324
|
+
|
|
325
|
+
m_shouldBuffer = false;
|
|
326
|
+
m_nativeToJsBridge = nativeToJsBridge;
|
|
327
|
+
while (!m_workBuffer.empty()) {
|
|
328
|
+
scheduleAsync(std::move(m_workBuffer.front()));
|
|
329
|
+
m_workBuffer.pop_front();
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
void Instance::JSCallInvoker::invokeSync(CallFunc&& /*work*/) {
|
|
334
|
+
// TODO: Replace JS Callinvoker with RuntimeExecutor.
|
|
335
|
+
throw std::runtime_error(
|
|
336
|
+
"Synchronous native -> JS calls are currently not supported.");
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
void Instance::JSCallInvoker::invokeAsync(CallFunc&& work) noexcept {
|
|
340
|
+
std::scoped_lock guard(m_mutex);
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Why is is necessary to queue up async work?
|
|
344
|
+
*
|
|
345
|
+
* 1. TurboModuleManager must be created synchronously after the Instance,
|
|
346
|
+
* before we load the source code. This is when the NativeModule system
|
|
347
|
+
* is initialized. RCTDevLoadingView shows bundle download progress.
|
|
348
|
+
* 2. TurboModuleManager requires a JS CallInvoker.
|
|
349
|
+
* 3. The JS CallInvoker requires the NativeToJsBridge, which is created on
|
|
350
|
+
* the JS thread in Instance::initializeBridge.
|
|
351
|
+
*
|
|
352
|
+
* Therefore, although we don't call invokeAsync before the JS bundle is
|
|
353
|
+
* executed, this buffering is implemented anyways to ensure that work
|
|
354
|
+
* isn't discarded.
|
|
355
|
+
*/
|
|
356
|
+
if (m_shouldBuffer) {
|
|
357
|
+
m_workBuffer.push_back(std::move(work));
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
scheduleAsync(std::move(work));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
void Instance::JSCallInvoker::scheduleAsync(CallFunc&& work) noexcept {
|
|
365
|
+
if (auto strongNativeToJsBridge = m_nativeToJsBridge.lock()) {
|
|
366
|
+
strongNativeToJsBridge->runOnExecutorQueue(
|
|
367
|
+
[work = std::move(work)](JSExecutor* executor) {
|
|
368
|
+
auto* runtime = (jsi::Runtime*)executor->getJavaScriptContext();
|
|
369
|
+
work(*runtime);
|
|
370
|
+
executor->flush();
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
} // namespace facebook::react
|
|
376
|
+
|
|
377
|
+
#endif // RCT_REMOVE_LEGACY_ARCH
|
|
378
|
+
|
|
379
|
+
#if _MSC_VER
|
|
380
|
+
#pragma warning(pop)
|
|
381
|
+
#endif
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
|
|
9
|
+
#if _MSC_VER
|
|
10
|
+
#pragma warning(push)
|
|
11
|
+
#pragma warning(disable : 4996) // deprecated APIs
|
|
12
|
+
#endif
|
|
13
|
+
#include "JSExecutor.h"
|
|
14
|
+
|
|
15
|
+
#include "RAMBundleRegistry.h"
|
|
16
|
+
|
|
17
|
+
#include <jsinspector-modern/ReactCdp.h>
|
|
18
|
+
|
|
19
|
+
#include <array>
|
|
20
|
+
|
|
21
|
+
namespace facebook::react {
|
|
22
|
+
|
|
23
|
+
std::string JSExecutor::getSyntheticBundlePath(
|
|
24
|
+
uint32_t bundleId,
|
|
25
|
+
const std::string& bundlePath) {
|
|
26
|
+
#ifndef RCT_REMOVE_LEGACY_ARCH
|
|
27
|
+
if (bundleId == RAMBundleRegistry::MAIN_BUNDLE_ID) {
|
|
28
|
+
return bundlePath;
|
|
29
|
+
}
|
|
30
|
+
#endif // RCT_REMOVE_LEGACY_ARCH
|
|
31
|
+
|
|
32
|
+
std::array<char, 32> buffer{};
|
|
33
|
+
std::snprintf(buffer.data(), buffer.size(), "seg-%u.js", bundleId);
|
|
34
|
+
return buffer.data();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
jsinspector_modern::RuntimeTargetDelegate&
|
|
38
|
+
JSExecutor::getRuntimeTargetDelegate() {
|
|
39
|
+
if (!runtimeTargetDelegate_) {
|
|
40
|
+
runtimeTargetDelegate_.emplace(getDescription());
|
|
41
|
+
}
|
|
42
|
+
return *runtimeTargetDelegate_;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
} // namespace facebook::react
|
|
46
|
+
|
|
47
|
+
#if _MSC_VER
|
|
48
|
+
#pragma warning(pop)
|
|
49
|
+
#endif
|
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
|
|
9
|
+
#if _MSC_VER
|
|
10
|
+
#pragma warning(push)
|
|
11
|
+
#pragma warning(disable : 4996) // deprecated APIs
|
|
12
|
+
#endif
|
|
13
|
+
#include "JSIndexedRAMBundle.h"
|
|
14
|
+
|
|
15
|
+
#ifndef RCT_REMOVE_LEGACY_ARCH
|
|
16
|
+
|
|
17
|
+
#include <glog/logging.h>
|
|
18
|
+
#include <fstream>
|
|
19
|
+
#include <memory>
|
|
20
|
+
#include <sstream>
|
|
21
|
+
|
|
22
|
+
#include <folly/lang/Bits.h>
|
|
23
|
+
#include <glog/logging.h>
|
|
24
|
+
|
|
25
|
+
namespace facebook::react {
|
|
26
|
+
|
|
27
|
+
std::function<std::unique_ptr<JSModulesUnbundle>(std::string)>
|
|
28
|
+
JSIndexedRAMBundle::buildFactory() {
|
|
29
|
+
return [](const std::string& bundlePath) {
|
|
30
|
+
return std::make_unique<JSIndexedRAMBundle>(bundlePath.c_str());
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
JSIndexedRAMBundle::JSIndexedRAMBundle(const char* sourcePath) {
|
|
35
|
+
m_bundle = std::make_unique<std::ifstream>(sourcePath, std::ifstream::binary);
|
|
36
|
+
if (!m_bundle) {
|
|
37
|
+
throw std::ios_base::failure(
|
|
38
|
+
std::string("Bundle ") + sourcePath +
|
|
39
|
+
"cannot be opened: " + std::to_string(m_bundle->rdstate()));
|
|
40
|
+
}
|
|
41
|
+
init();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
JSIndexedRAMBundle::JSIndexedRAMBundle(
|
|
45
|
+
std::unique_ptr<const JSBigString> script) {
|
|
46
|
+
// tmpStream is needed because m_bundle is std::istream type
|
|
47
|
+
// which has no member 'write'
|
|
48
|
+
std::unique_ptr<std::stringstream> tmpStream =
|
|
49
|
+
std::make_unique<std::stringstream>();
|
|
50
|
+
tmpStream->write(script->c_str(), script->size());
|
|
51
|
+
m_bundle = std::move(tmpStream);
|
|
52
|
+
if (!m_bundle) {
|
|
53
|
+
throw std::ios_base::failure(
|
|
54
|
+
"Bundle from string cannot be opened: " +
|
|
55
|
+
std::to_string(m_bundle->rdstate()));
|
|
56
|
+
}
|
|
57
|
+
init();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void JSIndexedRAMBundle::init() {
|
|
61
|
+
// read in magic header, number of entries, and length of the startup section
|
|
62
|
+
uint32_t header[3];
|
|
63
|
+
static_assert(
|
|
64
|
+
sizeof(header) == 12,
|
|
65
|
+
"header size must exactly match the input file format");
|
|
66
|
+
|
|
67
|
+
readBundle(reinterpret_cast<char*>(header), sizeof(header));
|
|
68
|
+
const size_t numTableEntries = folly::Endian::little(header[1]);
|
|
69
|
+
const size_t startupCodeSize = folly::Endian::little(header[2]);
|
|
70
|
+
|
|
71
|
+
// allocate memory for meta data and lookup table.
|
|
72
|
+
m_table = ModuleTable(numTableEntries);
|
|
73
|
+
m_baseOffset = sizeof(header) + m_table.byteLength();
|
|
74
|
+
|
|
75
|
+
// read the lookup table from the file
|
|
76
|
+
readBundle(reinterpret_cast<char*>(m_table.data.get()), m_table.byteLength());
|
|
77
|
+
|
|
78
|
+
// read the startup code
|
|
79
|
+
m_startupCode = std::make_unique<JSBigBufferString>(startupCodeSize - 1);
|
|
80
|
+
|
|
81
|
+
readBundle(m_startupCode->data(), startupCodeSize - 1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
JSIndexedRAMBundle::Module JSIndexedRAMBundle::getModule(
|
|
85
|
+
uint32_t moduleId) const {
|
|
86
|
+
Module ret;
|
|
87
|
+
ret.name = std::to_string(moduleId) + ".js";
|
|
88
|
+
ret.code = getModuleCode(moduleId);
|
|
89
|
+
return ret;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
std::unique_ptr<const JSBigString> JSIndexedRAMBundle::getStartupCode() {
|
|
93
|
+
CHECK(m_startupCode)
|
|
94
|
+
<< "startup code for a RAM Bundle can only be retrieved once";
|
|
95
|
+
return std::move(m_startupCode);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
std::string JSIndexedRAMBundle::getModuleCode(const uint32_t id) const {
|
|
99
|
+
const auto moduleData = id < m_table.numEntries ? &m_table.data[id] : nullptr;
|
|
100
|
+
|
|
101
|
+
// entries without associated code have offset = 0 and length = 0
|
|
102
|
+
const uint32_t length =
|
|
103
|
+
moduleData != nullptr ? folly::Endian::little(moduleData->length) : 0;
|
|
104
|
+
if (length == 0) {
|
|
105
|
+
throw std::ios_base::failure(
|
|
106
|
+
"Error loading module" + std::to_string(id) + "from RAM Bundle");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
std::string ret(length - 1, '\0');
|
|
110
|
+
readBundle(
|
|
111
|
+
&ret.front(),
|
|
112
|
+
length - 1,
|
|
113
|
+
m_baseOffset + folly::Endian::little(moduleData->offset));
|
|
114
|
+
return ret;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
void JSIndexedRAMBundle::readBundle(char* buffer, const std::streamsize bytes)
|
|
118
|
+
const {
|
|
119
|
+
if (!m_bundle->read(buffer, bytes)) {
|
|
120
|
+
if ((m_bundle->rdstate() & std::ios::eofbit) != 0) {
|
|
121
|
+
throw std::ios_base::failure("Unexpected end of RAM Bundle file");
|
|
122
|
+
}
|
|
123
|
+
throw std::ios_base::failure(
|
|
124
|
+
"Error reading RAM Bundle: " + std::to_string(m_bundle->rdstate()));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
void JSIndexedRAMBundle::readBundle(
|
|
129
|
+
char* buffer,
|
|
130
|
+
const std::streamsize bytes,
|
|
131
|
+
const std::ifstream::pos_type position) const {
|
|
132
|
+
if (!m_bundle->seekg(position)) {
|
|
133
|
+
throw std::ios_base::failure(
|
|
134
|
+
"Error reading RAM Bundle: " + std::to_string(m_bundle->rdstate()));
|
|
135
|
+
}
|
|
136
|
+
readBundle(buffer, bytes);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
} // namespace facebook::react
|
|
140
|
+
|
|
141
|
+
#endif // RCT_REMOVE_LEGACY_ARCH
|
|
142
|
+
|
|
143
|
+
#if _MSC_VER
|
|
144
|
+
#pragma warning(pop)
|
|
145
|
+
#endif
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
|
|
9
|
+
#if _MSC_VER
|
|
10
|
+
#pragma warning(push)
|
|
11
|
+
#pragma warning(disable : 4996) // deprecated APIs
|
|
12
|
+
#endif
|
|
13
|
+
#include "MethodCall.h"
|
|
14
|
+
|
|
15
|
+
#ifndef RCT_REMOVE_LEGACY_ARCH
|
|
16
|
+
|
|
17
|
+
#include <folly/json.h>
|
|
18
|
+
#include <stdexcept>
|
|
19
|
+
|
|
20
|
+
namespace facebook::react {
|
|
21
|
+
|
|
22
|
+
#define REQUEST_MODULE_IDS 0
|
|
23
|
+
#define REQUEST_METHOD_IDS 1
|
|
24
|
+
#define REQUEST_PARAMS 2
|
|
25
|
+
#define REQUEST_CALLID 3
|
|
26
|
+
|
|
27
|
+
static const char* errorPrefix = "Malformed calls from JS: ";
|
|
28
|
+
|
|
29
|
+
std::vector<MethodCall> parseMethodCalls(folly::dynamic&& jsonData) {
|
|
30
|
+
if (jsonData.isNull()) {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!jsonData.isArray()) {
|
|
35
|
+
throw std::invalid_argument(
|
|
36
|
+
std::string(errorPrefix) + " input isn't array but " +
|
|
37
|
+
jsonData.typeName());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (jsonData.size() < REQUEST_PARAMS + 1) {
|
|
41
|
+
throw std::invalid_argument(
|
|
42
|
+
std::string(errorPrefix) +
|
|
43
|
+
"size == " + std::to_string(jsonData.size()));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
auto& moduleIds = jsonData[REQUEST_MODULE_IDS];
|
|
47
|
+
auto& methodIds = jsonData[REQUEST_METHOD_IDS];
|
|
48
|
+
auto& params = jsonData[REQUEST_PARAMS];
|
|
49
|
+
int callId = -1;
|
|
50
|
+
|
|
51
|
+
if (!moduleIds.isArray() || !methodIds.isArray() || !params.isArray()) {
|
|
52
|
+
throw std::invalid_argument(
|
|
53
|
+
std::string(errorPrefix) + "not all fields are arrays.\n\n" +
|
|
54
|
+
folly::toJson(jsonData));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (moduleIds.size() != methodIds.size() ||
|
|
58
|
+
moduleIds.size() != params.size()) {
|
|
59
|
+
throw std::invalid_argument(
|
|
60
|
+
std::string(errorPrefix) + "field sizes are different.\n\n" +
|
|
61
|
+
folly::toJson(jsonData));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (jsonData.size() > REQUEST_CALLID) {
|
|
65
|
+
if (!jsonData[REQUEST_CALLID].isNumber()) {
|
|
66
|
+
throw std::invalid_argument(
|
|
67
|
+
std::string(errorPrefix) + "invalid callId" +
|
|
68
|
+
jsonData[REQUEST_CALLID].typeName());
|
|
69
|
+
}
|
|
70
|
+
callId = (int)jsonData[REQUEST_CALLID].asInt();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
std::vector<MethodCall> methodCalls;
|
|
74
|
+
for (size_t i = 0; i < moduleIds.size(); i++) {
|
|
75
|
+
if (!params[i].isArray()) {
|
|
76
|
+
throw std::invalid_argument(
|
|
77
|
+
std::string(errorPrefix) + "method arguments isn't array but " +
|
|
78
|
+
params[i].typeName());
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
methodCalls.emplace_back(
|
|
82
|
+
static_cast<int>(moduleIds[i].asInt()),
|
|
83
|
+
static_cast<int>(methodIds[i].asInt()),
|
|
84
|
+
std::move(params[i]),
|
|
85
|
+
callId);
|
|
86
|
+
|
|
87
|
+
// only increment callid if contains valid callid as callid is optional
|
|
88
|
+
callId += (callId != -1) ? 1 : 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return methodCalls;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
} // namespace facebook::react
|
|
95
|
+
|
|
96
|
+
#endif // RCT_REMOVE_LEGACY_ARCH
|
|
97
|
+
|
|
98
|
+
#if _MSC_VER
|
|
99
|
+
#pragma warning(pop)
|
|
100
|
+
#endif
|