happy-dom 15.7.0 → 15.7.2
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/cjs/mutation-observer/MutationObserver.cjs +7 -1
- package/cjs/mutation-observer/MutationObserver.cjs.map +1 -1
- package/cjs/mutation-observer/MutationObserver.d.ts +4 -0
- package/cjs/mutation-observer/MutationObserver.d.ts.map +1 -1
- package/cjs/query-selector/QuerySelector.cjs +45 -39
- package/cjs/query-selector/QuerySelector.cjs.map +1 -1
- package/cjs/query-selector/QuerySelector.d.ts.map +1 -1
- package/cjs/window/BrowserWindow.cjs +3 -1
- package/cjs/window/BrowserWindow.cjs.map +1 -1
- package/cjs/window/BrowserWindow.d.ts.map +1 -1
- package/lib/mutation-observer/MutationObserver.d.ts +4 -0
- package/lib/mutation-observer/MutationObserver.d.ts.map +1 -1
- package/lib/mutation-observer/MutationObserver.js +7 -1
- package/lib/mutation-observer/MutationObserver.js.map +1 -1
- package/lib/query-selector/QuerySelector.d.ts.map +1 -1
- package/lib/query-selector/QuerySelector.js +45 -39
- package/lib/query-selector/QuerySelector.js.map +1 -1
- package/lib/window/BrowserWindow.d.ts.map +1 -1
- package/lib/window/BrowserWindow.js +3 -1
- package/lib/window/BrowserWindow.js.map +1 -1
- package/package.json +1 -1
- package/src/mutation-observer/MutationObserver.ts +8 -2
- package/src/query-selector/QuerySelector.ts +58 -53
- package/src/window/BrowserWindow.ts +3 -1
@@ -13,7 +13,6 @@ import ISVGElementTagNameMap from '../config/ISVGElementTagNameMap.js';
|
|
13
13
|
import ICachedQuerySelectorAllItem from '../nodes/node/ICachedQuerySelectorAllResult.js';
|
14
14
|
import ICachedQuerySelectorItem from '../nodes/node/ICachedQuerySelectorResult.js';
|
15
15
|
import ICachedMatchesItem from '../nodes/node/ICachedMatchesResult.js';
|
16
|
-
import DOMExceptionNameEnum from '../exception/DOMExceptionNameEnum.js';
|
17
16
|
|
18
17
|
type DocumentPositionAndElement = {
|
19
18
|
documentPosition: string;
|
@@ -78,27 +77,32 @@ export default class QuerySelector {
|
|
78
77
|
node: Element | Document | DocumentFragment,
|
79
78
|
selector: string
|
80
79
|
): NodeList<Element> {
|
81
|
-
if (selector === null || selector === undefined) {
|
82
|
-
return new NodeList<Element>(PropertySymbol.illegalConstructor, []);
|
83
|
-
}
|
84
|
-
|
85
80
|
const window = node[PropertySymbol.window];
|
86
81
|
|
87
82
|
if (<string>selector === '') {
|
88
|
-
throw new window.
|
83
|
+
throw new window.DOMException(
|
89
84
|
`Failed to execute 'querySelectorAll' on '${node.constructor.name}': The provided selector is empty.`
|
90
85
|
);
|
91
86
|
}
|
92
87
|
|
93
|
-
if (typeof selector
|
88
|
+
if (typeof selector === 'function') {
|
94
89
|
throw new window.DOMException(
|
95
|
-
`Failed to execute 'querySelectorAll' on '${node.constructor.name}': '${selector}' is not a valid selector
|
96
|
-
'SyntaxError'
|
90
|
+
`Failed to execute 'querySelectorAll' on '${node.constructor.name}': '${selector}' is not a valid selector.`
|
97
91
|
);
|
98
92
|
}
|
99
93
|
|
94
|
+
if (typeof selector === 'symbol') {
|
95
|
+
throw new window.TypeError(`Cannot convert a Symbol value to a string`);
|
96
|
+
}
|
97
|
+
|
100
98
|
selector = String(selector);
|
101
99
|
|
100
|
+
if (INVALID_SELECTOR_REGEXP.test(selector)) {
|
101
|
+
throw new window.DOMException(
|
102
|
+
`Failed to execute 'querySelectorAll' on '${node.constructor.name}': '${selector}' is not a valid selector.`
|
103
|
+
);
|
104
|
+
}
|
105
|
+
|
102
106
|
const cache = node[PropertySymbol.cache].querySelectorAll;
|
103
107
|
const cachedResult = cache.get(selector);
|
104
108
|
|
@@ -109,12 +113,6 @@ export default class QuerySelector {
|
|
109
113
|
}
|
110
114
|
}
|
111
115
|
|
112
|
-
if (INVALID_SELECTOR_REGEXP.test(selector)) {
|
113
|
-
throw new window.Error(
|
114
|
-
`Failed to execute 'querySelectorAll' on '${node.constructor.name}': '${selector}' is not a valid selector.`
|
115
|
-
);
|
116
|
-
}
|
117
|
-
|
118
116
|
const groups = SelectorParser.getSelectorGroups(selector);
|
119
117
|
const items: Element[] = [];
|
120
118
|
const nodeList = new NodeList<Element>(PropertySymbol.illegalConstructor, items);
|
@@ -199,27 +197,38 @@ export default class QuerySelector {
|
|
199
197
|
node: Element | Document | DocumentFragment,
|
200
198
|
selector: string
|
201
199
|
): Element | null {
|
202
|
-
if (selector === null || selector === undefined) {
|
203
|
-
return null;
|
204
|
-
}
|
205
|
-
|
206
200
|
const window = node[PropertySymbol.window];
|
207
201
|
|
208
202
|
if (selector === '') {
|
209
|
-
throw new window.
|
203
|
+
throw new window.DOMException(
|
210
204
|
`Failed to execute 'querySelector' on '${node.constructor.name}': The provided selector is empty.`
|
211
205
|
);
|
212
206
|
}
|
213
207
|
|
214
|
-
if (typeof selector
|
208
|
+
if (typeof selector === 'function' || typeof selector === 'symbol') {
|
215
209
|
throw new window.DOMException(
|
216
|
-
`Failed to execute 'querySelector' on '${node.constructor.name}': '${selector}' is not a valid selector
|
217
|
-
|
210
|
+
`Failed to execute 'querySelector' on '${node.constructor.name}': '${selector}' is not a valid selector.`
|
211
|
+
);
|
212
|
+
}
|
213
|
+
|
214
|
+
if (typeof selector === 'function') {
|
215
|
+
throw new window.DOMException(
|
216
|
+
`Failed to execute 'querySelector' on '${node.constructor.name}': '${selector}' is not a valid selector.`
|
218
217
|
);
|
219
218
|
}
|
220
219
|
|
220
|
+
if (typeof selector === 'symbol') {
|
221
|
+
throw new window.TypeError(`Cannot convert a Symbol value to a string`);
|
222
|
+
}
|
223
|
+
|
221
224
|
selector = String(selector);
|
222
225
|
|
226
|
+
if (INVALID_SELECTOR_REGEXP.test(selector)) {
|
227
|
+
throw new window.DOMException(
|
228
|
+
`Failed to execute 'querySelector' on '${node.constructor.name}': '${selector}' is not a valid selector.`
|
229
|
+
);
|
230
|
+
}
|
231
|
+
|
223
232
|
const cachedResult = node[PropertySymbol.cache].querySelector.get(selector);
|
224
233
|
|
225
234
|
if (cachedResult?.result) {
|
@@ -229,12 +238,6 @@ export default class QuerySelector {
|
|
229
238
|
}
|
230
239
|
}
|
231
240
|
|
232
|
-
if (INVALID_SELECTOR_REGEXP.test(selector)) {
|
233
|
-
throw new window.Error(
|
234
|
-
`Failed to execute 'querySelector' on '${node.constructor.name}': '${selector}' is not a valid selector.`
|
235
|
-
);
|
236
|
-
}
|
237
|
-
|
238
241
|
const cachedItem: ICachedQuerySelectorItem = {
|
239
242
|
result: <WeakRef<Element | null>>{
|
240
243
|
deref: () => null
|
@@ -277,55 +280,57 @@ export default class QuerySelector {
|
|
277
280
|
selector: string,
|
278
281
|
options?: { ignoreErrors?: boolean }
|
279
282
|
): ISelectorMatch | null {
|
280
|
-
|
281
|
-
|
282
|
-
}
|
283
|
+
const ignoreErrors = options?.ignoreErrors;
|
284
|
+
const window = element[PropertySymbol.window];
|
283
285
|
|
284
|
-
if (selector ===
|
286
|
+
if (selector === '*') {
|
285
287
|
return {
|
286
|
-
priorityWeight:
|
288
|
+
priorityWeight: 1
|
287
289
|
};
|
288
290
|
}
|
289
291
|
|
290
|
-
const window = element[PropertySymbol.window];
|
291
|
-
|
292
292
|
if (<string>selector === '') {
|
293
|
-
|
293
|
+
if (ignoreErrors) {
|
294
|
+
return null;
|
295
|
+
}
|
296
|
+
throw new window.DOMException(
|
294
297
|
`Failed to execute 'matches' on '${element.constructor.name}': The provided selector is empty.`
|
295
298
|
);
|
296
299
|
}
|
297
300
|
|
298
|
-
if (typeof selector
|
301
|
+
if (typeof selector === 'function') {
|
302
|
+
if (ignoreErrors) {
|
303
|
+
return null;
|
304
|
+
}
|
299
305
|
throw new window.DOMException(
|
300
|
-
`Failed to execute 'matches' on '${element.constructor.name}': '${selector}' is not a valid selector
|
301
|
-
DOMExceptionNameEnum.syntaxError
|
306
|
+
`Failed to execute 'matches' on '${element.constructor.name}': '${selector}' is not a valid selector.`
|
302
307
|
);
|
303
308
|
}
|
304
309
|
|
305
|
-
selector
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
};
|
310
|
+
if (typeof selector === 'symbol') {
|
311
|
+
if (ignoreErrors) {
|
312
|
+
return null;
|
313
|
+
}
|
314
|
+
throw new window.TypeError(`Cannot convert a Symbol value to a string`);
|
311
315
|
}
|
312
316
|
|
313
|
-
|
314
|
-
const cachedResult = element[PropertySymbol.cache].matches.get(selector);
|
315
|
-
|
316
|
-
if (cachedResult?.result) {
|
317
|
-
return cachedResult.result.match;
|
318
|
-
}
|
317
|
+
selector = String(selector);
|
319
318
|
|
320
319
|
if (INVALID_SELECTOR_REGEXP.test(selector)) {
|
321
320
|
if (ignoreErrors) {
|
322
321
|
return null;
|
323
322
|
}
|
324
|
-
throw new window.
|
323
|
+
throw new window.DOMException(
|
325
324
|
`Failed to execute 'matches' on '${element.constructor.name}': '${selector}' is not a valid selector.`
|
326
325
|
);
|
327
326
|
}
|
328
327
|
|
328
|
+
const cachedResult = element[PropertySymbol.cache].matches.get(selector);
|
329
|
+
|
330
|
+
if (cachedResult?.result) {
|
331
|
+
return cachedResult.result.match;
|
332
|
+
}
|
333
|
+
|
329
334
|
const cachedItem: ICachedMatchesItem = {
|
330
335
|
result: { match: null }
|
331
336
|
};
|
@@ -1462,7 +1462,9 @@ export default class BrowserWindow extends EventTarget implements INodeJSGlobal
|
|
1462
1462
|
const mutationObservers = this[PropertySymbol.mutationObservers];
|
1463
1463
|
|
1464
1464
|
for (const mutationObserver of mutationObservers) {
|
1465
|
-
mutationObserver.
|
1465
|
+
if (mutationObserver[PropertySymbol.destroy]) {
|
1466
|
+
mutationObserver[PropertySymbol.destroy]();
|
1467
|
+
}
|
1466
1468
|
}
|
1467
1469
|
|
1468
1470
|
this[PropertySymbol.mutationObservers] = [];
|