Skip to content

Commit 908f27d

Browse files
asamuzaKdomenic
authored andcommitted
Update dom-selector and roll web platform tests
This update simplifies the integration with jsdom's exceptions, and fixes some of the WPTs introduced in this roll.
1 parent c039e52 commit 908f27d

9 files changed

Lines changed: 730 additions & 260 deletions

File tree

Lines changed: 16 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,33 @@
11
"use strict";
22

33
const domSelector = require("@asamuzakjp/dom-selector");
4-
const DOMException = require("../generated/DOMException");
5-
const idlUtils = require("../generated/utils");
4+
const { wrapperForImpl } = require("../generated/utils");
65

76
exports.matchesDontThrow = (selectors, elementImpl) => {
8-
let matched;
7+
const element = wrapperForImpl(elementImpl);
98
try {
10-
const element = idlUtils.wrapperForImpl(elementImpl);
11-
matched = domSelector.matches(selectors, element);
9+
return domSelector.matches(selectors, element);
1210
} catch {
13-
matched = false;
11+
return false;
1412
}
15-
return matched;
1613
};
1714

18-
exports.matches = (selectors, elementImpl, globalObject) => {
19-
let matched;
20-
try {
21-
const element = idlUtils.wrapperForImpl(elementImpl);
22-
matched = domSelector.matches(selectors, element);
23-
} catch (e) {
24-
if (e instanceof globalThis.DOMException &&
25-
!(e instanceof globalObject.DOMException)) {
26-
throw DOMException.create(globalObject, [e.message, e.name]);
27-
} else if (e instanceof globalThis.TypeError &&
28-
!(e instanceof globalObject.TypeError)) {
29-
throw new globalObject.TypeError(e.message);
30-
} else {
31-
throw e;
32-
}
33-
}
34-
return matched;
15+
exports.matches = (selectors, elementImpl) => {
16+
const element = wrapperForImpl(elementImpl);
17+
return domSelector.matches(selectors, element);
3518
};
3619

37-
exports.closest = (selectors, elementImpl, globalObject) => {
38-
let matched;
39-
try {
40-
const element = idlUtils.wrapperForImpl(elementImpl);
41-
matched = domSelector.closest(selectors, element);
42-
} catch (e) {
43-
if (e instanceof globalThis.DOMException &&
44-
!(e instanceof globalObject.DOMException)) {
45-
throw DOMException.create(globalObject, [e.message, e.name]);
46-
} else if (e instanceof globalThis.TypeError &&
47-
!(e instanceof globalObject.TypeError)) {
48-
throw new globalObject.TypeError(e.message);
49-
} else {
50-
throw e;
51-
}
52-
}
53-
return matched;
20+
exports.closest = (selectors, elementImpl) => {
21+
const element = wrapperForImpl(elementImpl);
22+
return domSelector.closest(selectors, element);
5423
};
5524

56-
exports.querySelector = (selectors, parentNodeImpl, globalObject) => {
57-
let matched;
58-
try {
59-
const node = idlUtils.wrapperForImpl(parentNodeImpl);
60-
matched = domSelector.querySelector(selectors, node);
61-
} catch (e) {
62-
if (e instanceof globalThis.DOMException &&
63-
!(e instanceof globalObject.DOMException)) {
64-
throw DOMException.create(globalObject, [e.message, e.name]);
65-
} else if (e instanceof globalThis.TypeError &&
66-
!(e instanceof globalObject.TypeError)) {
67-
throw new globalObject.TypeError(e.message);
68-
} else {
69-
throw e;
70-
}
71-
}
72-
return matched;
25+
exports.querySelector = (selectors, parentNodeImpl) => {
26+
const node = wrapperForImpl(parentNodeImpl);
27+
return domSelector.querySelector(selectors, node);
7328
};
7429

75-
exports.querySelectorAll = (selectors, parentNodeImpl, globalObject) => {
76-
let matched;
77-
try {
78-
const node = idlUtils.wrapperForImpl(parentNodeImpl);
79-
matched = domSelector.querySelectorAll(selectors, node);
80-
} catch (e) {
81-
if (e instanceof globalThis.DOMException &&
82-
!(e instanceof globalObject.DOMException)) {
83-
throw DOMException.create(globalObject, [e.message, e.name]);
84-
} else if (e instanceof globalThis.TypeError &&
85-
!(e instanceof globalObject.TypeError)) {
86-
throw new globalObject.TypeError(e.message);
87-
} else {
88-
throw e;
89-
}
90-
}
91-
return matched;
30+
exports.querySelectorAll = (selectors, parentNodeImpl) => {
31+
const node = wrapperForImpl(parentNodeImpl);
32+
return domSelector.querySelectorAll(selectors, node);
9233
};

lib/jsdom/living/helpers/style-rules.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use strict";
2+
23
const cssom = require("rrweb-cssom");
34
const { CSSStyleDeclaration } = require("cssstyle");
45
const defaultStyleSheet = require("../../browser/default-stylesheet");

lib/jsdom/living/nodes/Element-impl.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,15 +545,15 @@ class ElementImpl extends NodeImpl {
545545
}
546546

547547
closest(selectors) {
548-
return closest(selectors, this, this._globalObject);
548+
return closest(selectors, this);
549549
}
550550

551551
matches(selectors) {
552-
return matches(selectors, this, this._globalObject);
552+
return matches(selectors, this);
553553
}
554554

555555
webkitMatchesSelector(selectors) {
556-
return this.matches(selectors);
556+
return matches(selectors, this);
557557
}
558558

559559
// https://html.spec.whatwg.org/#reflecting-content-attributes-in-idl-attributes

lib/jsdom/living/nodes/ParentNode-impl.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ class ParentNodeImpl {
6161
}
6262

6363
querySelector(selectors) {
64-
return querySelector(selectors, this, this._globalObject);
64+
return querySelector(selectors, this);
6565
}
6666

6767
// Warning for internal users: this returns a NodeList containing IDL wrappers instead of impls
6868
querySelectorAll(selectors) {
69-
const nodes = querySelectorAll(selectors, this, this._globalObject);
69+
const nodes = querySelectorAll(selectors, this);
7070
return NodeList.create(this._globalObject, [], { nodes });
7171
}
7272
}

package-lock.json

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"license": "MIT",
2121
"repository": "jsdom/jsdom",
2222
"dependencies": {
23-
"@asamuzakjp/dom-selector": "^1.2.5",
23+
"@asamuzakjp/dom-selector": "^2.0.1",
2424
"cssstyle": "^4.0.1",
2525
"data-urls": "^5.0.0",
2626
"decimal.js": "^10.4.3",

test/web-platform-tests/tests

Submodule tests updated 125 files

test/web-platform-tests/to-run.yaml

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ invalidation/defined-in-has.html: [fail, Unknown]
244244
invalidation/defined.html: [fail, Unknown]
245245
invalidation/has-complexity.html: [timeout, Unknown]
246246
invalidation/has-css-nesting-shared.html: [fail, Unknown]
247+
invalidation/has-in-ancestor-position.html: [timeout, Unknown]
247248
invalidation/has-with-pseudo-class.html: [fail, Unknown]
248249
invalidation/host-context-pseudo-class-in-has.html: [fail, Unknown]
249250
invalidation/host-pseudo-class-in-has.html: [fail, Unknown]
@@ -253,10 +254,13 @@ invalidation/is.html: [fail, Unknown]
253254
invalidation/media-loading-pseudo-classes-in-has.html: [fail-slow, Unknown]
254255
invalidation/media-pseudo-classes-in-has.html: [fail-slow, Unknown]
255256
invalidation/not-002.html: [fail, Unknown]
257+
invalidation/part-dir.html: [fail, Unknown]
258+
invalidation/part-lang.html: [fail, Unknown]
256259
invalidation/placeholder-shown.html:
257260
"Set placeholder text to empty string": [fail, Unknown]
258261
invalidation/quirks-mode-stylesheet-dynamic-add-001.html: [fail, Unknown]
259262
invalidation/sibling.html: [fail, Unknown]
263+
invalidation/state-in-has.html: [fail, Unknown]
260264
invalidation/subject-has-invalidation-with-display-none-anchor-element.html: [fail, Unknown]
261265
invalidation/target-pseudo-in-has.html: [fail, Unknown]
262266
invalidation/where.html: [fail, Unknown]
@@ -310,7 +314,6 @@ CustomElementRegistry.html:
310314
'customElements.define must not throw when defining another custom element in a different global object during Get(constructor, "prototype")': [fail, Not supported]
311315
Document-createElement-customized-builtins.html:
312316
"document.createElement must report an exception thrown by a custom built-in element constructor": [fail, Unknown]
313-
"document.createElement must create an instance of autonomous custom elements when it has is attribute": [fail, :defined is not defined and throws]
314317
Document-createElement.html:
315318
"document.createElement must create an instance of autonomous custom elements when it has is attribute": [fail, :defined is not defined and throws]
316319
"document.createElement must report a NotSupportedError when the local name of the element does not match that of the custom element": [fail, throws TypeError instead]
@@ -359,8 +362,6 @@ reactions/HTMLElement.html: [fail, translate and spellcheck attributes are not i
359362
reactions/customized-builtins/HTMLAreaElement.html: [fail, HTMLAreaElement doesn't implement download ping and referrerPolicy]
360363
reactions/customized-builtins/HTMLButtonElement.html: [fail, HTMLButtonElement doesn't implement formAction formEnctype and formMethod]
361364
reactions/customized-builtins/HTMLImageElement.html: [fail, HTMLImageElement doesn't implement referrerPolicy and decoder]
362-
reactions/customized-builtins/HTMLModElement.html: [fail, test has incorrect <script src>]
363-
reactions/customized-builtins/HTMLOptGroupElement.html: [fail, test has incorrect <script src>]
364365
scoped-registry/*.tentative.html: [fail, Not implemented]
365366
state/tentative/**: [fail, Not implemented]
366367
throw-on-dynamic-markup-insertion-counter-construct-xml-parser.xhtml: [timeout, document.open() and document.close() implementation is not spec compliant]
@@ -727,26 +728,27 @@ window-open-popup-behavior.html: [fail, Depends on BroadcastChannel]
727728
window-open-windowfeatures-values.html: [fail, Depends on BroadcastChannel]
728729
window-opener-unconfigurable.window.html: [fail, Not implemented]
729730
window-properties.https.html:
731+
"Window attribute: name": [fail, Incorrectly implemented as a data property]
732+
"Window attribute: onmousewheel": [fail, Not implemented]
733+
"Window attribute: onmove": [fail, Unknown]
734+
"Window attribute: opener": [fail, Not implemented]
735+
"Window attribute: status": [fail, Incorrectly implemented as a data property]
730736
"Window method: createImageBitmap": [fail, Not implemented]
731737
"Window method: matchMedia": [fail, Not implemented]
732738
"Window readonly attribute: applicationCache": [fail, Not implemented]
733-
"Window attribute: name": [fail, Incorrectly implemented as a data property]
734-
"Window attribute: status": [fail, Incorrectly implemented as a data property]
735-
"Window attribute: opener": [fail, Not implemented]
736-
"Window attribute: onmousewheel": [fail, Not implemented]
737-
"Window replaceable attribute: scrollX": [fail, Incorrectly implemented as a data property]
738-
"Window replaceable attribute: scrollY": [fail, Incorrectly implemented as a data property]
739+
"Window replaceable attribute: devicePixelRatio": [fail, Incorrectly implemented as a data property]
740+
"Window replaceable attribute: innerHeight": [fail, Incorrectly implemented as a data property]
741+
"Window replaceable attribute: innerWidth": [fail, Incorrectly implemented as a data property]
742+
"Window replaceable attribute: outerHeight": [fail, Incorrectly implemented as a data property]
743+
"Window replaceable attribute: outerWidth": [fail, Incorrectly implemented as a data property]
739744
"Window replaceable attribute: pageXOffset": [fail, Incorrectly implemented as a data property]
740745
"Window replaceable attribute: pageYOffset": [fail, Incorrectly implemented as a data property]
741-
"Window replaceable attribute: innerWidth": [fail, Incorrectly implemented as a data property]
742-
"Window replaceable attribute: innerHeight": [fail, Incorrectly implemented as a data property]
743746
"Window replaceable attribute: screenLeft": [fail, Incorrectly implemented as a data property]
744747
"Window replaceable attribute: screenTop": [fail, Incorrectly implemented as a data property]
745748
"Window replaceable attribute: screenX": [fail, Incorrectly implemented as a data property]
746749
"Window replaceable attribute: screenY": [fail, Incorrectly implemented as a data property]
747-
"Window replaceable attribute: outerWidth": [fail, Incorrectly implemented as a data property]
748-
"Window replaceable attribute: outerHeight": [fail, Incorrectly implemented as a data property]
749-
"Window replaceable attribute: devicePixelRatio": [fail, Incorrectly implemented as a data property]
750+
"Window replaceable attribute: scrollX": [fail, Incorrectly implemented as a data property]
751+
"Window replaceable attribute: scrollY": [fail, Incorrectly implemented as a data property]
750752
"constructor": [fail, Unknown]
751753
window-prototype-chain.html:
752754
"Window.prototype": [fail, Unknown]

0 commit comments

Comments
 (0)