happy-dom 13.0.5 → 13.0.7

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.

Files changed (68) hide show
  1. package/cjs/async-task-manager/AsyncTaskManager.cjs +11 -5
  2. package/cjs/async-task-manager/AsyncTaskManager.cjs.map +1 -1
  3. package/cjs/async-task-manager/AsyncTaskManager.d.ts.map +1 -1
  4. package/cjs/dom-implementation/DOMImplementation.cjs +2 -4
  5. package/cjs/dom-implementation/DOMImplementation.cjs.map +1 -1
  6. package/cjs/dom-implementation/DOMImplementation.d.ts.map +1 -1
  7. package/cjs/nodes/NodeFactory.cjs +30 -0
  8. package/cjs/nodes/NodeFactory.cjs.map +1 -0
  9. package/cjs/nodes/NodeFactory.d.ts +23 -0
  10. package/cjs/nodes/NodeFactory.d.ts.map +1 -0
  11. package/cjs/nodes/document/Document.cjs +8 -20
  12. package/cjs/nodes/document/Document.cjs.map +1 -1
  13. package/cjs/nodes/document/Document.d.ts +2 -2
  14. package/cjs/nodes/document/Document.d.ts.map +1 -1
  15. package/cjs/nodes/document/IDocument.d.ts +2 -2
  16. package/cjs/nodes/element/Element.cjs +8 -9
  17. package/cjs/nodes/element/Element.cjs.map +1 -1
  18. package/cjs/nodes/element/Element.d.ts.map +1 -1
  19. package/cjs/nodes/node/Node.cjs +16 -16
  20. package/cjs/nodes/node/Node.cjs.map +1 -1
  21. package/cjs/nodes/node/Node.d.ts.map +1 -1
  22. package/cjs/version.cjs +1 -1
  23. package/cjs/window/BrowserWindow.cjs +23 -24
  24. package/cjs/window/BrowserWindow.cjs.map +1 -1
  25. package/cjs/window/BrowserWindow.d.ts.map +1 -1
  26. package/lib/async-task-manager/AsyncTaskManager.d.ts.map +1 -1
  27. package/lib/async-task-manager/AsyncTaskManager.js +11 -5
  28. package/lib/async-task-manager/AsyncTaskManager.js.map +1 -1
  29. package/lib/dom-implementation/DOMImplementation.d.ts.map +1 -1
  30. package/lib/dom-implementation/DOMImplementation.js +2 -4
  31. package/lib/dom-implementation/DOMImplementation.js.map +1 -1
  32. package/lib/nodes/NodeFactory.d.ts +23 -0
  33. package/lib/nodes/NodeFactory.d.ts.map +1 -0
  34. package/lib/nodes/NodeFactory.js +28 -0
  35. package/lib/nodes/NodeFactory.js.map +1 -0
  36. package/lib/nodes/document/Document.d.ts +2 -2
  37. package/lib/nodes/document/Document.d.ts.map +1 -1
  38. package/lib/nodes/document/Document.js +8 -20
  39. package/lib/nodes/document/Document.js.map +1 -1
  40. package/lib/nodes/document/IDocument.d.ts +2 -2
  41. package/lib/nodes/element/Element.d.ts.map +1 -1
  42. package/lib/nodes/element/Element.js +8 -9
  43. package/lib/nodes/element/Element.js.map +1 -1
  44. package/lib/nodes/node/Node.d.ts.map +1 -1
  45. package/lib/nodes/node/Node.js +16 -16
  46. package/lib/nodes/node/Node.js.map +1 -1
  47. package/lib/version.js +1 -1
  48. package/lib/window/BrowserWindow.d.ts.map +1 -1
  49. package/lib/window/BrowserWindow.js +23 -24
  50. package/lib/window/BrowserWindow.js.map +1 -1
  51. package/package.json +1 -1
  52. package/src/async-task-manager/AsyncTaskManager.ts +12 -5
  53. package/src/dom-implementation/DOMImplementation.ts +5 -4
  54. package/src/nodes/NodeFactory.ts +34 -0
  55. package/src/nodes/document/Document.ts +13 -21
  56. package/src/nodes/document/IDocument.ts +2 -2
  57. package/src/nodes/element/Element.ts +14 -12
  58. package/src/nodes/node/Node.ts +13 -12
  59. package/src/window/BrowserWindow.ts +22 -22
  60. package/cjs/nodes/document/NodeCreationOwnerDocument.cjs +0 -15
  61. package/cjs/nodes/document/NodeCreationOwnerDocument.cjs.map +0 -1
  62. package/cjs/nodes/document/NodeCreationOwnerDocument.d.ts +0 -15
  63. package/cjs/nodes/document/NodeCreationOwnerDocument.d.ts.map +0 -1
  64. package/lib/nodes/document/NodeCreationOwnerDocument.d.ts +0 -15
  65. package/lib/nodes/document/NodeCreationOwnerDocument.d.ts.map +0 -1
  66. package/lib/nodes/document/NodeCreationOwnerDocument.js +0 -13
  67. package/lib/nodes/document/NodeCreationOwnerDocument.js.map +0 -1
  68. package/src/nodes/document/NodeCreationOwnerDocument.ts +0 -14
@@ -11,14 +11,14 @@ import NodeUtility from './NodeUtility.js';
11
11
  import IAttr from '../attr/IAttr.js';
12
12
  import NodeList from './NodeList.js';
13
13
  import INodeList from './INodeList.js';
14
- import NodeCreationOwnerDocument from '../document/NodeCreationOwnerDocument.js';
14
+ import NodeFactory from '../NodeFactory.js';
15
15
 
16
16
  /**
17
17
  * Node.
18
18
  */
19
19
  export default class Node extends EventTarget implements INode {
20
20
  // Can be set before the Node is created.
21
- public static [PropertySymbol.ownerDocument]: IDocument | null = null;
21
+ public static [PropertySymbol.ownerDocument]: IDocument | null;
22
22
 
23
23
  // Public properties
24
24
  public static readonly ELEMENT_NODE = NodeTypeEnum.elementNode;
@@ -71,13 +71,16 @@ export default class Node extends EventTarget implements INode {
71
71
  */
72
72
  constructor() {
73
73
  super();
74
- if (
75
- NodeCreationOwnerDocument.ownerDocument ||
76
- (<typeof Node>this.constructor)[PropertySymbol.ownerDocument]
77
- ) {
78
- this.ownerDocument =
79
- NodeCreationOwnerDocument.ownerDocument ||
80
- (<typeof Node>this.constructor)[PropertySymbol.ownerDocument];
74
+ if ((<typeof Node>this.constructor)[PropertySymbol.ownerDocument] !== undefined) {
75
+ this.ownerDocument = (<typeof Node>this.constructor)[PropertySymbol.ownerDocument];
76
+ } else {
77
+ const ownerDocument = NodeFactory.pullOwnerDocument();
78
+ if (!ownerDocument) {
79
+ throw new Error(
80
+ 'Failed to construct "Node": No owner document in queue. Please use "NodeFactory" to create instances of a Node.'
81
+ );
82
+ }
83
+ this.ownerDocument = ownerDocument;
81
84
  }
82
85
  }
83
86
 
@@ -279,9 +282,7 @@ export default class Node extends EventTarget implements INode {
279
282
  * @returns Cloned node.
280
283
  */
281
284
  public cloneNode(deep = false): INode {
282
- NodeCreationOwnerDocument.ownerDocument = this.ownerDocument;
283
- const clone = new (<typeof Node>this.constructor)();
284
- NodeCreationOwnerDocument.ownerDocument = null;
285
+ const clone = NodeFactory.createNode<Node>(this.ownerDocument, <typeof Node>this.constructor);
285
286
 
286
287
  // Document has childNodes directly when it is created
287
288
  if (clone[PropertySymbol.childNodes].length) {
@@ -150,11 +150,15 @@ import RequestImplementation from '../fetch/Request.js';
150
150
  import ResponseImplementation from '../fetch/Response.js';
151
151
  import RangeImplementation from '../range/Range.js';
152
152
 
153
- const ORIGINAL_SET_TIMEOUT = setTimeout;
154
- const ORIGINAL_CLEAR_TIMEOUT = clearTimeout;
155
- const ORIGINAL_SET_INTERVAL = setInterval;
156
- const ORIGINAL_CLEAR_INTERVAL = clearInterval;
157
- const ORIGINAL_QUEUE_MICROTASK = queueMicrotask;
153
+ const TIMER = {
154
+ setTimeout: setTimeout,
155
+ clearTimeout: clearTimeout,
156
+ setInterval: setInterval,
157
+ clearInterval: clearInterval,
158
+ queueMicrotask: queueMicrotask,
159
+ setImmediate: setImmediate,
160
+ clearImmediate: clearImmediate
161
+ };
158
162
  const IS_NODE_JS_TIMEOUT_ENVIRONMENT = setTimeout.toString().includes('new Timeout');
159
163
 
160
164
  /**
@@ -493,11 +497,6 @@ export default class BrowserWindow extends EventTarget implements IBrowserWindow
493
497
  public readonly [PropertySymbol.readyStateManager] = new DocumentReadyStateManager(this);
494
498
 
495
499
  // Private properties
496
- #setTimeout: (callback: Function, delay?: number, ...args: unknown[]) => NodeJS.Timeout;
497
- #clearTimeout: (id: NodeJS.Timeout) => void;
498
- #setInterval: (callback: Function, delay?: number, ...args: unknown[]) => NodeJS.Timeout;
499
- #clearInterval: (id: NodeJS.Timeout) => void;
500
- #queueMicrotask: (callback: Function) => void;
501
500
  #browserFrame: IBrowserFrame;
502
501
  #innerWidth: number | null = null;
503
502
  #innerHeight: number | null = null;
@@ -516,11 +515,6 @@ export default class BrowserWindow extends EventTarget implements IBrowserWindow
516
515
  super();
517
516
 
518
517
  this.#browserFrame = browserFrame;
519
- this.#setTimeout = ORIGINAL_SET_TIMEOUT;
520
- this.#clearTimeout = ORIGINAL_CLEAR_TIMEOUT;
521
- this.#setInterval = ORIGINAL_SET_INTERVAL;
522
- this.#clearInterval = ORIGINAL_CLEAR_INTERVAL;
523
- this.#queueMicrotask = ORIGINAL_QUEUE_MICROTASK;
524
518
 
525
519
  this.customElements = new CustomElementRegistry();
526
520
  this.navigator = new Navigator(this);
@@ -648,6 +642,12 @@ export default class BrowserWindow extends EventTarget implements IBrowserWindow
648
642
  this.XMLDocument = XMLDocument;
649
643
  this.SVGDocument = SVGDocument;
650
644
 
645
+ // Override owner document
646
+ this.Document[PropertySymbol.ownerDocument] = null;
647
+ this.HTMLDocument[PropertySymbol.ownerDocument] = null;
648
+ this.XMLDocument[PropertySymbol.ownerDocument] = null;
649
+ this.SVGDocument[PropertySymbol.ownerDocument] = null;
650
+
651
651
  // Document
652
652
  this.document = new HTMLDocument();
653
653
  (<IBrowserWindow>this.document.defaultView) = this;
@@ -961,7 +961,7 @@ export default class BrowserWindow extends EventTarget implements IBrowserWindow
961
961
  !settings ||
962
962
  !settings.disableErrorCapturing ||
963
963
  settings.errorCapture === BrowserErrorCaptureEnum.tryAndCatch;
964
- const id = this.#setTimeout(() => {
964
+ const id = TIMER.setTimeout(() => {
965
965
  if (useTryCatch) {
966
966
  WindowErrorUtility.captureError(this, () => callback(...args));
967
967
  } else {
@@ -984,7 +984,7 @@ export default class BrowserWindow extends EventTarget implements IBrowserWindow
984
984
  if (IS_NODE_JS_TIMEOUT_ENVIRONMENT && (!id || id.constructor.name !== 'Timeout')) {
985
985
  return;
986
986
  }
987
- this.#clearTimeout(id);
987
+ TIMER.clearTimeout(id);
988
988
  this.#browserFrame[PropertySymbol.asyncTaskManager].endTimer(id);
989
989
  }
990
990
 
@@ -1002,7 +1002,7 @@ export default class BrowserWindow extends EventTarget implements IBrowserWindow
1002
1002
  !settings ||
1003
1003
  !settings.disableErrorCapturing ||
1004
1004
  settings.errorCapture === BrowserErrorCaptureEnum.tryAndCatch;
1005
- const id = this.#setInterval(() => {
1005
+ const id = TIMER.setInterval(() => {
1006
1006
  if (useTryCatch) {
1007
1007
  WindowErrorUtility.captureError(
1008
1008
  this,
@@ -1028,7 +1028,7 @@ export default class BrowserWindow extends EventTarget implements IBrowserWindow
1028
1028
  if (IS_NODE_JS_TIMEOUT_ENVIRONMENT && (!id || id.constructor.name !== 'Timeout')) {
1029
1029
  return;
1030
1030
  }
1031
- this.#clearInterval(id);
1031
+ TIMER.clearInterval(id);
1032
1032
  this.#browserFrame[PropertySymbol.asyncTaskManager].endTimer(id);
1033
1033
  }
1034
1034
 
@@ -1044,7 +1044,7 @@ export default class BrowserWindow extends EventTarget implements IBrowserWindow
1044
1044
  !settings ||
1045
1045
  !settings.disableErrorCapturing ||
1046
1046
  settings.errorCapture === BrowserErrorCaptureEnum.tryAndCatch;
1047
- const id = global.setImmediate(() => {
1047
+ const id = TIMER.setImmediate(() => {
1048
1048
  if (useTryCatch) {
1049
1049
  WindowErrorUtility.captureError(this, () => callback(this.performance.now()));
1050
1050
  } else {
@@ -1067,7 +1067,7 @@ export default class BrowserWindow extends EventTarget implements IBrowserWindow
1067
1067
  if (IS_NODE_JS_TIMEOUT_ENVIRONMENT && (!id || id.constructor.name !== 'Immediate')) {
1068
1068
  return;
1069
1069
  }
1070
- global.clearImmediate(id);
1070
+ TIMER.clearImmediate(id);
1071
1071
  this.#browserFrame[PropertySymbol.asyncTaskManager].endImmediate(id);
1072
1072
  }
1073
1073
 
@@ -1086,7 +1086,7 @@ export default class BrowserWindow extends EventTarget implements IBrowserWindow
1086
1086
  !settings ||
1087
1087
  !settings.disableErrorCapturing ||
1088
1088
  settings.errorCapture === BrowserErrorCaptureEnum.tryAndCatch;
1089
- this.#queueMicrotask(() => {
1089
+ TIMER.queueMicrotask(() => {
1090
1090
  if (!isAborted) {
1091
1091
  if (useTryCatch) {
1092
1092
  WindowErrorUtility.captureError(this, <() => unknown>callback);
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /**
4
- * When creating a new node, the ownerDocument property is set to the document object associated with the node's.
5
- * The ownerDocument property has to be available in the constructor of the node.
6
- *
7
- * This is used for setting current ownerDocument state when creating a new node.
8
- *
9
- * Another method for achieving this wich is also supported in Node, is to set a static property on the node class.
10
- * This may be necessary for sub-classes wich are bound to a document, but can cause problems in some cases when Node.js sets this.constructor to Reflect.comnstruct(), which is not the original class.
11
- */
12
- exports.default = {
13
- ownerDocument: null
14
- };
15
- //# sourceMappingURL=NodeCreationOwnerDocument.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NodeCreationOwnerDocument.cjs","sourceRoot":"","sources":["../../../src/nodes/document/NodeCreationOwnerDocument.ts"],"names":[],"mappings":";;AAEA;;;;;;;;GAQG;AACH,kBAAoD;IACnD,aAAa,EAAE,IAAI;CACnB,CAAC"}
@@ -1,15 +0,0 @@
1
- import IDocument from './IDocument.cjs';
2
- /**
3
- * When creating a new node, the ownerDocument property is set to the document object associated with the node's.
4
- * The ownerDocument property has to be available in the constructor of the node.
5
- *
6
- * This is used for setting current ownerDocument state when creating a new node.
7
- *
8
- * Another method for achieving this wich is also supported in Node, is to set a static property on the node class.
9
- * This may be necessary for sub-classes wich are bound to a document, but can cause problems in some cases when Node.js sets this.constructor to Reflect.comnstruct(), which is not the original class.
10
- */
11
- declare const _default: {
12
- ownerDocument: IDocument | null;
13
- };
14
- export default _default;
15
- //# sourceMappingURL=NodeCreationOwnerDocument.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NodeCreationOwnerDocument.d.ts","sourceRoot":"","sources":["../../../src/nodes/document/NodeCreationOwnerDocument.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC;;;;;;;;GAQG;;mBAC8B,SAAS,GAAG,IAAI;;AAAjD,wBAEE"}
@@ -1,15 +0,0 @@
1
- import IDocument from './IDocument.js';
2
- /**
3
- * When creating a new node, the ownerDocument property is set to the document object associated with the node's.
4
- * The ownerDocument property has to be available in the constructor of the node.
5
- *
6
- * This is used for setting current ownerDocument state when creating a new node.
7
- *
8
- * Another method for achieving this wich is also supported in Node, is to set a static property on the node class.
9
- * This may be necessary for sub-classes wich are bound to a document, but can cause problems in some cases when Node.js sets this.constructor to Reflect.comnstruct(), which is not the original class.
10
- */
11
- declare const _default: {
12
- ownerDocument: IDocument | null;
13
- };
14
- export default _default;
15
- //# sourceMappingURL=NodeCreationOwnerDocument.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NodeCreationOwnerDocument.d.ts","sourceRoot":"","sources":["../../../src/nodes/document/NodeCreationOwnerDocument.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,gBAAgB,CAAC;AAEvC;;;;;;;;GAQG;;mBAC8B,SAAS,GAAG,IAAI;;AAAjD,wBAEE"}
@@ -1,13 +0,0 @@
1
- /**
2
- * When creating a new node, the ownerDocument property is set to the document object associated with the node's.
3
- * The ownerDocument property has to be available in the constructor of the node.
4
- *
5
- * This is used for setting current ownerDocument state when creating a new node.
6
- *
7
- * Another method for achieving this wich is also supported in Node, is to set a static property on the node class.
8
- * This may be necessary for sub-classes wich are bound to a document, but can cause problems in some cases when Node.js sets this.constructor to Reflect.comnstruct(), which is not the original class.
9
- */
10
- export default {
11
- ownerDocument: null
12
- };
13
- //# sourceMappingURL=NodeCreationOwnerDocument.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NodeCreationOwnerDocument.js","sourceRoot":"","sources":["../../../src/nodes/document/NodeCreationOwnerDocument.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,eAAoD;IACnD,aAAa,EAAE,IAAI;CACnB,CAAC"}
@@ -1,14 +0,0 @@
1
- import IDocument from './IDocument.js';
2
-
3
- /**
4
- * When creating a new node, the ownerDocument property is set to the document object associated with the node's.
5
- * The ownerDocument property has to be available in the constructor of the node.
6
- *
7
- * This is used for setting current ownerDocument state when creating a new node.
8
- *
9
- * Another method for achieving this wich is also supported in Node, is to set a static property on the node class.
10
- * This may be necessary for sub-classes wich are bound to a document, but can cause problems in some cases when Node.js sets this.constructor to Reflect.comnstruct(), which is not the original class.
11
- */
12
- export default <{ ownerDocument: IDocument | null }>{
13
- ownerDocument: null
14
- };