happy-dom 2.49.2 → 2.50.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/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/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.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/url-search-params/URLSearchParams.js.map +1 -1
- package/lib/window/Window.d.ts +14 -2
- package/lib/window/Window.js +45 -4
- 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 +21 -21
- 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/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 +4 -4
- package/src/query-selector/SelectorItem.ts +12 -4
- package/src/url-search-params/URLSearchParams.ts +1 -1
- package/src/window/Window.ts +39 -7
- package/src/xml-parser/XMLParser.ts +1 -4
@@ -200,14 +200,14 @@ export default class HTMLLinkElement extends HTMLElement implements IHTMLLinkEle
|
|
200
200
|
) {
|
201
201
|
(<Document>this.ownerDocument)._readyStateManager.startTask();
|
202
202
|
ResourceFetcher.fetch({ window: this.ownerDocument.defaultView, url: href })
|
203
|
-
.then(code => {
|
203
|
+
.then((code) => {
|
204
204
|
const styleSheet = new CSSStyleSheet();
|
205
205
|
styleSheet.replaceSync(code);
|
206
206
|
(<CSSStyleSheet>this.sheet) = styleSheet;
|
207
207
|
this.dispatchEvent(new Event('load'));
|
208
208
|
(<Document>this.ownerDocument)._readyStateManager.endTask();
|
209
209
|
})
|
210
|
-
.catch(error => {
|
210
|
+
.catch((error) => {
|
211
211
|
this.dispatchEvent(
|
212
212
|
new ErrorEvent('error', {
|
213
213
|
message: error.message,
|
@@ -246,14 +246,14 @@ export default class HTMLLinkElement extends HTMLElement implements IHTMLLinkEle
|
|
246
246
|
if (href !== null && rel && rel.toLowerCase() === 'stylesheet') {
|
247
247
|
(<Document>this.ownerDocument)._readyStateManager.startTask();
|
248
248
|
ResourceFetcher.fetch({ window: this.ownerDocument.defaultView, url: href })
|
249
|
-
.then(code => {
|
249
|
+
.then((code) => {
|
250
250
|
const styleSheet = new CSSStyleSheet();
|
251
251
|
styleSheet.replaceSync(code);
|
252
252
|
(<CSSStyleSheet>this.sheet) = styleSheet;
|
253
253
|
this.dispatchEvent(new Event('load'));
|
254
254
|
(<Document>this.ownerDocument)._readyStateManager.endTask();
|
255
255
|
})
|
256
|
-
.catch(error => {
|
256
|
+
.catch((error) => {
|
257
257
|
this.dispatchEvent(
|
258
258
|
new ErrorEvent('error', {
|
259
259
|
message: error.message,
|
@@ -1,7 +1,8 @@
|
|
1
1
|
import DOMException from '../exception/DOMException';
|
2
2
|
import Element from '../nodes/element/Element';
|
3
3
|
|
4
|
-
const ATTRIBUTE_REGEXP =
|
4
|
+
const ATTRIBUTE_REGEXP =
|
5
|
+
/\[([a-zA-Z0-9-_]+)\]|\[([a-zA-Z0-9-_]+)([~|^$*]{0,1})[ ]*=[ ]*["']{0,1}([^"']+)["']{0,1}\]/g;
|
5
6
|
const ATTRIBUTE_NAME_REGEXP = /[^a-zA-Z0-9-_$]/;
|
6
7
|
const PSUEDO_REGEXP = /:([a-zA-Z-]+)\(([0-9n+-]+|odd|even)\)|:not\(([^)]+)\)|:([a-zA-Z-]+)/g;
|
7
8
|
const CLASS_REGEXP = /\.([a-zA-Z0-9-_$]+)/g;
|
@@ -127,13 +128,13 @@ export default class SelectorItem {
|
|
127
128
|
|
128
129
|
switch (psuedo.toLowerCase()) {
|
129
130
|
case 'nth-of-type':
|
130
|
-
children = children.filter(child => child.tagName === element.tagName);
|
131
|
+
children = children.filter((child) => child.tagName === element.tagName);
|
131
132
|
break;
|
132
133
|
case 'nth-last-child':
|
133
134
|
children = children.reverse();
|
134
135
|
break;
|
135
136
|
case 'nth-last-of-type':
|
136
|
-
children = children.filter(child => child.tagName === element.tagName).reverse();
|
137
|
+
children = children.filter((child) => child.tagName === element.tagName).reverse();
|
137
138
|
break;
|
138
139
|
}
|
139
140
|
|
@@ -285,7 +286,7 @@ export default class SelectorItem {
|
|
285
286
|
return !!element._attributes[attributeName.toLowerCase()];
|
286
287
|
}
|
287
288
|
|
288
|
-
/**
|
289
|
+
/** .
|
289
290
|
*
|
290
291
|
* Matches attribute name and value.
|
291
292
|
*
|
@@ -295,6 +296,13 @@ export default class SelectorItem {
|
|
295
296
|
* @param [matchType] Match type.
|
296
297
|
* @returns True if it is a match.
|
297
298
|
*/
|
299
|
+
/**
|
300
|
+
*
|
301
|
+
* @param element
|
302
|
+
* @param attributeName
|
303
|
+
* @param attributeValue
|
304
|
+
* @param matchType
|
305
|
+
*/
|
298
306
|
private matchesAttributeNameAndValue(
|
299
307
|
element: Element,
|
300
308
|
attributeName: string,
|
@@ -173,7 +173,7 @@ export default class URLSearchParams {
|
|
173
173
|
* Returns a string containing a query string suitable for use in a URL.
|
174
174
|
*/
|
175
175
|
public toString(): string {
|
176
|
-
return this._params.map(param => param.join('=')).join('&');
|
176
|
+
return this._params.map((param) => param.join('=')).join('&');
|
177
177
|
}
|
178
178
|
|
179
179
|
/**
|
package/src/window/Window.ts
CHANGED
@@ -210,7 +210,6 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
210
210
|
public EvalError = global ? global.EvalError : null;
|
211
211
|
public Float32Array = global ? global.Float32Array : null;
|
212
212
|
public Float64Array = global ? global.Float64Array : null;
|
213
|
-
public Function = global ? global.Function : null;
|
214
213
|
public GLOBAL = null;
|
215
214
|
public Infinity = global ? global.Infinity : null;
|
216
215
|
public Int16Array = global ? global.Int16Array : null;
|
@@ -221,7 +220,6 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
221
220
|
public Map = global ? global.Map : null;
|
222
221
|
public Math = global ? global.Math : null;
|
223
222
|
public NaN = global ? global.NaN : null;
|
224
|
-
public Object = global ? global.Object : null;
|
225
223
|
public Number = global ? global.Number : null;
|
226
224
|
public Promise = global ? global.Promise : null;
|
227
225
|
public RangeError = global ? global.RangeError : null;
|
@@ -262,6 +260,10 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
262
260
|
public AbortController = global ? global.AbortController : null;
|
263
261
|
public AbortSignal = global ? global.AbortSignal : null;
|
264
262
|
|
263
|
+
// Private properties
|
264
|
+
private _objectClass: typeof globalThis.Object = null;
|
265
|
+
private _functionClass: typeof globalThis.Function = null;
|
266
|
+
|
265
267
|
/**
|
266
268
|
* Constructor.
|
267
269
|
*/
|
@@ -298,6 +300,36 @@ 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 Function class.
|
320
|
+
*
|
321
|
+
* @returns Function class.
|
322
|
+
*/
|
323
|
+
public get Function(): typeof globalThis.Function {
|
324
|
+
if (this._functionClass) {
|
325
|
+
return this._functionClass;
|
326
|
+
}
|
327
|
+
// When inside a VM global.Function is not the same as (() => {}).constructor
|
328
|
+
// We will therefore run the code inside the VM to get the real constructor
|
329
|
+
this._functionClass = <typeof globalThis.Function>this.eval('(() => {}).constructor');
|
330
|
+
return this._functionClass;
|
331
|
+
}
|
332
|
+
|
301
333
|
/**
|
302
334
|
* The CSS interface holds useful CSS-related methods.
|
303
335
|
*
|
@@ -327,7 +359,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
327
359
|
vm = require('vm');
|
328
360
|
}
|
329
361
|
|
330
|
-
if (
|
362
|
+
if (vm && vm.isContext(this)) {
|
331
363
|
return vm.runInContext(code, this);
|
332
364
|
}
|
333
365
|
|
@@ -497,7 +529,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
497
529
|
this.happyDOM.asyncTaskManager.startTask(AsyncTaskTypeEnum.fetch);
|
498
530
|
|
499
531
|
fetch(RelativeURL.getAbsoluteURL(this.location, url), options)
|
500
|
-
.then(response => {
|
532
|
+
.then((response) => {
|
501
533
|
if (this.happyDOM.asyncTaskManager.getRunningCount(AsyncTaskTypeEnum.fetch) === 0) {
|
502
534
|
reject(new Error('Failed to complete fetch request. Task was canceled.'));
|
503
535
|
} else {
|
@@ -509,7 +541,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
509
541
|
|
510
542
|
asyncMethod
|
511
543
|
.call(response)
|
512
|
-
.then(response => {
|
544
|
+
.then((response) => {
|
513
545
|
if (
|
514
546
|
this.happyDOM.asyncTaskManager.getRunningCount(AsyncTaskTypeEnum.fetch) ===
|
515
547
|
0
|
@@ -520,7 +552,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
520
552
|
this.happyDOM.asyncTaskManager.endTask(AsyncTaskTypeEnum.fetch);
|
521
553
|
}
|
522
554
|
})
|
523
|
-
.catch(error => {
|
555
|
+
.catch((error) => {
|
524
556
|
reject(error);
|
525
557
|
this.happyDOM.asyncTaskManager.endTask(AsyncTaskTypeEnum.fetch, error);
|
526
558
|
});
|
@@ -532,7 +564,7 @@ export default class Window extends EventTarget implements IWindow, NodeJS.Globa
|
|
532
564
|
this.happyDOM.asyncTaskManager.endTask(AsyncTaskTypeEnum.fetch);
|
533
565
|
}
|
534
566
|
})
|
535
|
-
.catch(error => {
|
567
|
+
.catch((error) => {
|
536
568
|
reject(error);
|
537
569
|
this.happyDOM.asyncTaskManager.endTask(AsyncTaskTypeEnum.fetch, error);
|
538
570
|
});
|
@@ -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
|
}
|