diff --git a/lib/jsdom/browser/parser/html.js b/lib/jsdom/browser/parser/html.js index 48f31181ef..62352dbb04 100644 --- a/lib/jsdom/browser/parser/html.js +++ b/lib/jsdom/browser/parser/html.js @@ -173,7 +173,11 @@ class JSDOMParse5Adapter { Object.assign(JSDOMParse5Adapter.prototype, serializationAdapter); function parseFragment(markup, contextElement) { - const ownerDocument = contextElement._ownerDocument; + // TODO: Readjust the content document. + // Explain better + const ownerDocument = contextElement.localName === "template" ? + contextElement.content._ownerDocument : + contextElement._ownerDocument; const config = Object.assign({}, ownerDocument._parseOptions, { treeAdapter: new JSDOMParse5Adapter(ownerDocument, { diff --git a/lib/jsdom/living/helpers/ce-reactions.js b/lib/jsdom/living/helpers/ce-reactions.js index 692524aa18..dd98b8616a 100644 --- a/lib/jsdom/living/helpers/ce-reactions.js +++ b/lib/jsdom/living/helpers/ce-reactions.js @@ -444,7 +444,6 @@ const CE_REACTIONS_INTERFACES = { ], HTMLHeadingElement: ["align"], HTMLTextAreaElement: [ - "autocomplete", "autofocus", "cols", @@ -463,7 +462,6 @@ const CE_REACTIONS_INTERFACES = { "value" ], HTMLButtonElement: [ - "autofocus", "disabled", "formAction", diff --git a/lib/jsdom/living/helpers/custom-elements.js b/lib/jsdom/living/helpers/custom-elements.js index 667a3a26d8..8f1bb45f40 100644 --- a/lib/jsdom/living/helpers/custom-elements.js +++ b/lib/jsdom/living/helpers/custom-elements.js @@ -172,10 +172,10 @@ function invokeCEReactions(elementQueue) { ) { const reactions = element._ceReactionQueue; - while (reactions.length > 0) { - const reaction = reactions.shift(); + try { + while (reactions.length > 0) { + const reaction = reactions.shift(); - try { switch (reaction.type) { case "upgrade": upgradeElement(reaction.definition, element); @@ -185,9 +185,9 @@ function invokeCEReactions(elementQueue) { reaction.callback.apply(wrapperForImpl(element), reaction.args); break; } - } catch (error) { - reportException(element._ownerDocument._defaultView, error); } + } catch (error) { + reportException(element._ownerDocument._defaultView, error); } } } diff --git a/lib/jsdom/living/nodes/DOMStringMap-impl.js b/lib/jsdom/living/nodes/DOMStringMap-impl.js index 7471d4b534..cbb99336f9 100644 --- a/lib/jsdom/living/nodes/DOMStringMap-impl.js +++ b/lib/jsdom/living/nodes/DOMStringMap-impl.js @@ -60,10 +60,13 @@ class DOMStringMapImpl { } } -// This is poor work-around to make [CEReactions] work with interfaces using proxies. +// TODO: This is poor work-around to make [CEReactions] work with interfaces using proxies. // Instead of patching the interfaces, in those cases we patch directly the class impl -DOMStringMapImpl.prototype[idlUtils.namedSetNew] = wrapWithCEReactions(DOMStringMapImpl.prototype[idlUtils.namedSetNew]); -DOMStringMapImpl.prototype[idlUtils.namedSetExisting] = wrapWithCEReactions(DOMStringMapImpl.prototype[idlUtils.namedSetExisting]); -DOMStringMapImpl.prototype[idlUtils.namedDelete] = wrapWithCEReactions(DOMStringMapImpl.prototype[idlUtils.namedDelete]); +DOMStringMapImpl.prototype[idlUtils.namedSetNew] = + wrapWithCEReactions(DOMStringMapImpl.prototype[idlUtils.namedSetNew]); +DOMStringMapImpl.prototype[idlUtils.namedSetExisting] = + wrapWithCEReactions(DOMStringMapImpl.prototype[idlUtils.namedSetExisting]); +DOMStringMapImpl.prototype[idlUtils.namedDelete] = + wrapWithCEReactions(DOMStringMapImpl.prototype[idlUtils.namedDelete]); exports.implementation = DOMStringMapImpl; diff --git a/lib/jsdom/living/nodes/HTMLOptionsCollection-impl.js b/lib/jsdom/living/nodes/HTMLOptionsCollection-impl.js index cc46de72b3..d467b22796 100644 --- a/lib/jsdom/living/nodes/HTMLOptionsCollection-impl.js +++ b/lib/jsdom/living/nodes/HTMLOptionsCollection-impl.js @@ -6,8 +6,9 @@ const { DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_CONTAINED_BY } = require(" const Element = require("../generated/Element"); const Node = require("../generated/Node"); const HTMLCollectionImpl = require("./HTMLCollection-impl").implementation; +const { wrapWithCEReactions } = require("../helpers/ce-reactions"); -exports.implementation = class HTMLOptionsCollectionImpl extends HTMLCollectionImpl { +class HTMLOptionsCollectionImpl extends HTMLCollectionImpl { // inherits supported property indices get length() { this._update(); @@ -104,4 +105,11 @@ exports.implementation = class HTMLOptionsCollectionImpl extends HTMLCollectionI set selectedIndex(value) { this._element.selectedIndex = value; } -}; +} + +// TODO: This is poor work-around to make [CEReactions] work with interfaces using proxies. +// Instead of patching the interfaces, in those cases we patch directly the class impl +HTMLOptionsCollectionImpl.prototype[idlUtils.indexedSetNew] = + wrapWithCEReactions(HTMLOptionsCollectionImpl.prototype[idlUtils.indexedSetNew]); + +exports.implementation = HTMLOptionsCollectionImpl; diff --git a/lib/jsdom/living/nodes/HTMLSelectElement-impl.js b/lib/jsdom/living/nodes/HTMLSelectElement-impl.js index 6eae9f428c..c98b346a86 100644 --- a/lib/jsdom/living/nodes/HTMLSelectElement-impl.js +++ b/lib/jsdom/living/nodes/HTMLSelectElement-impl.js @@ -13,6 +13,7 @@ const HTMLCollection = require("../generated/HTMLCollection"); const HTMLOptionsCollection = require("../generated/HTMLOptionsCollection"); const { domSymbolTree } = require("../helpers/internal-constants"); const { getLabelsForLabelable, formOwner } = require("../helpers/form-controls"); +const { wrapWithCEReactions } = require("../helpers/ce-reactions"); class HTMLSelectElementImpl extends HTMLElementImpl { constructor(args, privateData) { diff --git a/test/web-platform-tests/to-run.yaml b/test/web-platform-tests/to-run.yaml index 7ab3c5a434..0f4a75ce9c 100644 --- a/test/web-platform-tests/to-run.yaml +++ b/test/web-platform-tests/to-run.yaml @@ -108,20 +108,19 @@ parser/parser-uses-registry-of-owner-document.html: [fail, TODO] parser/serializing-html-fragments.html: [fail, parse5 doesn't support is attribute for serialization] perform-microtask-checkpoint-before-construction.html: [fail, impossible to implement microtask checkpoint without patching Promise] pseudo-class-defined.html: [timeout, :defined is not defined and throws] -range-and-constructors.html: [fail, Range is not implemented] +range-and-constructors.html: [fail, Range is not implemented, https://github.com/jsdom/jsdom/issues/317] reactions/CSSStyleDeclaration.html: [fail, CSSStyleDeclaration is not implemented using wedidl2js] -reactions/Document.html: [fail, TODO] +reactions/Document.html: [fail, + Document.execCommand is not implemented, https://github.com/jsdom/jsdom/issues/1539 + Document.write implementation is not spec compliant] reactions/ElementContentEditable.html: [fail, contentEditable is not implemented] -# reactions/HTMLButtonElement.html: [fail, TODO] -reactions/HTMLElement.html: [fail, TODO] -reactions/HTMLOptionsCollection.html: [fail, TODO] -reactions/HTMLSelectElement.html: [fail, TODO] -reactions/Range.html: [fail, Range is not implemented] -reactions/Selection.html: [fail, Selection is not implemented] -throw-on-dynamic-markup-insertion-counter-construct.html: [timeout, TODO] -throw-on-dynamic-markup-insertion-counter-reactions.html: [timeout, TODO] -upgrading/Document-importNode.html: [fail, TODO] -upgrading/upgrading-enqueue-reactions.html: [fail, TODO] +reactions/HTMLButtonElement.html: [fail, HTMLButtonElement doesn't implement formAction formEnctype and formMethod] +reactions/HTMLElement.html: [fail, translate and spellcheck attributes are not implemented on HTMLElement] +reactions/Range.html: [fail, Range is not implemented, https://github.com/jsdom/jsdom/issues/317] +reactions/Selection.html: [fail, Selection is not implemented, https://github.com/jsdom/jsdom/issues/937] +throw-on-dynamic-markup-insertion-counter-construct.html: [timeout, Document.write implementation is not spec compliant] +throw-on-dynamic-markup-insertion-counter-reactions.html: [timeout, Document.write implementation is not spec compliant] +upgrading/Document-importNode.html: [fail, HTMLElement constructor is patched for each window and is different than the one used via createElement, TODO] ---