mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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:
committed by
Facebook GitHub Bot
parent
61c6788a3a
commit
14307b8212
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user