happy-dom 14.1.0 → 14.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of happy-dom might be problematic. Click here for more details.

@@ -408,18 +408,11 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
408
408
  // Public properties.
409
409
  public readonly document: DocumentImplementation;
410
410
  public readonly customElements: CustomElementRegistry;
411
- public readonly location: Location;
412
- public readonly history: History;
413
- public readonly navigator: Navigator;
414
- public readonly console: Console;
415
411
  public readonly self: BrowserWindow = this;
416
412
  public readonly top: BrowserWindow = this;
417
413
  public readonly parent: BrowserWindow = this;
418
414
  public readonly window: BrowserWindow = this;
419
415
  public readonly globalThis: BrowserWindow = this;
420
- public readonly screen: Screen;
421
- public readonly sessionStorage: Storage;
422
- public readonly localStorage: Storage;
423
416
  public readonly performance: typeof performance = performance;
424
417
  public readonly screenLeft: number = 0;
425
418
  public readonly screenTop: number = 0;
@@ -427,6 +420,7 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
427
420
  public readonly screenY: number = 0;
428
421
  public readonly crypto: typeof webcrypto = webcrypto;
429
422
  public readonly closed = false;
423
+ public console: Console;
430
424
  public name = '';
431
425
 
432
426
  // Node.js Globals
@@ -497,6 +491,12 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
497
491
  public [PropertySymbol.captureEventListenerCount]: { [eventType: string]: number } = {};
498
492
  public readonly [PropertySymbol.mutationObservers]: MutationObserver[] = [];
499
493
  public readonly [PropertySymbol.readyStateManager] = new DocumentReadyStateManager(this);
494
+ public [PropertySymbol.location]: Location;
495
+ public [PropertySymbol.history]: History;
496
+ public [PropertySymbol.navigator]: Navigator;
497
+ public [PropertySymbol.screen]: Screen;
498
+ public [PropertySymbol.sessionStorage]: Storage;
499
+ public [PropertySymbol.localStorage]: Storage;
500
500
 
501
501
  // Private properties
502
502
  #browserFrame: IBrowserFrame;
@@ -519,12 +519,13 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
519
519
  this.#browserFrame = browserFrame;
520
520
 
521
521
  this.customElements = new CustomElementRegistry(this);
522
- this.navigator = new Navigator(this);
523
- this.history = new History();
524
- this.screen = new Screen();
525
- this.sessionStorage = new Storage();
526
- this.localStorage = new Storage();
527
- this.location = new Location(this.#browserFrame, options?.url ?? 'about:blank');
522
+ this[PropertySymbol.navigator] = new Navigator(this);
523
+ this[PropertySymbol.history] = new History();
524
+ this[PropertySymbol.screen] = new Screen();
525
+ this[PropertySymbol.sessionStorage] = new Storage();
526
+ this[PropertySymbol.localStorage] = new Storage();
527
+ this[PropertySymbol.location] = new Location(this.#browserFrame, options?.url ?? 'about:blank');
528
+
528
529
  this.console = browserFrame.page.console;
529
530
 
530
531
  WindowBrowserSettingsReader.setSettings(this, this.#browserFrame.page.context.browser.settings);
@@ -673,6 +674,57 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
673
674
  });
674
675
  }
675
676
 
677
+ /**
678
+ * Returns location.
679
+ */
680
+ public get location(): Location {
681
+ return this[PropertySymbol.location];
682
+ }
683
+
684
+ /**
685
+ * Returns location.
686
+ *
687
+ * @param href Href.
688
+ */
689
+ public set location(href: string) {
690
+ this[PropertySymbol.location].href = href;
691
+ }
692
+
693
+ /**
694
+ * Returns history.
695
+ */
696
+ public get history(): History {
697
+ return this[PropertySymbol.history];
698
+ }
699
+
700
+ /**
701
+ * Returns navigator.
702
+ */
703
+ public get navigator(): Navigator {
704
+ return this[PropertySymbol.navigator];
705
+ }
706
+
707
+ /**
708
+ * Returns screen.
709
+ */
710
+ public get screen(): Screen {
711
+ return this[PropertySymbol.screen];
712
+ }
713
+
714
+ /**
715
+ * Returns session storage.
716
+ */
717
+ public get sessionStorage(): Storage {
718
+ return this[PropertySymbol.sessionStorage];
719
+ }
720
+
721
+ /**
722
+ * Returns local storage.
723
+ */
724
+ public get localStorage(): Storage {
725
+ return this[PropertySymbol.localStorage];
726
+ }
727
+
676
728
  /**
677
729
  * Returns opener.
678
730
  *
@@ -1,4 +1,6 @@
1
1
  import * as PropertySymbol from '../PropertySymbol.js';
2
+ import { IOptionalBrowserSettings } from '../index.js';
3
+ import BrowserWindow from './BrowserWindow.js';
2
4
  import Window from './Window.js';
3
5
  import { Buffer } from 'buffer';
4
6
 
@@ -70,6 +72,61 @@ export default class GlobalWindow extends Window {
70
72
  public gc: () => void = globalThis.gc;
71
73
  public v8debug?: unknown = globalThis.v8debug;
72
74
 
75
+ /**
76
+ * Constructor.
77
+ *
78
+ * @param [options] Options.
79
+ * @param [options.width] Window width. Defaults to "1024".
80
+ * @param [options.height] Window height. Defaults to "768".
81
+ * @param [options.innerWidth] Inner width. Deprecated. Defaults to "1024".
82
+ * @param [options.innerHeight] Inner height. Deprecated. Defaults to "768".
83
+ * @param [options.url] URL.
84
+ * @param [options.console] Console.
85
+ * @param [options.settings] Settings.
86
+ */
87
+ constructor(options?: {
88
+ width?: number;
89
+ height?: number;
90
+ /** @deprecated Replaced by the "width" property. */
91
+ innerWidth?: number;
92
+ /** @deprecated Replaced by the "height" property. */
93
+ innerHeight?: number;
94
+ url?: string;
95
+ console?: Console;
96
+ settings?: IOptionalBrowserSettings;
97
+ }) {
98
+ super(options);
99
+
100
+ /**
101
+ * Binds getts and setters, so that they will appear as an "own" property when using Object.getOwnPropertyNames().
102
+ *
103
+ * This is needed for Vitest to work as it relies on Object.getOwnPropertyNames() to get the list of properties.
104
+ *
105
+ * @see https://github.com/capricorn86/happy-dom/issues/1339
106
+ */
107
+ for (const windowClass of [GlobalWindow, Window, BrowserWindow]) {
108
+ const propertyDescriptors = Object.getOwnPropertyDescriptors(
109
+ Reflect.getPrototypeOf(windowClass.prototype)
110
+ );
111
+
112
+ for (const key of Object.keys(propertyDescriptors)) {
113
+ const windowPropertyDescriptor = propertyDescriptors[key];
114
+ if (windowPropertyDescriptor.get || windowPropertyDescriptor.set) {
115
+ const ownPropertyDescriptor = Object.getOwnPropertyDescriptor(this, key);
116
+
117
+ if (!ownPropertyDescriptor) {
118
+ Object.defineProperty(this, key, {
119
+ configurable: true,
120
+ enumerable: windowPropertyDescriptor.enumerable,
121
+ get: windowPropertyDescriptor.get?.bind(this),
122
+ set: windowPropertyDescriptor.set?.bind(this)
123
+ });
124
+ }
125
+ }
126
+ }
127
+ }
128
+ }
129
+
73
130
  /**
74
131
  * Setup of VM context.
75
132
  */