Setup a global Performance singleton, according to the standard

Summary:
Makes sure that the global (standard) `performance` instance is initialized to still both provide `Performance.now()` as before, but also allows for the newly implemented functionality from the WebPerf API, such as marks/measures.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D42017812

fbshipit-source-id: ddbe79e91b45a84871de94018305f2a4536ada4b
This commit is contained in:
Ruslan Shestopalyuk
2022-12-14 22:38:12 -08:00
committed by Facebook GitHub Bot
parent 61c6788a3a
commit 14307b8212
2 changed files with 6 additions and 13 deletions
+2 -13
View File
@@ -8,19 +8,8 @@
* @format
*/
'use strict';
import Performance from '../WebPerformance/Performance';
if (!global.performance) {
global.performance = ({}: {now?: () => number});
}
/**
* Returns a double, measured in milliseconds.
* https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
*/
if (typeof global.performance.now !== 'function') {
global.performance.now = function () {
const performanceNow = global.nativePerformanceNow || Date.now;
return performanceNow();
};
global.performance = new Performance();
}
+4
View File
@@ -188,6 +188,10 @@ export default class Performance {
NativePerformance.clearMeasures(measureName);
}
/**
* Returns a double, measured in milliseconds.
* https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
*/
now(): HighResTimeStamp {
return getCurrentTimeStamp();
}