From f3bcfca545ab5918fa1f2125fac7bac5ed864bad Mon Sep 17 00:00:00 2001 From: "asamuzaK (Kazz)" Date: Wed, 3 Jan 2024 19:17:53 +0900 Subject: [PATCH] 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. --- lib/jsdom/living/helpers/selectors.js | 91 +-- lib/jsdom/living/helpers/style-rules.js | 1 + lib/jsdom/living/nodes/Element-impl.js | 6 +- lib/jsdom/living/nodes/ParentNode-impl.js | 4 +- package-lock.json | 9 +- package.json | 2 +- test/web-platform-tests/tests | 2 +- test/web-platform-tests/to-run.yaml | 30 +- test/web-platform-tests/wpt-manifest.json | 845 ++++++++++++++++++---- 9 files changed, 730 insertions(+), 260 deletions(-) diff --git a/lib/jsdom/living/helpers/selectors.js b/lib/jsdom/living/helpers/selectors.js index 40fca15cb..1646f2bc3 100644 --- a/lib/jsdom/living/helpers/selectors.js +++ b/lib/jsdom/living/helpers/selectors.js @@ -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); }; diff --git a/lib/jsdom/living/helpers/style-rules.js b/lib/jsdom/living/helpers/style-rules.js index a2a6bce1f..f4fab927c 100644 --- a/lib/jsdom/living/helpers/style-rules.js +++ b/lib/jsdom/living/helpers/style-rules.js @@ -1,4 +1,5 @@ "use strict"; + const cssom = require("rrweb-cssom"); const { CSSStyleDeclaration } = require("cssstyle"); const defaultStyleSheet = require("../../browser/default-stylesheet"); diff --git a/lib/jsdom/living/nodes/Element-impl.js b/lib/jsdom/living/nodes/Element-impl.js index 54fede807..95162d88c 100644 --- a/lib/jsdom/living/nodes/Element-impl.js +++ b/lib/jsdom/living/nodes/Element-impl.js @@ -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 diff --git a/lib/jsdom/living/nodes/ParentNode-impl.js b/lib/jsdom/living/nodes/ParentNode-impl.js index 07b556f21..ea88e41bc 100644 --- a/lib/jsdom/living/nodes/ParentNode-impl.js +++ b/lib/jsdom/living/nodes/ParentNode-impl.js @@ -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 }); } } diff --git a/package-lock.json b/package-lock.json index 29e3e2ed5..e2130ee11 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "23.1.0", "license": "MIT", "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", @@ -68,9 +68,9 @@ } }, "node_modules/@asamuzakjp/dom-selector": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@asamuzakjp/dom-selector/-/dom-selector-1.2.5.tgz", - "integrity": "sha512-UbAEQXTUoSGWUX234GsHKdgwEVcf+VUwiSLz8fFt1CTLxYfST4rdtH9/VhB6D/8hktOTLPHLukN/dskOfP1G7A==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@asamuzakjp/dom-selector/-/dom-selector-2.0.1.tgz", + "integrity": "sha512-QJAJffmCiymkv6YyQ7voyQb5caCth6jzZsQncYCpHXrJ7RqdYG5y43+is8mnFcYubdOkr7cn1+na9BdFMxqw7w==", "dependencies": { "bidi-js": "^1.0.3", "css-tree": "^2.3.1", @@ -2412,7 +2412,6 @@ } }, "scripts/eslint-plugin": { - "name": "eslint-plugin-jsdom-internal", "version": "0.0.0", "dev": true } diff --git a/package.json b/package.json index fd19a8362..d45182d12 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/web-platform-tests/tests b/test/web-platform-tests/tests index 1fdfd84de..8082bfb90 160000 --- a/test/web-platform-tests/tests +++ b/test/web-platform-tests/tests @@ -1 +1 @@ -Subproject commit 1fdfd84de2a95458227cd3fceab3ce26b4e776f9 +Subproject commit 8082bfb906829f64853167c9fc2ef58b3cb1fd75 diff --git a/test/web-platform-tests/to-run.yaml b/test/web-platform-tests/to-run.yaml index f3c4e8c8f..f5d318543 100644 --- a/test/web-platform-tests/to-run.yaml +++ b/test/web-platform-tests/to-run.yaml @@ -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] @@ -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] @@ -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] @@ -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