happy-dom 2.49.1 → 2.51.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/.eslintrc.js +7 -6
- package/.prettierrc.js +2 -1
- package/lib/async-task-manager/AsyncTaskManager.d.ts +65 -0
- package/lib/{window → async-task-manager}/AsyncTaskManager.js +52 -55
- package/lib/async-task-manager/AsyncTaskManager.js.map +1 -0
- package/lib/cookie/CookieUtility.js +1 -4
- package/lib/cookie/CookieUtility.js.map +1 -1
- package/lib/custom-element/CustomElementRegistry.js.map +1 -1
- package/lib/dom-token-list/DOMTokenList.d.ts +0 -4
- package/lib/dom-token-list/DOMTokenList.js +0 -4
- package/lib/dom-token-list/DOMTokenList.js.map +1 -1
- package/lib/fetch/FetchHandler.d.ts +17 -0
- package/lib/fetch/FetchHandler.js +59 -0
- package/lib/fetch/FetchHandler.js.map +1 -0
- package/lib/fetch/Headers.d.ts +7 -0
- package/lib/fetch/Headers.js +53 -0
- package/lib/fetch/Headers.js.map +1 -0
- package/lib/fetch/IAbortSignal.d.ts +16 -0
- package/lib/fetch/IAbortSignal.js +4 -0
- package/lib/fetch/IAbortSignal.js.map +1 -0
- package/lib/fetch/IBody.d.ts +17 -0
- package/lib/{window/IFetchOptions.js → fetch/IBody.js} +1 -1
- package/lib/fetch/IBody.js.map +1 -0
- package/lib/fetch/IHeaders.d.ts +18 -0
- package/lib/fetch/IHeaders.js +3 -0
- package/lib/fetch/IHeaders.js.map +1 -0
- package/lib/fetch/IHeadersInit.d.ts +5 -0
- package/lib/fetch/IHeadersInit.js +3 -0
- package/lib/fetch/IHeadersInit.js.map +1 -0
- package/lib/fetch/IRequest.d.ts +18 -0
- package/lib/fetch/IRequest.js +3 -0
- package/lib/fetch/IRequest.js.map +1 -0
- package/lib/fetch/IRequestInit.d.ts +15 -0
- package/lib/fetch/IRequestInit.js +3 -0
- package/lib/fetch/IRequestInit.js.map +1 -0
- package/lib/fetch/IResponse.d.ts +20 -0
- package/lib/{window → fetch}/IResponse.js +0 -0
- package/lib/{window → fetch}/IResponse.js.map +1 -1
- package/lib/fetch/IResponseInit.d.ts +9 -0
- package/lib/fetch/IResponseInit.js +3 -0
- package/lib/fetch/IResponseInit.js.map +1 -0
- package/lib/fetch/Request.d.ts +69 -0
- package/lib/fetch/Request.js +179 -0
- package/lib/fetch/Request.js.map +1 -0
- package/lib/fetch/ResourceFetchHandler.d.ts +22 -0
- package/lib/fetch/{ResourceFetcher.js → ResourceFetchHandler.js} +19 -26
- package/lib/fetch/ResourceFetchHandler.js.map +1 -0
- package/lib/fetch/Response.d.ts +69 -0
- package/lib/fetch/Response.js +179 -0
- package/lib/fetch/Response.js.map +1 -0
- package/lib/file/Blob.d.ts +8 -1
- package/lib/file/Blob.js +48 -0
- package/lib/file/Blob.js.map +1 -1
- package/lib/file/IBlob.d.ts +10 -0
- package/lib/file/IBlob.js +3 -0
- package/lib/file/IBlob.js.map +1 -0
- package/lib/form-data/IFormData.d.ts +30 -0
- package/lib/form-data/IFormData.js +3 -0
- package/lib/form-data/IFormData.js.map +1 -0
- package/lib/index.d.ts +3 -5
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/location/URL.d.ts +10 -10
- package/lib/location/URL.js +34 -34
- package/lib/location/URL.js.map +1 -1
- package/lib/mutation-observer/MutationObserver.js.map +1 -1
- package/lib/nodes/character-data/CharacterData.d.ts +12 -12
- package/lib/nodes/character-data/CharacterData.js +24 -24
- package/lib/nodes/character-data/CharacterData.js.map +1 -1
- package/lib/nodes/document/Document.d.ts +8 -9
- package/lib/nodes/document/Document.js +9 -8
- package/lib/nodes/document/Document.js.map +1 -1
- package/lib/nodes/document/DocumentReadyStateManager.js.map +1 -1
- package/lib/nodes/html-input-element/HTMLInputElementValueSanitizer.js.map +1 -1
- package/lib/nodes/html-link-element/HTMLLinkElement.js +3 -3
- package/lib/nodes/html-link-element/HTMLLinkElement.js.map +1 -1
- package/lib/nodes/html-script-element/ScriptUtility.js +3 -9
- package/lib/nodes/html-script-element/ScriptUtility.js.map +1 -1
- package/lib/query-selector/SelectorItem.d.ts +8 -1
- package/lib/query-selector/SelectorItem.js +8 -1
- package/lib/query-selector/SelectorItem.js.map +1 -1
- package/lib/window/IWindow.d.ts +20 -16
- package/lib/window/Window.d.ts +59 -12
- package/lib/window/Window.js +117 -70
- package/lib/window/Window.js.map +1 -1
- package/lib/xml-parser/XMLParser.js +1 -4
- package/lib/xml-parser/XMLParser.js.map +1 -1
- package/package.json +22 -21
- package/src/async-task-manager/AsyncTaskManager.ts +128 -0
- package/src/cookie/CookieUtility.ts +1 -4
- package/src/custom-element/CustomElementRegistry.ts +1 -1
- package/src/dom-token-list/DOMTokenList.ts +0 -4
- package/src/fetch/FetchHandler.ts +54 -0
- package/src/fetch/Headers.ts +7 -0
- package/src/fetch/IAbortSignal.ts +34 -0
- package/src/fetch/IBody.ts +18 -0
- package/src/fetch/IHeaders.ts +18 -0
- package/src/fetch/IHeadersInit.ts +5 -0
- package/src/fetch/IRequest.ts +59 -0
- package/src/fetch/IRequestInit.ts +41 -0
- package/src/fetch/IResponse.ts +22 -0
- package/src/fetch/IResponseInit.ts +10 -0
- package/src/fetch/Request.ts +149 -0
- package/src/fetch/ResourceFetchHandler.ts +47 -0
- package/src/fetch/Response.ts +149 -0
- package/src/file/Blob.ts +12 -1
- package/src/file/IBlob.ts +10 -0
- package/src/form-data/IFormData.ts +33 -0
- package/src/index.ts +2 -6
- package/src/location/URL.ts +39 -38
- package/src/mutation-observer/MutationObserver.ts +1 -1
- package/src/nodes/character-data/CharacterData.ts +18 -17
- package/src/nodes/document/Document.ts +12 -9
- package/src/nodes/document/DocumentReadyStateManager.ts +1 -1
- package/src/nodes/html-input-element/HTMLInputElementValueSanitizer.ts +1 -1
- package/src/nodes/html-link-element/HTMLLinkElement.ts +7 -7
- package/src/nodes/html-script-element/ScriptUtility.ts +3 -9
- package/src/query-selector/SelectorItem.ts +12 -4
- package/src/window/IWindow.ts +14 -16
- package/src/window/Window.ts +103 -70
- package/src/xml-parser/XMLParser.ts +1 -4
- package/lib/fetch/ResourceFetcher.d.ts +0 -30
- package/lib/fetch/ResourceFetcher.js.map +0 -1
- package/lib/url-search-params/URLSearchParams.d.ts +0 -87
- package/lib/url-search-params/URLSearchParams.js +0 -196
- package/lib/url-search-params/URLSearchParams.js.map +0 -1
- package/lib/window/AsyncTaskManager.d.ts +0 -54
- package/lib/window/AsyncTaskManager.js.map +0 -1
- package/lib/window/AsyncTaskTypeEnum.d.ts +0 -5
- package/lib/window/AsyncTaskTypeEnum.js +0 -9
- package/lib/window/AsyncTaskTypeEnum.js.map +0 -1
- package/lib/window/IFetchOptions.d.ts +0 -13
- package/lib/window/IFetchOptions.js.map +0 -1
- package/lib/window/IResponse.d.ts +0 -32
- package/src/fetch/ResourceFetcher.ts +0 -55
- package/src/url-search-params/URLSearchParams.ts +0 -198
- package/src/window/AsyncTaskManager.ts +0 -127
- package/src/window/AsyncTaskTypeEnum.ts +0 -5
- package/src/window/IFetchOptions.ts +0 -11
- package/src/window/IResponse.ts +0 -34
package/src/window/IWindow.ts
CHANGED
@@ -60,13 +60,15 @@ import UIEvent from '../event/UIEvent';
|
|
60
60
|
import ErrorEvent from '../event/events/ErrorEvent';
|
61
61
|
import StorageEvent from '../event/events/StorageEvent';
|
62
62
|
import Screen from '../screen/Screen';
|
63
|
-
import AsyncTaskManager from '
|
64
|
-
import IResponse from '
|
63
|
+
import AsyncTaskManager from '../async-task-manager/AsyncTaskManager';
|
64
|
+
import IResponse from '../fetch/IResponse';
|
65
|
+
import IResponseInit from '../fetch/IResponseInit';
|
66
|
+
import IRequest from '../fetch/IRequest';
|
67
|
+
import IRequestInit from '../fetch/IRequestInit';
|
68
|
+
import IHeaders from '../fetch/IHeaders';
|
65
69
|
import Storage from '../storage/Storage';
|
66
|
-
import IFetchOptions from './IFetchOptions';
|
67
70
|
import NodeFilter from '../tree-walker/NodeFilter';
|
68
71
|
import Window from './Window';
|
69
|
-
import URLSearchParams from '../url-search-params/URLSearchParams';
|
70
72
|
import HTMLCollection from '../nodes/element/HTMLCollection';
|
71
73
|
import NodeList from '../nodes/node/NodeList';
|
72
74
|
import Selection from '../selection/Selection';
|
@@ -76,6 +78,7 @@ import MimeType from '../navigator/MimeType';
|
|
76
78
|
import MimeTypeArray from '../navigator/MimeTypeArray';
|
77
79
|
import Plugin from '../navigator/Plugin';
|
78
80
|
import PluginArray from '../navigator/PluginArray';
|
81
|
+
import { URLSearchParams } from 'url';
|
79
82
|
|
80
83
|
/**
|
81
84
|
* Window.
|
@@ -141,7 +144,9 @@ export default interface IWindow extends IEventTarget {
|
|
141
144
|
readonly Location: typeof Location;
|
142
145
|
readonly CustomElementRegistry: typeof CustomElementRegistry;
|
143
146
|
readonly Window: typeof Window;
|
144
|
-
readonly Headers:
|
147
|
+
readonly Headers: { new (init?: string[][] | Record<string, string> | IHeaders): IHeaders };
|
148
|
+
readonly Request: { new (input: string | IRequest, init?: IRequestInit): IRequest };
|
149
|
+
readonly Response: { new (body?: unknown | null, init?: IResponseInit): IResponse };
|
145
150
|
readonly XMLSerializer: typeof XMLSerializer;
|
146
151
|
readonly ResizeObserver: typeof ResizeObserver;
|
147
152
|
readonly CSSStyleSheet: typeof CSSStyleSheet;
|
@@ -221,7 +226,6 @@ export default interface IWindow extends IEventTarget {
|
|
221
226
|
/**
|
222
227
|
* Sets a timer which executes a function once the timer expires.
|
223
228
|
*
|
224
|
-
* @override
|
225
229
|
* @param callback Function to be executed.
|
226
230
|
* @param [delay=0] Delay in ms.
|
227
231
|
* @returns Timeout ID.
|
@@ -231,7 +235,6 @@ export default interface IWindow extends IEventTarget {
|
|
231
235
|
/**
|
232
236
|
* Cancels a timeout previously established by calling setTimeout().
|
233
237
|
*
|
234
|
-
* @override
|
235
238
|
* @param id ID of the timeout.
|
236
239
|
*/
|
237
240
|
clearTimeout(id: NodeJS.Timeout): void;
|
@@ -239,7 +242,6 @@ export default interface IWindow extends IEventTarget {
|
|
239
242
|
/**
|
240
243
|
* Calls a function with a fixed time delay between each call.
|
241
244
|
*
|
242
|
-
* @override
|
243
245
|
* @param callback Function to be executed.
|
244
246
|
* @param [delay=0] Delay in ms.
|
245
247
|
* @returns Interval ID.
|
@@ -249,7 +251,6 @@ export default interface IWindow extends IEventTarget {
|
|
249
251
|
/**
|
250
252
|
* Cancels a timed repeating action which was previously established by a call to setInterval().
|
251
253
|
*
|
252
|
-
* @override
|
253
254
|
* @param id ID of the interval.
|
254
255
|
*/
|
255
256
|
clearInterval(id: NodeJS.Timeout): void;
|
@@ -257,7 +258,6 @@ export default interface IWindow extends IEventTarget {
|
|
257
258
|
/**
|
258
259
|
* Mock animation frames with timeouts.
|
259
260
|
*
|
260
|
-
* @override
|
261
261
|
* @param {Function} callback Callback.
|
262
262
|
* @returns {NodeJS.Timeout} Timeout ID.
|
263
263
|
*/
|
@@ -266,18 +266,16 @@ export default interface IWindow extends IEventTarget {
|
|
266
266
|
/**
|
267
267
|
* Mock animation frames with timeouts.
|
268
268
|
*
|
269
|
-
* @override
|
270
269
|
* @param {NodeJS.Timeout} id Timeout ID.
|
271
270
|
*/
|
272
271
|
cancelAnimationFrame(id: NodeJS.Timeout): void;
|
273
272
|
|
274
273
|
/**
|
275
|
-
*
|
274
|
+
* This method provides an easy, logical way to fetch resources asynchronously across the network.
|
276
275
|
*
|
277
|
-
* @
|
278
|
-
* @param
|
279
|
-
* @param [options] Options.
|
276
|
+
* @param url URL.
|
277
|
+
* @param [init] Init.
|
280
278
|
* @returns Promise.
|
281
279
|
*/
|
282
|
-
fetch(url: string,
|
280
|
+
fetch(url: string, init?: IRequestInit): Promise<IResponse>;
|
283
281
|
}
|
package/src/window/Window.ts
CHANGED
@@ -63,14 +63,15 @@ import UIEvent from '../event/UIEvent';
|
|
63
63
|
import ErrorEvent from '../event/events/ErrorEvent';
|
64
64
|
import StorageEvent from '../event/events/StorageEvent';
|
65
65
|
import Screen from '../screen/Screen';
|
66
|
-
import AsyncTaskManager from '
|
67
|
-
import IResponse from '
|
68
|
-
import
|
69
|
-
import
|
66
|
+
import AsyncTaskManager from '../async-task-manager/AsyncTaskManager';
|
67
|
+
import IResponse from '../fetch/IResponse';
|
68
|
+
import IResponseInit from '../fetch/IResponseInit';
|
69
|
+
import IRequest from '../fetch/IRequest';
|
70
|
+
import IRequestInit from '../fetch/IRequestInit';
|
71
|
+
import IHeaders from '../fetch/IHeaders';
|
72
|
+
import IHeadersInit from '../fetch/IHeadersInit';
|
70
73
|
import Storage from '../storage/Storage';
|
71
|
-
import IFetchOptions from './IFetchOptions';
|
72
74
|
import IWindow from './IWindow';
|
73
|
-
import URLSearchParams from '../url-search-params/URLSearchParams';
|
74
75
|
import HTMLCollection from '../nodes/element/HTMLCollection';
|
75
76
|
import NodeList from '../nodes/node/NodeList';
|
76
77
|
import MediaQueryList from '../match-media/MediaQueryList';
|
@@ -81,8 +82,8 @@ import MimeType from '../navigator/MimeType';
|
|
81
82
|
import MimeTypeArray from '../navigator/MimeTypeArray';
|
82
83
|
import Plugin from '../navigator/Plugin';
|
83
84
|
import PluginArray from '../navigator/PluginArray';
|
84
|
-
|
85
|
-
|
85
|
+
import FetchHandler from '../fetch/FetchHandler';
|
86
|
+
import { URLSearchParams } from 'url';
|
86
87
|
|
87
88
|
/**
|
88
89
|
* Handles the Window.
|
@@ -94,7 +95,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
94
95
|
return await this.happyDOM.asyncTaskManager.whenComplete();
|
95
96
|
},
|
96
97
|
cancelAsync: (): void => {
|
97
|
-
this.happyDOM.asyncTaskManager.
|
98
|
+
this.happyDOM.asyncTaskManager.cancelAll();
|
98
99
|
},
|
99
100
|
asyncTaskManager: new AsyncTaskManager()
|
100
101
|
};
|
@@ -152,7 +153,6 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
152
153
|
public readonly Location = Location;
|
153
154
|
public readonly CustomElementRegistry = CustomElementRegistry;
|
154
155
|
public readonly Window = Window;
|
155
|
-
public readonly Headers = Map;
|
156
156
|
public readonly XMLSerializer = XMLSerializer;
|
157
157
|
public readonly ResizeObserver = ResizeObserver;
|
158
158
|
public readonly CSSStyleSheet = CSSStyleSheet;
|
@@ -200,7 +200,6 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
200
200
|
public readonly performance = PerfHooks.performance;
|
201
201
|
|
202
202
|
// Node.js Globals
|
203
|
-
public Array = global ? global.Array : null;
|
204
203
|
public ArrayBuffer = global ? global.ArrayBuffer : null;
|
205
204
|
public Boolean = global ? global.Boolean : null;
|
206
205
|
public Buffer = null;
|
@@ -210,7 +209,6 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
210
209
|
public EvalError = global ? global.EvalError : null;
|
211
210
|
public Float32Array = global ? global.Float32Array : null;
|
212
211
|
public Float64Array = global ? global.Float64Array : null;
|
213
|
-
public Function = global ? global.Function : null;
|
214
212
|
public GLOBAL = null;
|
215
213
|
public Infinity = global ? global.Infinity : null;
|
216
214
|
public Int16Array = global ? global.Int16Array : null;
|
@@ -221,7 +219,6 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
221
219
|
public Map = global ? global.Map : null;
|
222
220
|
public Math = global ? global.Math : null;
|
223
221
|
public NaN = global ? global.NaN : null;
|
224
|
-
public Object = global ? global.Object : null;
|
225
222
|
public Number = global ? global.Number : null;
|
226
223
|
public Promise = global ? global.Promise : null;
|
227
224
|
public RangeError = global ? global.RangeError : null;
|
@@ -262,6 +259,11 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
262
259
|
public AbortController = global ? global.AbortController : null;
|
263
260
|
public AbortSignal = global ? global.AbortSignal : null;
|
264
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;
|
266
|
+
|
265
267
|
/**
|
266
268
|
* Constructor.
|
267
269
|
*/
|
@@ -298,6 +300,51 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
298
300
|
}
|
299
301
|
}
|
300
302
|
|
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
|
+
}
|
317
|
+
|
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;
|
341
|
+
}
|
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
|
+
}
|
347
|
+
|
301
348
|
/**
|
302
349
|
* The CSS interface holds useful CSS-related methods.
|
303
350
|
*
|
@@ -307,6 +354,43 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
307
354
|
return new CSS();
|
308
355
|
}
|
309
356
|
|
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
|
+
|
310
394
|
/**
|
311
395
|
* Evaluates code.
|
312
396
|
*
|
@@ -327,7 +411,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
327
411
|
vm = require('vm');
|
328
412
|
}
|
329
413
|
|
330
|
-
if (
|
414
|
+
if (vm && vm.isContext(this)) {
|
331
415
|
return vm.runInContext(code, this);
|
332
416
|
}
|
333
417
|
|
@@ -477,65 +561,14 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
477
561
|
}
|
478
562
|
|
479
563
|
/**
|
480
|
-
*
|
564
|
+
* This method provides an easy, logical way to fetch resources asynchronously across the network.
|
481
565
|
*
|
482
566
|
* @override
|
483
|
-
* @param url URL
|
484
|
-
* @param [
|
567
|
+
* @param url URL.
|
568
|
+
* @param [init] Init.
|
485
569
|
* @returns Promise.
|
486
570
|
*/
|
487
|
-
public async fetch(url: string,
|
488
|
-
return
|
489
|
-
let fetch = null;
|
490
|
-
|
491
|
-
try {
|
492
|
-
fetch = require('node-fetch');
|
493
|
-
} catch (error) {
|
494
|
-
throw new Error('Failed to perform fetch. "node-fetch" could not be loaded.');
|
495
|
-
}
|
496
|
-
|
497
|
-
this.happyDOM.asyncTaskManager.startTask(AsyncTaskTypeEnum.fetch);
|
498
|
-
|
499
|
-
fetch(RelativeURL.getAbsoluteURL(this.location, url), options)
|
500
|
-
.then(response => {
|
501
|
-
if (this.happyDOM.asyncTaskManager.getRunningCount(AsyncTaskTypeEnum.fetch) === 0) {
|
502
|
-
reject(new Error('Failed to complete fetch request. Task was canceled.'));
|
503
|
-
} else {
|
504
|
-
for (const methodName of FETCH_RESPONSE_TYPE_METHODS) {
|
505
|
-
const asyncMethod = response[methodName];
|
506
|
-
response[methodName] = () => {
|
507
|
-
return new Promise((resolve, reject) => {
|
508
|
-
this.happyDOM.asyncTaskManager.startTask(AsyncTaskTypeEnum.fetch);
|
509
|
-
|
510
|
-
asyncMethod
|
511
|
-
.call(response)
|
512
|
-
.then(response => {
|
513
|
-
if (
|
514
|
-
this.happyDOM.asyncTaskManager.getRunningCount(AsyncTaskTypeEnum.fetch) ===
|
515
|
-
0
|
516
|
-
) {
|
517
|
-
reject(new Error('Failed to complete fetch request. Task was canceled.'));
|
518
|
-
} else {
|
519
|
-
resolve(response);
|
520
|
-
this.happyDOM.asyncTaskManager.endTask(AsyncTaskTypeEnum.fetch);
|
521
|
-
}
|
522
|
-
})
|
523
|
-
.catch(error => {
|
524
|
-
reject(error);
|
525
|
-
this.happyDOM.asyncTaskManager.endTask(AsyncTaskTypeEnum.fetch, error);
|
526
|
-
});
|
527
|
-
});
|
528
|
-
};
|
529
|
-
}
|
530
|
-
|
531
|
-
resolve(response);
|
532
|
-
this.happyDOM.asyncTaskManager.endTask(AsyncTaskTypeEnum.fetch);
|
533
|
-
}
|
534
|
-
})
|
535
|
-
.catch(error => {
|
536
|
-
reject(error);
|
537
|
-
this.happyDOM.asyncTaskManager.endTask(AsyncTaskTypeEnum.fetch, error);
|
538
|
-
});
|
539
|
-
});
|
571
|
+
public async fetch(url: string, init?: IRequestInit): Promise<IResponse> {
|
572
|
+
return await FetchHandler.fetch(this.document, url, init);
|
540
573
|
}
|
541
574
|
}
|
@@ -242,10 +242,7 @@ export default class XMLParser {
|
|
242
242
|
}
|
243
243
|
|
244
244
|
// Attributes with no value
|
245
|
-
for (const name of attributes
|
246
|
-
.replace(ATTRIBUTE_REGEXP, '')
|
247
|
-
.trim()
|
248
|
-
.split(' ')) {
|
245
|
+
for (const name of attributes.replace(ATTRIBUTE_REGEXP, '').trim().split(' ')) {
|
249
246
|
if (name) {
|
250
247
|
element.setAttributeNS(null, this._getAttributeName(namespaceURI, name), '');
|
251
248
|
}
|
@@ -1,30 +0,0 @@
|
|
1
|
-
import Window from '../window/Window';
|
2
|
-
/**
|
3
|
-
* Helper class for performing an asynchonous or synchrounous request to a resource.
|
4
|
-
*/
|
5
|
-
export default class ResourceFetcher {
|
6
|
-
/**
|
7
|
-
* Returns resource data asynchonously.
|
8
|
-
*
|
9
|
-
* @param options Options.
|
10
|
-
* @param options.window Location.
|
11
|
-
* @param options.url URL.
|
12
|
-
* @returns Response.
|
13
|
-
*/
|
14
|
-
static fetch(options: {
|
15
|
-
window: Window;
|
16
|
-
url: string;
|
17
|
-
}): Promise<string>;
|
18
|
-
/**
|
19
|
-
* Returns resource data synchonously.
|
20
|
-
*
|
21
|
-
* @param options Options.
|
22
|
-
* @param options.window Location.
|
23
|
-
* @param options.url URL.
|
24
|
-
* @returns Response.
|
25
|
-
*/
|
26
|
-
static fetchSync(options: {
|
27
|
-
window: Window;
|
28
|
-
url: string;
|
29
|
-
}): string;
|
30
|
-
}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ResourceFetcher.js","sourceRoot":"","sources":["../../src/fetch/ResourceFetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wEAAkD;AAElD,2EAAqD;AAErD;;GAEG;AACH;IAAA;IA+CA,CAAC;IA9CA;;;;;;;OAOG;IACiB,qBAAK,GAAzB,UAA0B,OAAwC;;;;;4BAChD,qBAAM,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAA;;wBAAlD,QAAQ,GAAG,SAAuC;wBACxD,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;4BACjB,MAAM,IAAI,sBAAY,CACrB,yCAAiC,OAAO,CAAC,GAAG,8BAAmB,QAAQ,CAAC,MAAM,CAAE,CAChF,CAAC;yBACF;wBACM,qBAAM,QAAQ,CAAC,IAAI,EAAE,EAAA;4BAA5B,sBAAO,SAAqB,EAAC;;;;KAC7B;IAED;;;;;;;OAOG;IACW,yBAAS,GAAvB,UAAwB,OAAwC;QAC/D,IAAM,GAAG,GAAG,qBAAW,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QAC7E,IAAI,OAAO,GAAG,IAAI,CAAC;QAEnB,IAAI;YACH,OAAO,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;SAClC;QAAC,OAAO,KAAK,EAAE;YACf,MAAM,IAAI,sBAAY,CAAC,4DAA4D,CAAC,CAAC;SACrF;QAED,IAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAErC,IAAI,QAAQ,CAAC,OAAO,EAAE,EAAE;YACvB,MAAM,IAAI,sBAAY,CACrB,yCAAiC,GAAG,8BAAmB,QAAQ,CAAC,UAAU,CAAE,CAC5E,CAAC;SACF;QAED,OAAO,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IACF,sBAAC;AAAD,CAAC,AA/CD,IA+CC"}
|
@@ -1,87 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* URLSearchParams.
|
3
|
-
*
|
4
|
-
* Reference:
|
5
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams.
|
6
|
-
*/
|
7
|
-
export default class URLSearchParams {
|
8
|
-
private _params;
|
9
|
-
/**
|
10
|
-
* Constructor.
|
11
|
-
*
|
12
|
-
* @param [params] Params string.
|
13
|
-
*/
|
14
|
-
constructor(params?: string);
|
15
|
-
/**
|
16
|
-
* Appends a specified key/value pair as a new search parameter.
|
17
|
-
*
|
18
|
-
* @param name Name.
|
19
|
-
* @param value Value.
|
20
|
-
*/
|
21
|
-
append(name: string, value: string): void;
|
22
|
-
/**
|
23
|
-
* Deletes the given search parameter, and its associated value, from the list of all search parameters.
|
24
|
-
*
|
25
|
-
* @param name Name.
|
26
|
-
*/
|
27
|
-
delete(name: string): void;
|
28
|
-
/**
|
29
|
-
* Returns an iterator.
|
30
|
-
*
|
31
|
-
* @returns Entries.
|
32
|
-
*/
|
33
|
-
entries(): IterableIterator<[string, string]>;
|
34
|
-
/**
|
35
|
-
* For each.
|
36
|
-
*
|
37
|
-
* @param callback Callback.
|
38
|
-
*/
|
39
|
-
forEach(callback: (value: any, key: any) => void): void;
|
40
|
-
/**
|
41
|
-
* Returns value.
|
42
|
-
*
|
43
|
-
* @param name Name.
|
44
|
-
*/
|
45
|
-
get(name: string): string;
|
46
|
-
/**
|
47
|
-
* Returns all values associated with a name.
|
48
|
-
*
|
49
|
-
* @param name Name.
|
50
|
-
* @returns Values.
|
51
|
-
*/
|
52
|
-
getAll(name: string): string[];
|
53
|
-
/**
|
54
|
-
* Returns "true" if param exists.
|
55
|
-
*
|
56
|
-
* @param name Name.
|
57
|
-
* @returns "true" if param exists.
|
58
|
-
*/
|
59
|
-
has(name: string): boolean;
|
60
|
-
/**
|
61
|
-
* Returns an iterator.
|
62
|
-
*
|
63
|
-
* @returns Keys iterator.
|
64
|
-
*/
|
65
|
-
keys(): IterableIterator<string>;
|
66
|
-
/**
|
67
|
-
* Sets the value associated with a given search parameter to the given value. If there are several values, the others are deleted.
|
68
|
-
*
|
69
|
-
* @param name Name.
|
70
|
-
* @param value Value.
|
71
|
-
*/
|
72
|
-
set(name: string, value: string): void;
|
73
|
-
/**
|
74
|
-
* Sorts all key/value pairs, if any, by their keys.
|
75
|
-
*/
|
76
|
-
sort(): void;
|
77
|
-
/**
|
78
|
-
* Returns a string containing a query string suitable for use in a URL.
|
79
|
-
*/
|
80
|
-
toString(): string;
|
81
|
-
/**
|
82
|
-
* Returns an iterator.
|
83
|
-
*
|
84
|
-
* @returns Values iterator.
|
85
|
-
*/
|
86
|
-
values(): IterableIterator<string>;
|
87
|
-
}
|
@@ -1,196 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
/**
|
4
|
-
* URLSearchParams.
|
5
|
-
*
|
6
|
-
* Reference:
|
7
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams.
|
8
|
-
*/
|
9
|
-
var URLSearchParams = /** @class */ (function () {
|
10
|
-
/**
|
11
|
-
* Constructor.
|
12
|
-
*
|
13
|
-
* @param [params] Params string.
|
14
|
-
*/
|
15
|
-
function URLSearchParams(params) {
|
16
|
-
this._params = [];
|
17
|
-
if (params) {
|
18
|
-
for (var _i = 0, _a = params.split('&'); _i < _a.length; _i++) {
|
19
|
-
var entry = _a[_i];
|
20
|
-
var _b = entry.split('='), name = _b[0], value = _b[1];
|
21
|
-
if (name) {
|
22
|
-
this._params.push([name, value]);
|
23
|
-
}
|
24
|
-
}
|
25
|
-
}
|
26
|
-
}
|
27
|
-
/**
|
28
|
-
* Appends a specified key/value pair as a new search parameter.
|
29
|
-
*
|
30
|
-
* @param name Name.
|
31
|
-
* @param value Value.
|
32
|
-
*/
|
33
|
-
URLSearchParams.prototype.append = function (name, value) {
|
34
|
-
this._params.push([name, value]);
|
35
|
-
};
|
36
|
-
/**
|
37
|
-
* Deletes the given search parameter, and its associated value, from the list of all search parameters.
|
38
|
-
*
|
39
|
-
* @param name Name.
|
40
|
-
*/
|
41
|
-
URLSearchParams.prototype.delete = function (name) {
|
42
|
-
for (var i = 0, max = this._params.length; i < max; i++) {
|
43
|
-
if (this._params[i][0] === name) {
|
44
|
-
this._params.splice(i, 1);
|
45
|
-
i--;
|
46
|
-
max--;
|
47
|
-
}
|
48
|
-
}
|
49
|
-
};
|
50
|
-
/**
|
51
|
-
* Returns an iterator.
|
52
|
-
*
|
53
|
-
* @returns Entries.
|
54
|
-
*/
|
55
|
-
URLSearchParams.prototype.entries = function () {
|
56
|
-
var params = this._params;
|
57
|
-
var Iterator = function Iterator() {
|
58
|
-
var index = 0;
|
59
|
-
this.next = function () {
|
60
|
-
var value = params[index];
|
61
|
-
var done = index >= params.length;
|
62
|
-
index++;
|
63
|
-
return { value: value, done: done };
|
64
|
-
};
|
65
|
-
this[Symbol.iterator] = function () { return new Iterator(); };
|
66
|
-
};
|
67
|
-
return new Iterator();
|
68
|
-
};
|
69
|
-
/**
|
70
|
-
* For each.
|
71
|
-
*
|
72
|
-
* @param callback Callback.
|
73
|
-
*/
|
74
|
-
URLSearchParams.prototype.forEach = function (callback) {
|
75
|
-
for (var _i = 0, _a = this._params; _i < _a.length; _i++) {
|
76
|
-
var param = _a[_i];
|
77
|
-
callback(param[0], param[1]);
|
78
|
-
}
|
79
|
-
};
|
80
|
-
/**
|
81
|
-
* Returns value.
|
82
|
-
*
|
83
|
-
* @param name Name.
|
84
|
-
*/
|
85
|
-
URLSearchParams.prototype.get = function (name) {
|
86
|
-
for (var _i = 0, _a = this._params; _i < _a.length; _i++) {
|
87
|
-
var param = _a[_i];
|
88
|
-
if (param[0] === name) {
|
89
|
-
return param[1];
|
90
|
-
}
|
91
|
-
}
|
92
|
-
return undefined;
|
93
|
-
};
|
94
|
-
/**
|
95
|
-
* Returns all values associated with a name.
|
96
|
-
*
|
97
|
-
* @param name Name.
|
98
|
-
* @returns Values.
|
99
|
-
*/
|
100
|
-
URLSearchParams.prototype.getAll = function (name) {
|
101
|
-
var values = [];
|
102
|
-
for (var _i = 0, _a = this._params; _i < _a.length; _i++) {
|
103
|
-
var param = _a[_i];
|
104
|
-
if (param[0] === name) {
|
105
|
-
values.push(param[1]);
|
106
|
-
}
|
107
|
-
}
|
108
|
-
return values;
|
109
|
-
};
|
110
|
-
/**
|
111
|
-
* Returns "true" if param exists.
|
112
|
-
*
|
113
|
-
* @param name Name.
|
114
|
-
* @returns "true" if param exists.
|
115
|
-
*/
|
116
|
-
URLSearchParams.prototype.has = function (name) {
|
117
|
-
for (var _i = 0, _a = this._params; _i < _a.length; _i++) {
|
118
|
-
var param = _a[_i];
|
119
|
-
if (param[0] === name) {
|
120
|
-
return true;
|
121
|
-
}
|
122
|
-
}
|
123
|
-
return false;
|
124
|
-
};
|
125
|
-
/**
|
126
|
-
* Returns an iterator.
|
127
|
-
*
|
128
|
-
* @returns Keys iterator.
|
129
|
-
*/
|
130
|
-
URLSearchParams.prototype.keys = function () {
|
131
|
-
var params = this._params;
|
132
|
-
var Iterator = function Iterator() {
|
133
|
-
var index = 0;
|
134
|
-
this.next = function () {
|
135
|
-
var value = params[index] !== undefined ? params[index][0] : undefined;
|
136
|
-
var done = index >= params.length;
|
137
|
-
index++;
|
138
|
-
return { value: value, done: done };
|
139
|
-
};
|
140
|
-
this[Symbol.iterator] = function () { return new Iterator(); };
|
141
|
-
};
|
142
|
-
return new Iterator();
|
143
|
-
};
|
144
|
-
/**
|
145
|
-
* Sets the value associated with a given search parameter to the given value. If there are several values, the others are deleted.
|
146
|
-
*
|
147
|
-
* @param name Name.
|
148
|
-
* @param value Value.
|
149
|
-
*/
|
150
|
-
URLSearchParams.prototype.set = function (name, value) {
|
151
|
-
this.delete(name);
|
152
|
-
this.append(name, value);
|
153
|
-
};
|
154
|
-
/**
|
155
|
-
* Sorts all key/value pairs, if any, by their keys.
|
156
|
-
*/
|
157
|
-
URLSearchParams.prototype.sort = function () {
|
158
|
-
this._params.sort(function (a, b) {
|
159
|
-
if (a[0] < b[0]) {
|
160
|
-
return -1;
|
161
|
-
}
|
162
|
-
else if (a[0] > b[0]) {
|
163
|
-
return 1;
|
164
|
-
}
|
165
|
-
return 0;
|
166
|
-
});
|
167
|
-
};
|
168
|
-
/**
|
169
|
-
* Returns a string containing a query string suitable for use in a URL.
|
170
|
-
*/
|
171
|
-
URLSearchParams.prototype.toString = function () {
|
172
|
-
return this._params.map(function (param) { return param.join('='); }).join('&');
|
173
|
-
};
|
174
|
-
/**
|
175
|
-
* Returns an iterator.
|
176
|
-
*
|
177
|
-
* @returns Values iterator.
|
178
|
-
*/
|
179
|
-
URLSearchParams.prototype.values = function () {
|
180
|
-
var params = this._params;
|
181
|
-
var Iterator = function Iterator() {
|
182
|
-
var index = 0;
|
183
|
-
this.next = function () {
|
184
|
-
var value = params[index] !== undefined ? params[index][1] : undefined;
|
185
|
-
var done = index >= params.length;
|
186
|
-
index++;
|
187
|
-
return { value: value, done: done };
|
188
|
-
};
|
189
|
-
this[Symbol.iterator] = function () { return new Iterator(); };
|
190
|
-
};
|
191
|
-
return new Iterator();
|
192
|
-
};
|
193
|
-
return URLSearchParams;
|
194
|
-
}());
|
195
|
-
exports.default = URLSearchParams;
|
196
|
-
//# sourceMappingURL=URLSearchParams.js.map
|