From 2680198b09e35f92a5338bae72b7c26fa82ca028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Mon, 22 Jul 2024 04:45:02 -0700 Subject: [PATCH] Use the right interfaces for PerformanceLongTaskTiming (#45526) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45526 Changelog: [internal] Just using the right interfaces so we can expose them in the global scope and do refinements as necessary using `instanceof`. Reviewed By: rshest Differential Revision: D59911144 fbshipit-source-id: 9779e3220f2c6f81955f54506f97142f0f4ffdd4 --- .../private/webapis/performance/LongTasks.js | 39 +++++++++++++++++++ .../performance/RawPerformanceEntry.js | 8 ++++ 2 files changed, 47 insertions(+) create mode 100644 packages/react-native/src/private/webapis/performance/LongTasks.js diff --git a/packages/react-native/src/private/webapis/performance/LongTasks.js b/packages/react-native/src/private/webapis/performance/LongTasks.js new file mode 100644 index 00000000000..20164b7fc32 --- /dev/null +++ b/packages/react-native/src/private/webapis/performance/LongTasks.js @@ -0,0 +1,39 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow strict + */ + +// flowlint unsafe-getters-setters:off + +import type {PerformanceEntryJSON} from './PerformanceEntry'; + +import {PerformanceEntry} from './PerformanceEntry'; + +export type PerformanceLongTaskTimingJSON = { + ...PerformanceEntryJSON, + attribution: $ReadOnlyArray, + ... +}; + +export class TaskAttributionTiming extends PerformanceEntry {} + +const EMPTY_ATTRIBUTION: $ReadOnlyArray = + Object.preventExtensions([]); + +export class PerformanceLongTaskTiming extends PerformanceEntry { + get attribution(): $ReadOnlyArray { + return EMPTY_ATTRIBUTION; + } + + toJSON(): PerformanceLongTaskTimingJSON { + return { + ...super.toJSON(), + attribution: this.attribution, + }; + } +} diff --git a/packages/react-native/src/private/webapis/performance/RawPerformanceEntry.js b/packages/react-native/src/private/webapis/performance/RawPerformanceEntry.js index 843886f19a3..5ccedba8e0c 100644 --- a/packages/react-native/src/private/webapis/performance/RawPerformanceEntry.js +++ b/packages/react-native/src/private/webapis/performance/RawPerformanceEntry.js @@ -14,6 +14,7 @@ import type { RawPerformanceEntryType, } from './specs/NativePerformanceObserver'; +import {PerformanceLongTaskTiming} from './LongTasks'; import {PerformanceEntry} from './PerformanceEntry'; import PerformanceEventTiming from './PerformanceEventTiming'; import {PerformanceMark, PerformanceMeasure} from './UserTiming'; @@ -37,6 +38,13 @@ export function rawToPerformanceEntry( processingEnd: entry.processingEnd, interactionId: entry.interactionId, }); + } else if (entry.entryType === RawPerformanceEntryTypeValues.LONGTASK) { + return new PerformanceLongTaskTiming({ + name: entry.name, + entryType: rawToPerformanceEntryType(entry.entryType), + startTime: entry.startTime, + duration: entry.duration, + }); } else if (entry.entryType === RawPerformanceEntryTypeValues.MARK) { return new PerformanceMark(entry.name, { startTime: entry.startTime,