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.
- package/README.md +26 -6
- package/lib/async-task-manager/AsyncTaskManager.js +34 -78
- package/lib/async-task-manager/AsyncTaskManager.js.map +1 -1
- package/lib/attribute/Attr.js +19 -28
- package/lib/attribute/Attr.js.map +1 -1
- package/lib/config/ElementTag.d.ts +2 -1
- package/lib/config/ElementTag.js +16 -15
- package/lib/config/ElementTag.js.map +1 -1
- package/lib/config/NonImplemenetedElementClasses.js +0 -1
- package/lib/config/NonImplemenetedElementClasses.js.map +1 -1
- package/lib/cookie/CookieUtility.js +21 -26
- package/lib/cookie/CookieUtility.js.map +1 -1
- package/lib/css/CSS.js +12 -18
- package/lib/css/CSS.js.map +1 -1
- package/lib/css/CSSParser.js +29 -33
- package/lib/css/CSSParser.js.map +1 -1
- package/lib/css/CSSRule.js +24 -29
- package/lib/css/CSSRule.js.map +1 -1
- package/lib/css/CSSStyleDeclaration.js +4516 -6005
- package/lib/css/CSSStyleDeclaration.js.map +1 -1
- package/lib/css/CSSStyleSheet.js +17 -59
- package/lib/css/CSSStyleSheet.js.map +1 -1
- package/lib/css/CSSUnitValue.js +4 -5
- package/lib/css/CSSUnitValue.js.map +1 -1
- package/lib/css/MediaList.js +23 -28
- package/lib/css/MediaList.js.map +1 -1
- package/lib/css/rules/CSSFontFaceRule.js +6 -24
- package/lib/css/rules/CSSFontFaceRule.js.map +1 -1
- package/lib/css/rules/CSSKeyframeRule.js +14 -36
- package/lib/css/rules/CSSKeyframeRule.js.map +1 -1
- package/lib/css/rules/CSSKeyframesRule.js +31 -54
- package/lib/css/rules/CSSKeyframesRule.js.map +1 -1
- package/lib/css/rules/CSSMediaRule.js +29 -56
- package/lib/css/rules/CSSMediaRule.js.map +1 -1
- package/lib/css/rules/CSSStyleRule.js +16 -38
- package/lib/css/rules/CSSStyleRule.js.map +1 -1
- package/lib/custom-element/CustomElementRegistry.js +21 -24
- package/lib/custom-element/CustomElementRegistry.js.map +1 -1
- package/lib/dom-implementation/DOMImplementation.js +12 -13
- package/lib/dom-implementation/DOMImplementation.js.map +1 -1
- package/lib/dom-parser/DOMParser.js +29 -35
- package/lib/dom-parser/DOMParser.js.map +1 -1
- package/lib/dom-token-list/DOMTokenList.js +64 -79
- package/lib/dom-token-list/DOMTokenList.js.map +1 -1
- package/lib/event/DataTransfer.js +4 -5
- package/lib/event/DataTransfer.js.map +1 -1
- package/lib/event/DataTransferItem.js +7 -8
- package/lib/event/DataTransferItem.js.map +1 -1
- package/lib/event/DataTransferItemList.js +10 -11
- package/lib/event/DataTransferItemList.js.map +1 -1
- package/lib/event/Event.js +11 -15
- package/lib/event/Event.js.map +1 -1
- package/lib/event/EventTarget.js +14 -16
- package/lib/event/EventTarget.js.map +1 -1
- package/lib/event/IUIEventInit.d.ts +2 -2
- package/lib/event/UIEvent.d.ts +2 -2
- package/lib/event/UIEvent.js +25 -46
- package/lib/event/UIEvent.js.map +1 -1
- package/lib/event/events/AnimationEvent.js +11 -29
- package/lib/event/events/AnimationEvent.js.map +1 -1
- package/lib/event/events/CustomEvent.js +9 -31
- package/lib/event/events/CustomEvent.js.map +1 -1
- package/lib/event/events/ErrorEvent.js +15 -34
- package/lib/event/events/ErrorEvent.js.map +1 -1
- package/lib/event/events/FocusEvent.js +7 -26
- package/lib/event/events/FocusEvent.js.map +1 -1
- package/lib/event/events/InputEvent.js +13 -32
- package/lib/event/events/InputEvent.js.map +1 -1
- package/lib/event/events/KeyboardEvent.js +27 -46
- package/lib/event/events/KeyboardEvent.js.map +1 -1
- package/lib/event/events/MouseEvent.js +33 -52
- package/lib/event/events/MouseEvent.js.map +1 -1
- package/lib/event/events/PointerEvent.js +25 -44
- package/lib/event/events/PointerEvent.js.map +1 -1
- package/lib/event/events/ProgressEvent.js +11 -30
- package/lib/event/events/ProgressEvent.js.map +1 -1
- package/lib/event/events/StorageEvent.js +13 -32
- package/lib/event/events/StorageEvent.js.map +1 -1
- package/lib/event/events/WheelEvent.js +16 -35
- package/lib/event/events/WheelEvent.js.map +1 -1
- package/lib/exception/DOMException.js +5 -24
- package/lib/exception/DOMException.js.map +1 -1
- package/lib/fetch/FetchHandler.js +18 -22
- package/lib/fetch/FetchHandler.js.map +1 -1
- package/lib/fetch/Headers.js +3 -23
- package/lib/fetch/Headers.js.map +1 -1
- package/lib/fetch/Request.js +61 -81
- package/lib/fetch/Request.js.map +1 -1
- package/lib/fetch/ResourceFetchHandler.js +18 -67
- package/lib/fetch/ResourceFetchHandler.js.map +1 -1
- package/lib/fetch/Response.js +61 -81
- package/lib/fetch/Response.js.map +1 -1
- package/lib/file/Blob.js +29 -78
- package/lib/file/Blob.js.map +1 -1
- package/lib/file/File.js +9 -27
- package/lib/file/File.js.map +1 -1
- package/lib/file/FileReader.js +57 -78
- package/lib/file/FileReader.js.map +1 -1
- package/lib/history/History.js +32 -37
- package/lib/history/History.js.map +1 -1
- package/lib/index.d.ts +5 -3
- package/lib/index.js +71 -69
- package/lib/index.js.map +1 -1
- package/lib/location/Location.js +11 -28
- package/lib/location/Location.js.map +1 -1
- package/lib/location/RelativeURL.js +5 -8
- package/lib/location/RelativeURL.js.map +1 -1
- package/lib/location/URL.js +46 -59
- package/lib/location/URL.js.map +1 -1
- package/lib/match-media/MediaQueryList.js +28 -54
- package/lib/match-media/MediaQueryList.js.map +1 -1
- package/lib/mutation-observer/MutationListener.js +3 -4
- package/lib/mutation-observer/MutationListener.js.map +1 -1
- package/lib/mutation-observer/MutationObserver.js +12 -13
- package/lib/mutation-observer/MutationObserver.js.map +1 -1
- package/lib/mutation-observer/MutationRecord.js +3 -4
- package/lib/mutation-observer/MutationRecord.js.map +1 -1
- package/lib/navigator/MimeType.js +5 -6
- package/lib/navigator/MimeType.js.map +1 -1
- package/lib/navigator/MimeTypeArray.js +10 -11
- package/lib/navigator/MimeTypeArray.js.map +1 -1
- package/lib/navigator/Navigator.js +7 -8
- package/lib/navigator/Navigator.js.map +1 -1
- package/lib/navigator/Plugin.js +10 -11
- package/lib/navigator/Plugin.js.map +1 -1
- package/lib/navigator/PluginArray.js +12 -13
- package/lib/navigator/PluginArray.js.map +1 -1
- package/lib/nodes/character-data/CharacterData.js +119 -184
- package/lib/nodes/character-data/CharacterData.js.map +1 -1
- package/lib/nodes/character-data/CharacterDataUtility.js +12 -15
- package/lib/nodes/character-data/CharacterDataUtility.js.map +1 -1
- package/lib/nodes/child-node/ChildNodeUtility.js +24 -45
- package/lib/nodes/child-node/ChildNodeUtility.js.map +1 -1
- package/lib/nodes/child-node/NonDocumentChildNodeUtility.js +9 -12
- package/lib/nodes/child-node/NonDocumentChildNodeUtility.js.map +1 -1
- package/lib/nodes/comment/Comment.js +20 -43
- package/lib/nodes/comment/Comment.js.map +1 -1
- package/lib/nodes/document/Document.d.ts +3 -3
- package/lib/nodes/document/Document.js +334 -461
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/document/DocumentReadyStateManager.js +16 -19
- package/lib/nodes/document/DocumentReadyStateManager.js.map +1 -1
- package/lib/nodes/document/IDocument.d.ts +2 -2
- package/lib/nodes/document-fragment/DocumentFragment.js +93 -153
- package/lib/nodes/document-fragment/DocumentFragment.js.map +1 -1
- package/lib/nodes/document-type/DocumentType.js +22 -45
- package/lib/nodes/document-type/DocumentType.js.map +1 -1
- package/lib/nodes/element/DOMRect.js +3 -4
- package/lib/nodes/element/DOMRect.js.map +1 -1
- package/lib/nodes/element/Element.js +367 -496
- package/lib/nodes/element/Element.js.map +1 -1
- package/lib/nodes/element/HTMLCollection.js +4 -24
- package/lib/nodes/element/HTMLCollection.js.map +1 -1
- package/lib/nodes/element/HTMLCollectionFactory.js +6 -9
- package/lib/nodes/element/HTMLCollectionFactory.js.map +1 -1
- package/lib/nodes/element/Range.js +89 -114
- package/lib/nodes/element/Range.js.map +1 -1
- package/lib/nodes/html-base-element/HTMLBaseElement.d.ts +42 -0
- package/lib/nodes/html-base-element/HTMLBaseElement.js +62 -0
- package/lib/nodes/html-base-element/HTMLBaseElement.js.map +1 -0
- package/lib/nodes/html-base-element/IHTMLBaseElement.d.ts +19 -0
- package/lib/nodes/html-base-element/IHTMLBaseElement.js +3 -0
- package/lib/nodes/html-base-element/IHTMLBaseElement.js.map +1 -0
- package/lib/nodes/html-document/HTMLDocument.js +3 -23
- package/lib/nodes/html-document/HTMLDocument.js.map +1 -1
- package/lib/nodes/html-element/DatasetUtility.js +9 -12
- package/lib/nodes/html-element/DatasetUtility.js.map +1 -1
- package/lib/nodes/html-element/HTMLElement.js +232 -290
- package/lib/nodes/html-element/HTMLElement.js.map +1 -1
- package/lib/nodes/html-form-element/HTMLFormElement.js +170 -235
- package/lib/nodes/html-form-element/HTMLFormElement.js.map +1 -1
- package/lib/nodes/html-image-element/HTMLImageElement.js +178 -237
- package/lib/nodes/html-image-element/HTMLImageElement.js.map +1 -1
- package/lib/nodes/html-image-element/Image.js +7 -27
- package/lib/nodes/html-image-element/Image.js.map +1 -1
- package/lib/nodes/html-input-element/HTMLInputElement.js +705 -872
- package/lib/nodes/html-input-element/HTMLInputElement.js.map +1 -1
- package/lib/nodes/html-input-element/HTMLInputElementValueSanitizer.js +9 -12
- package/lib/nodes/html-input-element/HTMLInputElementValueSanitizer.js.map +1 -1
- package/lib/nodes/html-input-element/HTMLInputElementValueStepping.js +5 -8
- package/lib/nodes/html-input-element/HTMLInputElementValueStepping.js.map +1 -1
- package/lib/nodes/html-input-element/ValidityState.js +47 -69
- package/lib/nodes/html-input-element/ValidityState.js.map +1 -1
- package/lib/nodes/html-label-element/HTMLLabelElement.js +53 -87
- package/lib/nodes/html-label-element/HTMLLabelElement.js.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElement.js +197 -252
- package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
- package/lib/nodes/html-meta-element/HTMLMetaElement.js +66 -102
- package/lib/nodes/html-meta-element/HTMLMetaElement.js.map +1 -1
- package/lib/nodes/html-script-element/HTMLScriptElement.js +145 -193
- package/lib/nodes/html-script-element/HTMLScriptElement.js.map +1 -1
- package/lib/nodes/html-script-element/ScriptUtility.js +58 -112
- package/lib/nodes/html-script-element/ScriptUtility.js.map +1 -1
- package/lib/nodes/html-slot-element/HTMLSlotElement.js +33 -65
- package/lib/nodes/html-slot-element/HTMLSlotElement.js.map +1 -1
- package/lib/nodes/html-style-element/HTMLStyleElement.js +75 -109
- package/lib/nodes/html-style-element/HTMLStyleElement.js.map +1 -1
- package/lib/nodes/html-template-element/HTMLTemplateElement.js +60 -99
- package/lib/nodes/html-template-element/HTMLTemplateElement.js.map +1 -1
- package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js +349 -444
- package/lib/nodes/html-text-area-element/HTMLTextAreaElement.js.map +1 -1
- package/lib/nodes/html-unknown-element/HTMLUnknownElement.js +17 -37
- package/lib/nodes/html-unknown-element/HTMLUnknownElement.js.map +1 -1
- package/lib/nodes/node/INode.d.ts +1 -0
- package/lib/nodes/node/Node.d.ts +6 -0
- package/lib/nodes/node/Node.js +193 -244
- package/lib/nodes/node/Node.js.map +1 -1
- package/lib/nodes/node/NodeList.js +4 -24
- package/lib/nodes/node/NodeList.js.map +1 -1
- package/lib/nodes/node/NodeListFactory.js +6 -9
- package/lib/nodes/node/NodeListFactory.js.map +1 -1
- package/lib/nodes/parent-node/ParentNodeUtility.js +43 -78
- package/lib/nodes/parent-node/ParentNodeUtility.js.map +1 -1
- package/lib/nodes/shadow-root/ShadowRoot.js +53 -83
- package/lib/nodes/shadow-root/ShadowRoot.js.map +1 -1
- package/lib/nodes/svg-document/SVGDocument.js +3 -23
- package/lib/nodes/svg-document/SVGDocument.js.map +1 -1
- package/lib/nodes/svg-element/DOMMatrix.js +3 -4
- package/lib/nodes/svg-element/DOMMatrix.js.map +1 -1
- package/lib/nodes/svg-element/SVGAngle.js +10 -11
- package/lib/nodes/svg-element/SVGAngle.js.map +1 -1
- package/lib/nodes/svg-element/SVGAnimatedRect.js +4 -5
- package/lib/nodes/svg-element/SVGAnimatedRect.js.map +1 -1
- package/lib/nodes/svg-element/SVGElement.js +58 -93
- package/lib/nodes/svg-element/SVGElement.js.map +1 -1
- package/lib/nodes/svg-element/SVGGraphicsElement.js +14 -32
- package/lib/nodes/svg-element/SVGGraphicsElement.js.map +1 -1
- package/lib/nodes/svg-element/SVGLength.js +16 -17
- package/lib/nodes/svg-element/SVGLength.js.map +1 -1
- package/lib/nodes/svg-element/SVGNumber.js +3 -4
- package/lib/nodes/svg-element/SVGNumber.js.map +1 -1
- package/lib/nodes/svg-element/SVGPoint.js +3 -4
- package/lib/nodes/svg-element/SVGPoint.js.map +1 -1
- package/lib/nodes/svg-element/SVGRect.js +3 -4
- package/lib/nodes/svg-element/SVGRect.js.map +1 -1
- package/lib/nodes/svg-element/SVGSVGElement.js +187 -248
- package/lib/nodes/svg-element/SVGSVGElement.js.map +1 -1
- package/lib/nodes/svg-element/SVGTransform.js +16 -17
- package/lib/nodes/svg-element/SVGTransform.js.map +1 -1
- package/lib/nodes/text/Text.js +20 -43
- package/lib/nodes/text/Text.js.map +1 -1
- package/lib/nodes/xml-document/XMLDocument.js +3 -23
- package/lib/nodes/xml-document/XMLDocument.js.map +1 -1
- package/lib/query-selector/QuerySelector.js +36 -44
- package/lib/query-selector/QuerySelector.js.map +1 -1
- package/lib/query-selector/SelectorItem.js +62 -66
- package/lib/query-selector/SelectorItem.js.map +1 -1
- package/lib/resize-observer/ResizeObserver.js +8 -11
- package/lib/resize-observer/ResizeObserver.js.map +1 -1
- package/lib/screen/Screen.js +3 -4
- package/lib/screen/Screen.js.map +1 -1
- package/lib/selection/Selection.js +29 -30
- package/lib/selection/Selection.js.map +1 -1
- package/lib/storage/Storage.js +22 -27
- package/lib/storage/Storage.js.map +1 -1
- package/lib/tree-walker/NodeFilterMask.js +1 -1
- package/lib/tree-walker/NodeFilterMask.js.map +1 -1
- package/lib/tree-walker/TreeWalker.js +30 -33
- package/lib/tree-walker/TreeWalker.js.map +1 -1
- package/lib/window/GlobalWindow.d.ts +84 -0
- package/lib/window/GlobalWindow.js +90 -0
- package/lib/window/GlobalWindow.js.map +1 -0
- package/lib/window/IWindow.d.ts +37 -18
- package/lib/window/VMGlobalPropertyScript.d.ts +2 -0
- package/lib/window/VMGlobalPropertyScript.js +65 -0
- package/lib/window/VMGlobalPropertyScript.js.map +1 -0
- package/lib/window/Window.d.ts +78 -105
- package/lib/window/Window.js +277 -489
- package/lib/window/Window.js.map +1 -1
- package/lib/xml-parser/XMLParser.js +65 -71
- package/lib/xml-parser/XMLParser.js.map +1 -1
- package/lib/xml-serializer/XMLSerializer.js +30 -37
- package/lib/xml-serializer/XMLSerializer.js.map +1 -1
- package/package.json +6 -7
- package/src/config/ElementTag.ts +2 -1
- package/src/config/NonImplemenetedElementClasses.ts +0 -1
- package/src/dom-parser/DOMParser.ts +4 -5
- package/src/event/IUIEventInit.ts +2 -2
- package/src/event/UIEvent.ts +2 -2
- package/src/fetch/FetchHandler.ts +3 -3
- package/src/fetch/ResourceFetchHandler.ts +3 -3
- package/src/index.ts +7 -3
- package/src/nodes/document/Document.ts +4 -4
- package/src/nodes/document/IDocument.ts +2 -2
- package/src/nodes/html-base-element/HTMLBaseElement.ts +61 -0
- package/src/nodes/html-base-element/IHTMLBaseElement.ts +21 -0
- package/src/nodes/html-link-element/HTMLLinkElement.ts +8 -2
- package/src/nodes/html-script-element/ScriptUtility.ts +4 -4
- package/src/nodes/node/INode.ts +1 -0
- package/src/nodes/node/Node.ts +14 -0
- package/src/window/GlobalWindow.ts +82 -0
- package/src/window/IWindow.ts +33 -12
- package/src/window/VMGlobalPropertyScript.ts +62 -0
- package/src/window/Window.ts +115 -173
- package/tsconfig.json +1 -1
- package/lib/window/AsyncWindow.d.ts +0 -10
- package/lib/window/AsyncWindow.js +0 -38
- package/lib/window/AsyncWindow.js.map +0 -1
- package/src/window/AsyncWindow.ts +0 -17
package/src/window/Window.ts
CHANGED
@@ -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
|
-
*
|
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
|
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 =
|
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
|
204
|
-
public Boolean
|
205
|
-
public Buffer =
|
206
|
-
public DataView
|
207
|
-
public Date
|
208
|
-
public Error
|
209
|
-
public EvalError
|
210
|
-
public Float32Array
|
211
|
-
public Float64Array
|
212
|
-
public GLOBAL
|
213
|
-
public Infinity
|
214
|
-
public Int16Array
|
215
|
-
public Int32Array
|
216
|
-
public Int8Array
|
217
|
-
public Intl
|
218
|
-
public JSON
|
219
|
-
public Map
|
220
|
-
public Math
|
221
|
-
public NaN
|
222
|
-
public Number
|
223
|
-
public Promise
|
224
|
-
public RangeError
|
225
|
-
public ReferenceError
|
226
|
-
public RegExp
|
227
|
-
public Reflect
|
228
|
-
public Set
|
229
|
-
public Symbol
|
230
|
-
public SyntaxError
|
231
|
-
public String
|
232
|
-
public TypeError
|
233
|
-
public URIError
|
234
|
-
public Uint16Array
|
235
|
-
public Uint32Array
|
236
|
-
public Uint8Array
|
237
|
-
public Uint8ClampedArray
|
238
|
-
public WeakMap
|
239
|
-
public WeakSet
|
240
|
-
public clearImmediate
|
241
|
-
public decodeURI
|
242
|
-
public decodeURIComponent
|
243
|
-
public encodeURI
|
244
|
-
public encodeURIComponent
|
245
|
-
public escape
|
246
|
-
public global
|
247
|
-
public isFinite
|
248
|
-
public isNaN
|
249
|
-
public parseFloat
|
250
|
-
public parseInt
|
251
|
-
public process
|
252
|
-
public root
|
253
|
-
public setImmediate
|
254
|
-
public queueMicrotask
|
255
|
-
public undefined
|
256
|
-
public unescape
|
257
|
-
public gc
|
258
|
-
public v8debug
|
259
|
-
public AbortController
|
260
|
-
public AbortSignal
|
261
|
-
|
262
|
-
|
263
|
-
|
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 =
|
280
|
-
FileReader._ownerDocument =
|
281
|
-
Image.ownerDocument =
|
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.
|
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
|
-
|
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
|
-
|
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
|
-
|
402
|
-
|
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
|
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 =
|
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
|
-
|
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 =
|
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
|
-
|
478
|
+
clearInterval(id);
|
537
479
|
this.happyDOM.asyncTaskManager.endTimer(id);
|
538
480
|
}
|
539
481
|
|
package/tsconfig.json
CHANGED
@@ -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
|
-
}
|