| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e0eb515 commit f0bf373
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -331,5 +331,6 @@ module.exports = { | |||
| 331 | 331 | globalThis: 'readable', | |
| 332 | 332 | btoa: 'readable', | |
| 333 | 333 | atob: 'readable', | |
| 334 | + performance: 'readable', | ||
| 334 | 335 | }, | |
| 335 | 336 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -279,6 +279,10 @@ The `MessagePort` class. See [`MessagePort`][] for more details. | |||
| 279 | 279 | ||
| 280 | 280 | This variable may appear to be global but is not. See [`module`][]. | |
| 281 | 281 | ||
| 282 | + ## `performance` | ||
| 283 | + | ||
| 284 | + The [`perf_hooks.performance`][] object. | ||
| 285 | + | ||
| 282 | 286 | ## `process` | |
| 283 | 287 | <!-- YAML | |
| 284 | 288 | added: v0.1.7 | |
@@ -428,6 +432,7 @@ The object that acts as the namespace for all W3C | |||
| 428 | 432 | [`console`]: console.md | |
| 429 | 433 | [`exports`]: modules.md#modules_exports | |
| 430 | 434 | [`module`]: modules.md#modules_module | |
| 435 | + [`perf_hooks.performance`]: perf_hooks.md#perf_hooks_perf_hooks_performance | ||
| 431 | 436 | [`process.nextTick()`]: process.md#process_process_nexttick_callback_args | |
| 432 | 437 | [`process` object]: process.md#process_process | |
| 433 | 438 | [`require()`]: modules.md#modules_require_id | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -236,6 +236,11 @@ if (!config.noBrowserGlobals) { | |||
| 236 | 236 | ||
| 237 | 237 | defineOperation(global, 'queueMicrotask', queueMicrotask); | |
| 238 | 238 | ||
| 239 | + defineLazyGlobal(global, 'performance', () => { | ||
| 240 | + const { performance } = require('perf_hooks'); | ||
| 241 | + return performance; | ||
| 242 | + }); | ||
| 243 | + | ||
| 239 | 244 | // Non-standard extensions: | |
| 240 | 245 | defineOperation(global, 'clearImmediate', timers.clearImmediate); | |
| 241 | 246 | defineOperation(global, 'setImmediate', timers.setImmediate); | |
@@ -481,3 +486,21 @@ function defineOperation(target, name, method) { | |||
| 481 | 486 | value: method | |
| 482 | 487 | }); | |
| 483 | 488 | } | |
| 489 | + | ||
| 490 | + function defineLazyGlobal(target, name, loader) { | ||
| 491 | + let value; | ||
| 492 | + let overridden = false; | ||
| 493 | + ObjectDefineProperty(target, name, { | ||
| 494 | + enumerable: true, | ||
| 495 | + configurable: true, | ||
| 496 | + get() { | ||
| 497 | + if (value === undefined && !overridden) | ||
| 498 | + value = loader(); | ||
| 499 | + return value; | ||
| 500 | + }, | ||
| 501 | + set(val) { | ||
| 502 | + value = val; | ||
| 503 | + overridden = true; | ||
| 504 | + } | ||
| 505 | + }); | ||
| 506 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -287,6 +287,10 @@ if (global.gc) { | |||
| 287 | 287 | knownGlobals.push(global.gc); | |
| 288 | 288 | } | |
| 289 | 289 | ||
| 290 | + if (global.performance) { | ||
| 291 | + knownGlobals.push(global.performance); | ||
| 292 | + } | ||
| 293 | + | ||
| 290 | 294 | function allowGlobals(...allowlist) { | |
| 291 | 295 | knownGlobals = knownGlobals.concat(allowlist); | |
| 292 | 296 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,6 +47,7 @@ builtinModules.forEach((moduleName) => { | |||
| 47 | 47 | 'clearImmediate', | |
| 48 | 48 | 'clearInterval', | |
| 49 | 49 | 'clearTimeout', | |
| 50 | + 'performance', | ||
| 50 | 51 | 'setImmediate', | |
| 51 | 52 | 'setInterval', | |
| 52 | 53 | 'setTimeout' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,18 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + /* eslint-disable no-global-assign */ | ||
| 3 | + | ||
| 4 | + require('../common'); | ||
| 5 | + | ||
| 6 | + const perf_hooks = require('perf_hooks'); | ||
| 7 | + const { | ||
| 8 | + strictEqual | ||
| 9 | + } = require('assert'); | ||
| 10 | + | ||
| 11 | + const perf = performance; | ||
| 12 | + strictEqual(globalThis.performance, perf_hooks.performance); | ||
| 13 | + performance = undefined; | ||
| 14 | + strictEqual(globalThis.performance, undefined); | ||
| 15 | + strictEqual(typeof perf_hooks.performance.now, 'function'); | ||
| 16 | + | ||
| 17 | + // Restore the value of performance for the known globals check | ||
| 18 | + performance = perf; | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,8 +9,7 @@ runner.setInitScript(` | |||
| 9 | 9 | const { Blob } = require('buffer'); | |
| 10 | 10 | global.Blob = Blob; | |
| 11 | 11 | ||
| 12 | - const { performance, PerformanceObserver } = require('perf_hooks'); | ||
| 13 | - global.performance = performance; | ||
| 12 | + const { PerformanceObserver } = require('perf_hooks'); | ||
| 14 | 13 | global.PerformanceObserver = PerformanceObserver; | |
| 15 | 14 | `); | |
| 16 | 15 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments