Skip to content

Commit

Permalink
#1158@patch: Use global perfomance.now() instead of perf_hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mash-graz committed Dec 4, 2023
1 parent 4118e58 commit 22cbd30
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 3 additions & 4 deletions packages/happy-dom/src/console/VirtualConsole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import IVirtualConsolePrinter from './types/IVirtualConsolePrinter.js';
import VirtualConsoleLogLevelEnum from './enums/VirtualConsoleLogLevelEnum.js';
import VirtualConsoleLogTypeEnum from './enums/VirtualConsoleLogTypeEnum.js';
import IVirtualConsoleLogGroup from './types/IVirtualConsoleLogGroup.js';
import * as PerfHooks from 'perf_hooks';
import { ConsoleConstructor } from 'console';

/**
Expand Down Expand Up @@ -276,7 +275,7 @@ export default class VirtualConsole implements Console {
* @param [label=default] Label.
*/
public time(label = 'default'): void {
this._time[label] = PerfHooks.performance.now();
this._time[label] = performance.now();
}

/**
Expand All @@ -288,7 +287,7 @@ export default class VirtualConsole implements Console {
public timeEnd(label = 'default'): void {
const time = this._time[label];
if (time) {
const duration = PerfHooks.performance.now() - time;
const duration = performance.now() - time;
this._printer.print({
type: VirtualConsoleLogTypeEnum.timeEnd,
level: VirtualConsoleLogLevelEnum.info,
Expand All @@ -308,7 +307,7 @@ export default class VirtualConsole implements Console {
public timeLog(label = 'default', ...args: Array<object | string>): void {
const time = this._time[label];
if (time) {
const duration = PerfHooks.performance.now() - time;
const duration = performance.now() - time;
this._printer.print({
type: VirtualConsoleLogTypeEnum.timeLog,
level: VirtualConsoleLogLevelEnum.info,
Expand Down
3 changes: 1 addition & 2 deletions packages/happy-dom/src/window/Window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ import Fetch from '../fetch/Fetch.js';
import RangeImplementation from '../range/Range.js';
import DOMRect from '../nodes/element/DOMRect.js';
import VMGlobalPropertyScript from './VMGlobalPropertyScript.js';
import * as PerfHooks from 'perf_hooks';
import VM from 'vm';
import { Buffer } from 'buffer';
import XMLHttpRequestImplementation from '../xml-http-request/XMLHttpRequest.js';
Expand Down Expand Up @@ -489,7 +488,7 @@ export default class Window extends EventTarget implements IWindow {
public readonly devicePixelRatio = 1;
public readonly sessionStorage: Storage;
public readonly localStorage: Storage;
public readonly performance = PerfHooks.performance;
public readonly performance = performance;
public readonly innerWidth: number = 1024;
public readonly innerHeight: number = 768;
public readonly outerWidth: number = 1024;
Expand Down

0 comments on commit 22cbd30

Please sign in to comment.