Skip to content
/ node Public
forked from nodejs/node

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.

PR-URL: nodejs#44483
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
legendecas authored and panva committed Oct 4, 2022
1 parent a4ee759 commit 9e4c582
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 73 deletions.
68 changes: 68 additions & 0 deletions doc/api/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,68 @@ The `MessagePort` class. See [`MessagePort`][] for more details.

This variable may appear to be global but is not. See [`module`][].

## `PerformanceEntry`

<!-- YAML
added: REPLACEME
-->

<!-- type=global -->

The `PerformanceEntry` class. See [`PerformanceEntry`][] for more details.

## `PerformanceMark`

<!-- YAML
added: REPLACEME
-->

<!-- type=global -->

The `PerformanceMark` class. See [`PerformanceMark`][] for more details.

## `PerformanceMeasure`

<!-- YAML
added: REPLACEME
-->

<!-- type=global -->

The `PerformanceMeasure` class. See [`PerformanceMeasure`][] for more details.

## `PerformanceObserver`

<!-- YAML
added: REPLACEME
-->

<!-- type=global -->

The `PerformanceObserver` class. See [`PerformanceObserver`][] for more details.

## `PerformanceObserverEntryList`

<!-- YAML
added: REPLACEME
-->

<!-- type=global -->

The `PerformanceObserverEntryList` class. See
[`PerformanceObserverEntryList`][] for more details.

## `PerformanceResourceTiming`

<!-- YAML
added: REPLACEME
-->

<!-- type=global -->

The `PerformanceResourceTiming` class. See [`PerformanceResourceTiming`][] for
more details.

## `performance`

<!-- YAML
Expand Down Expand Up @@ -899,6 +961,12 @@ A browser-compatible implementation of [`WritableStreamDefaultWriter`][].
[`MessageChannel`]: worker_threads.md#class-messagechannel
[`MessageEvent`]: https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/MessageEvent
[`MessagePort`]: worker_threads.md#class-messageport
[`PerformanceEntry`]: perf_hooks.md#class-performanceentry
[`PerformanceMark`]: perf_hooks.md#class-performancemark
[`PerformanceMeasure`]: perf_hooks.md#class-performancemeasure
[`PerformanceObserverEntryList`]: perf_hooks.md#class-performanceobserverentrylist
[`PerformanceObserver`]: perf_hooks.md#class-performanceobserver
[`PerformanceResourceTiming`]: perf_hooks.md#class-performanceresourcetiming
[`ReadableByteStreamController`]: webstreams.md#class-readablebytestreamcontroller
[`ReadableStreamBYOBReader`]: webstreams.md#class-readablestreambyobreader
[`ReadableStreamBYOBRequest`]: webstreams.md#class-readablestreambyobrequest
Expand Down
12 changes: 12 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ rules:
message: Use `const { MessageEvent } = require('internal/worker/io');` instead of the global.
- name: MessagePort
message: Use `const { MessagePort } = require('internal/worker/io');` instead of the global.
- name: PerformanceEntry
message: Use `const { PerformanceEntry } = require('perf_hooks');` instead of the global.
- name: PerformanceMark
message: Use `const { PerformanceMark } = require('perf_hooks');` instead of the global.
- name: PerformanceMeasure
message: Use `const { PerformanceMeasure } = require('perf_hooks');` instead of the global.
- name: PerformanceObserverEntryList
message: Use `const { PerformanceObserverEntryList } = require('perf_hooks');` instead of the global.
- name: PerformanceObserver
message: Use `const { PerformanceObserver } = require('perf_hooks');` instead of the global.
- name: PerformanceResourceTiming
message: Use `const { PerformanceResourceTiming } = require('perf_hooks');` instead of the global.
- name: ReadableStream
message: Use `const { ReadableStream } = require('internal/webstreams/readablestream')` instead of the global.
- name: ReadableStreamDefaultReader
Expand Down
6 changes: 6 additions & 0 deletions lib/internal/bootstrap/browser.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 9e4c582

Please sign in to comment.