Skip to content

Commit

Permalink
Update dom-selector and roll web platform tests
Browse files Browse the repository at this point in the history
This update simplifies the integration with jsdom's exceptions, and fixes some of the WPTs introduced in this roll.
  • Loading branch information
asamuzaK authored and domenic committed Jan 7, 2024
1 parent c039e52 commit 908f27d
Show file tree
Hide file tree
Showing 9 changed files with 730 additions and 260 deletions.
91 changes: 16 additions & 75 deletions lib/jsdom/living/helpers/selectors.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,33 @@
"use strict";

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

exports.matchesDontThrow = (selectors, elementImpl) => {
let matched;
const element = wrapperForImpl(elementImpl);
try {
const element = idlUtils.wrapperForImpl(elementImpl);
matched = domSelector.matches(selectors, element);
return domSelector.matches(selectors, element);
} catch {
matched = false;
return false;
}
return matched;
};

exports.matches = (selectors, elementImpl, globalObject) => {
let matched;
try {
const element = idlUtils.wrapperForImpl(elementImpl);
matched = domSelector.matches(selectors, element);
} catch (e) {
if (e instanceof globalThis.DOMException &&
!(e instanceof globalObject.DOMException)) {
throw DOMException.create(globalObject, [e.message, e.name]);
} else if (e instanceof globalThis.TypeError &&
!(e instanceof globalObject.TypeError)) {
throw new globalObject.TypeError(e.message);
} else {
throw e;
}
}
return matched;
exports.matches = (selectors, elementImpl) => {
const element = wrapperForImpl(elementImpl);
return domSelector.matches(selectors, element);
};

exports.closest = (selectors, elementImpl, globalObject) => {
let matched;
try {
const element = idlUtils.wrapperForImpl(elementImpl);
matched = domSelector.closest(selectors, element);
} catch (e) {
if (e instanceof globalThis.DOMException &&
!(e instanceof globalObject.DOMException)) {
throw DOMException.create(globalObject, [e.message, e.name]);
} else if (e instanceof globalThis.TypeError &&
!(e instanceof globalObject.TypeError)) {
throw new globalObject.TypeError(e.message);
} else {
throw e;
}
}
return matched;
exports.closest = (selectors, elementImpl) => {
const element = wrapperForImpl(elementImpl);
return domSelector.closest(selectors, element);
};

exports.querySelector = (selectors, parentNodeImpl, globalObject) => {
let matched;
try {
const node = idlUtils.wrapperForImpl(parentNodeImpl);
matched = domSelector.querySelector(selectors, node);
} catch (e) {
if (e instanceof globalThis.DOMException &&
!(e instanceof globalObject.DOMException)) {
throw DOMException.create(globalObject, [e.message, e.name]);
} else if (e instanceof globalThis.TypeError &&
!(e instanceof globalObject.TypeError)) {
throw new globalObject.TypeError(e.message);
} else {
throw e;
}
}
return matched;
exports.querySelector = (selectors, parentNodeImpl) => {
const node = wrapperForImpl(parentNodeImpl);
return domSelector.querySelector(selectors, node);
};

exports.querySelectorAll = (selectors, parentNodeImpl, globalObject) => {
let matched;
try {
const node = idlUtils.wrapperForImpl(parentNodeImpl);
matched = domSelector.querySelectorAll(selectors, node);
} catch (e) {
if (e instanceof globalThis.DOMException &&
!(e instanceof globalObject.DOMException)) {
throw DOMException.create(globalObject, [e.message, e.name]);
} else if (e instanceof globalThis.TypeError &&
!(e instanceof globalObject.TypeError)) {
throw new globalObject.TypeError(e.message);
} else {
throw e;
}
}
return matched;
exports.querySelectorAll = (selectors, parentNodeImpl) => {
const node = wrapperForImpl(parentNodeImpl);
return domSelector.querySelectorAll(selectors, node);
};
1 change: 1 addition & 0 deletions lib/jsdom/living/helpers/style-rules.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"use strict";

const cssom = require("rrweb-cssom");
const { CSSStyleDeclaration } = require("cssstyle");
const defaultStyleSheet = require("../../browser/default-stylesheet");
Expand Down
6 changes: 3 additions & 3 deletions lib/jsdom/living/nodes/Element-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,15 @@ class ElementImpl extends NodeImpl {
}

closest(selectors) {
return closest(selectors, this, this._globalObject);
return closest(selectors, this);
}

matches(selectors) {
return matches(selectors, this, this._globalObject);
return matches(selectors, this);
}

webkitMatchesSelector(selectors) {
return this.matches(selectors);
return matches(selectors, this);
}

// https://html.spec.whatwg.org/#reflecting-content-attributes-in-idl-attributes
Expand Down
4 changes: 2 additions & 2 deletions lib/jsdom/living/nodes/ParentNode-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ class ParentNodeImpl {
}

querySelector(selectors) {
return querySelector(selectors, this, this._globalObject);
return querySelector(selectors, this);
}

// Warning for internal users: this returns a NodeList containing IDL wrappers instead of impls
querySelectorAll(selectors) {
const nodes = querySelectorAll(selectors, this, this._globalObject);
const nodes = querySelectorAll(selectors, this);
return NodeList.create(this._globalObject, [], { nodes });
}
}
Expand Down
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"license": "MIT",
"repository": "jsdom/jsdom",
"dependencies": {
"@asamuzakjp/dom-selector": "^1.2.5",
"@asamuzakjp/dom-selector": "^2.0.1",
"cssstyle": "^4.0.1",
"data-urls": "^5.0.0",
"decimal.js": "^10.4.3",
Expand Down
2 changes: 1 addition & 1 deletion test/web-platform-tests/tests
Submodule tests updated 125 files
30 changes: 16 additions & 14 deletions test/web-platform-tests/to-run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ invalidation/defined-in-has.html: [fail, Unknown]
invalidation/defined.html: [fail, Unknown]
invalidation/has-complexity.html: [timeout, Unknown]
invalidation/has-css-nesting-shared.html: [fail, Unknown]
invalidation/has-in-ancestor-position.html: [timeout, Unknown]
invalidation/has-with-pseudo-class.html: [fail, Unknown]
invalidation/host-context-pseudo-class-in-has.html: [fail, Unknown]
invalidation/host-pseudo-class-in-has.html: [fail, Unknown]
Expand All @@ -253,10 +254,13 @@ invalidation/is.html: [fail, Unknown]
invalidation/media-loading-pseudo-classes-in-has.html: [fail-slow, Unknown]
invalidation/media-pseudo-classes-in-has.html: [fail-slow, Unknown]
invalidation/not-002.html: [fail, Unknown]
invalidation/part-dir.html: [fail, Unknown]
invalidation/part-lang.html: [fail, Unknown]
invalidation/placeholder-shown.html:
"Set placeholder text to empty string": [fail, Unknown]
invalidation/quirks-mode-stylesheet-dynamic-add-001.html: [fail, Unknown]
invalidation/sibling.html: [fail, Unknown]
invalidation/state-in-has.html: [fail, Unknown]
invalidation/subject-has-invalidation-with-display-none-anchor-element.html: [fail, Unknown]
invalidation/target-pseudo-in-has.html: [fail, Unknown]
invalidation/where.html: [fail, Unknown]
Expand Down Expand Up @@ -310,7 +314,6 @@ CustomElementRegistry.html:
'customElements.define must not throw when defining another custom element in a different global object during Get(constructor, "prototype")': [fail, Not supported]
Document-createElement-customized-builtins.html:
"document.createElement must report an exception thrown by a custom built-in element constructor": [fail, Unknown]
"document.createElement must create an instance of autonomous custom elements when it has is attribute": [fail, :defined is not defined and throws]
Document-createElement.html:
"document.createElement must create an instance of autonomous custom elements when it has is attribute": [fail, :defined is not defined and throws]
"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]
Expand Down Expand Up @@ -359,8 +362,6 @@ reactions/HTMLElement.html: [fail, translate and spellcheck attributes are not i
reactions/customized-builtins/HTMLAreaElement.html: [fail, HTMLAreaElement doesn't implement download ping and referrerPolicy]
reactions/customized-builtins/HTMLButtonElement.html: [fail, HTMLButtonElement doesn't implement formAction formEnctype and formMethod]
reactions/customized-builtins/HTMLImageElement.html: [fail, HTMLImageElement doesn't implement referrerPolicy and decoder]
reactions/customized-builtins/HTMLModElement.html: [fail, test has incorrect <script src>]
reactions/customized-builtins/HTMLOptGroupElement.html: [fail, test has incorrect <script src>]
scoped-registry/*.tentative.html: [fail, Not implemented]
state/tentative/**: [fail, Not implemented]
throw-on-dynamic-markup-insertion-counter-construct-xml-parser.xhtml: [timeout, document.open() and document.close() implementation is not spec compliant]
Expand Down Expand Up @@ -727,26 +728,27 @@ window-open-popup-behavior.html: [fail, Depends on BroadcastChannel]
window-open-windowfeatures-values.html: [fail, Depends on BroadcastChannel]
window-opener-unconfigurable.window.html: [fail, Not implemented]
window-properties.https.html:
"Window attribute: name": [fail, Incorrectly implemented as a data property]
"Window attribute: onmousewheel": [fail, Not implemented]
"Window attribute: onmove": [fail, Unknown]
"Window attribute: opener": [fail, Not implemented]
"Window attribute: status": [fail, Incorrectly implemented as a data property]
"Window method: createImageBitmap": [fail, Not implemented]
"Window method: matchMedia": [fail, Not implemented]
"Window readonly attribute: applicationCache": [fail, Not implemented]
"Window attribute: name": [fail, Incorrectly implemented as a data property]
"Window attribute: status": [fail, Incorrectly implemented as a data property]
"Window attribute: opener": [fail, Not implemented]
"Window attribute: onmousewheel": [fail, Not implemented]
"Window replaceable attribute: scrollX": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: scrollY": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: devicePixelRatio": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: innerHeight": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: innerWidth": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: outerHeight": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: outerWidth": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: pageXOffset": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: pageYOffset": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: innerWidth": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: innerHeight": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: screenLeft": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: screenTop": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: screenX": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: screenY": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: outerWidth": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: outerHeight": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: devicePixelRatio": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: scrollX": [fail, Incorrectly implemented as a data property]
"Window replaceable attribute: scrollY": [fail, Incorrectly implemented as a data property]
"constructor": [fail, Unknown]
window-prototype-chain.html:
"Window.prototype": [fail, Unknown]
Expand Down

0 comments on commit 908f27d

Please sign in to comment.