happy-dom 2.54.0 → 3.1.0

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 (299) hide show
  1. package/README.md +26 -6
  2. package/lib/async-task-manager/AsyncTaskManager.js +34 -78
  3. package/lib/async-task-manager/AsyncTaskManager.js.map +1 -1
  4. package/lib/attribute/Attr.js +19 -28
  5. package/lib/attribute/Attr.js.map +1 -1
  6. package/lib/config/ElementTag.d.ts +2 -1
  7. package/lib/config/ElementTag.js +16 -15
  8. package/lib/config/ElementTag.js.map +1 -1
  9. package/lib/config/NonImplemenetedElementClasses.js +0 -1
  10. package/lib/config/NonImplemenetedElementClasses.js.map +1 -1
  11. package/lib/cookie/CookieUtility.js +21 -26
  12. package/lib/cookie/CookieUtility.js.map +1 -1
  13. package/lib/css/CSS.js +12 -18
  14. package/lib/css/CSS.js.map +1 -1
  15. package/lib/css/CSSParser.js +29 -33
  16. package/lib/css/CSSParser.js.map +1 -1
  17. package/lib/css/CSSRule.js +24 -29
  18. package/lib/css/CSSRule.js.map +1 -1
  19. package/lib/css/CSSStyleDeclaration.js +4516 -6005
  20. package/lib/css/CSSStyleDeclaration.js.map +1 -1
  21. package/lib/css/CSSStyleSheet.js +17 -59
  22. package/lib/css/CSSStyleSheet.js.map +1 -1
  23. package/lib/css/CSSUnitValue.js +4 -5
  24. package/lib/css/CSSUnitValue.js.map +1 -1
  25. package/lib/css/MediaList.js +23 -28
  26. package/lib/css/MediaList.js.map +1 -1
  27. package/lib/css/rules/CSSFontFaceRule.js +6 -24
  28. package/lib/css/rules/CSSFontFaceRule.js.map +1 -1
  29. package/lib/css/rules/CSSKeyframeRule.js +14 -36
  30. package/lib/css/rules/CSSKeyframeRule.js.map +1 -1
  31. package/lib/css/rules/CSSKeyframesRule.js +31 -54
  32. package/lib/css/rules/CSSKeyframesRule.js.map +1 -1
  33. package/lib/css/rules/CSSMediaRule.js +29 -56
  34. package/lib/css/rules/CSSMediaRule.js.map +1 -1
  35. package/lib/css/rules/CSSStyleRule.js +16 -38
  36. package/lib/css/rules/CSSStyleRule.js.map +1 -1
  37. package/lib/custom-element/CustomElementRegistry.js +21 -24
  38. package/lib/custom-element/CustomElementRegistry.js.map +1 -1
  39. package/lib/dom-implementation/DOMImplementation.js +12 -13
  40. package/lib/dom-implementation/DOMImplementation.js.map +1 -1
  41. package/lib/dom-parser/DOMParser.js +29 -35
  42. package/lib/dom-parser/DOMParser.js.map +1 -1
  43. package/lib/dom-token-list/DOMTokenList.js +64 -79
  44. package/lib/dom-token-list/DOMTokenList.js.map +1 -1
  45. package/lib/event/DataTransfer.js +4 -5
  46. package/lib/event/DataTransfer.js.map +1 -1
  47. package/lib/event/DataTransferItem.js +7 -8
  48. package/lib/event/DataTransferItem.js.map +1 -1
  49. package/lib/event/DataTransferItemList.js +10 -11
  50. package/lib/event/DataTransferItemList.js.map +1 -1
  51. package/lib/event/Event.js +11 -15
  52. package/lib/event/Event.js.map +1 -1
  53. package/lib/event/EventTarget.js +14 -16
  54. package/lib/event/EventTarget.js.map +1 -1
  55. package/lib/event/IUIEventInit.d.ts +2 -2
  56. package/lib/event/UIEvent.d.ts +2 -2
  57. package/lib/event/UIEvent.js +25 -46
  58. package/lib/event/UIEvent.js.map +1 -1
  59. package/lib/event/events/AnimationEvent.js +11 -29
  60. package/lib/event/events/AnimationEvent.js.map +1 -1
  61. package/lib/event/events/CustomEvent.js +9 -31
  62. package/lib/event/events/CustomEvent.js.map +1 -1
  63. package/lib/event/events/ErrorEvent.js +15 -34
  64. package/lib/event/events/ErrorEvent.js.map +1 -1
  65. package/lib/event/events/FocusEvent.js +7 -26
  66. package/lib/event/events/FocusEvent.js.map +1 -1
  67. package/lib/event/events/InputEvent.js +13 -32
  68. package/lib/event/events/InputEvent.js.map +1 -1
  69. package/lib/event/events/KeyboardEvent.js +27 -46
  70. package/lib/event/events/KeyboardEvent.js.map +1 -1
  71. package/lib/event/events/MouseEvent.js +33 -52
  72. package/lib/event/events/MouseEvent.js.map +1 -1
  73. package/lib/event/events/PointerEvent.js +25 -44
  74. package/lib/event/events/PointerEvent.js.map +1 -1
  75. package/lib/event/events/ProgressEvent.js +11 -30
  76. package/lib/event/events/ProgressEvent.js.map +1 -1
  77. package/lib/event/events/StorageEvent.js +13 -32
  78. package/lib/event/events/StorageEvent.js.map +1 -1
  79. package/lib/event/events/WheelEvent.js +16 -35
  80. package/lib/event/events/WheelEvent.js.map +1 -1
  81. package/lib/exception/DOMException.js +5 -24
  82. package/lib/exception/DOMException.js.map +1 -1
  83. package/lib/fetch/FetchHandler.js +18 -22
  84. package/lib/fetch/FetchHandler.js.map +1 -1
  85. package/lib/fetch/Headers.js +3 -23
  86. package/lib/fetch/Headers.js.map +1 -1
  87. package/lib/fetch/Request.js +61 -81
  88. package/lib/fetch/Request.js.map +1 -1
  89. package/lib/fetch/ResourceFetchHandler.js +18 -67
  90. package/lib/fetch/ResourceFetchHandler.js.map +1 -1
  91. package/lib/fetch/Response.js +61 -81
  92. package/lib/fetch/Response.js.map +1 -1
  93. package/lib/file/Blob.js +29 -78
  94. package/lib/file/Blob.js.map +1 -1
  95. package/lib/file/File.js +9 -27
  96. package/lib/file/File.js.map +1 -1
  97. package/lib/file/FileReader.js +57 -78
  98. package/lib/file/FileReader.js.map +1 -1
  99. package/lib/history/History.js +32 -37
  100. package/lib/history/History.js.map +1 -1
  101. package/lib/index.d.ts +5 -3
  102. package/lib/index.js +71 -69
  103. package/lib/index.js.map +1 -1
  104. package/lib/location/Location.js +11 -28
  105. package/lib/location/Location.js.map +1 -1
  106. package/lib/location/RelativeURL.js +5 -8
  107. package/lib/location/RelativeURL.js.map +1 -1
  108. package/lib/location/URL.js +46 -59
  109. package/lib/location/URL.js.map +1 -1
  110. package/lib/match-media/MediaQueryList.js +28 -54
  111. package/lib/match-media/MediaQueryList.js.map +1 -1
  112. package/lib/mutation-observer/MutationListener.js +3 -4
  113. package/lib/mutation-observer/MutationListener.js.map +1 -1
  114. package/lib/mutation-observer/MutationObserver.js +12 -13
  115. package/lib/mutation-observer/MutationObserver.js.map +1 -1
  116. package/lib/mutation-observer/MutationRecord.js +3 -4
  117. package/lib/mutation-observer/MutationRecord.js.map +1 -1
  118. package/lib/navigator/MimeType.js +5 -6
  119. package/lib/navigator/MimeType.js.map +1 -1
  120. package/lib/navigator/MimeTypeArray.js +10 -11
  121. package/lib/navigator/MimeTypeArray.js.map +1 -1
  122. package/lib/navigator/Navigator.js +7 -8
  123. package/lib/navigator/Navigator.js.map +1 -1
  124. package/lib/navigator/Plugin.js +10 -11
  125. package/lib/navigator/Plugin.js.map +1 -1
  126. package/lib/navigator/PluginArray.js +12 -13
  127. package/lib/navigator/PluginArray.js.map +1 -1
  128. package/lib/nodes/character-data/CharacterData.js +119 -184
  129. package/lib/nodes/character-data/CharacterData.js.map +1 -1
  130. package/lib/nodes/character-data/CharacterDataUtility.js +12 -15
  131. package/lib/nodes/character-data/CharacterDataUtility.js.map +1 -1
  132. package/lib/nodes/child-node/ChildNodeUtility.js +24 -45
  133. package/lib/nodes/child-node/ChildNodeUtility.js.map +1 -1
  134. package/lib/nodes/child-node/NonDocumentChildNodeUtility.js +9 -12
  135. package/lib/nodes/child-node/NonDocumentChildNodeUtility.js.map +1 -1
  136. package/lib/nodes/comment/Comment.js +20 -43
  137. package/lib/nodes/comment/Comment.js.map +1 -1
  138. package/lib/nodes/document/Document.d.ts +3 -3
  139. package/lib/nodes/document/Document.js +334 -461
  140. package/lib/nodes/document/Document.js.map +1 -1
  141. package/lib/nodes/document/DocumentReadyStateManager.js +16 -19
  142. package/lib/nodes/document/DocumentReadyStateManager.js.map +1 -1
  143. package/lib/nodes/document/IDocument.d.ts +2 -2
  144. package/lib/nodes/document-fragment/DocumentFragment.js +93 -153
  145. package/lib/nodes/document-fragment/DocumentFragment.js.map +1 -1
  146. package/lib/nodes/document-type/DocumentType.js +22 -45
  147. package/lib/nodes/document-type/DocumentType.js.map +1 -1
  148. package/lib/nodes/element/DOMRect.js +3 -4
  149. package/lib/nodes/element/DOMRect.js.map +1 -1
  150. package/lib/nodes/element/Element.js +367 -496
  151. package/lib/nodes/element/Element.js.map +1 -1
  152. package/lib/nodes/element/HTMLCollection.js +4 -24
  153. package/lib/nodes/element/HTMLCollection.js.map +1 -1
  154. package/lib/nodes/element/HTMLCollectionFactory.js +6 -9
  155. package/lib/nodes/element/HTMLCollectionFactory.js.map +1 -1
  156. package/lib/nodes/element/Range.js +89 -114
  157. package/lib/nodes/element/Range.js.map +1 -1
  158. package/lib/nodes/html-base-element/HTMLBaseElement.d.ts +42 -0
  159. package/lib/nodes/html-base-element/HTMLBaseElement.js +62 -0
  160. package/lib/nodes/html-base-element/HTMLBaseElement.js.map +1 -0
  161. package/lib/nodes/html-base-element/IHTMLBaseElement.d.ts +19 -0
  162. package/lib/nodes/html-base-element/IHTMLBaseElement.js +3 -0
  163. package/lib/nodes/html-base-element/IHTMLBaseElement.js.map +1 -0
  164. package/lib/nodes/html-document/HTMLDocument.js +3 -23
  165. package/lib/nodes/html-document/HTMLDocument.js.map +1 -1
  166. package/lib/nodes/html-element/DatasetUtility.js +9 -12
  167. package/lib/nodes/html-element/DatasetUtility.js.map +1 -1
  168. package/lib/nodes/html-element/HTMLElement.js +232 -290
  169. package/lib/nodes/html-element/HTMLElement.js.map +1 -1
  170. package/lib/nodes/html-form-element/HTMLFormElement.js +170 -235
  171. package/lib/nodes/html-form-element/HTMLFormElement.js.map +1 -1
  172. package/lib/nodes/html-image-element/HTMLImageElement.js +178 -237
  173. package/lib/nodes/html-image-element/HTMLImageElement.js.map +1 -1
  174. package/lib/nodes/html-image-element/Image.js +7 -27
  175. package/lib/nodes/html-image-element/Image.js.map +1 -1
  176. package/lib/nodes/html-input-element/HTMLInputElement.js +705 -872
  177. package/lib/nodes/html-input-element/HTMLInputElement.js.map +1 -1
  178. package/lib/nodes/html-input-element/HTMLInputElementValueSanitizer.js +9 -12
  179. package/lib/nodes/html-input-element/HTMLInputElementValueSanitizer.js.map +1 -1
  180. package/lib/nodes/html-input-element/HTMLInputElementValueStepping.js +5 -8
  181. package/lib/nodes/html-input-element/HTMLInputElementValueStepping.js.map +1 -1
  182. package/lib/nodes/html-input-element/ValidityState.js +47 -69
  183. package/lib/nodes/html-input-element/ValidityState.js.map +1 -1
  184. package/lib/nodes/html-label-element/HTMLLabelElement.js +53 -87
  185. package/lib/nodes/html-label-element/HTMLLabelElement.js.map +1 -1
  186. package/lib/nodes/html-link-element/HTMLLinkElement.js +197 -252
  187. package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
  188. package/lib/nodes/html-meta-element/HTMLMetaElement.js +66 -102
  189. package/lib/nodes/html-meta-element/HTMLMetaElement.js.map +1 -1
  190. package/lib/nodes/html-script-element/HTMLScriptElement.js +145 -193
  191. package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
  192. package/lib/nodes/html-script-element/ScriptUtility.js +58 -112
  193. package/lib/nodes/html-script-element/ScriptUtility.js.map +1 -1
  194. package/lib/nodes/html-slot-element/HTMLSlotElement.js +33 -65
  195. package/lib/nodes/html-slot-element/HTMLSlotElement.js.map +1 -1
  196. package/lib/nodes/html-style-element/HTMLStyleElement.js +75 -109
  197. package/lib/nodes/html-style-element/HTMLStyleElement.js.map +1 -1
  198. package/lib/nodes/html-template-element/HTMLTemplateElement.js +60 -99
  199. package/lib/nodes/html-template-element/HTMLTemplateElement.js.map +1 -1
  200. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js +349 -444
  201. package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js.map +1 -1
  202. package/lib/nodes/html-unknown-element/HTMLUnknownElement.js +17 -37
  203. package/lib/nodes/html-unknown-element/HTMLUnknownElement.js.map +1 -1
  204. package/lib/nodes/node/INode.d.ts +1 -0
  205. package/lib/nodes/node/Node.d.ts +6 -0
  206. package/lib/nodes/node/Node.js +193 -244
  207. package/lib/nodes/node/Node.js.map +1 -1
  208. package/lib/nodes/node/NodeList.js +4 -24
  209. package/lib/nodes/node/NodeList.js.map +1 -1
  210. package/lib/nodes/node/NodeListFactory.js +6 -9
  211. package/lib/nodes/node/NodeListFactory.js.map +1 -1
  212. package/lib/nodes/parent-node/ParentNodeUtility.js +43 -78
  213. package/lib/nodes/parent-node/ParentNodeUtility.js.map +1 -1
  214. package/lib/nodes/shadow-root/ShadowRoot.js +53 -83
  215. package/lib/nodes/shadow-root/ShadowRoot.js.map +1 -1
  216. package/lib/nodes/svg-document/SVGDocument.js +3 -23
  217. package/lib/nodes/svg-document/SVGDocument.js.map +1 -1
  218. package/lib/nodes/svg-element/DOMMatrix.js +3 -4
  219. package/lib/nodes/svg-element/DOMMatrix.js.map +1 -1
  220. package/lib/nodes/svg-element/SVGAngle.js +10 -11
  221. package/lib/nodes/svg-element/SVGAngle.js.map +1 -1
  222. package/lib/nodes/svg-element/SVGAnimatedRect.js +4 -5
  223. package/lib/nodes/svg-element/SVGAnimatedRect.js.map +1 -1
  224. package/lib/nodes/svg-element/SVGElement.js +58 -93
  225. package/lib/nodes/svg-element/SVGElement.js.map +1 -1
  226. package/lib/nodes/svg-element/SVGGraphicsElement.js +14 -32
  227. package/lib/nodes/svg-element/SVGGraphicsElement.js.map +1 -1
  228. package/lib/nodes/svg-element/SVGLength.js +16 -17
  229. package/lib/nodes/svg-element/SVGLength.js.map +1 -1
  230. package/lib/nodes/svg-element/SVGNumber.js +3 -4
  231. package/lib/nodes/svg-element/SVGNumber.js.map +1 -1
  232. package/lib/nodes/svg-element/SVGPoint.js +3 -4
  233. package/lib/nodes/svg-element/SVGPoint.js.map +1 -1
  234. package/lib/nodes/svg-element/SVGRect.js +3 -4
  235. package/lib/nodes/svg-element/SVGRect.js.map +1 -1
  236. package/lib/nodes/svg-element/SVGSVGElement.js +187 -248
  237. package/lib/nodes/svg-element/SVGSVGElement.js.map +1 -1
  238. package/lib/nodes/svg-element/SVGTransform.js +16 -17
  239. package/lib/nodes/svg-element/SVGTransform.js.map +1 -1
  240. package/lib/nodes/text/Text.js +20 -43
  241. package/lib/nodes/text/Text.js.map +1 -1
  242. package/lib/nodes/xml-document/XMLDocument.js +3 -23
  243. package/lib/nodes/xml-document/XMLDocument.js.map +1 -1
  244. package/lib/query-selector/QuerySelector.js +36 -44
  245. package/lib/query-selector/QuerySelector.js.map +1 -1
  246. package/lib/query-selector/SelectorItem.js +62 -66
  247. package/lib/query-selector/SelectorItem.js.map +1 -1
  248. package/lib/resize-observer/ResizeObserver.js +8 -11
  249. package/lib/resize-observer/ResizeObserver.js.map +1 -1
  250. package/lib/screen/Screen.js +3 -4
  251. package/lib/screen/Screen.js.map +1 -1
  252. package/lib/selection/Selection.js +29 -30
  253. package/lib/selection/Selection.js.map +1 -1
  254. package/lib/storage/Storage.js +22 -27
  255. package/lib/storage/Storage.js.map +1 -1
  256. package/lib/tree-walker/NodeFilterMask.js +1 -1
  257. package/lib/tree-walker/NodeFilterMask.js.map +1 -1
  258. package/lib/tree-walker/TreeWalker.js +30 -33
  259. package/lib/tree-walker/TreeWalker.js.map +1 -1
  260. package/lib/window/GlobalWindow.d.ts +84 -0
  261. package/lib/window/GlobalWindow.js +90 -0
  262. package/lib/window/GlobalWindow.js.map +1 -0
  263. package/lib/window/IWindow.d.ts +37 -18
  264. package/lib/window/VMGlobalPropertyScript.d.ts +2 -0
  265. package/lib/window/VMGlobalPropertyScript.js +65 -0
  266. package/lib/window/VMGlobalPropertyScript.js.map +1 -0
  267. package/lib/window/Window.d.ts +78 -105
  268. package/lib/window/Window.js +277 -489
  269. package/lib/window/Window.js.map +1 -1
  270. package/lib/xml-parser/XMLParser.js +65 -71
  271. package/lib/xml-parser/XMLParser.js.map +1 -1
  272. package/lib/xml-serializer/XMLSerializer.js +30 -37
  273. package/lib/xml-serializer/XMLSerializer.js.map +1 -1
  274. package/package.json +6 -7
  275. package/src/config/ElementTag.ts +2 -1
  276. package/src/config/NonImplemenetedElementClasses.ts +0 -1
  277. package/src/dom-parser/DOMParser.ts +4 -5
  278. package/src/event/IUIEventInit.ts +2 -2
  279. package/src/event/UIEvent.ts +2 -2
  280. package/src/fetch/FetchHandler.ts +3 -3
  281. package/src/fetch/ResourceFetchHandler.ts +3 -3
  282. package/src/index.ts +7 -3
  283. package/src/nodes/document/Document.ts +4 -4
  284. package/src/nodes/document/IDocument.ts +2 -2
  285. package/src/nodes/html-base-element/HTMLBaseElement.ts +61 -0
  286. package/src/nodes/html-base-element/IHTMLBaseElement.ts +21 -0
  287. package/src/nodes/html-link-element/HTMLLinkElement.ts +8 -2
  288. package/src/nodes/html-script-element/ScriptUtility.ts +4 -4
  289. package/src/nodes/node/INode.ts +1 -0
  290. package/src/nodes/node/Node.ts +14 -0
  291. package/src/window/GlobalWindow.ts +82 -0
  292. package/src/window/IWindow.ts +33 -12
  293. package/src/window/VMGlobalPropertyScript.ts +62 -0
  294. package/src/window/Window.ts +115 -173
  295. package/tsconfig.json +1 -1
  296. package/lib/window/AsyncWindow.d.ts +0 -10
  297. package/lib/window/AsyncWindow.js +0 -38
  298. package/lib/window/AsyncWindow.js.map +0 -1
  299. package/src/window/AsyncWindow.ts +0 -17
@@ -20,6 +20,7 @@ import HTMLStyleElement from '../nodes/html-style-element/HTMLStyleElement';
20
20
  import HTMLSlotElement from '../nodes/html-slot-element/HTMLSlotElement';
21
21
  import HTMLLabelElement from '../nodes/html-label-element/HTMLLabelElement';
22
22
  import HTMLMetaElement from '../nodes/html-meta-element/HTMLMetaElement';
23
+ import HTMLBaseElement from '../nodes/html-base-element/HTMLBaseElement';
23
24
  import SVGSVGElement from '../nodes/svg-element/SVGSVGElement';
24
25
  import SVGElement from '../nodes/svg-element/SVGElement';
25
26
  import HTMLScriptElement from '../nodes/html-script-element/HTMLScriptElement';
@@ -70,25 +71,34 @@ import IRequest from '../fetch/IRequest';
70
71
  import IRequestInit from '../fetch/IRequestInit';
71
72
  import IHeaders from '../fetch/IHeaders';
72
73
  import IHeadersInit from '../fetch/IHeadersInit';
74
+ import Headers from '../fetch/Headers';
75
+ import Request from '../fetch/Request';
76
+ import Response from '../fetch/Response';
73
77
  import Storage from '../storage/Storage';
74
78
  import IWindow from './IWindow';
75
79
  import HTMLCollection from '../nodes/element/HTMLCollection';
76
80
  import NodeList from '../nodes/node/NodeList';
77
81
  import MediaQueryList from '../match-media/MediaQueryList';
78
82
  import Selection from '../selection/Selection';
79
- import * as PerfHooks from 'perf_hooks';
80
83
  import Navigator from '../navigator/Navigator';
81
84
  import MimeType from '../navigator/MimeType';
82
85
  import MimeTypeArray from '../navigator/MimeTypeArray';
83
86
  import Plugin from '../navigator/Plugin';
84
87
  import PluginArray from '../navigator/PluginArray';
85
- import FetchHandler from '../fetch/FetchHandler';
86
88
  import { URLSearchParams } from 'url';
89
+ import FetchHandler from '../fetch/FetchHandler';
90
+ import VMGlobalPropertyScript from './VMGlobalPropertyScript';
91
+ import * as PerfHooks from 'perf_hooks';
92
+ import VM from 'vm';
93
+ import { Buffer } from 'buffer';
87
94
 
88
95
  /**
89
- * Handles the Window.
96
+ * Browser window.
97
+ *
98
+ * Reference:
99
+ * https://developer.mozilla.org/en-US/docs/Web/API/Window.
90
100
  */
91
- export default class Window extends EventTarget implements IWindow, NodeJS.Global {
101
+ export default class Window extends EventTarget implements IWindow {
92
102
  // Public Properties
93
103
  public readonly happyDOM = {
94
104
  whenAsyncComplete: async (): Promise<void> => {
@@ -116,6 +126,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
116
126
  public readonly HTMLLabelElement = HTMLLabelElement;
117
127
  public readonly HTMLSlotElement = HTMLSlotElement;
118
128
  public readonly HTMLMetaElement = HTMLMetaElement;
129
+ public readonly HTMLBaseElement = HTMLBaseElement;
119
130
  public readonly SVGSVGElement = SVGSVGElement;
120
131
  public readonly SVGElement = SVGElement;
121
132
  public readonly Text = Text;
@@ -152,7 +163,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
152
163
  public readonly URL = URL;
153
164
  public readonly Location = Location;
154
165
  public readonly CustomElementRegistry = CustomElementRegistry;
155
- public readonly Window = Window;
166
+ public readonly Window = <typeof Window>this.constructor;
156
167
  public readonly XMLSerializer = XMLSerializer;
157
168
  public readonly ResizeObserver = ResizeObserver;
158
169
  public readonly CSSStyleSheet = CSSStyleSheet;
@@ -174,6 +185,13 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
174
185
  public readonly MimeTypeArray = MimeTypeArray;
175
186
  public readonly Plugin = Plugin;
176
187
  public readonly PluginArray = PluginArray;
188
+ public readonly Headers: { new (init?: IHeadersInit): IHeaders } = Headers;
189
+ public readonly Request: {
190
+ new (input: string | { href: string } | IRequest, init?: IRequestInit): IRequest;
191
+ } = Request;
192
+ public readonly Response: {
193
+ new (body?: NodeJS.ReadableStream | null, init?: IResponseInit): IResponse;
194
+ } = Response;
177
195
 
178
196
  // Events
179
197
  public onload: (event: Event) => void = null;
@@ -185,7 +203,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
185
203
  public readonly location = new Location();
186
204
  public readonly history = new History();
187
205
  public readonly navigator = new Navigator();
188
- public readonly console = global ? global.console : null;
206
+ public readonly console = console;
189
207
  public readonly self = this;
190
208
  public readonly top = this;
191
209
  public readonly parent = this;
@@ -200,69 +218,67 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
200
218
  public readonly performance = PerfHooks.performance;
201
219
 
202
220
  // Node.js Globals
203
- public ArrayBuffer = global ? global.ArrayBuffer : null;
204
- public Boolean = global ? global.Boolean : null;
205
- public Buffer = null;
206
- public DataView = global ? global.DataView : null;
207
- public Date = global ? global.Date : null;
208
- public Error = global ? global.Error : null;
209
- public EvalError = global ? global.EvalError : null;
210
- public Float32Array = global ? global.Float32Array : null;
211
- public Float64Array = global ? global.Float64Array : null;
212
- public GLOBAL = null;
213
- public Infinity = global ? global.Infinity : null;
214
- public Int16Array = global ? global.Int16Array : null;
215
- public Int32Array = global ? global.Int32Array : null;
216
- public Int8Array = global ? global.Int8Array : null;
217
- public Intl = global ? global.Intl : null;
218
- public JSON = global ? global.JSON : null;
219
- public Map = global ? global.Map : null;
220
- public Math = global ? global.Math : null;
221
- public NaN = global ? global.NaN : null;
222
- public Number = global ? global.Number : null;
223
- public Promise = global ? global.Promise : null;
224
- public RangeError = global ? global.RangeError : null;
225
- public ReferenceError = global ? global.ReferenceError : null;
226
- public RegExp = global ? global.RegExp : null;
227
- public Reflect = global ? global.Reflect : null;
228
- public Set = global ? global.Set : null;
229
- public Symbol = global ? global.Symbol : null;
230
- public SyntaxError = global ? global.SyntaxError : null;
231
- public String = global ? global.String : null;
232
- public TypeError = global ? global.TypeError : null;
233
- public URIError = global ? global.URIError : null;
234
- public Uint16Array = global ? global.Uint16Array : null;
235
- public Uint32Array = global ? global.Uint32Array : null;
236
- public Uint8Array = global ? global.Uint8Array : null;
237
- public Uint8ClampedArray = global ? global.Uint8ClampedArray : null;
238
- public WeakMap = global ? global.WeakMap : null;
239
- public WeakSet = global ? global.WeakSet : null;
240
- public clearImmediate = null;
241
- public decodeURI = global ? global.decodeURI : null;
242
- public decodeURIComponent = global ? global.decodeURIComponent : null;
243
- public encodeURI = global ? global.encodeURI : null;
244
- public encodeURIComponent = global ? global.encodeURIComponent : null;
245
- public escape = global ? global.escape : null;
246
- public global = null;
247
- public isFinite = global ? global.isFinite : null;
248
- public isNaN = global ? global.isNaN : null;
249
- public parseFloat = global ? global.parseFloat : null;
250
- public parseInt = global ? global.parseInt : null;
251
- public process = null;
252
- public root = null;
253
- public setImmediate = null;
254
- public queueMicrotask = global ? global.queueMicrotask : null;
255
- public undefined = global ? global.undefined : null;
256
- public unescape = global ? global.unescape : null;
257
- public gc = null;
258
- public v8debug = null;
259
- public AbortController = global ? global.AbortController : null;
260
- public AbortSignal = global ? global.AbortSignal : null;
261
-
262
- // Private properties
263
- private _objectClass: typeof globalThis.Object = null;
264
- private _arrayClass: typeof globalThis.Array = null;
265
- private _functionClass: typeof globalThis.Function = null;
221
+ public ArrayBuffer;
222
+ public Boolean;
223
+ public Buffer = Buffer;
224
+ public DataView;
225
+ public Date;
226
+ public Error;
227
+ public EvalError;
228
+ public Float32Array;
229
+ public Float64Array;
230
+ public GLOBAL;
231
+ public Infinity;
232
+ public Int16Array;
233
+ public Int32Array;
234
+ public Int8Array;
235
+ public Intl;
236
+ public JSON;
237
+ public Map;
238
+ public Math;
239
+ public NaN;
240
+ public Number;
241
+ public Promise;
242
+ public RangeError;
243
+ public ReferenceError;
244
+ public RegExp;
245
+ public Reflect;
246
+ public Set;
247
+ public Symbol;
248
+ public SyntaxError;
249
+ public String;
250
+ public TypeError;
251
+ public URIError;
252
+ public Uint16Array;
253
+ public Uint32Array;
254
+ public Uint8Array;
255
+ public Uint8ClampedArray;
256
+ public WeakMap;
257
+ public WeakSet;
258
+ public clearImmediate;
259
+ public decodeURI;
260
+ public decodeURIComponent;
261
+ public encodeURI;
262
+ public encodeURIComponent;
263
+ public escape;
264
+ public global;
265
+ public isFinite;
266
+ public isNaN;
267
+ public parseFloat;
268
+ public parseInt;
269
+ public process;
270
+ public root;
271
+ public setImmediate;
272
+ public queueMicrotask;
273
+ public undefined;
274
+ public unescape;
275
+ public gc;
276
+ public v8debug;
277
+ public AbortController;
278
+ public AbortSignal;
279
+ public Array;
280
+ public Object;
281
+ public Function;
266
282
 
267
283
  /**
268
284
  * Constructor.
@@ -276,9 +292,11 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
276
292
  this.dispatchEvent(new Event('load'));
277
293
  });
278
294
 
279
- DOMParser._ownerDocument = DOMParser._ownerDocument || this.document;
280
- FileReader._ownerDocument = FileReader._ownerDocument || this.document;
281
- Image.ownerDocument = Image.ownerDocument || this.document;
295
+ DOMParser._ownerDocument = this.document;
296
+ FileReader._ownerDocument = this.document;
297
+ Image.ownerDocument = this.document;
298
+ Request._ownerDocument = this.document;
299
+ Response._ownerDocument = this.document;
282
300
 
283
301
  for (const eventType of NonImplementedEventTypes) {
284
302
  if (!this[eventType]) {
@@ -293,56 +311,20 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
293
311
  }
294
312
 
295
313
  // Binds all methods to "this", so that it will use the correct context when called globally.
296
- for (const key of Object.keys(Window.prototype)) {
297
- if (typeof this[key] === 'function') {
314
+ for (const key of Object.getOwnPropertyNames(this.constructor.prototype)) {
315
+ if (key !== 'constructor' && key !== 'CSS' && typeof this[key] === 'function') {
298
316
  this[key] = this[key].bind(this);
299
317
  }
300
318
  }
301
- }
302
319
 
303
- /**
304
- * Returns Object class.
305
- *
306
- * @returns Object class.
307
- */
308
- public get Object(): typeof globalThis.Object {
309
- if (this._objectClass) {
310
- return this._objectClass;
311
- }
312
- // When inside a VM global.Object is not the same as ({}).constructor
313
- // We will therefore run the code inside the VM to get the real constructor
314
- this._objectClass = <typeof globalThis.Object>this.eval('({}).constructor');
315
- return this._objectClass;
316
- }
320
+ // Only contextify if there isn't any sub-class handling globals (like GlobalWindow)
321
+ if (this.Array === undefined && !VM.isContext(this)) {
322
+ VM.createContext(this);
317
323
 
318
- /**
319
- * Returns Array class.
320
- *
321
- * @returns Array class.
322
- */
323
- public get Array(): typeof globalThis.Array {
324
- if (this._arrayClass) {
325
- return this._arrayClass;
326
- }
327
- // When inside a VM global.Object is not the same as [].constructor
328
- // We will therefore run the code inside the VM to get the real constructor
329
- this._arrayClass = <typeof globalThis.Array>this.eval('[].constructor');
330
- return this._arrayClass;
331
- }
332
-
333
- /**
334
- * Returns Function class.
335
- *
336
- * @returns Function class.
337
- */
338
- public get Function(): typeof globalThis.Function {
339
- if (this._functionClass) {
340
- return this._functionClass;
324
+ // Sets global properties from the VM to the Window object.
325
+ // Otherwise "this.Array" will be undefined for example.
326
+ VM.runInContext(VMGlobalPropertyScript, this);
341
327
  }
342
- // When inside a VM global.Function is not the same as (() => {}).constructor
343
- // We will therefore run the code inside the VM to get the real constructor
344
- this._functionClass = <typeof globalThis.Function>this.eval('(() => {}).constructor');
345
- return this._functionClass;
346
328
  }
347
329
 
348
330
  /**
@@ -354,68 +336,19 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
354
336
  return new CSS();
355
337
  }
356
338
 
357
- /**
358
- * Returns Headers class.
359
- *
360
- * @returns Headers.
361
- */
362
- public get Headers(): {
363
- new (init?: IHeadersInit): IHeaders;
364
- } {
365
- return require('../fetch/Headers').default;
366
- }
367
-
368
- /**
369
- * Returns Request class.
370
- *
371
- * @returns Request.
372
- */
373
- public get Request(): {
374
- new (input: string | { href: string } | IRequest, init?: IRequestInit): IRequest;
375
- } {
376
- const Request = require('../fetch/Request').default;
377
- Request._ownerDocument = Request._ownerDocument || this.document;
378
- return Request;
379
- }
380
-
381
- /**
382
- * Returns Response class.
383
- *
384
- * @returns Response.
385
- */
386
- public get Response(): {
387
- new (body?: NodeJS.ReadableStream | null, init?: IResponseInit): IResponse;
388
- } {
389
- const Response = require('../fetch/Response').default;
390
- Response._ownerDocument = Response._ownerDocument || this.document;
391
- return Response;
392
- }
393
-
394
339
  /**
395
340
  * Evaluates code.
396
341
  *
342
+ * @override
397
343
  * @param code Code.
398
344
  * @returns Result.
399
345
  */
400
346
  public eval(code: string): unknown {
401
- let vmExists = false;
402
- let vm = null;
403
-
404
- try {
405
- vmExists = !!require.resolve('vm');
406
- } catch (error) {
407
- // Ignore error;
408
- }
409
-
410
- if (vmExists) {
411
- vm = require('vm');
412
- }
413
-
414
- if (vm && vm.isContext(this)) {
415
- return vm.runInContext(code, this);
347
+ if (VM.isContext(this)) {
348
+ return VM.runInContext(code, this);
416
349
  }
417
350
 
418
- return global.eval(code);
351
+ return eval(code);
419
352
  }
420
353
 
421
354
  /**
@@ -428,6 +361,15 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
428
361
  return new CSSStyleDeclaration(element._attributes, element);
429
362
  }
430
363
 
364
+ /**
365
+ * Returns selection.
366
+ *
367
+ * @returns Selection.
368
+ */
369
+ public getSelection(): Selection {
370
+ return this.document.getSelection();
371
+ }
372
+
431
373
  /**
432
374
  * Scrolls to a particular set of coordinates.
433
375
  *
@@ -493,7 +435,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
493
435
  * @returns Timeout ID.
494
436
  */
495
437
  public setTimeout(callback: () => void, delay = 0): NodeJS.Timeout {
496
- const id = global.setTimeout(() => {
438
+ const id = setTimeout(() => {
497
439
  this.happyDOM.asyncTaskManager.endTimer(id);
498
440
  callback();
499
441
  }, delay);
@@ -508,7 +450,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
508
450
  * @param id ID of the timeout.
509
451
  */
510
452
  public clearTimeout(id: NodeJS.Timeout): void {
511
- global.clearTimeout(id);
453
+ clearTimeout(id);
512
454
  this.happyDOM.asyncTaskManager.endTimer(id);
513
455
  }
514
456
 
@@ -521,7 +463,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
521
463
  * @returns Interval ID.
522
464
  */
523
465
  public setInterval(callback: () => void, delay = 0): NodeJS.Timeout {
524
- const id = global.setInterval(callback, delay);
466
+ const id = setInterval(callback, delay);
525
467
  this.happyDOM.asyncTaskManager.startTimer(id);
526
468
  return id;
527
469
  }
@@ -533,7 +475,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
533
475
  * @param id ID of the interval.
534
476
  */
535
477
  public clearInterval(id: NodeJS.Timeout): void {
536
- global.clearInterval(id);
478
+ clearInterval(id);
537
479
  this.happyDOM.asyncTaskManager.endTimer(id);
538
480
  }
539
481
 
package/tsconfig.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "outDir": "lib",
4
4
  "rootDir": "src",
5
5
  "tsBuildInfoFile": "tmp/.tsbuildinfo",
6
- "target": "es5",
6
+ "target": "es2020",
7
7
  "declaration": true,
8
8
  "module": "CommonJS",
9
9
  "moduleResolution": "node",
@@ -1,10 +0,0 @@
1
- import Window from './Window';
2
- /**
3
- * The async Window makes it possible to wait for asyncrounous tasks to complete by calling the method whenAsyncComplete(). It also adds support for the method fetch().
4
- */
5
- export default class AsyncWindow extends Window {
6
- /**
7
- * Constructor.
8
- */
9
- constructor();
10
- }
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __importDefault = (this && this.__importDefault) || function (mod) {
18
- return (mod && mod.__esModule) ? mod : { "default": mod };
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- var Window_1 = __importDefault(require("./Window"));
22
- /**
23
- * The async Window makes it possible to wait for asyncrounous tasks to complete by calling the method whenAsyncComplete(). It also adds support for the method fetch().
24
- */
25
- var AsyncWindow = /** @class */ (function (_super) {
26
- __extends(AsyncWindow, _super);
27
- /**
28
- * Constructor.
29
- */
30
- function AsyncWindow() {
31
- var _this = _super.call(this) || this;
32
- _this.console.warn('⚠ AsyncWindow has been deprecated in Happy DOM. All the functionality of AsyncWindow has been added to Window, so there is no need to use AsyncWindow. AsyncWindow will be removed in the future.');
33
- return _this;
34
- }
35
- return AsyncWindow;
36
- }(Window_1.default));
37
- exports.default = AsyncWindow;
38
- //# sourceMappingURL=AsyncWindow.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AsyncWindow.js","sourceRoot":"","sources":["../../src/window/AsyncWindow.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,oDAA8B;AAE9B;;GAEG;AACH;IAAyC,+BAAM;IAC9C;;OAEG;IACH;QAAA,YACC,iBAAO,SAKP;QAHA,KAAI,CAAC,OAAO,CAAC,IAAI,CAChB,mMAAmM,CACnM,CAAC;;IACH,CAAC;IACF,kBAAC;AAAD,CAAC,AAXD,CAAyC,gBAAM,GAW9C"}
@@ -1,17 +0,0 @@
1
- import Window from './Window';
2
-
3
- /**
4
- * The async Window makes it possible to wait for asyncrounous tasks to complete by calling the method whenAsyncComplete(). It also adds support for the method fetch().
5
- */
6
- export default class AsyncWindow extends Window {
7
- /**
8
- * Constructor.
9
- */
10
- constructor() {
11
- super();
12
-
13
- this.console.warn(
14
- '⚠ AsyncWindow has been deprecated in Happy DOM. All the functionality of AsyncWindow has been added to Window, so there is no need to use AsyncWindow. AsyncWindow will be removed in the future.'
15
- );
16
- }
17
- }