react-native-windows 0.82.3 → 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/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/CompositionEventHandler.cpp +2 -52
- 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/UriImageManager.cpp +5 -0
- package/Microsoft.ReactNative/IReactCompositionViewComponentBuilder.idl +1 -0
- 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/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/Generated/PackageVersion.g.props +5 -5
- package/PropertySheets/Warnings.props +2 -1
- package/ReactCommon/ReactCommon.vcxproj +11 -2
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/CxxNativeModule.cpp +2 -2
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/Instance.cpp +4 -2
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSExecutor.cpp +4 -2
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/JSIndexedRAMBundle.cpp +4 -2
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/MethodCall.cpp +4 -2
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/ModuleRegistry.cpp +5 -3
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/NativeToJsBridge.cpp +4 -4
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/RAMBundleRegistry.cpp +6 -4
- package/ReactCommon/TEMP_UntilReactCommonUpdate/cxxreact/ReactMarker.cpp +2 -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 +15 -8
- package/ReactCommon/TEMP_UntilReactCommonUpdate/jsiexecutor/jsireact/JSINativeModules.cpp +4 -2
- 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 +5 -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 +2 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/core/EventQueueProcessor.cpp +2 -0
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/imagemanager/primitives.h +25 -31
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/renderer/uimanager/UIManager.cpp +19 -5
- package/ReactCommon/TEMP_UntilReactCommonUpdate/react/runtime/ReactInstance.cpp +16 -1
- 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 +15 -3
- 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 +1 -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/BaseViewProps.cpp +0 -628
- 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
|
@@ -21,37 +21,34 @@ class SyncCallback;
|
|
|
21
21
|
template <typename... Args>
|
|
22
22
|
class AsyncCallback {
|
|
23
23
|
public:
|
|
24
|
-
AsyncCallback(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
std::move(jsInvoker))) {}
|
|
32
|
-
|
|
33
|
-
void operator()(Args... args) const noexcept {
|
|
24
|
+
AsyncCallback(jsi::Runtime &runtime, jsi::Function function, std::shared_ptr<CallInvoker> jsInvoker)
|
|
25
|
+
: callback_(std::make_shared<SyncCallback<void(Args...)>>(runtime, std::move(function), std::move(jsInvoker)))
|
|
26
|
+
{
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
void operator()(Args... args) const noexcept
|
|
30
|
+
{
|
|
34
31
|
call(std::forward<Args>(args)...);
|
|
35
32
|
}
|
|
36
33
|
|
|
37
|
-
void call(Args... args) const noexcept
|
|
34
|
+
void call(Args... args) const noexcept
|
|
35
|
+
{
|
|
38
36
|
callWithArgs(std::nullopt, std::forward<Args>(args)...);
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
void callWithPriority(SchedulerPriority priority, Args... args)
|
|
42
|
-
|
|
39
|
+
void callWithPriority(SchedulerPriority priority, Args... args) const noexcept
|
|
40
|
+
{
|
|
43
41
|
callWithArgs(priority, std::forward<Args>(args)...);
|
|
44
42
|
}
|
|
45
43
|
|
|
46
|
-
void call(std::function<void(jsi::Runtime&, jsi::Function&)
|
|
47
|
-
|
|
44
|
+
void call(std::function<void(jsi::Runtime &, jsi::Function &)> &&callImpl) const noexcept
|
|
45
|
+
{
|
|
48
46
|
callWithFunction(std::nullopt, std::move(callImpl));
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
void callWithPriority(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const noexcept {
|
|
49
|
+
void callWithPriority(SchedulerPriority priority, std::function<void(jsi::Runtime &, jsi::Function &)> &&callImpl)
|
|
50
|
+
const noexcept
|
|
51
|
+
{
|
|
55
52
|
callWithFunction(priority, std::move(callImpl));
|
|
56
53
|
}
|
|
57
54
|
|
|
@@ -60,15 +57,14 @@ class AsyncCallback {
|
|
|
60
57
|
|
|
61
58
|
std::shared_ptr<SyncCallback<void(Args...)>> callback_;
|
|
62
59
|
|
|
63
|
-
void callWithArgs(std::optional<SchedulerPriority> priority, Args... args)
|
|
64
|
-
|
|
60
|
+
void callWithArgs(std::optional<SchedulerPriority> priority, Args... args) const noexcept
|
|
61
|
+
{
|
|
65
62
|
if (auto wrapper = callback_->wrapper_.lock()) {
|
|
66
63
|
auto fn = [callback = callback_,
|
|
67
|
-
argsPtr = std::make_shared<std::tuple<Args...>>(
|
|
68
|
-
|
|
69
|
-
jsi::Runtime&) { callback->apply(std::move(*argsPtr)); };
|
|
64
|
+
argsPtr = std::make_shared<std::tuple<Args...>>(std::make_tuple(std::forward<Args>(args)...))](
|
|
65
|
+
jsi::Runtime &) { callback->apply(std::move(*argsPtr)); };
|
|
70
66
|
|
|
71
|
-
auto&
|
|
67
|
+
auto &jsInvoker = wrapper->jsInvoker();
|
|
72
68
|
if (priority) {
|
|
73
69
|
jsInvoker.invokeAsync(*priority, std::move(fn));
|
|
74
70
|
} else {
|
|
@@ -79,20 +75,19 @@ class AsyncCallback {
|
|
|
79
75
|
|
|
80
76
|
void callWithFunction(
|
|
81
77
|
std::optional<SchedulerPriority> priority,
|
|
82
|
-
std::function<void(jsi::Runtime&, jsi::Function&)
|
|
83
|
-
|
|
78
|
+
std::function<void(jsi::Runtime &, jsi::Function &)> &&callImpl) const noexcept
|
|
79
|
+
{
|
|
84
80
|
if (auto wrapper = callback_->wrapper_.lock()) {
|
|
85
81
|
// Capture callback_ and not wrapper_. If callback_ is deallocated or the
|
|
86
82
|
// JSVM is shutdown before the async task is scheduled, the underlying
|
|
87
83
|
// function will have been deallocated.
|
|
88
|
-
auto fn = [callback = callback_,
|
|
89
|
-
callImpl = std::move(callImpl)](jsi::Runtime& rt) {
|
|
84
|
+
auto fn = [callback = callback_, callImpl = std::move(callImpl)](jsi::Runtime &rt) {
|
|
90
85
|
if (auto wrapper2 = callback->wrapper_.lock()) {
|
|
91
86
|
callImpl(rt, wrapper2->callback());
|
|
92
87
|
}
|
|
93
88
|
};
|
|
94
89
|
|
|
95
|
-
auto&
|
|
90
|
+
auto &jsInvoker = wrapper->jsInvoker();
|
|
96
91
|
if (priority) {
|
|
97
92
|
jsInvoker.invokeAsync(*priority, std::move(fn));
|
|
98
93
|
} else {
|
|
@@ -108,40 +103,39 @@ class AsyncCallback {
|
|
|
108
103
|
template <typename R, typename... Args>
|
|
109
104
|
class SyncCallback<R(Args...)> {
|
|
110
105
|
public:
|
|
111
|
-
SyncCallback(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
: wrapper_(CallbackWrapper::createWeak(
|
|
116
|
-
std::move(function),
|
|
117
|
-
rt,
|
|
118
|
-
std::move(jsInvoker))) {}
|
|
106
|
+
SyncCallback(jsi::Runtime &rt, jsi::Function function, std::shared_ptr<CallInvoker> jsInvoker)
|
|
107
|
+
: wrapper_(CallbackWrapper::createWeak(std::move(function), rt, std::move(jsInvoker)))
|
|
108
|
+
{
|
|
109
|
+
}
|
|
119
110
|
|
|
120
111
|
// Disallow copying, as we can no longer safely destroy the callback
|
|
121
112
|
// from the destructor if there's multiple copies
|
|
122
|
-
SyncCallback(const SyncCallback&) = delete;
|
|
123
|
-
SyncCallback&
|
|
113
|
+
SyncCallback(const SyncCallback &) = delete;
|
|
114
|
+
SyncCallback &operator=(const SyncCallback &) = delete;
|
|
124
115
|
|
|
125
116
|
// Allow move
|
|
126
|
-
SyncCallback(SyncCallback&& other)
|
|
127
|
-
: wrapper_(std::move(other.wrapper_)) {}
|
|
117
|
+
SyncCallback(SyncCallback &&other) noexcept : wrapper_(std::move(other.wrapper_)) {}
|
|
128
118
|
|
|
129
|
-
SyncCallback&
|
|
119
|
+
SyncCallback &operator=(SyncCallback &&other) noexcept
|
|
120
|
+
{
|
|
130
121
|
wrapper_ = std::move(other.wrapper_);
|
|
131
122
|
return *this;
|
|
132
123
|
}
|
|
133
124
|
|
|
134
|
-
~SyncCallback()
|
|
125
|
+
~SyncCallback()
|
|
126
|
+
{
|
|
135
127
|
if (auto wrapper = wrapper_.lock()) {
|
|
136
128
|
wrapper->destroy();
|
|
137
129
|
}
|
|
138
130
|
}
|
|
139
131
|
|
|
140
|
-
R operator()(Args... args) const
|
|
132
|
+
R operator()(Args... args) const
|
|
133
|
+
{
|
|
141
134
|
return call(std::forward<Args>(args)...);
|
|
142
135
|
}
|
|
143
136
|
|
|
144
|
-
R call(Args... args) const
|
|
137
|
+
R call(Args... args) const
|
|
138
|
+
{
|
|
145
139
|
auto wrapper = wrapper_.lock();
|
|
146
140
|
|
|
147
141
|
// If the wrapper has been deallocated, we can no longer provide a return
|
|
@@ -154,19 +148,15 @@ class SyncCallback<R(Args...)> {
|
|
|
154
148
|
}
|
|
155
149
|
}
|
|
156
150
|
|
|
157
|
-
auto&
|
|
158
|
-
auto&
|
|
151
|
+
auto &callback = wrapper->callback();
|
|
152
|
+
auto &rt = wrapper->runtime();
|
|
159
153
|
auto jsInvoker = wrapper->jsInvokerPtr();
|
|
160
154
|
|
|
161
155
|
if constexpr (std::is_void_v<R>) {
|
|
162
|
-
callback.call(
|
|
163
|
-
rt, bridging::toJs(rt, std::forward<Args>(args), jsInvoker)...);
|
|
156
|
+
callback.call(rt, bridging::toJs(rt, std::forward<Args>(args), jsInvoker)...);
|
|
164
157
|
} else {
|
|
165
158
|
return bridging::fromJs<R>(
|
|
166
|
-
rt,
|
|
167
|
-
callback.call(
|
|
168
|
-
rt, bridging::toJs(rt, std::forward<Args>(args), jsInvoker)...),
|
|
169
|
-
jsInvoker);
|
|
159
|
+
rt, callback.call(rt, bridging::toJs(rt, std::forward<Args>(args), jsInvoker)...), jsInvoker);
|
|
170
160
|
}
|
|
171
161
|
}
|
|
172
162
|
|
|
@@ -174,12 +164,14 @@ class SyncCallback<R(Args...)> {
|
|
|
174
164
|
friend AsyncCallback<Args...>;
|
|
175
165
|
friend Bridging<SyncCallback>;
|
|
176
166
|
|
|
177
|
-
R apply(std::tuple<Args
|
|
167
|
+
R apply(std::tuple<Args...> &&args) const
|
|
168
|
+
{
|
|
178
169
|
return apply(std::move(args), std::index_sequence_for<Args...>{});
|
|
179
170
|
}
|
|
180
171
|
|
|
181
172
|
template <size_t... Index>
|
|
182
|
-
R apply(std::tuple<Args
|
|
173
|
+
R apply(std::tuple<Args...> &&args, std::index_sequence<Index...> /*unused*/) const
|
|
174
|
+
{
|
|
183
175
|
return call(std::move(std::get<Index>(args))...);
|
|
184
176
|
}
|
|
185
177
|
|
|
@@ -189,32 +181,28 @@ class SyncCallback<R(Args...)> {
|
|
|
189
181
|
|
|
190
182
|
template <typename... Args>
|
|
191
183
|
struct Bridging<AsyncCallback<Args...>> {
|
|
192
|
-
static AsyncCallback<Args...>
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
const std::shared_ptr<CallInvoker>& jsInvoker) {
|
|
184
|
+
static AsyncCallback<Args...>
|
|
185
|
+
fromJs(jsi::Runtime &rt, jsi::Function &&value, const std::shared_ptr<CallInvoker> &jsInvoker)
|
|
186
|
+
{
|
|
196
187
|
return AsyncCallback<Args...>(rt, std::move(value), jsInvoker);
|
|
197
188
|
}
|
|
198
189
|
|
|
199
|
-
static jsi::Function toJs(
|
|
200
|
-
|
|
201
|
-
const AsyncCallback<Args...>& value) {
|
|
190
|
+
static jsi::Function toJs(jsi::Runtime &rt, const AsyncCallback<Args...> &value)
|
|
191
|
+
{
|
|
202
192
|
return value.callback_->function_.getFunction(rt);
|
|
203
193
|
}
|
|
204
194
|
};
|
|
205
195
|
|
|
206
196
|
template <typename R, typename... Args>
|
|
207
197
|
struct Bridging<SyncCallback<R(Args...)>> {
|
|
208
|
-
static SyncCallback<R(Args...)>
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const std::shared_ptr<CallInvoker>& jsInvoker) {
|
|
198
|
+
static SyncCallback<R(Args...)>
|
|
199
|
+
fromJs(jsi::Runtime &rt, jsi::Function &&value, const std::shared_ptr<CallInvoker> &jsInvoker)
|
|
200
|
+
{
|
|
212
201
|
return SyncCallback<R(Args...)>(rt, std::move(value), jsInvoker);
|
|
213
202
|
}
|
|
214
203
|
|
|
215
|
-
static jsi::Function toJs(
|
|
216
|
-
|
|
217
|
-
const SyncCallback<R(Args...)>& value) {
|
|
204
|
+
static jsi::Function toJs(jsi::Runtime &rt, const SyncCallback<R(Args...)> &value)
|
|
205
|
+
{
|
|
218
206
|
return value.function_.getFunction(rt);
|
|
219
207
|
}
|
|
220
208
|
};
|
|
@@ -226,19 +214,14 @@ struct Bridging<std::function<R(Args...)>> {
|
|
|
226
214
|
|
|
227
215
|
static constexpr size_t kArgumentCount = sizeof...(Args);
|
|
228
216
|
|
|
229
|
-
static jsi::Function toJs(
|
|
230
|
-
|
|
231
|
-
Func fn,
|
|
232
|
-
const std::shared_ptr<CallInvoker>& jsInvoker) {
|
|
217
|
+
static jsi::Function toJs(jsi::Runtime &rt, Func fn, const std::shared_ptr<CallInvoker> &jsInvoker)
|
|
218
|
+
{
|
|
233
219
|
return jsi::Function::createFromHostFunction(
|
|
234
220
|
rt,
|
|
235
221
|
jsi::PropNameID::forAscii(rt, "BridgedFunction"),
|
|
236
222
|
kArgumentCount,
|
|
237
223
|
[fn = std::make_shared<Func>(std::move(fn)), jsInvoker](
|
|
238
|
-
jsi::Runtime&
|
|
239
|
-
const jsi::Value&,
|
|
240
|
-
const jsi::Value* args,
|
|
241
|
-
size_t count) -> jsi::Value {
|
|
224
|
+
jsi::Runtime &rt, const jsi::Value &, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
242
225
|
if (count < kArgumentCount) {
|
|
243
226
|
throw jsi::JSError(rt, "Incorrect number of arguments");
|
|
244
227
|
}
|
|
@@ -247,10 +230,7 @@ struct Bridging<std::function<R(Args...)>> {
|
|
|
247
230
|
callFromJs(*fn, rt, args, jsInvoker, IndexSequence{});
|
|
248
231
|
return jsi::Value();
|
|
249
232
|
} else {
|
|
250
|
-
return bridging::toJs(
|
|
251
|
-
rt,
|
|
252
|
-
callFromJs(*fn, rt, args, jsInvoker, IndexSequence{}),
|
|
253
|
-
jsInvoker);
|
|
233
|
+
return bridging::toJs(rt, callFromJs(*fn, rt, args, jsInvoker, IndexSequence{}), jsInvoker);
|
|
254
234
|
}
|
|
255
235
|
});
|
|
256
236
|
}
|
|
@@ -258,11 +238,12 @@ struct Bridging<std::function<R(Args...)>> {
|
|
|
258
238
|
private:
|
|
259
239
|
template <size_t... Index>
|
|
260
240
|
static R callFromJs(
|
|
261
|
-
Func&
|
|
262
|
-
jsi::Runtime&
|
|
263
|
-
const jsi::Value*
|
|
264
|
-
const std::shared_ptr<CallInvoker
|
|
265
|
-
std::index_sequence<Index...>)
|
|
241
|
+
Func &fn,
|
|
242
|
+
jsi::Runtime &rt,
|
|
243
|
+
const jsi::Value *args,
|
|
244
|
+
const std::shared_ptr<CallInvoker> &jsInvoker,
|
|
245
|
+
std::index_sequence<Index...> /*unused*/)
|
|
246
|
+
{
|
|
266
247
|
return fn(bridging::fromJs<Args>(rt, args[Index], jsInvoker)...);
|
|
267
248
|
}
|
|
268
249
|
};
|
|
@@ -270,8 +251,7 @@ struct Bridging<std::function<R(Args...)>> {
|
|
|
270
251
|
template <typename R, typename... Args>
|
|
271
252
|
struct Bridging<
|
|
272
253
|
std::function<R(Args...)>,
|
|
273
|
-
std::enable_if_t<
|
|
274
|
-
!std::is_same_v<std::function<R(Args...)>, std::function<R(Args...)>>>>
|
|
254
|
+
std::enable_if_t<!std::is_same_v<std::function<R(Args...)>, std::function<R(Args...)>>>>
|
|
275
255
|
: Bridging<std::function<R(Args...)>> {};
|
|
276
256
|
|
|
277
257
|
template <typename R, typename... Args>
|
|
@@ -14,26 +14,26 @@ namespace facebook::react {
|
|
|
14
14
|
|
|
15
15
|
template <>
|
|
16
16
|
struct Bridging<HighResTimeStamp> {
|
|
17
|
-
static HighResTimeStamp fromJs(
|
|
18
|
-
|
|
19
|
-
const jsi::Value& jsiValue) {
|
|
17
|
+
static HighResTimeStamp fromJs(jsi::Runtime & /*rt*/, const jsi::Value &jsiValue)
|
|
18
|
+
{
|
|
20
19
|
return HighResTimeStamp::fromDOMHighResTimeStamp(jsiValue.asNumber());
|
|
21
20
|
}
|
|
22
21
|
|
|
23
|
-
static double toJs(jsi::Runtime& /*rt*/, const HighResTimeStamp&
|
|
22
|
+
static double toJs(jsi::Runtime & /*rt*/, const HighResTimeStamp &value)
|
|
23
|
+
{
|
|
24
24
|
return value.toDOMHighResTimeStamp();
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
template <>
|
|
29
29
|
struct Bridging<HighResDuration> {
|
|
30
|
-
static HighResDuration fromJs(
|
|
31
|
-
|
|
32
|
-
const jsi::Value& jsiValue) {
|
|
30
|
+
static HighResDuration fromJs(jsi::Runtime & /*rt*/, const jsi::Value &jsiValue)
|
|
31
|
+
{
|
|
33
32
|
return HighResDuration::fromDOMHighResTimeStamp(jsiValue.asNumber());
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
static double toJs(jsi::Runtime& /*rt*/, const HighResDuration&
|
|
35
|
+
static double toJs(jsi::Runtime & /*rt*/, const HighResDuration &value)
|
|
36
|
+
{
|
|
37
37
|
return value.toDOMHighResTimeStamp();
|
|
38
38
|
}
|
|
39
39
|
};
|
|
@@ -32,9 +32,9 @@ class LongLivedObject {
|
|
|
32
32
|
virtual void allowRelease();
|
|
33
33
|
|
|
34
34
|
protected:
|
|
35
|
-
explicit LongLivedObject(jsi::Runtime&
|
|
35
|
+
explicit LongLivedObject(jsi::Runtime &runtime) : runtime_(runtime) {}
|
|
36
36
|
virtual ~LongLivedObject() = default;
|
|
37
|
-
jsi::Runtime&
|
|
37
|
+
jsi::Runtime &runtime_;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -42,14 +42,14 @@ class LongLivedObject {
|
|
|
42
42
|
*/
|
|
43
43
|
class LongLivedObjectCollection {
|
|
44
44
|
public:
|
|
45
|
-
static LongLivedObjectCollection&
|
|
45
|
+
static LongLivedObjectCollection &get(jsi::Runtime &runtime);
|
|
46
46
|
|
|
47
47
|
LongLivedObjectCollection() = default;
|
|
48
|
-
LongLivedObjectCollection(const LongLivedObjectCollection&) = delete;
|
|
49
|
-
void operator=(const LongLivedObjectCollection&) = delete;
|
|
48
|
+
LongLivedObjectCollection(const LongLivedObjectCollection &) = delete;
|
|
49
|
+
void operator=(const LongLivedObjectCollection &) = delete;
|
|
50
50
|
|
|
51
51
|
void add(std::shared_ptr<LongLivedObject> o);
|
|
52
|
-
void remove(const LongLivedObject*
|
|
52
|
+
void remove(const LongLivedObject *o);
|
|
53
53
|
void clear();
|
|
54
54
|
size_t size() const;
|
|
55
55
|
|
|
@@ -13,44 +13,52 @@ namespace facebook::react {
|
|
|
13
13
|
|
|
14
14
|
template <>
|
|
15
15
|
struct Bridging<double> {
|
|
16
|
-
static double fromJs(jsi::Runtime& /*unused*/, const jsi::Value&
|
|
16
|
+
static double fromJs(jsi::Runtime & /*unused*/, const jsi::Value &value)
|
|
17
|
+
{
|
|
17
18
|
return value.asNumber();
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
static double toJs(jsi::Runtime& /*unused*/, double value)
|
|
21
|
+
static double toJs(jsi::Runtime & /*unused*/, double value)
|
|
22
|
+
{
|
|
21
23
|
return value;
|
|
22
24
|
}
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
template <>
|
|
26
28
|
struct Bridging<float> {
|
|
27
|
-
static float fromJs(jsi::Runtime& /*unused*/, const jsi::Value&
|
|
29
|
+
static float fromJs(jsi::Runtime & /*unused*/, const jsi::Value &value)
|
|
30
|
+
{
|
|
28
31
|
return (float)value.asNumber();
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
static float toJs(jsi::Runtime& /*unused*/, float value)
|
|
34
|
+
static float toJs(jsi::Runtime & /*unused*/, float value)
|
|
35
|
+
{
|
|
32
36
|
return value;
|
|
33
37
|
}
|
|
34
38
|
};
|
|
35
39
|
|
|
36
40
|
template <>
|
|
37
41
|
struct Bridging<int32_t> {
|
|
38
|
-
static int32_t fromJs(jsi::Runtime& /*unused*/, const jsi::Value&
|
|
42
|
+
static int32_t fromJs(jsi::Runtime & /*unused*/, const jsi::Value &value)
|
|
43
|
+
{
|
|
39
44
|
return (int32_t)value.asNumber();
|
|
40
45
|
}
|
|
41
46
|
|
|
42
|
-
static int32_t toJs(jsi::Runtime& /*unused*/, int32_t value)
|
|
47
|
+
static int32_t toJs(jsi::Runtime & /*unused*/, int32_t value)
|
|
48
|
+
{
|
|
43
49
|
return value;
|
|
44
50
|
}
|
|
45
51
|
};
|
|
46
52
|
|
|
47
53
|
template <>
|
|
48
54
|
struct Bridging<uint32_t> {
|
|
49
|
-
static uint32_t fromJs(jsi::Runtime& /*unused*/, const jsi::Value&
|
|
55
|
+
static uint32_t fromJs(jsi::Runtime & /*unused*/, const jsi::Value &value)
|
|
56
|
+
{
|
|
50
57
|
return (uint32_t)value.asNumber();
|
|
51
58
|
}
|
|
52
59
|
|
|
53
|
-
static jsi::Value toJs(jsi::Runtime& /*unused*/, uint32_t value)
|
|
60
|
+
static jsi::Value toJs(jsi::Runtime & /*unused*/, uint32_t value)
|
|
61
|
+
{
|
|
54
62
|
return double(value);
|
|
55
63
|
}
|
|
56
64
|
};
|
|
@@ -17,24 +17,26 @@ namespace facebook::react {
|
|
|
17
17
|
|
|
18
18
|
template <>
|
|
19
19
|
struct Bridging<jsi::WeakObject> {
|
|
20
|
-
static jsi::WeakObject fromJs(jsi::Runtime&
|
|
20
|
+
static jsi::WeakObject fromJs(jsi::Runtime &rt, const jsi::Object &value)
|
|
21
|
+
{
|
|
21
22
|
return jsi::WeakObject(rt, value);
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
static jsi::Value toJs(jsi::Runtime&
|
|
25
|
+
static jsi::Value toJs(jsi::Runtime &rt, jsi::WeakObject &value)
|
|
26
|
+
{
|
|
25
27
|
return value.lock(rt);
|
|
26
28
|
}
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
template <typename T>
|
|
30
|
-
struct Bridging<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
static std::shared_ptr<T> fromJs(jsi::Runtime& rt, const jsi::Object& value) {
|
|
32
|
+
struct Bridging<std::shared_ptr<T>, std::enable_if_t<std::is_base_of_v<jsi::HostObject, T>>> {
|
|
33
|
+
static std::shared_ptr<T> fromJs(jsi::Runtime &rt, const jsi::Object &value)
|
|
34
|
+
{
|
|
34
35
|
return value.getHostObject<T>(rt);
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
static jsi::Object toJs(jsi::Runtime&
|
|
38
|
+
static jsi::Object toJs(jsi::Runtime &rt, std::shared_ptr<T> value)
|
|
39
|
+
{
|
|
38
40
|
return jsi::Object::createFromHostObject(rt, std::move(value));
|
|
39
41
|
}
|
|
40
42
|
};
|
|
@@ -43,10 +45,8 @@ namespace map_detail {
|
|
|
43
45
|
|
|
44
46
|
template <typename T>
|
|
45
47
|
struct Bridging {
|
|
46
|
-
static T fromJs(
|
|
47
|
-
|
|
48
|
-
const jsi::Object& value,
|
|
49
|
-
const std::shared_ptr<CallInvoker>& jsInvoker) {
|
|
48
|
+
static T fromJs(jsi::Runtime &rt, const jsi::Object &value, const std::shared_ptr<CallInvoker> &jsInvoker)
|
|
49
|
+
{
|
|
50
50
|
T result;
|
|
51
51
|
auto propertyNames = value.getPropertyNames(rt);
|
|
52
52
|
auto length = propertyNames.length(rt);
|
|
@@ -56,24 +56,18 @@ struct Bridging {
|
|
|
56
56
|
|
|
57
57
|
result.emplace(
|
|
58
58
|
bridging::fromJs<std::string>(rt, propertyName, jsInvoker),
|
|
59
|
-
bridging::fromJs<typename T::mapped_type>(
|
|
60
|
-
rt, value.getProperty(rt, propertyName.asString(rt)), jsInvoker));
|
|
59
|
+
bridging::fromJs<typename T::mapped_type>(rt, value.getProperty(rt, propertyName.asString(rt)), jsInvoker));
|
|
61
60
|
}
|
|
62
61
|
|
|
63
62
|
return result;
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
static jsi::Object toJs(
|
|
67
|
-
|
|
68
|
-
const T& map,
|
|
69
|
-
const std::shared_ptr<CallInvoker>& jsInvoker) {
|
|
65
|
+
static jsi::Object toJs(jsi::Runtime &rt, const T &map, const std::shared_ptr<CallInvoker> &jsInvoker)
|
|
66
|
+
{
|
|
70
67
|
auto resultObject = jsi::Object(rt);
|
|
71
68
|
|
|
72
|
-
for (const auto&
|
|
73
|
-
resultObject.setProperty(
|
|
74
|
-
rt,
|
|
75
|
-
jsi::PropNameID::forUtf8(rt, key),
|
|
76
|
-
bridging::toJs(rt, value, jsInvoker));
|
|
69
|
+
for (const auto &[key, value] : map) {
|
|
70
|
+
resultObject.setProperty(rt, jsi::PropNameID::forUtf8(rt, key), bridging::toJs(rt, value, jsInvoker));
|
|
77
71
|
}
|
|
78
72
|
|
|
79
73
|
return resultObject;
|
|
@@ -83,8 +77,7 @@ struct Bridging {
|
|
|
83
77
|
} // namespace map_detail
|
|
84
78
|
|
|
85
79
|
template <typename... Args>
|
|
86
|
-
struct Bridging<std::map<std::string, Args...>>
|
|
87
|
-
: map_detail::Bridging<std::map<std::string, Args...>> {};
|
|
80
|
+
struct Bridging<std::map<std::string, Args...>> : map_detail::Bridging<std::map<std::string, Args...>> {};
|
|
88
81
|
|
|
89
82
|
template <typename... Args>
|
|
90
83
|
struct Bridging<std::unordered_map<std::string, Args...>>
|
|
@@ -18,13 +18,12 @@ namespace facebook::react {
|
|
|
18
18
|
|
|
19
19
|
template <typename... T>
|
|
20
20
|
class AsyncPromise {
|
|
21
|
-
static_assert(
|
|
22
|
-
sizeof...(T) <= 1,
|
|
23
|
-
"AsyncPromise must have at most one argument");
|
|
21
|
+
static_assert(sizeof...(T) <= 1, "AsyncPromise must have at most one argument");
|
|
24
22
|
|
|
25
23
|
public:
|
|
26
|
-
AsyncPromise(jsi::Runtime&
|
|
27
|
-
: state_(std::make_shared<SharedState>())
|
|
24
|
+
AsyncPromise(jsi::Runtime &rt, const std::shared_ptr<CallInvoker> &jsInvoker)
|
|
25
|
+
: state_(std::make_shared<SharedState>())
|
|
26
|
+
{
|
|
28
27
|
auto constructor = rt.global().getPropertyAsFunction(rt, "Promise");
|
|
29
28
|
|
|
30
29
|
auto promise = constructor.callAsConstructor(
|
|
@@ -32,23 +31,21 @@ class AsyncPromise {
|
|
|
32
31
|
bridging::toJs(
|
|
33
32
|
rt,
|
|
34
33
|
// Safe to capture this since this is called synchronously.
|
|
35
|
-
[this](
|
|
36
|
-
AsyncCallback<T...> resolve,
|
|
37
|
-
const AsyncCallback<Error>& reject) {
|
|
34
|
+
[this](AsyncCallback<T...> resolve, const AsyncCallback<Error> &reject) {
|
|
38
35
|
state_->resolve = std::move(resolve);
|
|
39
36
|
state_->reject = std::move(reject);
|
|
40
37
|
},
|
|
41
38
|
jsInvoker));
|
|
42
39
|
|
|
43
|
-
auto promiseHolder =
|
|
44
|
-
std::make_shared<PromiseHolder>(rt, promise.asObject(rt));
|
|
40
|
+
auto promiseHolder = std::make_shared<PromiseHolder>(rt, promise.asObject(rt));
|
|
45
41
|
LongLivedObjectCollection::get(rt).add(promiseHolder);
|
|
46
42
|
|
|
47
43
|
// The shared state can retain the promise holder weakly now.
|
|
48
44
|
state_->promiseHolder = promiseHolder;
|
|
49
45
|
}
|
|
50
46
|
|
|
51
|
-
void resolve(T... value)
|
|
47
|
+
void resolve(T... value)
|
|
48
|
+
{
|
|
52
49
|
std::lock_guard<std::mutex> lock(state_->mutex);
|
|
53
50
|
|
|
54
51
|
if (state_->resolve) {
|
|
@@ -58,7 +55,8 @@ class AsyncPromise {
|
|
|
58
55
|
}
|
|
59
56
|
}
|
|
60
57
|
|
|
61
|
-
void reject(Error error)
|
|
58
|
+
void reject(Error error)
|
|
59
|
+
{
|
|
62
60
|
std::lock_guard<std::mutex> lock(state_->mutex);
|
|
63
61
|
|
|
64
62
|
if (state_->reject) {
|
|
@@ -68,7 +66,8 @@ class AsyncPromise {
|
|
|
68
66
|
}
|
|
69
67
|
}
|
|
70
68
|
|
|
71
|
-
jsi::Object get(jsi::Runtime&
|
|
69
|
+
jsi::Object get(jsi::Runtime &rt) const
|
|
70
|
+
{
|
|
72
71
|
if (auto holder = state_->promiseHolder.lock()) {
|
|
73
72
|
return jsi::Value(rt, holder->promise).asObject(rt);
|
|
74
73
|
} else {
|
|
@@ -78,14 +77,14 @@ class AsyncPromise {
|
|
|
78
77
|
|
|
79
78
|
private:
|
|
80
79
|
struct PromiseHolder : LongLivedObject {
|
|
81
|
-
PromiseHolder(jsi::Runtime&
|
|
82
|
-
: LongLivedObject(runtime), promise(std::move(p)) {}
|
|
80
|
+
PromiseHolder(jsi::Runtime &runtime, jsi::Object p) : LongLivedObject(runtime), promise(std::move(p)) {}
|
|
83
81
|
|
|
84
82
|
jsi::Object promise;
|
|
85
83
|
};
|
|
86
84
|
|
|
87
85
|
struct SharedState {
|
|
88
|
-
~SharedState()
|
|
86
|
+
~SharedState()
|
|
87
|
+
{
|
|
89
88
|
if (auto holder = promiseHolder.lock()) {
|
|
90
89
|
holder->allowRelease();
|
|
91
90
|
}
|
|
@@ -102,7 +101,8 @@ class AsyncPromise {
|
|
|
102
101
|
|
|
103
102
|
template <typename... T>
|
|
104
103
|
struct Bridging<AsyncPromise<T...>> {
|
|
105
|
-
static jsi::Object toJs(jsi::Runtime&
|
|
104
|
+
static jsi::Object toJs(jsi::Runtime &rt, const AsyncPromise<T...> &promise)
|
|
105
|
+
{
|
|
106
106
|
return promise.get(rt);
|
|
107
107
|
}
|
|
108
108
|
};
|