Skip to content

Commit

Permalink
perf_hooks: expose webperf global scope interfaces
Browse files Browse the repository at this point in the history
Exposes `PerformanceEntry`, `PerformanceMark`, `PerformanceMeasure`,
`PerformanceObserver`, `PerformanceObserverEntryList`,
and `PerformanceResourceTiming` to the global scope.
  • Loading branch information
legendecas committed Sep 14, 2022
1 parent 1d86a0f commit 5420d66
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 73 deletions.
6 changes: 6 additions & 0 deletions lib/internal/bootstrap/browser.js
Expand Up @@ -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);

Expand Down
24 changes: 0 additions & 24 deletions test/wpt/test-performance-timeline.js
Expand Up @@ -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({
Expand Down
17 changes: 0 additions & 17 deletions test/wpt/test-resource-timing.js
Expand Up @@ -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,
Expand Down
32 changes: 0 additions & 32 deletions test/wpt/test-user-timing.js
Expand Up @@ -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();

0 comments on commit 5420d66

Please sign in to comment.