@office-iss/react-native-win32 0.0.0-canary.298 → 0.0.0-canary.299

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 (220) hide show
  1. package/.flowconfig +5 -3
  2. package/CHANGELOG.json +28 -1
  3. package/CHANGELOG.md +16 -6
  4. package/IntegrationTests/IntegrationTestsApp.js +1 -0
  5. package/IntegrationTests/LoggingTestModule.js +16 -20
  6. package/IntegrationTests/TimersTest.js +1 -0
  7. package/IntegrationTests/WebSocketTest.js +1 -0
  8. package/Libraries/ActionSheetIOS/NativeActionSheetManager.js +1 -0
  9. package/Libraries/Alert/Alert.js +2 -2
  10. package/Libraries/Alert/NativeAlertManager.js +1 -0
  11. package/Libraries/Alert/RCTAlertManager.android.js +19 -13
  12. package/Libraries/Alert/RCTAlertManager.ios.js +9 -11
  13. package/Libraries/Alert/RCTAlertManager.js +1 -3
  14. package/Libraries/Alert/RCTAlertManager.js.flow +4 -6
  15. package/Libraries/Animated/AnimatedEvent.js +4 -3
  16. package/Libraries/Animated/AnimatedExports.js.flow +5 -0
  17. package/Libraries/Animated/AnimatedImplementation.js +44 -44
  18. package/Libraries/Animated/AnimatedMock.js +2 -2
  19. package/Libraries/Animated/NativeAnimatedModule.js +1 -0
  20. package/Libraries/Animated/NativeAnimatedTurboModule.js +1 -0
  21. package/Libraries/Animated/animations/Animation.js +6 -1
  22. package/Libraries/Animated/components/AnimatedScrollView.js +6 -5
  23. package/Libraries/Animated/components/AnimatedText.js +2 -5
  24. package/Libraries/Animated/components/AnimatedView.js +2 -1
  25. package/Libraries/Animated/createAnimatedComponent.js +2 -4
  26. package/Libraries/Animated/nodes/AnimatedProps.js +2 -7
  27. package/Libraries/AppState/NativeAppState.js +1 -0
  28. package/Libraries/Blob/NativeBlobModule.js +1 -0
  29. package/Libraries/Blob/NativeFileReaderModule.js +1 -0
  30. package/Libraries/Components/AccessibilityInfo/NativeAccessibilityInfo.js +1 -2
  31. package/Libraries/Components/AccessibilityInfo/NativeAccessibilityInfoWin32.js +1 -2
  32. package/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js +1 -2
  33. package/Libraries/Components/ActivityIndicator/ActivityIndicatorViewNativeComponent.js +1 -2
  34. package/Libraries/Components/Button.js +7 -4
  35. package/Libraries/Components/Button.win32.js +7 -4
  36. package/Libraries/Components/Clipboard/NativeClipboard.js +1 -2
  37. package/Libraries/Components/DrawerAndroid/AndroidDrawerLayoutNativeComponent.js +1 -2
  38. package/Libraries/Components/Keyboard/NativeKeyboardObserver.js +1 -2
  39. package/Libraries/Components/Pressable/Pressable.js +8 -2
  40. package/Libraries/Components/Pressable/Pressable.win32.js +8 -8
  41. package/Libraries/Components/ProgressBarAndroid/ProgressBarAndroidNativeComponent.js +1 -2
  42. package/Libraries/Components/RefreshControl/AndroidSwipeRefreshLayoutNativeComponent.js +1 -2
  43. package/Libraries/Components/RefreshControl/PullToRefreshViewNativeComponent.js +1 -0
  44. package/Libraries/Components/SafeAreaView/RCTSafeAreaViewNativeComponent.js +1 -2
  45. package/Libraries/Components/SafeAreaView/SafeAreaView.d.ts +9 -0
  46. package/Libraries/Components/SafeAreaView/SafeAreaView.js +3 -2
  47. package/Libraries/Components/SafeAreaView/SafeAreaView.win32.js +3 -2
  48. package/Libraries/Components/ScrollView/AndroidHorizontalScrollContentViewNativeComponent.js +1 -2
  49. package/Libraries/Components/ScrollView/ScrollView.d.ts +10 -1
  50. package/Libraries/Components/ScrollView/ScrollView.js +3 -1
  51. package/Libraries/Components/Sound/NativeSoundManager.js +1 -2
  52. package/Libraries/Components/StatusBar/NativeStatusBarManagerAndroid.js +1 -2
  53. package/Libraries/Components/StatusBar/NativeStatusBarManagerIOS.js +1 -2
  54. package/Libraries/Components/StatusBar/StatusBar.d.ts +4 -0
  55. package/Libraries/Components/StatusBar/StatusBar.js +5 -0
  56. package/Libraries/Components/Switch/AndroidSwitchNativeComponent.js +1 -2
  57. package/Libraries/Components/Switch/Switch.js +2 -1
  58. package/Libraries/Components/Switch/SwitchNativeComponent.js +1 -2
  59. package/Libraries/Components/TextInput/AndroidTextInputNativeComponent.js +8 -7
  60. package/Libraries/Components/TextInput/RCTInputAccessoryViewNativeComponent.js +1 -2
  61. package/Libraries/Components/TextInput/TextInput.flow.js +1 -1
  62. package/Libraries/Components/TextInput/TextInput.js +2 -4
  63. package/Libraries/Components/TextInput/TextInput.win32.js +28 -3
  64. package/Libraries/Components/ToastAndroid/NativeToastAndroid.js +1 -2
  65. package/Libraries/Components/Touchable/Touchable.js +7 -3
  66. package/Libraries/Components/Touchable/Touchable.win32.js +7 -3
  67. package/Libraries/Components/Touchable/TouchableHighlight.js +5 -1
  68. package/Libraries/Components/Touchable/TouchableNativeFeedback.js +3 -2
  69. package/Libraries/Components/Touchable/TouchableNativeFeedback.win32.js +3 -2
  70. package/Libraries/Components/Touchable/TouchableOpacity.d.ts +1 -0
  71. package/Libraries/Components/Touchable/TouchableOpacity.js +3 -2
  72. package/Libraries/Components/UnimplementedViews/UnimplementedNativeViewNativeComponent.js +1 -2
  73. package/Libraries/Components/View/ReactNativeStyleAttributes.js +6 -15
  74. package/Libraries/Components/View/View.js +17 -18
  75. package/Libraries/Components/View/View.win32.js +16 -2
  76. package/Libraries/Components/View/ViewAccessibility.js +0 -7
  77. package/Libraries/Components/View/ViewAccessibility.win32.js +0 -7
  78. package/Libraries/Components/View/ViewPropTypes.d.ts +4 -0
  79. package/Libraries/Components/View/ViewPropTypes.js +8 -0
  80. package/Libraries/Components/View/ViewPropTypes.win32.js +8 -0
  81. package/Libraries/Core/ExceptionsManager.js +28 -15
  82. package/Libraries/Core/NativeExceptionsManager.js +1 -0
  83. package/Libraries/Core/ReactNativeVersion.js +1 -1
  84. package/Libraries/Core/SegmentFetcher/NativeSegmentFetcher.js +1 -0
  85. package/Libraries/Core/Timers/NativeTiming.js +1 -0
  86. package/Libraries/Core/checkNativeVersion.js +1 -0
  87. package/Libraries/Core/setUpReactDevTools.js +21 -4
  88. package/Libraries/Debugging/DebuggingOverlayNativeComponent.js +1 -0
  89. package/Libraries/EventEmitter/NativeEventEmitter.js +3 -3
  90. package/Libraries/Image/Image.android.js +3 -3
  91. package/Libraries/Image/ImageSource.d.ts +5 -0
  92. package/Libraries/Image/ImageViewNativeComponent.js +3 -3
  93. package/Libraries/Image/NativeImageEditor.js +1 -0
  94. package/Libraries/Image/NativeImageLoaderAndroid.js +1 -0
  95. package/Libraries/Image/NativeImageLoaderIOS.js +1 -0
  96. package/Libraries/Image/NativeImageLoaderWin32.js +1 -0
  97. package/Libraries/Image/NativeImageStoreAndroid.js +1 -0
  98. package/Libraries/Image/NativeImageStoreIOS.js +1 -0
  99. package/Libraries/Image/RelativeImageStub.js +1 -1
  100. package/Libraries/Image/TextInlineImageNativeComponent.js +3 -3
  101. package/Libraries/Interaction/InteractionManager.js +6 -1
  102. package/Libraries/Interaction/NativeFrameRateLogger.js +1 -0
  103. package/Libraries/Interaction/TaskQueue.js +14 -0
  104. package/Libraries/LayoutAnimation/LayoutAnimation.js +12 -8
  105. package/Libraries/Linking/NativeIntentAndroid.js +1 -0
  106. package/Libraries/Linking/NativeLinkingManager.js +1 -0
  107. package/Libraries/Lists/FlatList.js +5 -6
  108. package/Libraries/Lists/SectionList.js +4 -4
  109. package/Libraries/Lists/VirtualizedList.js +3 -2
  110. package/Libraries/LogBox/Data/LogBoxData.js +7 -4
  111. package/Libraries/LogBox/LogBox.js +72 -101
  112. package/Libraries/Modal/Modal.d.ts +8 -2
  113. package/Libraries/Modal/Modal.js +19 -2
  114. package/Libraries/Modal/NativeModalManager.js +1 -0
  115. package/Libraries/Modal/RCTModalHostViewNativeComponent.js +1 -0
  116. package/Libraries/NativeComponent/BaseViewConfig.android.js +6 -15
  117. package/Libraries/NativeComponent/BaseViewConfig.ios.js +6 -15
  118. package/Libraries/NativeComponent/BaseViewConfig.win32.js +6 -15
  119. package/Libraries/NativeModules/specs/NativeDevMenu.js +1 -0
  120. package/Libraries/NativeModules/specs/NativeDevSettings.js +1 -0
  121. package/Libraries/NativeModules/specs/NativeDeviceEventManager.js +1 -0
  122. package/Libraries/NativeModules/specs/NativeDialogManagerAndroid.js +1 -0
  123. package/Libraries/NativeModules/specs/NativeLogBox.js +1 -0
  124. package/Libraries/NativeModules/specs/NativeRedBox.js +1 -0
  125. package/Libraries/NativeModules/specs/NativeSourceCode.js +1 -0
  126. package/Libraries/Network/NativeNetworkingAndroid.js +1 -0
  127. package/Libraries/Network/NativeNetworkingIOS.js +1 -0
  128. package/Libraries/Network/XMLHttpRequest.js +2 -0
  129. package/Libraries/PermissionsAndroid/NativePermissionsAndroid.js +1 -0
  130. package/Libraries/PermissionsAndroid/PermissionsAndroid.js +3 -2
  131. package/Libraries/PushNotificationIOS/NativePushNotificationManagerIOS.js +1 -0
  132. package/Libraries/ReactNative/AppRegistry.flow.js +2 -2
  133. package/Libraries/ReactNative/AppRegistryImpl.js +0 -10
  134. package/Libraries/ReactNative/BridgelessUIManager.js +1 -1
  135. package/Libraries/ReactNative/NativeHeadlessJsTaskSupport.js +1 -0
  136. package/Libraries/ReactNative/NativeI18nManager.js +1 -0
  137. package/Libraries/ReactNative/NativeUIManager.js +1 -0
  138. package/Libraries/ReactNative/ReactFabricPublicInstance/ReactNativeAttributePayload.js +80 -61
  139. package/Libraries/ReactPrivate/ReactNativePrivateInterface.js +1 -1
  140. package/Libraries/ReactPrivate/ReactNativePrivateInterface.js.flow +2 -2
  141. package/Libraries/Renderer/implementations/ReactFabric-dev.js +3 -1
  142. package/Libraries/Renderer/implementations/ReactFabric-prod.js +3 -1
  143. package/Libraries/Renderer/implementations/ReactFabric-profiling.js +3 -1
  144. package/Libraries/Renderer/shims/ReactNativeTypes.js +3 -12
  145. package/Libraries/Renderer/shims/ReactNativeTypes.win32.js +3 -12
  146. package/Libraries/Settings/NativeSettingsManager.js +1 -0
  147. package/Libraries/Share/NativeShareModule.js +1 -0
  148. package/Libraries/StyleSheet/StyleSheet.js +1 -0
  149. package/Libraries/StyleSheet/processAspectRatio.js +2 -0
  150. package/Libraries/Text/Text.js +4 -6
  151. package/Libraries/Text/TextAncestor.js +3 -10
  152. package/Libraries/Text/TextAncestorContext.js +23 -0
  153. package/Libraries/Text/TextProps.js +2 -2
  154. package/Libraries/Text/TextProps.win32.js +2 -2
  155. package/Libraries/TurboModule/samples/NativeSampleTurboModule.js +1 -0
  156. package/Libraries/Types/CodegenTypesNamespace.js +1 -0
  157. package/Libraries/Utilities/HMRClient.js +12 -2
  158. package/Libraries/Utilities/NativeAppearance.js +1 -0
  159. package/Libraries/Utilities/NativeDevLoadingView.js +1 -0
  160. package/Libraries/Utilities/NativeDeviceInfo.js +1 -2
  161. package/Libraries/Utilities/NativePlatformConstantsAndroid.js +1 -0
  162. package/Libraries/Utilities/NativePlatformConstantsIOS.js +1 -0
  163. package/Libraries/Utilities/NativePlatformConstantsWin.js +1 -0
  164. package/Libraries/Utilities/Platform.android.js +1 -4
  165. package/Libraries/Utilities/Platform.ios.js +1 -4
  166. package/Libraries/Utilities/Platform.js.flow +2 -2
  167. package/Libraries/Utilities/Platform.win32.js +1 -4
  168. package/Libraries/Utilities/PlatformTypes.js +1 -1
  169. package/Libraries/Utilities/codegenNativeCommands.js +4 -2
  170. package/Libraries/Utilities/codegenNativeComponent.js +3 -3
  171. package/Libraries/Utilities/createPerformanceLogger.js +32 -0
  172. package/Libraries/Vibration/NativeVibration.js +1 -0
  173. package/Libraries/WebSocket/NativeWebSocketModule.js +1 -0
  174. package/Libraries/vendor/emitter/EventEmitter.js +6 -6
  175. package/index.js +21 -0
  176. package/index.win32.js +12 -1
  177. package/jest/setup.js +1 -0
  178. package/overrides.json +25 -25
  179. package/package.json +11 -11
  180. package/src/private/animated/createAnimatedPropsHook.js +4 -1
  181. package/src/private/animated/createAnimatedPropsMemoHook.js +2 -2
  182. package/src/private/components/virtualview/VirtualView.js +145 -0
  183. package/src/private/components/virtualview/VirtualViewNativeComponent.js +90 -0
  184. package/src/private/featureflags/ReactNativeFeatureFlags.js +43 -23
  185. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +9 -5
  186. package/src/private/setup/setUpPerformanceObserver.js +7 -0
  187. package/src/private/specs_DEPRECATED/components/ActivityIndicatorViewNativeComponent.js +7 -4
  188. package/src/private/specs_DEPRECATED/components/AndroidDrawerLayoutNativeComponent.js +3 -3
  189. package/src/private/specs_DEPRECATED/components/AndroidHorizontalScrollContentViewNativeComponent.js +3 -3
  190. package/src/private/specs_DEPRECATED/components/AndroidSwipeRefreshLayoutNativeComponent.js +3 -3
  191. package/src/private/specs_DEPRECATED/components/AndroidSwitchNativeComponent.js +10 -7
  192. package/src/private/specs_DEPRECATED/components/DebuggingOverlayNativeComponent.js +5 -4
  193. package/src/private/specs_DEPRECATED/components/ProgressBarAndroidNativeComponent.js +7 -4
  194. package/src/private/specs_DEPRECATED/components/PullToRefreshViewNativeComponent.js +9 -6
  195. package/src/private/specs_DEPRECATED/components/RCTInputAccessoryViewNativeComponent.js +9 -6
  196. package/src/private/specs_DEPRECATED/components/RCTModalHostViewNativeComponent.js +14 -5
  197. package/src/private/specs_DEPRECATED/components/RCTSafeAreaViewNativeComponent.js +8 -5
  198. package/src/private/specs_DEPRECATED/components/SwitchNativeComponent.js +5 -5
  199. package/src/private/specs_DEPRECATED/components/UnimplementedNativeViewNativeComponent.js +3 -3
  200. package/src/private/specs_DEPRECATED/modules/NativeDeviceInfo.js +1 -0
  201. package/src/private/specs_DEPRECATED/modules/NativeUIManager.js +9 -6
  202. package/src/private/styles/composeStyles.js +5 -12
  203. package/src/private/webapis/errors/DOMException.js +1 -1
  204. package/src/private/webapis/idlecallbacks/specs/NativeIdleCallbacks.js +4 -2
  205. package/src/private/webapis/intersectionobserver/IntersectionObserver.js +12 -7
  206. package/src/private/webapis/intersectionobserver/internals/IntersectionObserverManager.js +13 -0
  207. package/src/private/webapis/intersectionobserver/specs/NativeIntersectionObserver.js +2 -1
  208. package/src/private/webapis/performance/Performance.js +164 -61
  209. package/src/private/webapis/performance/PerformanceEntry.js +20 -16
  210. package/src/private/webapis/performance/PerformanceObserver.js +31 -27
  211. package/src/private/webapis/performance/ResourceTiming.js +108 -0
  212. package/src/private/webapis/performance/UserTiming.js +60 -8
  213. package/src/private/webapis/performance/internals/RawPerformanceEntry.js +47 -32
  214. package/src/private/webapis/performance/specs/NativePerformance.js +13 -1
  215. package/src-win/Libraries/Components/View/ViewPropTypes.d.ts +4 -0
  216. package/Libraries/BugReporting/BugReporting.js +0 -140
  217. package/Libraries/BugReporting/NativeBugReporting.js +0 -13
  218. package/Libraries/BugReporting/dumpReactTree.js +0 -151
  219. package/Libraries/BugReporting/getReactData.js +0 -187
  220. package/src/private/specs_DEPRECATED/modules/NativeBugReporting.js +0 -20
@@ -18,6 +18,7 @@ import type {
18
18
  import type {DetailType, PerformanceMarkOptions} from './UserTiming';
19
19
 
20
20
  import DOMException from '../errors/DOMException';
21
+ import structuredClone from '../structuredClone/structuredClone';
21
22
  import {setPlatformObject} from '../webidl/PlatformObjects';
22
23
  import {EventCounts} from './EventTiming';
23
24
  import {
@@ -38,12 +39,17 @@ declare var global: {
38
39
  const getCurrentTimeStamp: () => DOMHighResTimeStamp =
39
40
  NativePerformance?.now ?? global.nativePerformanceNow ?? (() => Date.now());
40
41
 
41
- export type PerformanceMeasureOptions = {
42
- detail?: DetailType,
43
- start?: DOMHighResTimeStamp,
44
- duration?: DOMHighResTimeStamp,
45
- end?: DOMHighResTimeStamp,
46
- };
42
+ export type PerformanceMeasureOptions =
43
+ | {
44
+ detail?: DetailType,
45
+ start?: DOMHighResTimeStamp | string,
46
+ duration?: DOMHighResTimeStamp,
47
+ }
48
+ | {
49
+ detail?: DetailType,
50
+ start?: DOMHighResTimeStamp | string,
51
+ end?: DOMHighResTimeStamp | string,
52
+ };
47
53
 
48
54
  const ENTRY_TYPES_AVAILABLE_FROM_TIMELINE: $ReadOnlyArray<PerformanceEntryType> =
49
55
  ['mark', 'measure'];
@@ -111,11 +117,39 @@ export default class Performance {
111
117
  markName: string,
112
118
  markOptions?: PerformanceMarkOptions,
113
119
  ): PerformanceMark {
120
+ if (markName == null) {
121
+ throw new TypeError(
122
+ `Failed to execute 'mark' on 'Performance': 1 argument required, but only 0 present.`,
123
+ );
124
+ }
125
+
126
+ let resolvedDetail;
127
+ if (markOptions?.detail != null) {
128
+ resolvedDetail = structuredClone(markOptions.detail);
129
+ }
130
+
114
131
  let computedStartTime;
115
132
  if (NativePerformance?.markWithResult) {
133
+ let resolvedStartTime;
134
+
135
+ const startTime = markOptions?.startTime;
136
+ if (startTime !== undefined) {
137
+ resolvedStartTime = Number(startTime);
138
+ if (resolvedStartTime < 0) {
139
+ throw new TypeError(
140
+ `Failed to execute 'mark' on 'Performance': '${markName}' cannot have a negative start time.`,
141
+ );
142
+ } else if (!Number.isFinite(resolvedStartTime)) {
143
+ throw new TypeError(
144
+ `Failed to execute 'mark' on 'Performance': Failed to read the 'startTime' property from 'PerformanceMarkOptions': The provided double value is non-finite.`,
145
+ );
146
+ }
147
+ }
148
+
149
+ // $FlowExpectedError[not-a-function]
116
150
  computedStartTime = NativePerformance.markWithResult(
117
151
  markName,
118
- markOptions?.startTime,
152
+ resolvedStartTime,
119
153
  );
120
154
  } else {
121
155
  warnNoNativePerformance();
@@ -124,7 +158,7 @@ export default class Performance {
124
158
 
125
159
  return new PerformanceMark(markName, {
126
160
  startTime: computedStartTime,
127
- detail: markOptions?.detail,
161
+ detail: resolvedDetail,
128
162
  });
129
163
  }
130
164
 
@@ -142,66 +176,135 @@ export default class Performance {
142
176
  startMarkOrOptions?: string | PerformanceMeasureOptions,
143
177
  endMark?: string,
144
178
  ): 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) {
158
- throw new TypeError(
159
- "Performance.measure: Can't have both options and endMark",
160
- );
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
171
- ) {
172
- throw new TypeError(
173
- "Performance.measure: Can't have both start/end and duration explicitly in options",
174
- );
179
+ let resolvedStartTime: number | void;
180
+ let resolvedStartMark: string | void;
181
+ let resolvedEndTime: number | void;
182
+ let resolvedEndMark: string | void;
183
+ let resolvedDuration: number | void;
184
+ let resolvedDetail: mixed;
185
+
186
+ if (startMarkOrOptions != null) {
187
+ switch (typeof startMarkOrOptions) {
188
+ case 'object': {
189
+ if (endMark != null) {
190
+ throw new TypeError(
191
+ `Failed to execute 'measure' on 'Performance': If a non-empty PerformanceMeasureOptions object was passed, |end_mark| must not be passed.`,
192
+ );
193
+ }
194
+
195
+ const start = startMarkOrOptions.start;
196
+ switch (typeof start) {
197
+ case 'number': {
198
+ resolvedStartTime = start;
199
+ break;
200
+ }
201
+ case 'string': {
202
+ resolvedStartMark = start;
203
+ break;
204
+ }
205
+ case 'undefined': {
206
+ break;
207
+ }
208
+ default: {
209
+ resolvedStartMark = String(start);
210
+ }
211
+ }
212
+
213
+ const end = startMarkOrOptions.end;
214
+ switch (typeof end) {
215
+ case 'number': {
216
+ resolvedEndTime = end;
217
+ break;
218
+ }
219
+ case 'string': {
220
+ resolvedEndMark = end;
221
+ break;
222
+ }
223
+ case 'undefined': {
224
+ break;
225
+ }
226
+ default: {
227
+ resolvedEndMark = String(end);
228
+ }
229
+ }
230
+
231
+ const duration = startMarkOrOptions.duration;
232
+ switch (typeof duration) {
233
+ case 'number': {
234
+ resolvedDuration = duration;
235
+ break;
236
+ }
237
+ case 'undefined':
238
+ break;
239
+ default: {
240
+ resolvedDuration = Number(duration);
241
+ if (!Number.isFinite(resolvedDuration)) {
242
+ throw new TypeError(
243
+ `Failed to execute 'measure' on 'Performance': Failed to read the 'duration' property from 'PerformanceMeasureOptions': The provided double value is non-finite.`,
244
+ );
245
+ }
246
+ }
247
+ }
248
+
249
+ if (
250
+ resolvedDuration != null &&
251
+ (resolvedEndMark != null || resolvedEndTime != null)
252
+ ) {
253
+ throw new TypeError(
254
+ `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`,
255
+ );
256
+ }
257
+
258
+ const detail = startMarkOrOptions.detail;
259
+ if (detail != null) {
260
+ resolvedDetail = structuredClone(detail);
261
+ }
262
+
263
+ break;
264
+ }
265
+ case 'string': {
266
+ resolvedStartMark = startMarkOrOptions;
267
+
268
+ if (endMark !== undefined) {
269
+ resolvedEndMark = String(endMark);
270
+ }
271
+ break;
272
+ }
273
+ default: {
274
+ resolvedStartMark = String(startMarkOrOptions);
275
+ }
175
276
  }
176
-
177
- if (typeof options.start === 'number') {
178
- startTime = options.start;
179
- } else {
180
- startMarkName = options.start;
181
- }
182
-
183
- if (typeof options.end === 'number') {
184
- endTime = options.end;
185
- } else {
186
- endMarkName = options.end;
187
- }
188
-
189
- duration = options.duration ?? duration;
190
277
  }
191
278
 
192
- let computedStartTime = startTime;
193
- let computedDuration = duration;
279
+ let computedStartTime = 0;
280
+ let computedDuration = 0;
194
281
 
195
- if (NativePerformance?.measureWithResult) {
282
+ if (NativePerformance?.measure) {
283
+ try {
284
+ [computedStartTime, computedDuration] = NativePerformance.measure(
285
+ measureName,
286
+ resolvedStartTime,
287
+ resolvedEndTime,
288
+ resolvedDuration,
289
+ resolvedStartMark,
290
+ resolvedEndMark,
291
+ );
292
+ } catch (error) {
293
+ throw new DOMException(
294
+ "Failed to execute 'measure' on 'Performance': " + error.message,
295
+ 'SyntaxError',
296
+ );
297
+ }
298
+ } else if (NativePerformance?.measureWithResult) {
196
299
  try {
197
300
  [computedStartTime, computedDuration] =
198
301
  NativePerformance.measureWithResult(
199
302
  measureName,
200
- startTime,
201
- endTime,
202
- duration,
203
- startMarkName,
204
- endMarkName,
303
+ resolvedStartTime ?? 0,
304
+ resolvedEndTime ?? 0,
305
+ resolvedDuration,
306
+ resolvedStartMark,
307
+ resolvedEndMark,
205
308
  );
206
309
  } catch (error) {
207
310
  throw new DOMException(
@@ -216,7 +319,7 @@ export default class Performance {
216
319
  const measure = new PerformanceMeasure(measureName, {
217
320
  startTime: computedStartTime,
218
321
  duration: computedDuration ?? 0,
219
- detail: options?.detail,
322
+ detail: resolvedDetail,
220
323
  });
221
324
 
222
325
  return measure;
@@ -29,10 +29,14 @@ export type PerformanceEntryJSON = {
29
29
  };
30
30
 
31
31
  export class PerformanceEntry {
32
- #name: string;
33
- #entryType: PerformanceEntryType;
34
- #startTime: DOMHighResTimeStamp;
35
- #duration: DOMHighResTimeStamp;
32
+ // We don't use private fields because they're significantly slower to
33
+ // initialize on construction and to access.
34
+ // We also need these to be protected so they can be initialized in subclasses
35
+ // where we avoid calling `super()` for performance reasons.
36
+ __name: string;
37
+ __entryType: PerformanceEntryType;
38
+ __startTime: DOMHighResTimeStamp;
39
+ __duration: DOMHighResTimeStamp;
36
40
 
37
41
  constructor(init: {
38
42
  name: string,
@@ -40,34 +44,34 @@ export class PerformanceEntry {
40
44
  startTime: DOMHighResTimeStamp,
41
45
  duration: DOMHighResTimeStamp,
42
46
  }) {
43
- this.#name = init.name;
44
- this.#entryType = init.entryType;
45
- this.#startTime = init.startTime;
46
- this.#duration = init.duration;
47
+ this.__name = init.name;
48
+ this.__entryType = init.entryType;
49
+ this.__startTime = init.startTime;
50
+ this.__duration = init.duration;
47
51
  }
48
52
 
49
53
  get name(): string {
50
- return this.#name;
54
+ return this.__name;
51
55
  }
52
56
 
53
57
  get entryType(): PerformanceEntryType {
54
- return this.#entryType;
58
+ return this.__entryType;
55
59
  }
56
60
 
57
61
  get startTime(): DOMHighResTimeStamp {
58
- return this.#startTime;
62
+ return this.__startTime;
59
63
  }
60
64
 
61
65
  get duration(): DOMHighResTimeStamp {
62
- return this.#duration;
66
+ return this.__duration;
63
67
  }
64
68
 
65
69
  toJSON(): PerformanceEntryJSON {
66
70
  return {
67
- name: this.#name,
68
- entryType: this.#entryType,
69
- startTime: this.#startTime,
70
- duration: this.#duration,
71
+ name: this.__name,
72
+ entryType: this.__entryType,
73
+ startTime: this.__startTime,
74
+ duration: this.__duration,
71
75
  };
72
76
  }
73
77
  }
@@ -23,6 +23,7 @@ import {
23
23
  } from './internals/RawPerformanceEntry';
24
24
  import {warnNoNativePerformance} from './internals/Utilities';
25
25
  import NativePerformance from './specs/NativePerformance';
26
+ import nullthrows from 'nullthrows';
26
27
 
27
28
  export {PerformanceEntry} from './PerformanceEntry';
28
29
 
@@ -130,14 +131,16 @@ export class PerformanceObserver {
130
131
  this.#nativeObserverHandle = this.#createNativeObserver();
131
132
  }
132
133
 
134
+ const observerHandle = nullthrows(this.#nativeObserverHandle);
135
+
133
136
  if (options.entryTypes) {
134
137
  this.#type = 'multiple';
135
- NativePerformance.observe?.(this.#nativeObserverHandle, {
138
+ NativePerformance.observe?.(observerHandle, {
136
139
  entryTypes: options.entryTypes.map(performanceEntryTypeToRaw),
137
140
  });
138
141
  } else if (options.type) {
139
142
  this.#type = 'single';
140
- NativePerformance.observe?.(this.#nativeObserverHandle, {
143
+ NativePerformance.observe?.(observerHandle, {
141
144
  type: performanceEntryTypeToRaw(options.type),
142
145
  buffered: options.buffered,
143
146
  durationThreshold: options.durationThreshold,
@@ -158,37 +161,38 @@ export class PerformanceObserver {
158
161
  NativePerformance.disconnect(this.#nativeObserverHandle);
159
162
  }
160
163
 
161
- #createNativeObserver(): OpaqueNativeObserverHandle {
164
+ #createNativeObserver(): OpaqueNativeObserverHandle | null {
162
165
  if (!NativePerformance || !NativePerformance.createObserver) {
163
166
  warnNoNativePerformance();
164
- return;
167
+ return null;
165
168
  }
166
169
 
167
170
  this.#calledAtLeastOnce = false;
168
171
 
169
- return NativePerformance.createObserver(() => {
170
- const rawEntries = NativePerformance.takeRecords?.(
171
- this.#nativeObserverHandle,
172
- true, // sort records
173
- );
174
- if (!rawEntries) {
175
- return;
176
- }
177
-
178
- const entries = rawEntries.map(rawToPerformanceEntry);
179
- const entryList = new PerformanceObserverEntryList(entries);
180
-
181
- let droppedEntriesCount = 0;
182
- if (!this.#calledAtLeastOnce) {
183
- droppedEntriesCount =
184
- NativePerformance.getDroppedEntriesCount?.(
185
- this.#nativeObserverHandle,
186
- ) ?? 0;
187
- this.#calledAtLeastOnce = true;
188
- }
189
-
190
- this.#callback(entryList, this, {droppedEntriesCount});
191
- });
172
+ const observerHandle: OpaqueNativeObserverHandle =
173
+ NativePerformance.createObserver(() => {
174
+ const rawEntries = NativePerformance.takeRecords?.(
175
+ observerHandle,
176
+ true, // sort records
177
+ );
178
+ if (!rawEntries) {
179
+ return;
180
+ }
181
+
182
+ const entries = rawEntries.map(rawToPerformanceEntry);
183
+ const entryList = new PerformanceObserverEntryList(entries);
184
+
185
+ let droppedEntriesCount = 0;
186
+ if (!this.#calledAtLeastOnce) {
187
+ droppedEntriesCount =
188
+ NativePerformance.getDroppedEntriesCount?.(observerHandle) ?? 0;
189
+ this.#calledAtLeastOnce = true;
190
+ }
191
+
192
+ this.#callback(entryList, this, {droppedEntriesCount});
193
+ });
194
+
195
+ return observerHandle;
192
196
  }
193
197
 
194
198
  #validateObserveOptions(options: PerformanceObserverInit): void {
@@ -0,0 +1,108 @@
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
+ * @format
8
+ * @flow strict
9
+ */
10
+
11
+ // flowlint unsafe-getters-setters:off
12
+
13
+ import type {
14
+ DOMHighResTimeStamp,
15
+ PerformanceEntryJSON,
16
+ } from './PerformanceEntry';
17
+
18
+ import {PerformanceEntry} from './PerformanceEntry';
19
+
20
+ export type PerformanceResourceTimingJSON = {
21
+ ...PerformanceEntryJSON,
22
+ fetchStart: DOMHighResTimeStamp,
23
+ requestStart: DOMHighResTimeStamp,
24
+ connectStart: DOMHighResTimeStamp,
25
+ connectEnd: DOMHighResTimeStamp,
26
+ responseStart: DOMHighResTimeStamp,
27
+ responseEnd: DOMHighResTimeStamp,
28
+ responseStatus: ?number,
29
+ ...
30
+ };
31
+
32
+ export class PerformanceResourceTiming extends PerformanceEntry {
33
+ #fetchStart: DOMHighResTimeStamp;
34
+ #requestStart: DOMHighResTimeStamp;
35
+ #connectStart: DOMHighResTimeStamp;
36
+ #connectEnd: DOMHighResTimeStamp;
37
+ #responseStart: DOMHighResTimeStamp;
38
+ #responseEnd: DOMHighResTimeStamp;
39
+ #responseStatus: ?number;
40
+
41
+ constructor(init: {
42
+ name: string,
43
+ startTime: DOMHighResTimeStamp,
44
+ duration: DOMHighResTimeStamp,
45
+ fetchStart: DOMHighResTimeStamp,
46
+ requestStart: DOMHighResTimeStamp,
47
+ connectStart: DOMHighResTimeStamp,
48
+ connectEnd: DOMHighResTimeStamp,
49
+ responseStart: DOMHighResTimeStamp,
50
+ responseEnd: DOMHighResTimeStamp,
51
+ responseStatus?: number,
52
+ }) {
53
+ super({
54
+ name: init.name,
55
+ entryType: 'resource',
56
+ startTime: init.startTime,
57
+ duration: init.duration,
58
+ });
59
+ this.#fetchStart = init.fetchStart;
60
+ this.#requestStart = init.requestStart;
61
+ this.#connectStart = init.connectStart;
62
+ this.#connectEnd = init.connectEnd;
63
+ this.#responseStart = init.responseStart;
64
+ this.#responseEnd = init.responseEnd;
65
+ this.#responseStatus = init.responseStatus;
66
+ }
67
+
68
+ get fetchStart(): DOMHighResTimeStamp {
69
+ return this.#fetchStart;
70
+ }
71
+
72
+ get requestStart(): DOMHighResTimeStamp {
73
+ return this.#requestStart;
74
+ }
75
+
76
+ get connectStart(): DOMHighResTimeStamp {
77
+ return this.#connectStart;
78
+ }
79
+
80
+ get connectEnd(): DOMHighResTimeStamp {
81
+ return this.#connectEnd;
82
+ }
83
+
84
+ get responseStart(): DOMHighResTimeStamp {
85
+ return this.#responseStart;
86
+ }
87
+
88
+ get responseEnd(): DOMHighResTimeStamp {
89
+ return this.#responseEnd;
90
+ }
91
+
92
+ get responseStatus(): ?number {
93
+ return this.#responseStatus;
94
+ }
95
+
96
+ toJSON(): PerformanceResourceTimingJSON {
97
+ return {
98
+ ...super.toJSON(),
99
+ fetchStart: this.#fetchStart,
100
+ requestStart: this.#requestStart,
101
+ connectStart: this.#connectStart,
102
+ connectEnd: this.#connectEnd,
103
+ responseStart: this.#responseStart,
104
+ responseEnd: this.#responseEnd,
105
+ responseStatus: this.#responseStatus,
106
+ };
107
+ }
108
+ }
@@ -29,9 +29,12 @@ export type PerformanceMeasureInit = {
29
29
  duration: DOMHighResTimeStamp,
30
30
  };
31
31
 
32
- export class PerformanceMark extends PerformanceEntry {
33
- #detail: DetailType;
32
+ class PerformanceMarkTemplate extends PerformanceEntry {
33
+ // We don't use private fields because they're significantly slower to
34
+ // initialize on construction and to access.
35
+ _detail: DetailType;
34
36
 
37
+ // This constructor isn't really used. See `PerformanceMark` below.
35
38
  constructor(markName: string, markOptions?: PerformanceMarkOptions) {
36
39
  super({
37
40
  name: markName,
@@ -41,18 +44,46 @@ export class PerformanceMark extends PerformanceEntry {
41
44
  });
42
45
 
43
46
  if (markOptions) {
44
- this.#detail = markOptions.detail;
47
+ this._detail = markOptions.detail;
45
48
  }
46
49
  }
47
50
 
48
51
  get detail(): DetailType {
49
- return this.#detail;
52
+ return this._detail;
50
53
  }
51
54
  }
52
55
 
53
- export class PerformanceMeasure extends PerformanceEntry {
54
- #detail: DetailType;
56
+ // This is the real value we're exporting where we define the class a function
57
+ // so we don't need to call `super()` and we can avoid the performance penalty
58
+ // of the current code transpiled with Babel.
59
+ // We should remove this when we have built-in support for classes in the
60
+ // runtime.
61
+ export const PerformanceMark: typeof PerformanceMarkTemplate =
62
+ // $FlowExpectedError[incompatible-type]
63
+ function PerformanceMark(
64
+ this: PerformanceMarkTemplate,
65
+ markName: string,
66
+ markOptions?: PerformanceMarkOptions,
67
+ ) {
68
+ this.__name = markName;
69
+ this.__entryType = 'mark';
70
+ this.__startTime = markOptions?.startTime ?? performance.now();
71
+ this.__duration = 0;
55
72
 
73
+ if (markOptions) {
74
+ this._detail = markOptions.detail;
75
+ }
76
+ };
77
+
78
+ // $FlowExpectedError[prop-missing]
79
+ PerformanceMark.prototype = PerformanceMarkTemplate.prototype;
80
+
81
+ class PerformanceMeasureTemplate extends PerformanceEntry {
82
+ // We don't use private fields because they're significantly slower to
83
+ // initialize on construction and to access.
84
+ _detail: DetailType;
85
+
86
+ // This constructor isn't really used. See `PerformanceMeasure` below.
56
87
  constructor(measureName: string, measureOptions: PerformanceMeasureInit) {
57
88
  super({
58
89
  name: measureName,
@@ -62,11 +93,32 @@ export class PerformanceMeasure extends PerformanceEntry {
62
93
  });
63
94
 
64
95
  if (measureOptions) {
65
- this.#detail = measureOptions.detail;
96
+ this._detail = measureOptions.detail;
66
97
  }
67
98
  }
68
99
 
69
100
  get detail(): DetailType {
70
- return this.#detail;
101
+ return this._detail;
71
102
  }
72
103
  }
104
+
105
+ // We do the same here as we do for `PerformanceMark` for performance reasons.
106
+ export const PerformanceMeasure: typeof PerformanceMeasureTemplate =
107
+ // $FlowExpectedError[incompatible-type]
108
+ function PerformanceMeasure(
109
+ this: PerformanceMeasureTemplate,
110
+ measureName: string,
111
+ measureOptions: PerformanceMeasureInit,
112
+ ) {
113
+ this.__name = measureName;
114
+ this.__entryType = 'measure';
115
+ this.__startTime = measureOptions.startTime;
116
+ this.__duration = measureOptions.duration;
117
+
118
+ if (measureOptions) {
119
+ this._detail = measureOptions.detail;
120
+ }
121
+ };
122
+
123
+ // $FlowExpectedError[prop-missing]
124
+ PerformanceMeasure.prototype = PerformanceMeasureTemplate.prototype;