mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 17:03:34 +00:00
perf_hooks: expose webperf global scope interfaces
Exposes `PerformanceEntry`, `PerformanceMark`, `PerformanceMeasure`, `PerformanceObserver`, `PerformanceObserverEntryList`, and `PerformanceResourceTiming` to the global scope. PR-URL: https://github.com/nodejs/node/pull/44483 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
364c0e196c
commit
587367d107
@ -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
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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({
|
||||
|
@ -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,
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user