@office-iss/react-native-win32 0.81.2 → 0.82.0-preview.2

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.
Files changed (209) hide show
  1. package/.flowconfig +3 -11
  2. package/CHANGELOG.json +118 -43
  3. package/CHANGELOG.md +45 -27
  4. package/IntegrationTests/IntegrationTestsApp.js +2 -2
  5. package/IntegrationTests/LayoutEventsTest.js +3 -3
  6. package/Libraries/ActionSheetIOS/ActionSheetIOS.js +7 -3
  7. package/Libraries/Alert/RCTAlertManager.android.js +4 -2
  8. package/Libraries/Animated/Animated.d.ts +2 -0
  9. package/Libraries/Animated/AnimatedEvent.js +1 -1
  10. package/Libraries/Animated/AnimatedExports.js.flow +1 -0
  11. package/Libraries/Animated/AnimatedImplementation.js +4 -2
  12. package/Libraries/Animated/AnimatedMock.js +1 -1
  13. package/Libraries/Animated/Easing.js +2 -0
  14. package/Libraries/Animated/NativeAnimatedAllowlist.js +1 -0
  15. package/Libraries/Animated/animations/Animation.js +19 -20
  16. package/Libraries/Animated/animations/TimingAnimation.js +2 -0
  17. package/Libraries/Animated/components/AnimatedScrollView.js +3 -2
  18. package/Libraries/Animated/components/AnimatedSectionList.js +1 -1
  19. package/Libraries/Animated/nodes/AnimatedColor.js +9 -9
  20. package/Libraries/Animated/nodes/AnimatedInterpolation.js +4 -4
  21. package/Libraries/Animated/nodes/AnimatedNode.js +14 -7
  22. package/Libraries/Animated/nodes/AnimatedObject.js +7 -7
  23. package/Libraries/Animated/nodes/AnimatedProps.js +32 -32
  24. package/Libraries/Animated/nodes/AnimatedStyle.js +23 -21
  25. package/Libraries/Animated/nodes/AnimatedTransform.js +6 -6
  26. package/Libraries/Animated/nodes/AnimatedValue.js +18 -26
  27. package/Libraries/AppState/AppState.js +8 -4
  28. package/Libraries/BatchedBridge/BatchedBridge.js +1 -0
  29. package/Libraries/BatchedBridge/MessageQueue.js +5 -0
  30. package/Libraries/BatchedBridge/NativeModules.js +1 -1
  31. package/Libraries/Blob/BlobManager.js +1 -1
  32. package/Libraries/Blob/URLSearchParams.js +2 -0
  33. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js +2 -2
  34. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.win32.js +2 -2
  35. package/Libraries/Components/Button.js +1 -1
  36. package/Libraries/Components/Button.win32.js +1 -1
  37. package/Libraries/Components/Pressable/Pressable.js +10 -1
  38. package/Libraries/Components/Pressable/Pressable.win32.js +9 -0
  39. package/Libraries/Components/Pressable/useAndroidRippleForView.js +2 -2
  40. package/Libraries/Components/ScrollView/ScrollView.js +13 -4
  41. package/Libraries/Components/ScrollView/ScrollViewStickyHeader.js +1 -1
  42. package/Libraries/Components/StatusBar/StatusBar.js +2 -2
  43. package/Libraries/Components/Switch/Switch.js +1 -1
  44. package/Libraries/Components/TextInput/TextInput.flow.js +12 -5
  45. package/Libraries/Components/TextInput/TextInput.flow.win32.js +12 -5
  46. package/Libraries/Components/TextInput/TextInput.js +14 -5
  47. package/Libraries/Components/TextInput/TextInput.win32.js +15 -7
  48. package/Libraries/Components/TextInput/TextInputState.js +1 -1
  49. package/Libraries/Components/TextInput/TextInputState.win32.js +1 -1
  50. package/Libraries/Components/TextInput/Win32TextInputNativeComponent.js +2 -3
  51. package/Libraries/Components/Touchable/TouchableBounce.js +1 -1
  52. package/Libraries/Components/Touchable/TouchableHighlight.js +1 -1
  53. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +1 -1
  54. package/Libraries/Components/Touchable/TouchableOpacity.js +1 -1
  55. package/Libraries/Components/Touchable/TouchableWin32.js +1 -1
  56. package/Libraries/Components/Touchable/TouchableWin32.js.map +1 -1
  57. package/Libraries/Components/Touchable/TouchableWithoutFeedback.js +3 -3
  58. package/Libraries/Components/View/View.js +81 -167
  59. package/Libraries/Components/View/View.win32.js +3 -1
  60. package/Libraries/Core/Devtools/loadBundleFromServer.js +1 -1
  61. package/Libraries/Core/Devtools/loadBundleFromServer.win32.js +1 -1
  62. package/Libraries/Core/ExceptionsManager.js +4 -2
  63. package/Libraries/Core/ReactFiberErrorDialog.js +3 -3
  64. package/Libraries/Core/ReactNativeVersion.js +37 -10
  65. package/Libraries/Core/Timers/JSTimers.js +4 -1
  66. package/Libraries/Core/Timers/NativeTiming.js +1 -0
  67. package/Libraries/Core/Timers/immediateShim.js +2 -1
  68. package/Libraries/Core/Timers/queueMicrotask.js +1 -0
  69. package/Libraries/Core/setUpPerformance.js +3 -4
  70. package/Libraries/Debugging/DebuggingOverlayRegistry.js +5 -3
  71. package/Libraries/Image/Image.android.js +327 -111
  72. package/Libraries/Image/Image.ios.js +6 -1
  73. package/Libraries/Image/Image.win32.js +6 -1
  74. package/Libraries/Image/ImageSourceUtils.js +8 -2
  75. package/Libraries/Image/assetPaths.js +1 -1
  76. package/Libraries/Image/resolveAssetSource.js +1 -1
  77. package/Libraries/Image/resolveAssetSource.win32.js +6 -7
  78. package/Libraries/Interaction/InteractionManager.js +118 -167
  79. package/Libraries/Interaction/PanResponder.js +7 -52
  80. package/Libraries/LayoutAnimation/LayoutAnimation.js +2 -0
  81. package/Libraries/Lists/FlatList.js +5 -6
  82. package/Libraries/LogBox/Data/LogBoxData.js +5 -2
  83. package/Libraries/LogBox/Data/parseLogBoxLog.js +1 -1
  84. package/Libraries/LogBox/UI/LogBoxInspectorHeader.win32.js +2 -2
  85. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.js +1 -1
  86. package/Libraries/LogBox/UI/LogBoxInspectorSourceMapStatus.win32.js +1 -1
  87. package/Libraries/Modal/Modal.js +3 -3
  88. package/Libraries/NativeComponent/NativeComponentRegistry.js +1 -1
  89. package/Libraries/NativeComponent/ViewConfig.js +2 -2
  90. package/Libraries/Network/RCTNetworking.android.js +1 -1
  91. package/Libraries/Network/RCTNetworking.ios.js +1 -1
  92. package/Libraries/Network/RCTNetworking.win32.js +1 -1
  93. package/Libraries/Network/XMLHttpRequest.js +20 -5
  94. package/Libraries/Network/convertRequestBody.js +1 -1
  95. package/Libraries/PermissionsAndroid/PermissionsAndroid.js +10 -9
  96. package/Libraries/Pressability/HoverState.js +2 -0
  97. package/Libraries/Pressability/HoverState.win32.js +2 -0
  98. package/Libraries/Pressability/Pressability.js +1 -1
  99. package/Libraries/Pressability/Pressability.win32.js +1 -1
  100. package/Libraries/PushNotificationIOS/PushNotificationIOS.js +2 -2
  101. package/Libraries/ReactNative/AppRegistryImpl.js +4 -2
  102. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricHostComponent.js +2 -0
  103. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactFabricPublicInstance.js +3 -3
  104. package/Libraries/ReactNative/RendererImplementation.js +116 -116
  105. package/Libraries/ReactNative/UIManager.js +3 -3
  106. package/Libraries/ReactNative/renderApplication.js +1 -0
  107. package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +1 -1
  108. package/Libraries/Renderer/implementations/ReactFabric-dev.js +38 -35
  109. package/Libraries/Renderer/implementations/ReactFabric-prod.js +51 -22
  110. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +54 -24
  111. package/Libraries/Renderer/implementations/ReactNativeRenderer-dev.js +36 -33
  112. package/Libraries/Renderer/implementations/ReactNativeRenderer-prod.js +5 -5
  113. package/Libraries/Renderer/implementations/ReactNativeRenderer-profiling.js +5 -5
  114. package/Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js +3 -1
  115. package/Libraries/Share/Share.js +4 -0
  116. package/Libraries/StyleSheet/PlatformColorValueTypes.android.js +2 -2
  117. package/Libraries/StyleSheet/PlatformColorValueTypes.ios.js +2 -2
  118. package/Libraries/StyleSheet/PlatformColorValueTypes.win32.js +4 -0
  119. package/Libraries/StyleSheet/StyleSheet.d.ts +7 -22
  120. package/Libraries/StyleSheet/StyleSheetExports.js +2 -8
  121. package/Libraries/StyleSheet/StyleSheetExports.js.flow +11 -18
  122. package/Libraries/StyleSheet/flattenStyle.js +2 -2
  123. package/Libraries/StyleSheet/processAspectRatio.js +2 -0
  124. package/Libraries/StyleSheet/processFilter.js +5 -5
  125. package/Libraries/StyleSheet/splitLayoutProps.js +2 -2
  126. package/Libraries/Text/Text.js +534 -234
  127. package/Libraries/Text/Text.win32.js +647 -274
  128. package/Libraries/Text/TextNativeComponent.js +2 -2
  129. package/Libraries/Text/TextNativeComponent.win32.js +2 -2
  130. package/Libraries/Utilities/Appearance.d.ts +3 -5
  131. package/Libraries/Utilities/Appearance.js +5 -17
  132. package/Libraries/Utilities/HMRClient.js +2 -1
  133. package/Libraries/Utilities/Platform.android.js +3 -3
  134. package/Libraries/Utilities/Platform.d.ts +1 -0
  135. package/Libraries/Utilities/Platform.ios.js +1 -1
  136. package/Libraries/Utilities/Platform.win32.js +3 -3
  137. package/Libraries/Utilities/PlatformTypes.js +1 -1
  138. package/Libraries/Utilities/ReactNativeTestTools.js +12 -0
  139. package/Libraries/Utilities/SceneTracker.js +1 -1
  140. package/Libraries/Utilities/codegenNativeCommands.js +1 -1
  141. package/Libraries/Utilities/codegenNativeComponent.js +1 -1
  142. package/Libraries/Utilities/createPerformanceLogger.js +32 -0
  143. package/Libraries/Utilities/deepFreezeAndThrowOnMutationInDev.js +2 -0
  144. package/Libraries/Utilities/differ/pointsDiffer.js +1 -1
  145. package/Libraries/Utilities/useMergeRefs.js +1 -1
  146. package/Libraries/WebSocket/WebSocketInterceptor.js +2 -0
  147. package/Libraries/promiseRejectionTrackingOptions.js +17 -31
  148. package/Libraries/vendor/emitter/EventEmitter.js +1 -1
  149. package/flow/bom.js.flow +223 -1
  150. package/flow/prettier.js.flow +14 -0
  151. package/index.js +14 -2
  152. package/index.win32.js +16 -2
  153. package/jest/local-setup.js +2 -2
  154. package/jest/mock.js +1 -1
  155. package/jest/mockComponent.js +9 -9
  156. package/jest/mockNativeComponent.js +3 -2
  157. package/jest/mocks/Modal.js +1 -1
  158. package/jest/mocks/ScrollView.js +1 -1
  159. package/jest/mocks/ViewNativeComponent.js +1 -1
  160. package/jest/setup.js +23 -12
  161. package/overrides.json +23 -23
  162. package/package.json +28 -27
  163. package/saveAssetPlugin.js +2 -2
  164. package/src/private/animated/NativeAnimatedHelper.js +16 -5
  165. package/src/private/animated/NativeAnimatedHelper.win32.js +16 -5
  166. package/src/private/animated/createAnimatedPropsHook.js +11 -60
  167. package/src/private/animated/createAnimatedPropsMemoHook.js +8 -54
  168. package/src/private/components/virtualview/VirtualView.js +43 -12
  169. package/src/private/components/virtualview/VirtualViewExperimentalNativeComponent.js +93 -0
  170. package/src/private/components/virtualview/VirtualViewNativeComponent.js +6 -0
  171. package/src/private/devsupport/devmenu/elementinspector/Inspector.js +2 -2
  172. package/src/private/devsupport/devmenu/elementinspector/ReactDevToolsOverlay.js +2 -2
  173. package/src/private/featureflags/ReactNativeFeatureFlags.js +85 -52
  174. package/src/private/featureflags/ReactNativeFeatureFlagsBase.js +23 -4
  175. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +15 -6
  176. package/src/private/renderer/errorhandling/ErrorHandlers.js +3 -3
  177. package/src/private/setup/{setUpPerformanceObserver.js → setUpPerformanceModern.js} +43 -18
  178. package/src/private/specs_DEPRECATED/modules/NativeTiming.js +1 -0
  179. package/src/private/types/HostInstance.js +4 -1
  180. package/src/private/webapis/dom/nodes/ReactNativeDocument.js +22 -2
  181. package/src/private/webapis/dom/nodes/ReactNativeElement.js +1 -1
  182. package/src/private/webapis/dom/nodes/ReadOnlyElement.js +5 -3
  183. package/src/private/webapis/dom/nodes/ReadOnlyNode.js +16 -13
  184. package/src/private/webapis/dom/nodes/internals/NodeInternals.js +45 -22
  185. package/src/private/webapis/dom/nodes/internals/ReactNativeDocumentInstanceHandle.js +1 -1
  186. package/src/private/webapis/dom/nodes/specs/NativeDOM.js +26 -192
  187. package/src/private/webapis/dom/oldstylecollections/HTMLCollection.js +15 -12
  188. package/src/private/webapis/dom/oldstylecollections/NodeList.js +14 -11
  189. package/src/private/webapis/geometry/DOMRectList.js +2 -2
  190. package/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js +19 -74
  191. package/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +0 -4
  192. package/src/private/webapis/mutationobserver/internals/MutationObserverManager.js +1 -1
  193. package/src/private/webapis/performance/EventTiming.js +40 -25
  194. package/src/private/webapis/performance/LongTasks.js +35 -2
  195. package/src/private/webapis/performance/Performance.js +347 -166
  196. package/src/private/webapis/performance/PerformanceEntry.js +40 -23
  197. package/src/private/webapis/performance/PerformanceObserver.js +37 -29
  198. package/src/private/webapis/performance/ReactNativeStartupTiming.js +3 -24
  199. package/src/private/webapis/performance/ResourceTiming.js +29 -18
  200. package/src/private/webapis/performance/UserTiming.js +92 -34
  201. package/src/private/webapis/performance/UserTimingExtensibility.js.flow +38 -0
  202. package/src/private/webapis/performance/internals/RawPerformanceEntry.js +3 -4
  203. package/src/private/webapis/performance/internals/Utilities.js +9 -0
  204. package/src/private/webapis/performance/specs/NativePerformance.js +23 -23
  205. package/src/private/webapis/structuredClone/structuredClone.js +10 -10
  206. package/src-win/Libraries/Components/Touchable/TouchableWin32.tsx +1 -1
  207. package/Libraries/Interaction/InteractionManagerStub.js +0 -184
  208. package/Libraries/Interaction/TaskQueue.js +0 -183
  209. package/Libraries/ReactNative/ReactNativeFeatureFlags.js +0 -31
@@ -15,38 +15,78 @@ import type {
15
15
  PerformanceEntryList,
16
16
  PerformanceEntryType,
17
17
  } from './PerformanceEntry';
18
- import type {DetailType, PerformanceMarkOptions} from './UserTiming';
18
+ import type {
19
+ DetailType,
20
+ PerformanceMarkOptions,
21
+ PerformanceMeasureInit,
22
+ } from './UserTiming';
19
23
 
20
24
  import DOMException from '../errors/DOMException';
25
+ import structuredClone from '../structuredClone/structuredClone';
21
26
  import {setPlatformObject} from '../webidl/PlatformObjects';
22
27
  import {EventCounts} from './EventTiming';
23
28
  import {
24
29
  performanceEntryTypeToRaw,
25
30
  rawToPerformanceEntry,
26
31
  } from './internals/RawPerformanceEntry';
27
- import {warnNoNativePerformance} from './internals/Utilities';
32
+ import {getCurrentTimeStamp} from './internals/Utilities';
28
33
  import MemoryInfo from './MemoryInfo';
29
34
  import ReactNativeStartupTiming from './ReactNativeStartupTiming';
30
- import NativePerformance from './specs/NativePerformance';
35
+ import MaybeNativePerformance from './specs/NativePerformance';
31
36
  import {PerformanceMark, PerformanceMeasure} from './UserTiming';
37
+ import nullthrows from 'nullthrows';
38
+
39
+ export type PerformanceMeasureOptions =
40
+ | $ReadOnly<{
41
+ detail?: DetailType,
42
+ start?: DOMHighResTimeStamp | string,
43
+ duration?: DOMHighResTimeStamp,
44
+ }>
45
+ | $ReadOnly<{
46
+ detail?: DetailType,
47
+ start?: DOMHighResTimeStamp | string,
48
+ end?: DOMHighResTimeStamp | string,
49
+ }>
50
+ | $ReadOnly<{
51
+ detail?: DetailType,
52
+ duration?: DOMHighResTimeStamp | string,
53
+ end?: DOMHighResTimeStamp | string,
54
+ }>;
32
55
 
33
- declare var global: {
34
- // This value is defined directly via JSI, if available.
35
- +nativePerformanceNow?: ?() => number,
36
- };
56
+ const ENTRY_TYPES_AVAILABLE_FROM_TIMELINE: $ReadOnlyArray<PerformanceEntryType> =
57
+ ['mark', 'measure'];
58
+
59
+ const NativePerformance = nullthrows(MaybeNativePerformance);
37
60
 
38
- const getCurrentTimeStamp: () => DOMHighResTimeStamp =
39
- NativePerformance?.now ?? global.nativePerformanceNow ?? (() => Date.now());
61
+ const cachedReportMark = NativePerformance.reportMark;
62
+ const cachedReportMeasure = NativePerformance.reportMeasure;
63
+ const cachedGetMarkTime = NativePerformance.getMarkTime;
64
+ const cachedNativeClearMarks = NativePerformance.clearMarks;
65
+ const cachedNativeClearMeasures = NativePerformance.clearMeasures;
66
+ let cachedTimeOrigin: ?DOMHighResTimeStamp;
40
67
 
41
- export type PerformanceMeasureOptions = {
42
- detail?: DetailType,
43
- start?: DOMHighResTimeStamp,
44
- duration?: DOMHighResTimeStamp,
45
- end?: DOMHighResTimeStamp,
68
+ const MARK_OPTIONS_REUSABLE_OBJECT: PerformanceMarkOptions = {
69
+ startTime: 0,
70
+ detail: undefined,
46
71
  };
47
72
 
48
- const ENTRY_TYPES_AVAILABLE_FROM_TIMELINE: $ReadOnlyArray<PerformanceEntryType> =
49
- ['mark', 'measure'];
73
+ const MEASURE_OPTIONS_REUSABLE_OBJECT: PerformanceMeasureInit = {
74
+ name: '',
75
+ startTime: 0,
76
+ duration: 0,
77
+ detail: undefined,
78
+ };
79
+
80
+ const getMarkTimeForMeasure = (markName: string): number => {
81
+ const markTime = cachedGetMarkTime(markName);
82
+ if (markTime == null) {
83
+ throw new DOMException(
84
+ `Failed to execute 'measure' on 'Performance': The mark '${markName}' does not exist.`,
85
+ 'SyntaxError',
86
+ );
87
+ }
88
+ return markTime;
89
+ };
50
90
 
51
91
  /**
52
92
  * Partial implementation of the Performance interface for RN,
@@ -54,181 +94,324 @@ const ENTRY_TYPES_AVAILABLE_FROM_TIMELINE: $ReadOnlyArray<PerformanceEntryType>
54
94
  * https://www.w3.org/TR/user-timing/#extensions-performance-interface
55
95
  */
56
96
  export default class Performance {
57
- eventCounts: EventCounts = new EventCounts();
97
+ #eventCounts: EventCounts = new EventCounts();
98
+
99
+ get eventCounts(): EventCounts {
100
+ return this.#eventCounts;
101
+ }
58
102
 
59
103
  // Get the current JS memory information.
60
104
  get memory(): MemoryInfo {
61
- if (NativePerformance?.getSimpleMemoryInfo) {
62
- // JSI API implementations may have different variants of names for the JS
63
- // heap information we need here. We will parse the result based on our
64
- // guess of the implementation for now.
65
- const memoryInfo = NativePerformance.getSimpleMemoryInfo();
66
- if (memoryInfo.hasOwnProperty('hermes_heapSize')) {
67
- // We got memory information from Hermes
68
- const {
69
- hermes_heapSize: totalJSHeapSize,
70
- hermes_allocatedBytes: usedJSHeapSize,
71
- } = memoryInfo;
72
-
73
- return new MemoryInfo({
74
- jsHeapSizeLimit: null, // We don't know the heap size limit from Hermes.
75
- totalJSHeapSize,
76
- usedJSHeapSize,
77
- });
78
- } else {
79
- // JSC and V8 has no native implementations for memory information in JSI::Instrumentation
80
- return new MemoryInfo();
81
- }
105
+ // JSI API implementations may have different variants of names for the JS
106
+ // heap information we need here. We will parse the result based on our
107
+ // guess of the implementation for now.
108
+ const memoryInfo = NativePerformance.getSimpleMemoryInfo();
109
+ if (memoryInfo.hasOwnProperty('hermes_heapSize')) {
110
+ // We got memory information from Hermes
111
+ const {
112
+ hermes_heapSize: totalJSHeapSize,
113
+ hermes_allocatedBytes: usedJSHeapSize,
114
+ } = memoryInfo;
115
+
116
+ return new MemoryInfo({
117
+ jsHeapSizeLimit: null, // We don't know the heap size limit from Hermes.
118
+ totalJSHeapSize,
119
+ usedJSHeapSize,
120
+ });
121
+ } else {
122
+ // JSC and V8 has no native implementations for memory information in JSI::Instrumentation
123
+ return new MemoryInfo();
82
124
  }
83
-
84
- return new MemoryInfo();
85
125
  }
86
126
 
87
127
  // Startup metrics is not used in web, but only in React Native.
88
128
  get rnStartupTiming(): ReactNativeStartupTiming {
89
- if (NativePerformance?.getReactNativeStartupTiming) {
90
- const {
91
- startTime,
92
- endTime,
93
- initializeRuntimeStart,
94
- initializeRuntimeEnd,
95
- executeJavaScriptBundleEntryPointStart,
96
- executeJavaScriptBundleEntryPointEnd,
97
- } = NativePerformance.getReactNativeStartupTiming();
98
- return new ReactNativeStartupTiming({
99
- startTime,
100
- endTime,
101
- initializeRuntimeStart,
102
- initializeRuntimeEnd,
103
- executeJavaScriptBundleEntryPointStart,
104
- executeJavaScriptBundleEntryPointEnd,
105
- });
129
+ const {
130
+ startTime,
131
+ initializeRuntimeStart,
132
+ executeJavaScriptBundleEntryPointStart,
133
+ endTime,
134
+ } = NativePerformance.getReactNativeStartupTiming();
135
+ return new ReactNativeStartupTiming({
136
+ startTime,
137
+ initializeRuntimeStart,
138
+ executeJavaScriptBundleEntryPointStart,
139
+ endTime,
140
+ });
141
+ }
142
+
143
+ /**
144
+ * Returns the high resolution timestamp that is used as the baseline for
145
+ * performance-related timestamps.
146
+ * https://developer.mozilla.org/en-US/docs/Web/API/Performance/timeOrigin
147
+ */
148
+ get timeOrigin(): DOMHighResTimeStamp {
149
+ if (cachedTimeOrigin == null) {
150
+ if (NativePerformance.timeOrigin) {
151
+ cachedTimeOrigin = NativePerformance?.timeOrigin();
152
+ } else {
153
+ // Very naive polyfill.
154
+ cachedTimeOrigin = Date.now() - getCurrentTimeStamp();
155
+ }
106
156
  }
107
- return new ReactNativeStartupTiming();
157
+
158
+ return cachedTimeOrigin;
108
159
  }
109
160
 
110
161
  mark(
111
162
  markName: string,
112
163
  markOptions?: PerformanceMarkOptions,
113
164
  ): PerformanceMark {
114
- let computedStartTime;
115
- if (NativePerformance?.markWithResult) {
116
- computedStartTime = NativePerformance.markWithResult(
117
- markName,
118
- markOptions?.startTime,
165
+ // IMPORTANT: this method has been micro-optimized.
166
+ // Please run the benchmarks in `Performance-benchmarks-itest` to ensure
167
+ // changes do not regress performance.
168
+
169
+ if (markName === undefined) {
170
+ throw new TypeError(
171
+ `Failed to execute 'mark' on 'Performance': 1 argument required, but only 0 present.`,
119
172
  );
120
- } else {
121
- warnNoNativePerformance();
122
- computedStartTime = performance.now();
123
173
  }
124
174
 
125
- return new PerformanceMark(markName, {
126
- startTime: computedStartTime,
127
- detail: markOptions?.detail,
128
- });
129
- }
175
+ const resolvedMarkName =
176
+ typeof markName === 'string' ? markName : String(markName);
130
177
 
131
- clearMarks(markName?: string): void {
132
- if (!NativePerformance?.clearMarks) {
133
- warnNoNativePerformance();
134
- return;
135
- }
178
+ let resolvedStartTime;
179
+ let resolvedDetail;
136
180
 
137
- NativePerformance.clearMarks(markName);
138
- }
181
+ let startTime;
182
+ let detail;
183
+ if (markOptions != null) {
184
+ ({startTime, detail} = markOptions);
185
+ }
139
186
 
140
- measure(
141
- measureName: string,
142
- startMarkOrOptions?: string | PerformanceMeasureOptions,
143
- endMark?: string,
144
- ): PerformanceMeasure {
145
- let options;
146
- let startMarkName,
147
- endMarkName = endMark,
148
- duration,
149
- startTime = 0,
150
- endTime = 0;
151
-
152
- if (typeof startMarkOrOptions === 'string') {
153
- startMarkName = startMarkOrOptions;
154
- options = {};
155
- } else if (startMarkOrOptions !== undefined) {
156
- options = startMarkOrOptions;
157
- if (endMark !== undefined) {
187
+ if (startTime !== undefined) {
188
+ resolvedStartTime =
189
+ typeof startTime === 'number' ? startTime : Number(startTime);
190
+ if (resolvedStartTime < 0) {
158
191
  throw new TypeError(
159
- "Performance.measure: Can't have both options and endMark",
192
+ `Failed to execute 'mark' on 'Performance': '${resolvedMarkName}' cannot have a negative start time.`,
160
193
  );
161
- }
162
- if (options.start === undefined && options.end === undefined) {
163
- throw new TypeError(
164
- 'Performance.measure: Must have at least one of start/end specified in options',
165
- );
166
- }
167
- if (
168
- options.start !== undefined &&
169
- options.end !== undefined &&
170
- options.duration !== undefined
194
+ } else if (
195
+ // This is faster than calling Number.isFinite()
196
+ // eslint-disable-next-line no-self-compare
197
+ resolvedStartTime !== resolvedStartTime ||
198
+ resolvedStartTime === Infinity
171
199
  ) {
172
200
  throw new TypeError(
173
- "Performance.measure: Can't have both start/end and duration explicitly in options",
201
+ `Failed to execute 'mark' on 'Performance': Failed to read the 'startTime' property from 'PerformanceMarkOptions': The provided double value is non-finite.`,
174
202
  );
175
203
  }
204
+ } else {
205
+ resolvedStartTime = getCurrentTimeStamp();
206
+ }
176
207
 
177
- if (typeof options.start === 'number') {
178
- startTime = options.start;
179
- } else {
180
- startMarkName = options.start;
181
- }
208
+ if (detail !== undefined) {
209
+ resolvedDetail = structuredClone(detail);
210
+ }
182
211
 
183
- if (typeof options.end === 'number') {
184
- endTime = options.end;
185
- } else {
186
- endMarkName = options.end;
187
- }
212
+ // $FlowExpectedError[cannot-write]
213
+ MARK_OPTIONS_REUSABLE_OBJECT.startTime = resolvedStartTime;
214
+ // $FlowExpectedError[cannot-write]
215
+ MARK_OPTIONS_REUSABLE_OBJECT.detail = resolvedDetail;
188
216
 
189
- duration = options.duration ?? duration;
217
+ const entry = new PerformanceMark(
218
+ resolvedMarkName,
219
+ MARK_OPTIONS_REUSABLE_OBJECT,
220
+ );
221
+
222
+ cachedReportMark(resolvedMarkName, resolvedStartTime, entry);
223
+
224
+ return entry;
225
+ }
226
+
227
+ clearMarks(markName?: string): void {
228
+ cachedNativeClearMarks(markName);
229
+ }
230
+
231
+ measure(
232
+ measureName: string,
233
+ startMarkOrOptions?: string | PerformanceMeasureOptions,
234
+ endMark?: string,
235
+ ): PerformanceMeasure {
236
+ // IMPORTANT: this method has been micro-optimized.
237
+ // Please run the benchmarks in `Performance-benchmarks-itest` to ensure
238
+ // changes do not regress performance.
239
+
240
+ let resolvedMeasureName: string;
241
+ let resolvedStartTime: number;
242
+ let resolvedDuration: number;
243
+ let resolvedDetail: mixed;
244
+
245
+ if (measureName === undefined) {
246
+ throw new TypeError(
247
+ `Failed to execute 'measure' on 'Performance': 1 argument required, but only 0 present.`,
248
+ );
190
249
  }
191
250
 
192
- let computedStartTime = startTime;
193
- let computedDuration = duration;
194
-
195
- if (NativePerformance?.measureWithResult) {
196
- try {
197
- [computedStartTime, computedDuration] =
198
- NativePerformance.measureWithResult(
199
- measureName,
200
- startTime,
201
- endTime,
202
- duration,
203
- startMarkName,
204
- endMarkName,
205
- );
206
- } catch (error) {
207
- throw new DOMException(
208
- "Failed to execute 'measure' on 'Performance': " + error.message,
209
- 'SyntaxError',
210
- );
251
+ resolvedMeasureName =
252
+ typeof measureName === 'string' ? measureName : String(measureName);
253
+
254
+ if (startMarkOrOptions != null) {
255
+ switch (typeof startMarkOrOptions) {
256
+ case 'object': {
257
+ if (endMark !== undefined) {
258
+ throw new TypeError(
259
+ `Failed to execute 'measure' on 'Performance': If a non-empty PerformanceMeasureOptions object was passed, |end_mark| must not be passed.`,
260
+ );
261
+ }
262
+
263
+ const {start, end, duration, detail} = startMarkOrOptions;
264
+
265
+ let resolvedEndTime;
266
+
267
+ if (
268
+ start !== undefined &&
269
+ end !== undefined &&
270
+ duration !== undefined
271
+ ) {
272
+ throw new TypeError(
273
+ `Failed to execute 'measure' on 'Performance': If a non-empty PerformanceMeasureOptions object was passed, it must not have all of its 'start', 'duration', and 'end' properties defined`,
274
+ );
275
+ }
276
+
277
+ switch (typeof start) {
278
+ case 'undefined': {
279
+ // This will be handled after all options have been processed.
280
+ break;
281
+ }
282
+ case 'number': {
283
+ resolvedStartTime = start;
284
+ break;
285
+ }
286
+ case 'string': {
287
+ resolvedStartTime = getMarkTimeForMeasure(start);
288
+ break;
289
+ }
290
+ default: {
291
+ resolvedStartTime = getMarkTimeForMeasure(String(start));
292
+ }
293
+ }
294
+
295
+ switch (typeof end) {
296
+ case 'undefined': {
297
+ // This will be handled after all options have been processed.
298
+ break;
299
+ }
300
+ case 'number': {
301
+ resolvedEndTime = end;
302
+ break;
303
+ }
304
+ case 'string': {
305
+ resolvedEndTime = getMarkTimeForMeasure(end);
306
+ break;
307
+ }
308
+ default: {
309
+ resolvedEndTime = getMarkTimeForMeasure(String(end));
310
+ }
311
+ }
312
+
313
+ switch (typeof duration) {
314
+ case 'undefined': {
315
+ // This will be handled after all options have been processed.
316
+ break;
317
+ }
318
+ case 'number': {
319
+ resolvedDuration = duration;
320
+ break;
321
+ }
322
+ default: {
323
+ resolvedDuration = Number(duration);
324
+ if (!Number.isFinite(resolvedDuration)) {
325
+ throw new TypeError(
326
+ `Failed to execute 'measure' on 'Performance': Failed to read the 'duration' property from 'PerformanceMeasureOptions': The provided double value is non-finite.`,
327
+ );
328
+ }
329
+ }
330
+ }
331
+
332
+ if (resolvedStartTime === undefined) {
333
+ if (
334
+ resolvedEndTime !== undefined &&
335
+ resolvedDuration !== undefined
336
+ ) {
337
+ resolvedStartTime = resolvedEndTime - resolvedDuration;
338
+ } else {
339
+ resolvedStartTime = 0;
340
+ }
341
+ }
342
+
343
+ if (resolvedDuration === undefined) {
344
+ if (
345
+ resolvedStartTime !== undefined &&
346
+ resolvedEndTime !== undefined
347
+ ) {
348
+ resolvedDuration = resolvedEndTime - resolvedStartTime;
349
+ } else {
350
+ resolvedDuration = getCurrentTimeStamp() - resolvedStartTime;
351
+ }
352
+ }
353
+
354
+ if (detail !== undefined) {
355
+ resolvedDetail = structuredClone(detail);
356
+ }
357
+
358
+ break;
359
+ }
360
+ case 'string': {
361
+ resolvedStartTime = getMarkTimeForMeasure(startMarkOrOptions);
362
+
363
+ if (endMark !== undefined) {
364
+ resolvedDuration =
365
+ getMarkTimeForMeasure(endMark) - resolvedStartTime;
366
+ } else {
367
+ resolvedDuration = getCurrentTimeStamp() - resolvedStartTime;
368
+ }
369
+ break;
370
+ }
371
+ default: {
372
+ resolvedStartTime = getMarkTimeForMeasure(String(startMarkOrOptions));
373
+
374
+ if (endMark !== undefined) {
375
+ resolvedDuration =
376
+ getMarkTimeForMeasure(endMark) - resolvedStartTime;
377
+ } else {
378
+ resolvedDuration = getCurrentTimeStamp() - resolvedStartTime;
379
+ }
380
+ }
211
381
  }
212
382
  } else {
213
- warnNoNativePerformance();
214
- }
383
+ resolvedStartTime = 0;
215
384
 
216
- const measure = new PerformanceMeasure(measureName, {
217
- startTime: computedStartTime,
218
- duration: computedDuration ?? 0,
219
- detail: options?.detail,
220
- });
385
+ if (endMark !== undefined) {
386
+ resolvedDuration = getMarkTimeForMeasure(endMark) - resolvedStartTime;
387
+ } else {
388
+ resolvedDuration = getCurrentTimeStamp() - resolvedStartTime;
389
+ }
390
+ }
221
391
 
222
- return measure;
392
+ // $FlowExpectedError[cannot-write]
393
+ MEASURE_OPTIONS_REUSABLE_OBJECT.name = resolvedMeasureName;
394
+ // $FlowExpectedError[cannot-write]
395
+ MEASURE_OPTIONS_REUSABLE_OBJECT.startTime = resolvedStartTime;
396
+ // $FlowExpectedError[cannot-write]
397
+ MEASURE_OPTIONS_REUSABLE_OBJECT.duration = resolvedDuration;
398
+ // $FlowExpectedError[cannot-write]
399
+ MEASURE_OPTIONS_REUSABLE_OBJECT.detail = resolvedDetail;
400
+
401
+ const entry = new PerformanceMeasure(MEASURE_OPTIONS_REUSABLE_OBJECT);
402
+
403
+ cachedReportMeasure(
404
+ resolvedMeasureName,
405
+ resolvedStartTime,
406
+ resolvedDuration,
407
+ entry,
408
+ );
409
+
410
+ return entry;
223
411
  }
224
412
 
225
413
  clearMeasures(measureName?: string): void {
226
- if (!NativePerformance?.clearMeasures) {
227
- warnNoNativePerformance();
228
- return;
229
- }
230
-
231
- NativePerformance?.clearMeasures(measureName);
414
+ cachedNativeClearMeasures(measureName);
232
415
  }
233
416
 
234
417
  /**
@@ -243,10 +426,6 @@ export default class Performance {
243
426
  * https://www.w3.org/TR/performance-timeline/#extensions-to-the-performance-interface
244
427
  */
245
428
  getEntries(): PerformanceEntryList {
246
- if (!NativePerformance?.getEntries) {
247
- warnNoNativePerformance();
248
- return [];
249
- }
250
429
  return NativePerformance.getEntries().map(rawToPerformanceEntry);
251
430
  }
252
431
 
@@ -259,11 +438,6 @@ export default class Performance {
259
438
  return [];
260
439
  }
261
440
 
262
- if (!NativePerformance?.getEntriesByType) {
263
- warnNoNativePerformance();
264
- return [];
265
- }
266
-
267
441
  return NativePerformance.getEntriesByType(
268
442
  performanceEntryTypeToRaw(entryType),
269
443
  ).map(rawToPerformanceEntry);
@@ -281,11 +455,6 @@ export default class Performance {
281
455
  return [];
282
456
  }
283
457
 
284
- if (!NativePerformance?.getEntriesByName) {
285
- warnNoNativePerformance();
286
- return [];
287
- }
288
-
289
458
  return NativePerformance.getEntriesByName(
290
459
  entryName,
291
460
  entryType != null ? performanceEntryTypeToRaw(entryType) : undefined,
@@ -293,4 +462,16 @@ export default class Performance {
293
462
  }
294
463
  }
295
464
 
465
+ export const Performance_public: typeof Performance =
466
+ /* eslint-disable no-shadow */
467
+ // $FlowExpectedError[incompatible-type]
468
+ function Performance() {
469
+ throw new TypeError(
470
+ "Failed to construct 'Performance': Illegal constructor",
471
+ );
472
+ };
473
+
474
+ // $FlowExpectedError[prop-missing]
475
+ Performance_public.prototype = Performance.prototype;
476
+
296
477
  setPlatformObject(Performance);