Skip to content

Commit

Permalink
Last (!?) fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
domenic committed Feb 16, 2020
1 parent 458552a commit 925f1b0
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/jsdom/browser/parser/html.js
Expand Up @@ -2,7 +2,7 @@

const parse5 = require("parse5");

const { internalCreateElementSteps } = require("../../living/helpers/create-element");
const { createElement } = require("../../living/helpers/create-element");

const DocumentType = require("../../living/generated/DocumentType");
const DocumentFragment = require("../../living/generated/DocumentFragment");
Expand Down Expand Up @@ -100,7 +100,7 @@ class JSDOMParse5Adapter {
customElementReactionsStack.push([]);
}

const element = internalCreateElementSteps(ownerDocument, localName, namespace, null, isValue, willExecuteScript);
const element = createElement(ownerDocument, localName, namespace, null, isValue, willExecuteScript);
this.adoptAttributes(element, attrs);

if (willExecuteScript) {
Expand Down
4 changes: 2 additions & 2 deletions lib/jsdom/browser/parser/xml.js
Expand Up @@ -3,7 +3,7 @@
const { SaxesParser } = require("saxes");
const DOMException = require("domexception/webidl2js-wrapper");

const { internalCreateElementSteps } = require("../../living/helpers/create-element");
const { createElement } = require("../../living/helpers/create-element");

const DocumentFragment = require("../../living/generated/DocumentFragment");
const DocumentType = require("../../living/generated/DocumentType");
Expand Down Expand Up @@ -108,7 +108,7 @@ function createParser(rootNode, globalObject, saxesOptions) {
const tagPrefix = tag.prefix === "" ? null : tag.prefix;
const isValue = tagAttributes.is === undefined ? null : tagAttributes.is.value;

const elem = internalCreateElementSteps(ownerDocument, tagLocal, tagNamespace, tagPrefix, isValue, true);
const elem = createElement(ownerDocument, tagLocal, tagNamespace, tagPrefix, isValue, true);

// We mark a script element as "parser-inserted", which prevents it from
// being immediately executed.
Expand Down
Expand Up @@ -217,7 +217,10 @@ class CustomElementRegistryImpl {
// https://html.spec.whatwg.org/#dom-customelementregistry-whendefined
whenDefined(name) {
if (!isValidCustomElementName(name)) {
return Promise.reject(new DOMException("Name argument is not a valid custom element name.", "SyntaxError"));
return Promise.reject(DOMException.create(
this._globalObject,
["Name argument is not a valid custom element name.", "SyntaxError"]
));
}

const alreadyRegistered = this._customElementDefinitions.some(entry => entry.name === name);
Expand Down
6 changes: 3 additions & 3 deletions lib/jsdom/living/helpers/create-element.js
Expand Up @@ -165,7 +165,7 @@ function getValidTagNames(namespace, name) {
}

// https://dom.spec.whatwg.org/#concept-create-element
function internalCreateElementSteps(
function createElement(
document,
localName,
namespace,
Expand Down Expand Up @@ -301,7 +301,7 @@ function internalCreateElementNSSteps(document, namespace, qualifiedName, option
isValue = options.is;
}

return internalCreateElementSteps(
return createElement(
document,
extracted.localName,
extracted.namespace,
Expand All @@ -312,7 +312,7 @@ function internalCreateElementNSSteps(document, namespace, qualifiedName, option
}

module.exports = {
internalCreateElementSteps,
createElement,
internalCreateElementNSSteps,

getValidTagNames,
Expand Down
4 changes: 2 additions & 2 deletions lib/jsdom/living/helpers/html-constructor.js
@@ -1,7 +1,7 @@
"use strict";

const { HTML_NS } = require("./namespaces");
const { internalCreateElementSteps, getValidTagNames } = require("./create-element");
const { createElement, getValidTagNames } = require("./create-element");

const { implForWrapper, wrapperForImpl } = require("../generated/utils");

Expand Down Expand Up @@ -47,7 +47,7 @@ function HTMLConstructor(globalObject, constructorName, newTarget) {
if (definition.constructionStack.length === 0) {
const documentImpl = implForWrapper(globalObject.document);

const elementImpl = internalCreateElementSteps(documentImpl, definition.localName, HTML_NS);
const elementImpl = createElement(documentImpl, definition.localName, HTML_NS);

const element = wrapperForImpl(elementImpl);
Object.setPrototypeOf(element, prototype);
Expand Down
4 changes: 3 additions & 1 deletion lib/jsdom/living/interfaces.js
Expand Up @@ -8,6 +8,8 @@ const nodeFilter = require("./node-filter");

// This object defines the mapping between the interface name and the generated interface wrapper code.
// Note: The mapping needs to stay as-is in order due to interface evaluation.
// We cannot "refactor" this to something less duplicative because that would break bundlers which depend on static
// analysis of require()s.
const generatedInterfaces = {
DOMException: require("domexception/webidl2js-wrapper"),

Expand Down Expand Up @@ -211,7 +213,7 @@ exports.installInterfaces = window => {
nodeFilter(window);
};

/** Returns an interface webidl2js wrapper given its an interface name. */
// Returns an interface webidl2js wrapper given its an interface name.
exports.getInterfaceWrapper = name => {
return generatedInterfaces[name];
};
4 changes: 2 additions & 2 deletions lib/jsdom/living/node.js
Expand Up @@ -3,7 +3,7 @@ const { appendAttribute } = require("./attributes");
const NODE_TYPE = require("./node-type");

const orderedSetParse = require("./helpers/ordered-set").parse;
const { internalCreateElementSteps } = require("./helpers/create-element");
const { createElement } = require("./helpers/create-element");
const { HTML_NS, XMLNS_NS } = require("./helpers/namespaces");
const { cloningSteps, domSymbolTree } = require("./helpers/internal-constants");
const { asciiCaseInsensitiveMatch, asciiLowercase } = require("./helpers/strings");
Expand Down Expand Up @@ -32,7 +32,7 @@ exports.clone = (node, document, cloneChildren) => {
break;

case NODE_TYPE.ELEMENT_NODE:
copy = internalCreateElementSteps(
copy = createElement(
document,
node._localName,
node._namespaceURI,
Expand Down
10 changes: 5 additions & 5 deletions lib/jsdom/living/nodes/DOMImplementation-impl.js
Expand Up @@ -2,7 +2,7 @@

const validateNames = require("../helpers/validate-names");
const { HTML_NS, SVG_NS } = require("../helpers/namespaces");
const { internalCreateElementSteps, internalCreateElementNSSteps } = require("../helpers/create-element");
const { createElement, internalCreateElementNSSteps } = require("../helpers/create-element");

const DocumentType = require("../generated/DocumentType");
const Document = require("../generated/Document");
Expand Down Expand Up @@ -80,19 +80,19 @@ class DOMImplementationImpl {
document.appendChild(doctype);

// Create an html element in the HTML namespace, and append it to doc.
const htmlElement = internalCreateElementSteps(document, "html", HTML_NS);
const htmlElement = createElement(document, "html", HTML_NS);
document.appendChild(htmlElement);

// Create a head element in the HTML namespace, and append it to the html
// element created in the previous step.
const headElement = internalCreateElementSteps(document, "head", HTML_NS);
const headElement = createElement(document, "head", HTML_NS);
htmlElement.appendChild(headElement);

// If the title argument is not omitted:
if (title !== undefined) {
// Create a title element in the HTML namespace, and append it to the head
// element created in the previous step.
const titleElement = internalCreateElementSteps(document, "title", HTML_NS);
const titleElement = createElement(document, "title", HTML_NS);
headElement.appendChild(titleElement);

// Create a Text node, set its data to title (which could be the empty
Expand All @@ -102,7 +102,7 @@ class DOMImplementationImpl {

// Create a body element in the HTML namespace, and append it to the html
// element created in the earlier step.
const bodyElement = internalCreateElementSteps(document, "body", HTML_NS);
const bodyElement = createElement(document, "body", HTML_NS);
htmlElement.appendChild(bodyElement);

// doc's origin is an alias to the origin of the context object's associated
Expand Down
4 changes: 2 additions & 2 deletions lib/jsdom/living/nodes/Document-impl.js
Expand Up @@ -26,7 +26,7 @@ const { validateAndExtract } = require("../helpers/validate-names");
const { fireAnEvent } = require("../helpers/events");
const { shadowIncludingInclusiveDescendantsIterator } = require("../helpers/shadow-dom");
const { enqueueCECallbackReaction } = require("../helpers/custom-elements");
const { internalCreateElementSteps, internalCreateElementNSSteps } = require("../helpers/create-element");
const { createElement, internalCreateElementNSSteps } = require("../helpers/create-element");

const DocumentOrShadowRootImpl = require("./DocumentOrShadowRoot-impl").implementation;
const GlobalEventHandlersImpl = require("./GlobalEventHandlers-impl").implementation;
Expand Down Expand Up @@ -712,7 +712,7 @@ class DocumentImpl extends NodeImpl {

const namespace = this._parsingMode === "html" || this.contentType === "application/xhtml+xml" ? HTML_NS : null;

return internalCreateElementSteps(this, localName, namespace, null, isValue, true);
return createElement(this, localName, namespace, null, isValue, true);
}

// https://dom.spec.whatwg.org/#dom-document-createelementns
Expand Down
4 changes: 2 additions & 2 deletions lib/jsdom/living/range/Range-impl.js
Expand Up @@ -10,7 +10,7 @@ const { HTML_NS } = require("../helpers/namespaces");
const { domSymbolTree } = require("../helpers/internal-constants");
const { compareBoundaryPointsPosition } = require("./boundary-point");
const { nodeRoot, nodeLength, isInclusiveAncestor } = require("../helpers/node");
const { internalCreateElementSteps } = require("../helpers/create-element");
const { createElement } = require("../helpers/create-element");

const AbstractRangeImpl = require("./AbstractRange-impl").implementation;

Expand Down Expand Up @@ -440,7 +440,7 @@ class RangeImpl extends AbstractRangeImpl {
element._namespaceURI === HTML_NS
)
) {
element = internalCreateElementSteps(node._ownerDocument, "body", HTML_NS);
element = createElement(node._ownerDocument, "body", HTML_NS);
}

return parseFragment(fragment, element);
Expand Down

0 comments on commit 925f1b0

Please sign in to comment.