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
This commit is contained in:
Rubén Norte
2024-07-22 04:45:02 -07:00
committed by Facebook GitHub Bot
parent 2a91a703cc
commit 2680198b09
2 changed files with 47 additions and 0 deletions
@@ -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<TaskAttributionTiming>,
...
};
export class TaskAttributionTiming extends PerformanceEntry {}
const EMPTY_ATTRIBUTION: $ReadOnlyArray<TaskAttributionTiming> =
Object.preventExtensions([]);
export class PerformanceLongTaskTiming extends PerformanceEntry {
get attribution(): $ReadOnlyArray<TaskAttributionTiming> {
return EMPTY_ATTRIBUTION;
}
toJSON(): PerformanceLongTaskTimingJSON {
return {
...super.toJSON(),
attribution: this.attribution,
};
}
}
@@ -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,