From 5420d66e61b361be43a7f10966b29c64eaf3fbbb Mon Sep 17 00:00:00 2001 From: legendecas Date: Thu, 15 Sep 2022 02:06:23 +0800 Subject: [PATCH] perf_hooks: expose webperf global scope interfaces Exposes `PerformanceEntry`, `PerformanceMark`, `PerformanceMeasure`, `PerformanceObserver`, `PerformanceObserverEntryList`, and `PerformanceResourceTiming` to the global scope. --- lib/internal/bootstrap/browser.js | 6 +++++ test/wpt/test-performance-timeline.js | 24 -------------------- test/wpt/test-resource-timing.js | 17 -------------- test/wpt/test-user-timing.js | 32 --------------------------- 4 files changed, 6 insertions(+), 73 deletions(-) diff --git a/lib/internal/bootstrap/browser.js b/lib/internal/bootstrap/browser.js index 92d57688e21115..b4125f1b54f99e 100644 --- a/lib/internal/bootstrap/browser.js +++ b/lib/internal/bootstrap/browser.js @@ -75,6 +75,12 @@ exposeInterface(globalThis, 'Blob', buffer.Blob); // https://www.w3.org/TR/hr-time-2/#the-performance-attribute const perf_hooks = require('perf_hooks'); exposeInterface(globalThis, 'Performance', perf_hooks.Performance); +exposeInterface(globalThis, 'PerformanceEntry', perf_hooks.PerformanceEntry); +exposeInterface(globalThis, 'PerformanceMark', perf_hooks.PerformanceMark); +exposeInterface(globalThis, 'PerformanceMeasure', perf_hooks.PerformanceMeasure); +exposeInterface(globalThis, 'PerformanceObserver', perf_hooks.PerformanceObserver); +exposeInterface(globalThis, 'PerformanceObserverEntryList', perf_hooks.PerformanceObserverEntryList); +exposeInterface(globalThis, 'PerformanceResourceTiming', perf_hooks.PerformanceResourceTiming); defineReplaceableAttribute(globalThis, 'performance', perf_hooks.performance); diff --git a/test/wpt/test-performance-timeline.js b/test/wpt/test-performance-timeline.js index fb6e35155fcd8c..928090fc5f3e0e 100644 --- a/test/wpt/test-performance-timeline.js +++ b/test/wpt/test-performance-timeline.js @@ -7,30 +7,6 @@ const runner = new WPTRunner('performance-timeline'); runner.pretendGlobalThisAs('Window'); runner.brandCheckGlobalScopeAttribute('performance'); runner.setInitScript(` - const { - PerformanceEntry, - PerformanceObserver, - PerformanceObserverEntryList, - } = require('perf_hooks'); - Object.defineProperty(global, 'PerformanceEntry', { - value: PerformanceEntry, - enumerable: false, - writable: true, - configurable: true, - }); - Object.defineProperty(global, 'PerformanceObserver', { - value: PerformanceObserver, - enumerable: false, - writable: true, - configurable: true, - }); - Object.defineProperty(global, 'PerformanceObserverEntryList', { - value: PerformanceObserverEntryList, - enumerable: false, - writable: true, - configurable: true, - }); - // Create a dummy resource timing entry to mimic how the browser would // record the initial page load. performance.markResourceTiming({ diff --git a/test/wpt/test-resource-timing.js b/test/wpt/test-resource-timing.js index ea383f73b6d881..881888b1fd601c 100644 --- a/test/wpt/test-resource-timing.js +++ b/test/wpt/test-resource-timing.js @@ -6,23 +6,6 @@ const runner = new WPTRunner('resource-timing'); runner.pretendGlobalThisAs('Window'); runner.setInitScript(` - const { - PerformanceEntry, - PerformanceResourceTiming, - } = require('perf_hooks'); - Object.defineProperty(global, 'PerformanceEntry', { - value: PerformanceEntry, - enumerable: false, - writable: true, - configurable: true, - }); - Object.defineProperty(global, 'PerformanceResourceTiming', { - value: PerformanceResourceTiming, - enumerable: false, - writable: true, - configurable: true, - }); - global.resource = performance.markResourceTiming({ startTime: 0, endTime: 0, diff --git a/test/wpt/test-user-timing.js b/test/wpt/test-user-timing.js index f82d2411c3ece2..8c3c3812430514 100644 --- a/test/wpt/test-user-timing.js +++ b/test/wpt/test-user-timing.js @@ -7,37 +7,5 @@ const runner = new WPTRunner('user-timing'); runner.pretendGlobalThisAs('Window'); runner.brandCheckGlobalScopeAttribute('performance'); -runner.setInitScript(` - const { - PerformanceEntry, - PerformanceMark, - PerformanceMeasure, - PerformanceObserver, - } = require('perf_hooks'); - Object.defineProperty(global, 'PerformanceEntry', { - value: PerformanceEntry, - enumerable: false, - writable: true, - configurable: true, - }); - Object.defineProperty(global, 'PerformanceMark', { - value: PerformanceMark, - enumerable: false, - writable: true, - configurable: true, - }); - Object.defineProperty(global, 'PerformanceMeasure', { - value: PerformanceMeasure, - enumerable: false, - writable: true, - configurable: true, - }); - Object.defineProperty(global, 'PerformanceObserver', { - value: PerformanceObserver, - enumerable: false, - writable: true, - configurable: true, - }); -`); runner.runJsTests();