1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-15 03:52:48 +00:00

updated bunch of file paths and changed the way posts are loaded

This commit is contained in:
2016-01-05 12:28:04 -06:00
parent 4bb8cae81e
commit 6ab45fe935
13249 changed files with 317868 additions and 2101398 deletions

419
node_modules/jsdom/lib/jsdom/living/attributes.js generated vendored Normal file
View File

@@ -0,0 +1,419 @@
"use strict";
const DOMException = require("../web-idl/DOMException");
const defineGetter = require("../utils").defineGetter;
const idlUtils = require("./generated/utils");
const attrGenerated = require("./generated/Attr");
const changeAttributeImpl = require("./attributes/Attr-impl").changeAttributeImpl;
const getAttrImplQualifiedName = require("./attributes/Attr-impl").getAttrImplQualifiedName;
// https://dom.spec.whatwg.org/#namednodemap
const INTERNAL = Symbol("NamedNodeMap internal");
// TODO: use NamedPropertyTracker when https://github.com/tmpvar/jsdom/pull/1116 lands?
// Don't emulate named getters for these properties.
// Compiled later after NamedNodeMap is all set up.
const reservedNames = new Set();
function NamedNodeMap() {
throw new TypeError("Illegal constructor");
}
defineGetter(NamedNodeMap.prototype, "length", function () {
return this[INTERNAL].attributeList.length;
});
NamedNodeMap.prototype.item = function (index) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to NamedNodeMap.prototype.item");
}
// Don't bother with full unsigned long long conversion. When we have better WebIDL support generally, revisit.
index = Number(index);
return this[index] || null;
};
NamedNodeMap.prototype.getNamedItem = function (name) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to NamedNodeMap.prototype.getNamedItem");
}
name = String(name);
return exports.getAttributeByName(this[INTERNAL].element, name);
};
NamedNodeMap.prototype.getNamedItemNS = function (namespace, localName) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to NamedNodeMap.prototype.getNamedItemNS");
}
if (namespace === undefined || namespace === null) {
namespace = null;
} else {
namespace = String(namespace);
}
localName = String(localName);
return exports.getAttributeByNameNS(this[INTERNAL].element, namespace, localName);
};
NamedNodeMap.prototype.setNamedItem = function (attr) {
if (!attrGenerated.is(attr)) {
throw new TypeError("First argument to NamedNodeMap.prototype.setNamedItem must be an Attr");
}
return exports.setAttribute(this[INTERNAL].element, attr);
};
NamedNodeMap.prototype.setNamedItemNS = function (attr) {
if (!attrGenerated.is(attr)) {
throw new TypeError("First argument to NamedNodeMap.prototype.setNamedItemNS must be an Attr");
}
return exports.setAttribute(this[INTERNAL].element, attr);
};
NamedNodeMap.prototype.removeNamedItem = function (name) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to NamedNodeMap.prototype.getNamedItem");
}
name = String(name);
const attr = exports.removeAttributeByName(this[INTERNAL].element, name);
if (attr === null) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "Tried to remove an attribute that was not present");
}
return attr;
};
NamedNodeMap.prototype.removeNamedItemNS = function (namespace, localName) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to NamedNodeMap.prototype.removeNamedItemNS");
}
if (namespace === undefined || namespace === null) {
namespace = null;
} else {
namespace = String(namespace);
}
localName = String(localName);
const attr = exports.removeAttributeByNameNS(this[INTERNAL].element, namespace, localName);
if (attr === null) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "Tried to remove an attribute that was not present");
}
return attr;
};
exports.NamedNodeMap = NamedNodeMap;
{
let prototype = NamedNodeMap.prototype;
while (prototype) {
for (const name of Object.getOwnPropertyNames(prototype)) {
reservedNames.add(name);
}
prototype = Object.getPrototypeOf(prototype);
}
}
exports.createNamedNodeMap = function (element) {
const nnm = Object.create(NamedNodeMap.prototype);
nnm[INTERNAL] = {
element,
attributeList: [],
attributesByNameMap: new Map()
};
return nnm;
};
// The following three are for https://dom.spec.whatwg.org/#concept-element-attribute-has. We don't just have a
// predicate tester since removing that kind of flexibility gives us the potential for better future optimizations.
exports.hasAttribute = function (element, A) {
const attributesNNM = element._attributes;
const attributeList = attributesNNM[INTERNAL].attributeList;
return attributeList.indexOf(A) !== -1;
};
exports.hasAttributeByName = function (element, name) {
const attributesNNM = element._attributes;
const attributesByNameMap = attributesNNM[INTERNAL].attributesByNameMap;
return attributesByNameMap.has(name);
};
exports.hasAttributeByNameNS = function (element, namespace, localName) {
const attributesNNM = element._attributes;
const attributeList = attributesNNM[INTERNAL].attributeList;
return attributeList.some(attribute => {
const impl = idlUtils.implForWrapper(attribute);
return impl && impl._localName === localName && impl._namespace === namespace;
});
};
exports.changeAttribute = function (element, attribute, value) {
// https://dom.spec.whatwg.org/#concept-element-attributes-change
// The partitioning here works around a particularly bad circular require problem. See
// https://github.com/tmpvar/jsdom/pull/1247#issuecomment-149060470
changeAttributeImpl(element, idlUtils.implForWrapper(attribute), value);
};
exports.appendAttribute = function (element, attribute) {
// https://dom.spec.whatwg.org/#concept-element-attributes-append
const impl = idlUtils.implForWrapper(attribute);
const attributesNNM = element._attributes;
const attributeList = attributesNNM[INTERNAL].attributeList;
// TODO mutation observer stuff
attributeList.push(attribute);
impl._element = element;
// Sync target indexed properties
attributesNNM[attributeList.length - 1] = attribute;
// Sync target named properties
const name = getAttrImplQualifiedName(impl);
if (!reservedNames.has(name)) {
attributesNNM[name] = attribute;
}
// Sync name cache
const cache = attributesNNM[INTERNAL].attributesByNameMap;
let entry = cache.get(name);
if (!entry) {
entry = [];
cache.set(name, entry);
}
entry.push(attribute);
// Run jsdom hooks; roughly correspond to spec's "An attribute is set and an attribute is added."
element._attrModified(name, impl._value, null);
};
exports.removeAttribute = function (element, attribute) {
// https://dom.spec.whatwg.org/#concept-element-attributes-remove
const attributesNNM = element._attributes;
const attributeList = attributesNNM[INTERNAL].attributeList;
// TODO mutation observer stuff
for (let i = 0; i < attributeList.length; ++i) {
if (attributeList[i] === attribute) {
const impl = idlUtils.implForWrapper(attribute);
attributeList.splice(i, 1);
impl._element = null;
// Sync target indexed properties
for (let j = i; j < attributeList.length; ++j) {
attributesNNM[j] = attributeList[j];
}
delete attributesNNM[attributeList.length];
// Sync target named properties
const name = getAttrImplQualifiedName(impl);
if (!reservedNames.has(name)) {
delete attributesNNM[name];
}
// Sync name cache
const cache = attributesNNM[INTERNAL].attributesByNameMap;
const entry = cache.get(name);
entry.splice(entry.indexOf(attribute), 1);
if (entry.length === 0) {
cache.delete(name);
}
// Run jsdom hooks; roughly correspond to spec's "An attribute is removed."
element._attrModified(name, null, impl._value);
return;
}
}
};
exports.getAttributeByName = function (element, name) {
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name
if (element._namespaceURI === "http://www.w3.org/1999/xhtml" &&
element._ownerDocument._parsingMode === "html") {
name = name.toLowerCase();
}
const cache = element._attributes[INTERNAL].attributesByNameMap;
const entry = cache.get(name);
if (!entry) {
return null;
}
return entry[0];
};
exports.getAttributeValue = function (element, name) {
const attr = exports.getAttributeByName(element, name);
if (!attr) {
return null;
}
return idlUtils.implForWrapper(attr)._value;
};
exports.getAttributeByNameNS = function (element, namespace, localName) {
// https://dom.spec.whatwg.org/#concept-element-attributes-get-by-namespace
if (namespace === "") {
namespace = null;
}
const attributeList = element._attributes[INTERNAL].attributeList;
for (let i = 0; i < attributeList.length; ++i) {
const attr = attributeList[i];
const impl = idlUtils.implForWrapper(attr);
if (impl._namespace === namespace && impl._localName === localName) {
return attr;
}
}
return null;
};
exports.getAttributeValueByNameNS = function (element, namespace, localName) {
const attr = exports.getAttributeByNameNS(element, namespace, localName);
if (!attr) {
return null;
}
return idlUtils.implForWrapper(attr)._value;
};
exports.setAttribute = function (element, attr) {
// https://dom.spec.whatwg.org/#concept-element-attributes-set
const impl = idlUtils.implForWrapper(attr);
if (impl._element !== null && impl._element !== element) {
throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR);
}
const oldAttr = exports.getAttributeByNameNS(element, impl._namespace, impl._localName);
if (oldAttr === attr) {
return attr;
}
if (oldAttr !== null) {
exports.removeAttribute(element, oldAttr);
}
exports.appendAttribute(element, attr);
return oldAttr;
};
exports.setAttributeValue = function (element, localName, value, prefix, namespace) {
// https://dom.spec.whatwg.org/#concept-element-attributes-set-value
if (prefix === undefined) {
prefix = null;
}
if (namespace === undefined) {
namespace = null;
}
const attribute = exports.getAttributeByNameNS(element, namespace, localName);
if (attribute === null) {
const newAttribute = attrGenerated.create([], { namespace, namespacePrefix: prefix, localName, value });
exports.appendAttribute(element, newAttribute);
return;
}
exports.changeAttribute(element, attribute, value);
};
exports.removeAttributeByName = function (element, name) {
// https://dom.spec.whatwg.org/#concept-element-attributes-remove-by-name
const attr = exports.getAttributeByName(element, name);
if (attr !== null) {
exports.removeAttribute(element, attr);
}
return attr;
};
exports.removeAttributeByNameNS = function (element, namespace, localName) {
// https://dom.spec.whatwg.org/#concept-element-attributes-remove-by-namespace
const attr = exports.getAttributeByNameNS(element, namespace, localName);
if (attr !== null) {
exports.removeAttribute(element, attr);
}
return attr;
};
exports.copyAttributeList = function (sourceElement, destElement) {
// Needed by https://dom.spec.whatwg.org/#concept-node-clone
for (const sourceAttr of sourceElement._attributes[INTERNAL].attributeList) {
const sourceImpl = idlUtils.implForWrapper(sourceAttr);
const destAttr = attrGenerated.create([], {
namespace: sourceImpl._namespace,
prefix: sourceImpl._prefix,
localName: sourceImpl._localName,
value: sourceImpl._value
});
exports.appendAttribute(destElement, destAttr);
}
};
exports.attributeListsEqual = function (elementA, elementB) {
// Needed by https://dom.spec.whatwg.org/#concept-node-equals
const listA = elementA._attributes[INTERNAL].attributeList;
const listB = elementB._attributes[INTERNAL].attributeList;
if (listA.length !== listB.length) {
return false;
}
for (let i = 0; i < listA.length; ++i) {
const attrA = listA[i];
const implA = idlUtils.implForWrapper(attrA);
if (!listB.some(attrB => equalsA(attrB))) {
return false;
}
function equalsA(attrB) {
const implB = idlUtils.implForWrapper(attrB);
return implA._namespace === implB._namespace && implA._localName === implB._localName &&
implA._value === implB._value;
}
}
return true;
};
exports.hasAttributes = function (element) {
// Needed by https://dom.spec.whatwg.org/#dom-element-hasattributes
return element._attributes[INTERNAL].attributeList.length > 0;
};

View File

@@ -0,0 +1,82 @@
"use strict";
exports.implementation = class AttrImpl {
constructor(_, privateData) {
this._namespace = privateData.namespace !== undefined ? privateData.namespace : null;
this._namespacePrefix = privateData.namespacePrefix !== undefined ? privateData.namespacePrefix : null;
this._localName = privateData.localName;
this._value = privateData.value !== undefined ? privateData.value : "";
this._element = privateData.element !== undefined ? privateData.element : null;
this.specified = true;
}
get namespaceURI() {
return this._namespace;
}
get prefix() {
return this._namespacePrefix;
}
get localName() {
return this._localName;
}
get name() {
return exports.getAttrImplQualifiedName(this);
}
get value() {
return this._value;
}
set value(v) {
if (this._element === null) {
this._value = v;
} else {
exports.changeAttributeImpl(this._element, this, v);
}
}
// Delegate to value
get nodeValue() {
return this.value;
}
set nodeValue(v) {
this.value = v;
}
// Delegate to value
get textContent() {
return this.value;
}
set textContent(v) {
this.value = v;
}
get ownerElement() {
return this._element;
}
};
exports.changeAttributeImpl = function (element, attributeImpl, value) {
// https://dom.spec.whatwg.org/#concept-element-attributes-change
// TODO mutation observer stuff
const oldValue = attributeImpl._value;
attributeImpl._value = value;
// Run jsdom hooks; roughly correspond to spec's "An attribute is set and an attribute is changed."
element._attrModified(exports.getAttrImplQualifiedName(attributeImpl), value, oldValue);
};
exports.getAttrImplQualifiedName = function (attributeImpl) {
// https://dom.spec.whatwg.org/#concept-attribute-qualified-name
if (attributeImpl._namespacePrefix === null) {
return attributeImpl._localName;
}
return attributeImpl._namespacePrefix + ":" + attributeImpl._localName;
};

7
node_modules/jsdom/lib/jsdom/living/blob-symbols.js generated vendored Normal file
View File

@@ -0,0 +1,7 @@
"use strict";
exports.buffer = Symbol("buffer");
exports.type = Symbol("type");
exports.lastModified = Symbol("lastModified");
exports.closed = Symbol("closed");

76
node_modules/jsdom/lib/jsdom/living/blob.js generated vendored Normal file
View File

@@ -0,0 +1,76 @@
"use strict";
const blobSymbols = require("./blob-symbols");
class Blob {
constructor() {
if (!(this instanceof Blob)) {
throw new TypeError("DOM object constructor cannot be called as a function.");
}
const parts = arguments[0];
const properties = arguments[1];
if (arguments.length > 0) {
if (!parts || typeof parts !== "object" || parts instanceof Date || parts instanceof RegExp) {
throw new TypeError("Blob parts must be objects that are not Dates or RegExps");
}
}
const buffers = [];
if (parts) {
const l = Number(parts.length);
for (let i = 0; i < l; i++) {
const part = parts[i];
let buffer;
if (part instanceof ArrayBuffer) {
buffer = new Buffer(new Uint8Array(part));
} else if (part instanceof Blob) {
buffer = part[blobSymbols.buffer];
} else if (ArrayBuffer.isView(part)) {
buffer = new Buffer(new Uint8Array(part.buffer, part.byteOffset, part.byteLength));
} else {
buffer = new Buffer(typeof part === "string" ? part : String(part));
}
buffers.push(buffer);
}
}
this[blobSymbols.buffer] = Buffer.concat(buffers);
this[blobSymbols.type] = properties && properties.type ? String(properties.type).toLowerCase() : "";
if (!this[blobSymbols.type].match(/^ *[a-z0-9-]+(?:\/[a-z0-9-]+)? *(; *charset *= *[a-z0-9-]+ *)?$/)) {
this[blobSymbols.type] = "";
}
this[blobSymbols.lastModified] = properties && properties.lastModified ? properties.lastModified : null;
this[blobSymbols.closed] = false;
}
get size() {
return this[blobSymbols.buffer].length;
}
get type() {
return this[blobSymbols.type];
}
get lastModified() {
return this[blobSymbols.lastModified];
}
slice() {
const buffer = this[blobSymbols.buffer];
const slicedBuffer = buffer.slice(
arguments[0] || 0,
arguments[1] || this.size
);
const blob = new Blob([], { type: arguments[2] || this.type });
blob[blobSymbols.buffer] = slicedBuffer;
return blob;
}
close() {
this[blobSymbols.closed] = true;
}
toString() {
return "[object Blob]";
}
}
module.exports = function (core) {
core.Blob = Blob;
};

113
node_modules/jsdom/lib/jsdom/living/character-data.js generated vendored Normal file
View File

@@ -0,0 +1,113 @@
"use strict";
const inheritFrom = require("../utils").inheritFrom;
const domSymbolTree = require("./helpers/internal-constants").domSymbolTree;
module.exports = function (core) {
core.CharacterData = function CharacterData(ownerDocument, data) {
core.Node.call(this, ownerDocument);
this._data = data;
};
inheritFrom(core.Node, core.CharacterData, {
get data() {
return this._data;
},
set data(data) {
if (data === null) {
data = "";
}
data = String(data);
this._setData(data);
},
get length() {
return this._data.length;
},
substringData(offset, count) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to CharacterData.prototype.substringData");
}
offset >>>= 0;
count >>>= 0;
const length = this.length;
if (offset > length) {
throw new core.DOMException(core.DOMException.INDEX_SIZE_ERR);
}
if (offset + count > length) {
return this._data.substring(offset);
}
return this._data.substring(offset, offset + count);
},
appendData(data) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to CharacterData.prototype.appendData");
}
this.replaceData(this.length, 0, data);
},
insertData(offset, data) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to CharacterData.prototype.insertData");
}
this.replaceData(offset, 0, data);
},
deleteData(offset, count) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to CharacterData.prototype.deleteData");
}
this.replaceData(offset, count, "");
},
replaceData(offset, count, data) {
if (arguments.length < 3) {
throw new TypeError("Not enough arguments to CharacterData.prototype.replaceData");
}
offset >>>= 0;
count >>>= 0;
data = String(data);
const length = this.length;
if (offset > length) {
throw new core.DOMException(core.DOMException.INDEX_SIZE_ERR);
}
if (offset + count > length) {
count = length - offset;
}
const start = this._data.substring(0, offset);
const end = this._data.substring(offset + count);
this._setData(start + data + end);
// TODO: range stuff
},
_setData(newData) {
// TODO: remove this once we no longer rely on mutation events internally, since they are nonstandard
const oldData = this._data;
this._data = newData;
if (this._ownerDocument &&
domSymbolTree.parent(this) &&
this._ownerDocument.implementation._hasFeature("MutationEvents")) {
const ev = this._ownerDocument.createEvent("MutationEvents");
ev.initMutationEvent("DOMCharacterDataModified", true, false, this, oldData, newData, null, null);
this.dispatchEvent(ev);
}
}
});
};

14
node_modules/jsdom/lib/jsdom/living/comment.js generated vendored Normal file
View File

@@ -0,0 +1,14 @@
"use strict";
const inheritFrom = require("../utils").inheritFrom;
const NODE_TYPE = require("../living/node-type");
module.exports = function (core) {
// TODO: constructor should not take ownerDocument
core.Comment = function Comment(ownerDocument, data) {
core.CharacterData.call(this, ownerDocument, data);
};
inheritFrom(core.CharacterData, core.Comment, {
nodeType: NODE_TYPE.COMMENT_NODE // TODO should be on prototype, not here
});
};

47
node_modules/jsdom/lib/jsdom/living/document-type.js generated vendored Normal file
View File

@@ -0,0 +1,47 @@
"use strict";
const NODE_TYPE = require("../living/node-type");
const privates = Symbol("DocumentType internal slots");
module.exports = core => {
core.DocumentType = class DocumentType extends core.Node {
constructor(secret, ownerDocument, name, publicId, systemId) {
if (secret !== privates) {
throw new TypeError("Invalid constructor");
}
super(ownerDocument);
this[privates] = { name, publicId, systemId };
}
get name() {
return this[privates].name;
}
get publicId() {
return this[privates].publicId;
}
get systemId() {
return this[privates].systemId;
}
};
core.DocumentType.prototype.nodeType = NODE_TYPE.DOCUMENT_TYPE_NODE; // TODO should be on Node, not here
};
module.exports.create = (core, ownerDocument, name, publicId, systemId) => {
return new core.DocumentType(privates, ownerDocument, name, publicId, systemId);
};
module.exports.clone = (core, otherDoctype) => {
return new core.DocumentType(
privates,
otherDoctype._ownerDocument,
otherDoctype[privates].name,
otherDoctype[privates].publicId,
otherDoctype[privates].systemId
);
};
module.exports.getPrivates = doctype => {
return doctype[privates];
};

162
node_modules/jsdom/lib/jsdom/living/document.js generated vendored Normal file
View File

@@ -0,0 +1,162 @@
"use strict";
const DOMException = require("../web-idl/DOMException");
const validateNames = require("./helpers/validate-names");
const defineGetter = require("../utils").defineGetter;
const defineSetter = require("../utils").defineSetter;
const memoizeQuery = require("../utils").memoizeQuery;
const generatedAttr = require("./generated/Attr");
const clone = require("./node").clone;
const listOfElementsWithClassNames = require("./node").listOfElementsWithClassNames;
const validateName = require("./helpers/validate-names").name;
const validateAndExtract = require("./helpers/validate-names").validateAndExtract;
const NODE_TYPE = require("../living/node-type");
module.exports = function (core) {
core.Document.prototype.createProcessingInstruction = function (target, data) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to Document.prototype.createProcessingInstruction");
}
target = String(target);
data = String(data);
validateNames.name(target);
if (data.indexOf("?>") !== -1) {
throw new core.DOMException(core.DOMException.INVALID_CHARACTER_ERR,
"Processing instruction data cannot contain the string \"?>\"");
}
return new core.ProcessingInstruction(this._ownerDocument, target, data);
};
core.Document.prototype.createTextNode = function (data) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Document.prototype.createTextNode");
}
data = String(data);
return new core.Text(this, data);
};
core.Document.prototype.createComment = function (data) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Document.prototype.createComment");
}
data = String(data);
return new core.Comment(this, data);
};
core.Document.prototype.createElement = function (localName) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Document.prototype.createElement");
}
localName = String(localName);
validateName(localName);
if (this._parsingMode === "html") {
localName = localName.toLowerCase();
}
const element = this._createElementWithCorrectElementInterface(localName, "http://www.w3.org/1999/xhtml");
element._namespaceURI = "http://www.w3.org/1999/xhtml";
element._localName = localName;
element._ownerDocument = this;
return element;
};
core.Document.prototype.createElementNS = function (namespace, qualifiedName) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to Document.prototype.createElementNS");
}
namespace = namespace !== null ? String(namespace) : namespace;
qualifiedName = String(qualifiedName);
const extracted = validateAndExtract(namespace, qualifiedName);
const element = this._createElementWithCorrectElementInterface(extracted.localName, extracted.namespace);
element._namespaceURI = extracted.namespace;
element._prefix = extracted.prefix;
element._localName = extracted.localName;
element._ownerDocument = this;
return element;
};
core.Document.prototype.createDocumentFragment = function () {
return new core.DocumentFragment(this);
};
core.Document.prototype.createAttribute = function (localName) {
if (arguments.length < 1) {
throw new TypeError("not enough arguments to Document.prototype.createAttribute");
}
localName = String(localName);
validateName(localName);
if (this._parsingMode === "html") {
localName = localName.toLowerCase();
}
return generatedAttr.create([], { localName });
};
core.Document.prototype.createAttributeNS = function (namespace, name) {
if (arguments.length < 2) {
throw new TypeError("not enough arguments to Document.prototype.createAttributeNS");
}
if (namespace === undefined) {
namespace = null;
}
namespace = namespace !== null ? String(namespace) : namespace;
name = String(name);
const extracted = validateAndExtract(namespace, name);
return generatedAttr.create([], {
namespace: extracted.namespace,
namespacePrefix: extracted.prefix,
localName: extracted.localName
});
};
core.Document.prototype.importNode = function (node, deep) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Document.prototype.createElement");
}
if (!("_ownerDocument" in node)) {
throw new TypeError("First argument to importNode must be a Node");
}
deep = Boolean(deep);
if (node.nodeType === NODE_TYPE.DOCUMENT_NODE) {
throw new DOMException(DOMException.NOT_SUPPORTED_ERR, "Cannot import a document node");
}
return clone(core, node, this, deep);
};
core.Document.prototype.getElementsByClassName = memoizeQuery(function getElementsByClassName(classNames) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Document.prototype.getElementsByClassName");
}
classNames = String(classNames);
return listOfElementsWithClassNames(classNames, this);
});
// https://html.spec.whatwg.org/multipage/dom.html#dom-document-cookie
defineGetter(core.Document.prototype, "cookie", function () {
return this._cookieJar.getCookieStringSync(this._URL, { http: false });
});
defineSetter(core.Document.prototype, "cookie", function (cookieStr) {
cookieStr = String(cookieStr);
this._cookieJar.setCookieSync(cookieStr, this._URL, {
http: false,
ignoreError: true
});
});
};

View File

@@ -0,0 +1,90 @@
"use strict";
const validateNames = require("./helpers/validate-names");
const createDocumentTypeInternal = require("./document-type").create;
module.exports = function (core) {
core.DOMImplementation.prototype.hasFeature = function () {
return true;
};
core.DOMImplementation.prototype.createDocumentType = function (qualifiedName, publicId, systemId) {
if (arguments.length < 3) {
throw new TypeError("Expected 3 arguments to createDocumentType");
}
qualifiedName = String(qualifiedName);
publicId = String(publicId);
systemId = String(systemId);
validateNames.qname(qualifiedName);
return createDocumentTypeInternal(core, this._ownerDocument, qualifiedName, publicId, systemId);
};
core.DOMImplementation.prototype.createDocument = function (namespace, qualifiedName, doctype) {
namespace = namespace !== null ? String(namespace) : namespace;
qualifiedName = qualifiedName === null ? "" : String(qualifiedName);
if (doctype === undefined) {
doctype = null;
}
const document = new core.Document({ parsingMode: "xml" });
let element = null;
if (qualifiedName !== "") {
element = document.createElementNS(namespace, qualifiedName);
}
if (doctype !== null) {
document.appendChild(doctype);
}
if (element !== null) {
document.appendChild(element);
}
return document;
};
core.DOMImplementation.prototype.createHTMLDocument = function (title) {
// Let doc be a new document that is an HTML document.
// Set doc's content type to "text/html".
const document = new core.HTMLDocument({ parsingMode: "html" });
// Create a doctype, with "html" as its name and with its node document set
// to doc. Append the newly created node to doc.
const doctype = createDocumentTypeInternal(core, this, "html", "", "");
document.appendChild(doctype);
// Create an html element in the HTML namespace, and append it to doc.
const htmlElement = document.createElementNS("http://www.w3.org/1999/xhtml", "html");
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 = document.createElement("head");
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 = document.createElement("title");
headElement.appendChild(titleElement);
// Create a Text node, set its data to title (which could be the empty
// string), and append it to the title element created in the previous step.
titleElement.appendChild(document.createTextNode(title));
}
// Create a body element in the HTML namespace, and append it to the html
// element created in the earlier step.
htmlElement.appendChild(document.createElement("body"));
// doc's origin is an alias to the origin of the context object's associated
// document, and doc's effective script origin is an alias to the effective
// script origin of the context object's associated document.
return document;
};
};

193
node_modules/jsdom/lib/jsdom/living/dom-token-list.js generated vendored Normal file
View File

@@ -0,0 +1,193 @@
"use strict";
const DOMException = require("../web-idl/DOMException");
const orderedSetParser = require("./helpers/ordered-set-parser");
// https://dom.spec.whatwg.org/#domtokenlist
const INTERNAL = Symbol("DOMTokenList internal");
class DOMTokenList {
constructor() {
throw new TypeError("Illegal constructor");
}
item(index) {
const length = this.length;
return length <= index || index < 0 ? null : this[index];
}
contains(token) {
token = String(token);
validateToken(token);
return indexOf(this, token) !== -1;
}
add(/* tokens... */) {
for (let i = 0; i < arguments.length; i++) {
const token = String(arguments[i]);
validateToken(token);
if (indexOf(this, token) === -1) {
push(this, token);
}
}
update(this);
}
remove(/* tokens... */) {
for (let i = 0; i < arguments.length; i++) {
const token = String(arguments[i]);
validateToken(token);
const index = indexOf(this, token);
if (index !== -1) {
spliceLite(this, index, 1);
}
}
update(this);
}
// if force is true, this behaves like add
// if force is false, this behaves like remove
// if force is undefined, this behaves as one would expect toggle to
// always returns whether classList contains token after toggling
toggle(token, force) {
token = String(token);
force = force === undefined ? undefined : Boolean(force);
validateToken(token);
const index = indexOf(this, token);
if (index !== -1) {
if (force === false || force === undefined) {
spliceLite(this, index, 1);
update(this);
return false;
}
return true;
}
if (force === false) {
return false;
}
push(this, token);
update(this);
return true;
}
get length() {
return this[INTERNAL].tokens.length;
}
toString() {
return this[INTERNAL].tokens.join(" ");
}
}
function validateToken(token) {
if (token === "") {
throw new DOMException(DOMException.SYNTAX_ERR, "The token provided must not be empty.");
}
if (/\s/.test(token)) {
const whitespaceMsg = "The token provided contains HTML space characters, which are not valid in tokens.";
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, whitespaceMsg);
}
}
function update(list) {
const attribute = list[INTERNAL].attribute;
if (attribute !== undefined) {
list[INTERNAL].element.setAttribute(attribute, list.toString());
}
}
// calls indexOf on internal array
function indexOf(dtl, token) {
return dtl[INTERNAL].tokens.indexOf(token);
}
// calls push on internal array, then manually adds indexed property to dtl
function push(dtl, token) {
const len = dtl[INTERNAL].tokens.push(token);
dtl[len - 1] = token;
return len;
}
// calls splice on internal array then rewrites indexed properties of dtl
// does not allow items to be added, only removed, so splice-lite
function spliceLite(dtl, start, deleteCount) {
const tokens = dtl[INTERNAL].tokens;
const removedTokens = tokens.splice(start, deleteCount);
// remove indexed properties from list
const re = /^\d+$/;
for (const prop in dtl) {
if (re.test(prop)) {
delete dtl[prop];
}
}
// copy indexed properties from internal array
const len = tokens.length;
for (let i = 0; i < len; i++) {
dtl[i] = tokens[i];
}
return removedTokens;
}
exports.DOMTokenList = DOMTokenList;
// set dom token list without running update steps
exports.reset = function resetDOMTokenList(list, value) {
const tokens = list[INTERNAL].tokens;
spliceLite(list, 0, tokens.length);
value = (value || "").trim();
if (value !== "") {
for (const token of orderedSetParser(value)) {
push(list, token);
}
}
};
exports.create = function createDOMTokenList(element, attribute) {
const list = Object.create(DOMTokenList.prototype);
list[INTERNAL] = {
element,
attribute,
tokens: []
};
exports.reset(list, element.getAttribute(attribute));
return list;
};
exports.contains = function domTokenListContains(list, token, options) {
const caseInsensitive = options && options.caseInsensitive;
if (!caseInsensitive) {
return indexOf(list, token) !== -1;
}
const tokens = list[INTERNAL].tokens;
const lowerToken = token.toLowerCase();
for (let i = 0; i < tokens.length; ++i) {
if (tokens[i].toLowerCase() === lowerToken) {
return true;
}
}
return false;
};

215
node_modules/jsdom/lib/jsdom/living/element.js generated vendored Normal file
View File

@@ -0,0 +1,215 @@
"use strict";
const defineGetter = require("../utils").defineGetter;
const memoizeQuery = require("../utils").memoizeQuery;
const attributes = require("./attributes");
const attrGenerated = require("./generated/Attr");
const createDOMTokenList = require("./dom-token-list").create;
const listOfElementsWithClassNames = require("./node").listOfElementsWithClassNames;
const validateNames = require("./helpers/validate-names");
const DOMException = require("../web-idl/DOMException");
module.exports = function (core) {
defineGetter(core.Element, "attributes", function () {
return this._attributes;
});
defineGetter(core.Element.prototype, "classList", function () {
if (this._classList === undefined) {
this._classList = createDOMTokenList(this, "class");
}
return this._classList;
});
core.Element.prototype.hasAttributes = function hasAttributes() {
return attributes.hasAttributes(this);
};
core.Element.prototype.getAttribute = function getAttribute(name) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Element.prototype.getAttribute");
}
name = String(name);
return attributes.getAttributeValue(this, name);
};
core.Element.prototype.getAttributeNS = function getAttributeNS(namespace, localName) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to Element.prototype.getAttributeNS");
}
if (namespace === undefined || namespace === null) {
namespace = null;
} else {
namespace = String(namespace);
}
localName = String(localName);
return attributes.getAttributeValueByNameNS(this, namespace, localName);
};
core.Element.prototype.setAttribute = function setAttribute(name, value) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to Element.prototype.setAttribute");
}
name = String(name);
value = String(value);
validateNames.name(name);
if (this._namespaceURI === "http://www.w3.org/1999/xhtml" && this._ownerDocument._parsingMode === "html") {
name = name.toLowerCase();
}
const attribute = attributes.getAttributeByName(this, name);
if (attribute === null) {
const newAttr = attrGenerated.create([], { localName: name, value });
attributes.appendAttribute(this, newAttr);
return;
}
attributes.changeAttribute(this, attribute, value);
};
core.Element.prototype.setAttributeNS = function setAttributeNS(namespace, name, value) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to Element.prototype.setAttributeNS");
}
if (namespace === undefined || namespace === null) {
namespace = null;
} else {
namespace = String(namespace);
}
name = String(name);
value = String(value);
const extracted = validateNames.validateAndExtract(namespace, name);
attributes.setAttributeValue(this, extracted.localName, value, extracted.prefix, extracted.namespace);
};
core.Element.prototype.removeAttribute = function removeAttribute(name) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Element.prototype.removeAttribute");
}
name = String(name);
attributes.removeAttributeByName(this, name);
};
core.Element.prototype.removeAttributeNS = function removeAttributeNS(namespace, localName) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to Element.prototype.removeAttributeNS");
}
if (namespace === undefined || namespace === null) {
namespace = null;
} else {
namespace = String(namespace);
}
localName = String(localName);
attributes.removeAttributeByNameNS(this, namespace, localName);
};
core.Element.prototype.hasAttribute = function hasAttribute(name) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Element.prototype.hasAttribute");
}
name = String(name);
if (this._namespaceURI === "http://www.w3.org/1999/xhtml" && this._ownerDocument._parsingMode === "html") {
name = name.toLowerCase();
}
return attributes.hasAttributeByName(this, name);
};
core.Element.prototype.hasAttributeNS = function hasAttributeNS(namespace, localName) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to Element.prototype.hasAttributeNS");
}
if (namespace === undefined || namespace === null) {
namespace = null;
} else {
namespace = String(namespace);
}
localName = String(localName);
if (namespace === "") {
namespace = null;
}
return attributes.hasAttributeByNameNS(this, namespace, localName);
};
core.Element.prototype.getAttributeNode = function getAttributeNode(name) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Element.prototype.getAttributeNode");
}
name = String(name);
return attributes.getAttributeByName(this, name);
};
core.Element.prototype.getAttributeNodeNS = function getAttributeNodeNS(namespace, localName) {
if (arguments.length < 2) {
throw new TypeError("Not enough arguments to Element.prototype.getAttributeNodeNS");
}
if (namespace === undefined || namespace === null) {
namespace = null;
} else {
namespace = String(namespace);
}
localName = String(localName);
return attributes.getAttributeByNameNS(this, namespace, localName);
};
core.Element.prototype.setAttributeNode = function setAttributeNode(attr) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Element.prototype.setAttributeNode");
}
if (!attrGenerated.is(attr)) {
throw new TypeError("First argument to Element.prototype.setAttributeNode must be an Attr");
}
return attributes.setAttribute(this, attr);
};
core.Element.prototype.setAttributeNodeNS = function setAttributeNodeNS(attr) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Element.prototype.setAttributeNodeNS");
}
if (!attrGenerated.is(attr)) {
throw new TypeError("First argument to Element.prototype.setAttributeNodeNS must be an Attr");
}
return attributes.setAttribute(this, attr);
};
core.Element.prototype.removeAttributeNode = function removeAttributeNode(attr) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Element.prototype.setAttributeNode");
}
if (!attrGenerated.is(attr)) {
throw new TypeError("First argument to Element.prototype.removeAttributeNode must be an Attr");
}
if (!attributes.hasAttribute(this, attr)) {
throw new DOMException(DOMException.NOT_FOUND_ERR, "Tried to remove an attribute that was not present");
}
attributes.removeAttribute(this, attr);
return attr;
};
core.Element.prototype.getElementsByClassName = memoizeQuery(function getElementsByClassName(classNames) {
if (arguments.length < 1) {
throw new TypeError("Not enough arguments to Element.prototype.getElementsByClassName");
}
classNames = String(classNames);
return listOfElementsWithClassNames(classNames, this);
});
};

View File

@@ -0,0 +1,18 @@
"use strict";
const EventImpl = require("./Event-impl").implementation;
class CustomEventImpl extends EventImpl {
initCustomEvent(type, bubbles, cancelable, detail) {
if (this._dispatchFlag) {
return;
}
this.initEvent(type, bubbles, cancelable);
this.detail = detail;
}
}
module.exports = {
implementation: CustomEventImpl
};

View File

@@ -0,0 +1,11 @@
"use strict";
const EventImpl = require("./Event-impl").implementation;
class ErrorEventImpl extends EventImpl {
}
module.exports = {
implementation: ErrorEventImpl
};

View File

@@ -0,0 +1,87 @@
"use strict";
const EventInit = require("../generated/EventInit");
class EventImpl {
constructor(args, privateData) {
const type = args[0]; // TODO: Replace with destructuring
const eventInitDict = args[1] || EventInit.convert(undefined);
if (type) {
this.type = type;
this._initializedFlag = true;
} else {
this.type = "";
this._initializedFlag = false;
}
const wrapper = privateData.wrapper;
for (const key in eventInitDict) {
if (key in wrapper) {
this[key] = eventInitDict[key];
}
}
this.target = null;
this.currentTarget = null;
this.eventPhase = 0;
this._stopPropagationFlag = false;
this._stopImmediatePropagationFlag = false;
this._canceledFlag = false;
this._dispatchFlag = false;
this.isTrusted = false;
this.timeStamp = Date.now();
}
get defaultPrevented() {
return this._canceledFlag;
}
stopPropagation() {
this._stopPropagationFlag = true;
}
stopImmediatePropagation() {
this._stopPropagationFlag = true;
this._stopImmediatePropagation = true;
}
preventDefault() {
if (this.cancelable) {
this._canceledFlag = true;
}
}
_initialize(type, bubbles, cancelable) {
if (type) {
this.type = type;
this._initializedFlag = true;
} else {
this.type = "";
this._initializedFlag = false;
}
this._stopPropagationFlag = false;
this._stopImmediatePropagationFlag = false;
this._canceledFlag = false;
this.isTrusted = false;
this.target = null;
this.bubbles = bubbles;
this.cancelable = cancelable;
}
initEvent(type, bubbles, cancelable) {
if (this._dispatchFlag) {
return;
}
this._initialize(type, bubbles, cancelable);
}
}
module.exports = {
implementation: EventImpl
};

View File

@@ -0,0 +1,244 @@
"use strict";
const DOMException = require("../../web-idl/DOMException");
const reportException = require("../helpers/runtime-script-errors");
const domSymbolTree = require("../helpers/internal-constants").domSymbolTree;
const idlUtils = require("../generated/utils");
const Event = require("../generated/Event").interface;
class EventTargetImpl {
constructor() {
this._eventListeners = Object.create(null);
}
addEventListener(type, callback, capture) {
// webidl2js currently can't handle neither optional arguments nor callback interfaces
if (callback === undefined || callback === null) {
callback = null;
} else if (typeof callback === "object") {
callback = callback.handleEvent;
} else if (typeof callback !== "function") {
throw new TypeError("Only undefined, null, an object, or a function are allowed for the callback parameter");
}
if (callback === null) {
return;
}
if (!this._eventListeners[type]) {
this._eventListeners[type] = [];
}
for (let i = 0; i < this._eventListeners[type].length; ++i) {
const listener = this._eventListeners[type][i];
if (listener.capture === capture && listener.callback === callback) {
return;
}
}
this._eventListeners[type].push({
callback,
capture
});
}
removeEventListener(type, callback, capture) {
if (callback === undefined || callback === null) {
callback = null;
} else if (typeof callback === "object") {
callback = callback.handleEvent;
} else if (typeof callback !== "function") {
throw new TypeError("Only undefined, null, an object, or a function are allowed for the callback parameter");
}
if (callback === null) {
// Optimization, not in the spec.
return;
}
if (!this._eventListeners[type]) {
return;
}
for (let i = 0; i < this._eventListeners[type].length; ++i) {
const listener = this._eventListeners[type][i];
if (listener.callback === callback && listener.capture === capture) {
this._eventListeners[type].splice(i, 1);
break;
}
}
}
dispatchEvent(event) {
if (!(event instanceof Event)) {
throw new TypeError("Argument to dispatchEvent must be an Event");
}
const eventImpl = idlUtils.implForWrapper(event);
if (eventImpl._dispatchFlag || !eventImpl._initializedFlag) {
throw new DOMException(DOMException.INVALID_STATE_ERR, "Tried to dispatch an uninitialized event");
}
if (event.eventPhase !== event.NONE) {
throw new DOMException(DOMException.INVALID_STATE_ERR, "Tried to dispatch a dispatching event");
}
eventImpl.isTrusted = false;
return this._dispatch(event);
}
_dispatch(event, targetOverride) {
const eventImpl = idlUtils.implForWrapper(event);
eventImpl._dispatchFlag = true;
eventImpl.target = targetOverride || idlUtils.wrapperForImpl(this);
const eventPath = [];
let targetParent = domSymbolTree.parent(eventImpl.target);
let target = eventImpl.target;
while (targetParent) {
eventPath.push(targetParent);
target = targetParent;
targetParent = domSymbolTree.parent(targetParent);
}
if (event.type !== "load" && target._defaultView) { // https://html.spec.whatwg.org/#events-and-the-window-object
eventPath.push(target._defaultView);
}
eventImpl.eventPhase = Event.CAPTURING_PHASE;
for (let i = eventPath.length - 1; i >= 0; --i) {
if (eventImpl._stopPropagationFlag) {
break;
}
const object = eventPath[i];
const objectImpl = idlUtils.implForWrapper(object);
const eventListeners = objectImpl._eventListeners[event.type];
invokeEventListeners(eventListeners, object, event);
}
eventImpl.eventPhase = Event.AT_TARGET;
if (!eventImpl._stopPropagationFlag) {
invokeInlineListeners(eventImpl.target, event);
if (this._eventListeners[event.type]) {
const eventListeners = this._eventListeners[event.type];
invokeEventListeners(eventListeners, eventImpl.target, event);
}
}
if (event.bubbles) {
eventImpl.eventPhase = Event.BUBBLING_PHASE;
for (let i = 0; i < eventPath.length; ++i) {
if (eventImpl._stopPropagationFlag) {
break;
}
const object = eventPath[i];
const objectImpl = idlUtils.implForWrapper(object);
const eventListeners = objectImpl._eventListeners[event.type];
invokeInlineListeners(object, event);
invokeEventListeners(eventListeners, object, event);
}
}
eventImpl._dispatchFlag = false;
eventImpl.eventPhase = Event.NONE;
eventImpl.currentTarget = null;
return !eventImpl._canceledFlag;
}
}
module.exports = {
implementation: EventTargetImpl
};
function invokeInlineListeners(object, event) {
const inlineListener = getListenerForInlineEventHandler(object, event.type);
if (inlineListener) {
const document = object._ownerDocument || object._document;
// Will be falsy for windows that have closed
if (document && (!object.nodeName || document.implementation._hasFeature("ProcessExternalResources", "script"))) {
invokeEventListeners([{ callback: inlineListener }], object, event);
}
}
}
function invokeEventListeners(listeners, target, event) {
const document = target._ownerDocument || target._document;
// Will be falsy for windows that have closed
if (!document) {
return;
}
const eventImpl = idlUtils.implForWrapper(event);
eventImpl.currentTarget = target;
if (!listeners) {
return;
}
const handlers = listeners.slice();
for (let i = 0; i < handlers.length; ++i) {
if (eventImpl._stopImmediatePropagationFlag) {
return;
}
const listener = handlers[i];
if (listeners.indexOf(listener) === -1 ||
(event.eventPhase === Event.CAPTURING_PHASE && !listener.capture) ||
(event.eventPhase === Event.BUBBLING_PHASE && listener.capture)) {
continue;
}
try {
listener.callback.call(eventImpl.currentTarget, event);
} catch (e) {
let window = null;
if (target._document) {
window = target;
} else if (target._ownerDocument) {
window = target._ownerDocument._defaultView;
}
if (window) {
reportException(window, e);
}
// Errors in window-less documents just get swallowed... can you think of anything better?
}
}
}
const wrappedListener = Symbol("inline event listener wrapper");
function getListenerForInlineEventHandler(target, type) {
const callback = target["on" + type];
if (!callback) { // TODO event handlers: only check null
return null;
}
if (!callback[wrappedListener]) {
// https://html.spec.whatwg.org/multipage/webappapis.html#the-event-handler-processing-algorithm
callback[wrappedListener] = function (E) {
const isWindowError = E.constructor.name === "ErrorEvent" && type === "error"; // TODO branding
let returnValue;
if (isWindowError) {
returnValue = callback.call(E.currentTarget, E.message, E.filename, E.lineno, E.colno, E.error);
} else {
returnValue = callback.call(E.currentTarget, E);
}
if (type === "mouseover" || isWindowError) {
if (returnValue) {
E.preventDefault();
}
} else if (!returnValue) {
E.preventDefault();
}
};
}
return callback[wrappedListener];
}

View File

@@ -0,0 +1,11 @@
"use strict";
const EventImpl = require("./Event-impl").implementation;
class HashChangeEventImpl extends EventImpl {
}
module.exports = {
implementation: HashChangeEventImpl
};

View File

@@ -0,0 +1,21 @@
"use strict";
const UIEventImpl = require("./UIEvent-impl").implementation;
class KeyboardEventImpl extends UIEventImpl {
initKeyboardEvent(type, bubbles, cancelable, view, key, location, modifiersList, repeat, locale) {
if (this._dispatchFlag) {
return;
}
this.initUIEvent(type, bubbles, cancelable, view, key);
this.location = location;
this.modifiersList = modifiersList;
this.repeat = repeat;
this.locale = locale;
}
}
module.exports = {
implementation: KeyboardEventImpl
};

View File

@@ -0,0 +1,22 @@
"use strict";
const EventImpl = require("./Event-impl").implementation;
class MessageEventImpl extends EventImpl {
initMessageEvent(type, bubbles, cancelable, data, origin, lastEventId, source, ports) {
if (this._dispatchFlag) {
return;
}
this.initEvent(type, bubbles, cancelable);
this.data = data;
this.origin = origin;
this.lastEventId = lastEventId;
this.source = source;
this.ports = ports;
}
}
module.exports = {
implementation: MessageEventImpl
};

View File

@@ -0,0 +1,28 @@
"use strict";
const UIEventImpl = require("./UIEvent-impl").implementation;
class MouseEventImpl extends UIEventImpl {
initMouseEvent(type, bubbles, cancelable, view, detail, screenX, screenY, clientX, clientY,
ctrlKey, altKey, shiftKey, metaKey, button, relatedTarget) {
if (this._dispatchFlag) {
return;
}
this.initUIEvent(type, bubbles, cancelable, view, detail);
this.screenX = screenX;
this.screenY = screenY;
this.clientX = clientX;
this.clientY = clientY;
this.ctrlKey = ctrlKey;
this.altKey = altKey;
this.shiftKey = shiftKey;
this.metaKey = metaKey;
this.button = button;
this.relatedTarget = relatedTarget;
}
}
module.exports = {
implementation: MouseEventImpl
};

View File

@@ -0,0 +1,22 @@
"use strict";
const EventImpl = require("./Event-impl").implementation;
class MutationEventImpl extends EventImpl {
initMutationEvent(type, bubbles, cancelable, relatedNode, prevValue, newValue, attrName, attrChange) {
if (this._dispatchFlag) {
return;
}
this.initEvent(type, bubbles, cancelable);
this.relatedNode = relatedNode;
this.prevValue = prevValue;
this.newValue = newValue;
this.attrName = attrName;
this.attrChange = attrChange;
}
}
module.exports = {
implementation: MutationEventImpl
};

View File

@@ -0,0 +1,11 @@
"use strict";
const EventImpl = require("./Event-impl").implementation;
class ProgressEventImpl extends EventImpl {
}
module.exports = {
implementation: ProgressEventImpl
};

View File

@@ -0,0 +1,11 @@
"use strict";
const UIEventImpl = require("./UIEvent-impl").implementation;
class TouchEventImpl extends UIEventImpl {
}
module.exports = {
implementation: TouchEventImpl
};

View File

@@ -0,0 +1,19 @@
"use strict";
const EventImpl = require("./Event-impl").implementation;
class UIEventImpl extends EventImpl {
initUIEvent(type, bubbles, cancelable, view, detail) {
if (this._dispatchFlag) {
return;
}
this.initEvent(type, bubbles, cancelable);
this.view = view;
this.detail = detail;
}
}
module.exports = {
implementation: UIEventImpl
};

145
node_modules/jsdom/lib/jsdom/living/file-reader.js generated vendored Normal file
View File

@@ -0,0 +1,145 @@
"use strict";
const DOMException = require("../web-idl/DOMException");
const EventTarget = require("./generated/EventTarget");
const addConstants = require("../utils").addConstants;
const blobSymbols = require("./blob-symbols");
function FileReaderEventTarget() {
if (!(this instanceof FileReaderEventTarget)) {
throw new TypeError("DOM object constructor cannot be called as a function.");
}
EventTarget.setup(this);
}
FileReaderEventTarget.prototype = Object.create(EventTarget.interface.prototype);
module.exports = function createFileReader(window) {
const ProgressEvent = window.ProgressEvent;
class FileReader extends FileReaderEventTarget {
constructor() {
super();
this.error = null;
this.readyState = FileReader.EMPTY;
this.result = null;
this.onloadstart = null;
this.onprogress = null;
this.onload = null;
this.onabort = null;
this.onerror = null;
this.onloadend = null;
}
readAsArrayBuffer(file) {
readFile(this, file, "buffer");
}
readAsBinaryString(file) {
readFile(this, file, "binary");
}
readAsDataURL(file) {
readFile(this, file, "dataUrl");
}
readAsText(file, encoding) {
readFile(this, file, "text", encoding);
}
abort() {
if (this.readyState === this.DONE || this.readyState === this.EMPTY) {
this.result = null;
return;
}
if (this.readyState === this.LOADING) {
this.readyState = this.DONE;
}
this.dispatchEvent(new ProgressEvent("abort"));
this.dispatchEvent(new ProgressEvent("loadend"));
}
get _ownerDocument() {
return window.document;
}
}
addConstants(FileReader, {
EMPTY: 0,
LOADING: 1,
DONE: 2
});
function readFile(self, file, format, encoding) {
if (self.readyState === self.LOADING) {
throw new DOMException(DOMException.INVALID_STATE_ERR);
}
if (file[blobSymbols.closed]) {
self.error = new DOMException(DOMException.INVALID_STATE_ERR);
self.dispatchEvent(new ProgressEvent("error"));
}
self.readyState = self.LOADING;
self.dispatchEvent(new ProgressEvent("loadstart"));
process.nextTick(() => {
let data = file[blobSymbols.buffer];
if (!data) {
data = new Buffer("");
}
self.dispatchEvent(new ProgressEvent("progress", {
lengthComputable: !isNaN(file.size),
total: file.size,
loaded: data.length
}));
process.nextTick(() => {
self.readyState = self.DONE;
switch (format) {
default:
case "buffer":
const ab = new ArrayBuffer(data.length);
const view = new Uint8Array(ab);
for (let i = 0; i < data.length; ++i) {
view[i] = data[i];
}
self.result = ab;
break;
case "binary":
self.result = data.toString("binary");
break;
case "dataUrl":
let dataUrl = "data:";
if (file.type) {
dataUrl += file.type + ";";
}
if (/text/i.test(file.type)) {
dataUrl += "charset=utf-8,";
dataUrl += data.toString("utf8");
} else {
dataUrl += "base64,";
dataUrl += data.toString("base64");
}
self.result = dataUrl;
break;
case "text":
if (encoding) {
encoding = encoding.toLowerCase();
if (encoding === "utf-16" || encoding === "utf16") {
encoding = "utf-16le";
}
} else {
encoding = "utf8";
}
self.result = data.toString(encoding);
break;
}
self.dispatchEvent(new ProgressEvent("load"));
process.nextTick(() => {
if (self.readyState !== self.LOADING) {
self.dispatchEvent(new ProgressEvent("loadend"));
}
});
});
});
}
return FileReader;
};

3
node_modules/jsdom/lib/jsdom/living/file-symbols.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
"use strict";
exports.name = Symbol("name");

21
node_modules/jsdom/lib/jsdom/living/file.js generated vendored Normal file
View File

@@ -0,0 +1,21 @@
"use strict";
const fileSymbols = require("./file-symbols");
module.exports = function (core) {
const Blob = core.Blob;
class File extends Blob {
constructor(fileBits, fileName) {
super(fileBits, arguments[2]);
if (!(this instanceof File)) {
throw new TypeError("DOM object constructor cannot be called as a function.");
}
this[fileSymbols.name] = fileName.replace(/\//g, ":");
}
get name() {
return this[fileSymbols.name];
}
}
core.File = File;
};

View File

@@ -0,0 +1,3 @@
"use strict";
exports.list = Symbol("list");

21
node_modules/jsdom/lib/jsdom/living/filelist.js generated vendored Normal file
View File

@@ -0,0 +1,21 @@
"use strict";
const filelistSymbols = require("./filelist-symbols");
module.exports = function (core) {
class FileList {
constructor() {
if (!(this instanceof FileList)) {
throw new TypeError("DOM object constructor cannot be called as a function.");
}
this[filelistSymbols.list] = [];
}
item(index) {
return this[filelistSymbols.list][index] || null;
}
get length() {
return this[filelistSymbols.list].length;
}
}
core.FileList = FileList;
};

View File

@@ -0,0 +1,3 @@
"use strict";
exports.formData = Symbol("entries");

79
node_modules/jsdom/lib/jsdom/living/form-data.js generated vendored Normal file
View File

@@ -0,0 +1,79 @@
"use strict";
const formDataSymbols = require("./form-data-symbols");
module.exports = function (core) {
const Blob = core.Blob;
const File = core.File;
class FormData {
constructor(form) {
if (!(this instanceof FormData)) {
throw new TypeError("DOM object constructor cannot be called as a function.");
}
const entries = this[formDataSymbols.entries] = [];
if (form && form.elements) {
for (let i = 0; i < form.elements.length; i++) {
const el = form.elements[i];
if (el.type === "file") {
for (let j = 0; j < el.files.length; j++) {
entries.push({ name: el.name, value: el.files.item(j) });
}
} else {
entries.push({ name: el.name, value: el.value });
}
}
}
}
append(name, value, filename) {
if (value instanceof Blob) {
value = new File(
[value],
filename || value.name || "blob",
{ type: value.type, lastModified: value.lastModified }
);
} else {
value = String(value);
}
const entries = this[formDataSymbols.entries];
entries.push({ name, value });
}
delete(name) {
this[formDataSymbols.entries] = this[formDataSymbols.entries].filter(entry => entry.name !== name);
}
get(name) {
return this[formDataSymbols.entries].find(entry => entry.name === name) || null;
}
getAll(name) {
return this[formDataSymbols.entries].filter(entry => entry.name === name).map(entry => entry.value);
}
has(name) {
return this[formDataSymbols.entries].findIndex(entry => entry.name === name) !== -1;
}
set(name, value, filename) {
if (value instanceof Blob) {
value = new File(
[value],
filename || value.name || "blob",
{ type: value.type, lastModified: value.lastModified }
);
} else {
value = String(value);
}
const newEntry = { name, value };
const entries = this[formDataSymbols.entries];
const existing = entries.findIndex(entry => entry.name === name);
if (existing !== -1) {
entries[existing] = newEntry;
this[formDataSymbols.entries] = entries.filter((entry, index) => entry.name !== name || index === existing);
} else {
entries.push(newEntry);
}
}
toString() {
return "[object FormData]";
}
}
core.FormData = FormData;
};

View File

118
node_modules/jsdom/lib/jsdom/living/generated/Attr.js generated vendored Normal file
View File

@@ -0,0 +1,118 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../attributes/Attr-impl.js");
const impl = utils.implSymbol;
function Attr() {
throw new TypeError("Illegal constructor");
}
Object.defineProperty(Attr.prototype, "namespaceURI", {
get() {
return this[impl].namespaceURI;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Attr.prototype, "prefix", {
get() {
return this[impl].prefix;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Attr.prototype, "localName", {
get() {
return this[impl].localName;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Attr.prototype, "name", {
get() {
return this[impl].name;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Attr.prototype, "value", {
get() {
return this[impl].value;
},
set(V) {
V = conversions["DOMString"](V);
this[impl].value = V;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Attr.prototype, "nodeValue", {
get() {
return this[impl].nodeValue;
},
set(V) {
V = conversions["DOMString"](V, { treatNullAsEmptyString: true });
this[impl].nodeValue = V;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Attr.prototype, "textContent", {
get() {
return this[impl].textContent;
},
set(V) {
V = conversions["DOMString"](V, { treatNullAsEmptyString: true });
this[impl].textContent = V;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Attr.prototype, "ownerElement", {
get() {
return this[impl].ownerElement;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Attr.prototype, "specified", {
get() {
return this[impl].specified;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(Attr.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: Attr,
expose: {
Window: { Attr: Attr }
}
};

View File

@@ -0,0 +1,77 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../events/CustomEvent-impl.js");
const Event = require("./Event.js");
const impl = utils.implSymbol;
const convertCustomEventInit = require("./CustomEventInit").convert;
function CustomEvent(type) {
if (!this || this[impl] || !(this instanceof CustomEvent)) {
throw new TypeError("Failed to construct 'CustomEvent': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
}
if (arguments.length < 1) {
throw new TypeError("Failed to construct 'CustomEvent': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 2; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = convertCustomEventInit(args[1]);
module.exports.setup(this, args);
}
CustomEvent.prototype = Object.create(Event.interface.prototype);
CustomEvent.prototype.constructor = CustomEvent;
CustomEvent.prototype.initCustomEvent = function initCustomEvent(type, bubbles, cancelable, detail) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 4) {
throw new TypeError("Failed to execute 'initCustomEvent' on 'CustomEvent': 4 arguments required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 4; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = conversions["boolean"](args[1]);
args[2] = conversions["boolean"](args[2]);
return this[impl].initCustomEvent.apply(this[impl], args);
};
Object.defineProperty(CustomEvent.prototype, "detail", {
get() {
return this[impl].detail;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(CustomEvent.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: CustomEvent,
expose: {
Window: { CustomEvent: CustomEvent },
Worker: { CustomEvent: CustomEvent }
}
};

View File

@@ -0,0 +1,34 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const EventInit = require("./EventInit");
module.exports = {
convertInherit(obj, ret) {
EventInit.convertInherit(obj, ret);
let key, value;
key = "detail";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = (value);
} else {
ret[key] = null;
}
},
convert(obj) {
if (obj !== undefined && typeof obj !== "object") {
throw new TypeError("Dictionary has to be an object");
}
if (obj instanceof Date || obj instanceof RegExp) {
throw new TypeError("Dictionary may not be a Date or RegExp object");
}
const ret = Object.create(null);
module.exports.convertInherit(obj, ret);
return ret;
}
};

View File

@@ -0,0 +1,92 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../events/ErrorEvent-impl.js");
const Event = require("./Event.js");
const impl = utils.implSymbol;
const convertErrorEventInit = require("./ErrorEventInit").convert;
function ErrorEvent(type) {
if (!this || this[impl] || !(this instanceof ErrorEvent)) {
throw new TypeError("Failed to construct 'ErrorEvent': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
}
if (arguments.length < 1) {
throw new TypeError("Failed to construct 'ErrorEvent': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 2; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = convertErrorEventInit(args[1]);
module.exports.setup(this, args);
}
ErrorEvent.prototype = Object.create(Event.interface.prototype);
ErrorEvent.prototype.constructor = ErrorEvent;
Object.defineProperty(ErrorEvent.prototype, "message", {
get() {
return this[impl].message;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ErrorEvent.prototype, "filename", {
get() {
return this[impl].filename;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ErrorEvent.prototype, "lineno", {
get() {
return this[impl].lineno;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ErrorEvent.prototype, "colno", {
get() {
return this[impl].colno;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ErrorEvent.prototype, "error", {
get() {
return this[impl].error;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(ErrorEvent.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: ErrorEvent,
expose: {
Window: { ErrorEvent: ErrorEvent },
Worker: { ErrorEvent: ErrorEvent }
}
};

View File

@@ -0,0 +1,56 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const EventInit = require("./EventInit");
module.exports = {
convertInherit(obj, ret) {
EventInit.convertInherit(obj, ret);
let key, value;
key = "colno";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["unsigned long"](value);
}
key = "error";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = (value);
}
key = "filename";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["DOMString"](value);
}
key = "lineno";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["unsigned long"](value);
}
key = "message";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["DOMString"](value);
}
},
convert(obj) {
if (obj !== undefined && typeof obj !== "object") {
throw new TypeError("Dictionary has to be an object");
}
if (obj instanceof Date || obj instanceof RegExp) {
throw new TypeError("Dictionary may not be a Date or RegExp object");
}
const ret = Object.create(null);
module.exports.convertInherit(obj, ret);
return ret;
}
};

208
node_modules/jsdom/lib/jsdom/living/generated/Event.js generated vendored Normal file
View File

@@ -0,0 +1,208 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../events/Event-impl.js");
const impl = utils.implSymbol;
const convertEventInit = require("./EventInit").convert;
function Event(type) {
if (!this || this[impl] || !(this instanceof Event)) {
throw new TypeError("Failed to construct 'Event': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
}
if (arguments.length < 1) {
throw new TypeError("Failed to construct 'Event': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 2; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = convertEventInit(args[1]);
module.exports.setup(this, args);
}
Event.prototype.stopPropagation = function stopPropagation() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
const args = [];
for (let i = 0; i < arguments.length && i < 0; ++i) {
args[i] = arguments[i];
}
return this[impl].stopPropagation.apply(this[impl], args);
};
Event.prototype.stopImmediatePropagation = function stopImmediatePropagation() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
const args = [];
for (let i = 0; i < arguments.length && i < 0; ++i) {
args[i] = arguments[i];
}
return this[impl].stopImmediatePropagation.apply(this[impl], args);
};
Event.prototype.preventDefault = function preventDefault() {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
const args = [];
for (let i = 0; i < arguments.length && i < 0; ++i) {
args[i] = arguments[i];
}
return this[impl].preventDefault.apply(this[impl], args);
};
Event.prototype.initEvent = function initEvent(type, bubbles, cancelable) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 3) {
throw new TypeError("Failed to execute 'initEvent' on 'Event': 3 arguments required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 3; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = conversions["boolean"](args[1]);
args[2] = conversions["boolean"](args[2]);
return this[impl].initEvent.apply(this[impl], args);
};
Object.defineProperty(Event.prototype, "type", {
get() {
return this[impl].type;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Event.prototype, "target", {
get() {
return this[impl].target;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Event.prototype, "currentTarget", {
get() {
return this[impl].currentTarget;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Event, "NONE", {
value: 0,
enumerable: true
});
Object.defineProperty(Event.prototype, "NONE", {
value: 0,
enumerable: true
});
Object.defineProperty(Event, "CAPTURING_PHASE", {
value: 1,
enumerable: true
});
Object.defineProperty(Event.prototype, "CAPTURING_PHASE", {
value: 1,
enumerable: true
});
Object.defineProperty(Event, "AT_TARGET", {
value: 2,
enumerable: true
});
Object.defineProperty(Event.prototype, "AT_TARGET", {
value: 2,
enumerable: true
});
Object.defineProperty(Event, "BUBBLING_PHASE", {
value: 3,
enumerable: true
});
Object.defineProperty(Event.prototype, "BUBBLING_PHASE", {
value: 3,
enumerable: true
});
Object.defineProperty(Event.prototype, "eventPhase", {
get() {
return this[impl].eventPhase;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Event.prototype, "bubbles", {
get() {
return this[impl].bubbles;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Event.prototype, "cancelable", {
get() {
return this[impl].cancelable;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Event.prototype, "defaultPrevented", {
get() {
return this[impl].defaultPrevented;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Event.prototype, "timeStamp", {
get() {
return this[impl].timeStamp;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(Event.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
Object.defineProperty(obj, "isTrusted", {
get() {
return obj[impl].isTrusted;
},
enumerable: true,
configurable: false
});
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: Event,
expose: {
Window: { Event: Event },
Worker: { Event: Event }
}
};

View File

@@ -0,0 +1,40 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
module.exports = {
convertInherit(obj, ret) {
let key, value;
key = "bubbles";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "cancelable";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
},
convert(obj) {
if (obj !== undefined && typeof obj !== "object") {
throw new TypeError("Dictionary has to be an object");
}
if (obj instanceof Date || obj instanceof RegExp) {
throw new TypeError("Dictionary may not be a Date or RegExp object");
}
const ret = Object.create(null);
module.exports.convertInherit(obj, ret);
return ret;
}
};

View File

@@ -0,0 +1,146 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const UIEventInit = require("./UIEventInit");
module.exports = {
convertInherit(obj, ret) {
UIEventInit.convertInherit(obj, ret);
let key, value;
key = "altKey";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "ctrlKey";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "metaKey";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "modifierAltGraph";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "modifierCapsLock";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "modifierFn";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "modifierFnLock";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "modifierHyper";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "modifierNumLock";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "modifierOS";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "modifierScrollLock";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "modifierSuper";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "modifierSymbol";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "modifierSymbolLock";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "shiftKey";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
},
convert(obj) {
if (obj !== undefined && typeof obj !== "object") {
throw new TypeError("Dictionary has to be an object");
}
if (obj instanceof Date || obj instanceof RegExp) {
throw new TypeError("Dictionary may not be a Date or RegExp object");
}
const ret = Object.create(null);
module.exports.convertInherit(obj, ret);
return ret;
}
};

View File

@@ -0,0 +1,85 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../events/EventTarget-impl.js");
const impl = utils.implSymbol;
function EventTarget() {
throw new TypeError("Illegal constructor");
}
EventTarget.prototype.addEventListener = function addEventListener(type, callback) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 2) {
throw new TypeError("Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 3; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
if (args[2] !== undefined) {
args[2] = conversions["boolean"](args[2]);
}
return this[impl].addEventListener.apply(this[impl], args);
};
EventTarget.prototype.removeEventListener = function removeEventListener(type, callback) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 2) {
throw new TypeError("Failed to execute 'removeEventListener' on 'EventTarget': 2 arguments required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 3; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
if (args[2] !== undefined) {
args[2] = conversions["boolean"](args[2]);
}
return this[impl].removeEventListener.apply(this[impl], args);
};
EventTarget.prototype.dispatchEvent = function dispatchEvent(event) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new TypeError("Failed to execute 'dispatchEvent' on 'EventTarget': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 1; ++i) {
args[i] = arguments[i];
}
return this[impl].dispatchEvent.apply(this[impl], args);
};
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(EventTarget.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: EventTarget,
expose: {
Window: { EventTarget: EventTarget },
Worker: { EventTarget: EventTarget }
}
};

View File

@@ -0,0 +1,45 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../elements/HTMLTemplateElement-impl.js");
const HTMLElement = require("./HTMLElement.js");
const impl = utils.implSymbol;
function HTMLTemplateElement() {
throw new TypeError("Illegal constructor");
}
HTMLTemplateElement.prototype = Object.create(HTMLElement.interface.prototype);
HTMLTemplateElement.prototype.constructor = HTMLTemplateElement;
Object.defineProperty(HTMLTemplateElement.prototype, "content", {
get() {
return this[impl].content;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(HTMLTemplateElement.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: HTMLTemplateElement,
expose: {
Window: { HTMLTemplateElement: HTMLTemplateElement }
}
};

View File

@@ -0,0 +1,68 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../events/HashChangeEvent-impl.js");
const Event = require("./Event.js");
const impl = utils.implSymbol;
const convertHashChangeEventInit = require("./HashChangeEventInit").convert;
function HashChangeEvent(type) {
if (!this || this[impl] || !(this instanceof HashChangeEvent)) {
throw new TypeError("Failed to construct 'HashChangeEvent': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
}
if (arguments.length < 1) {
throw new TypeError("Failed to construct 'HashChangeEvent': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 2; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = convertHashChangeEventInit(args[1]);
module.exports.setup(this, args);
}
HashChangeEvent.prototype = Object.create(Event.interface.prototype);
HashChangeEvent.prototype.constructor = HashChangeEvent;
Object.defineProperty(HashChangeEvent.prototype, "oldURL", {
get() {
return this[impl].oldURL;
},
enumerable: true,
configurable: true
});
Object.defineProperty(HashChangeEvent.prototype, "newURL", {
get() {
return this[impl].newURL;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(HashChangeEvent.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: HashChangeEvent,
expose: {
Window: { HashChangeEvent: HashChangeEvent },
Worker: { HashChangeEvent: HashChangeEvent }
}
};

View File

@@ -0,0 +1,38 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const EventInit = require("./EventInit");
module.exports = {
convertInherit(obj, ret) {
EventInit.convertInherit(obj, ret);
let key, value;
key = "newURL";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["DOMString"](value);
}
key = "oldURL";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["DOMString"](value);
}
},
convert(obj) {
if (obj !== undefined && typeof obj !== "object") {
throw new TypeError("Dictionary has to be an object");
}
if (obj instanceof Date || obj instanceof RegExp) {
throw new TypeError("Dictionary may not be a Date or RegExp object");
}
const ret = Object.create(null);
module.exports.convertInherit(obj, ret);
return ret;
}
};

View File

@@ -0,0 +1,220 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../events/KeyboardEvent-impl.js");
const UIEvent = require("./UIEvent.js");
const impl = utils.implSymbol;
const convertKeyboardEventInit = require("./KeyboardEventInit").convert;
function KeyboardEvent(typeArg) {
if (!this || this[impl] || !(this instanceof KeyboardEvent)) {
throw new TypeError("Failed to construct 'KeyboardEvent': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
}
if (arguments.length < 1) {
throw new TypeError("Failed to construct 'KeyboardEvent': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 2; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = convertKeyboardEventInit(args[1]);
module.exports.setup(this, args);
}
KeyboardEvent.prototype = Object.create(UIEvent.interface.prototype);
KeyboardEvent.prototype.constructor = KeyboardEvent;
KeyboardEvent.prototype.getModifierState = function getModifierState(keyArg) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new TypeError("Failed to execute 'getModifierState' on 'KeyboardEvent': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 1; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
return this[impl].getModifierState.apply(this[impl], args);
};
KeyboardEvent.prototype.initKeyboardEvent = function initKeyboardEvent(typeArg, bubblesArg, cancelableArg, viewArg, keyArg, locationArg, modifiersListArg, repeat, locale) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 9) {
throw new TypeError("Failed to execute 'initKeyboardEvent' on 'KeyboardEvent': 9 arguments required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 9; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = conversions["boolean"](args[1]);
args[2] = conversions["boolean"](args[2]);
args[4] = conversions["DOMString"](args[4]);
args[5] = conversions["unsigned long"](args[5]);
args[6] = conversions["DOMString"](args[6]);
args[7] = conversions["boolean"](args[7]);
args[8] = conversions["DOMString"](args[8]);
return this[impl].initKeyboardEvent.apply(this[impl], args);
};
Object.defineProperty(KeyboardEvent, "DOM_KEY_LOCATION_STANDARD", {
value: 0,
enumerable: true
});
Object.defineProperty(KeyboardEvent.prototype, "DOM_KEY_LOCATION_STANDARD", {
value: 0,
enumerable: true
});
Object.defineProperty(KeyboardEvent, "DOM_KEY_LOCATION_LEFT", {
value: 1,
enumerable: true
});
Object.defineProperty(KeyboardEvent.prototype, "DOM_KEY_LOCATION_LEFT", {
value: 1,
enumerable: true
});
Object.defineProperty(KeyboardEvent, "DOM_KEY_LOCATION_RIGHT", {
value: 2,
enumerable: true
});
Object.defineProperty(KeyboardEvent.prototype, "DOM_KEY_LOCATION_RIGHT", {
value: 2,
enumerable: true
});
Object.defineProperty(KeyboardEvent, "DOM_KEY_LOCATION_NUMPAD", {
value: 3,
enumerable: true
});
Object.defineProperty(KeyboardEvent.prototype, "DOM_KEY_LOCATION_NUMPAD", {
value: 3,
enumerable: true
});
Object.defineProperty(KeyboardEvent.prototype, "key", {
get() {
return this[impl].key;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "code", {
get() {
return this[impl].code;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "location", {
get() {
return this[impl].location;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "ctrlKey", {
get() {
return this[impl].ctrlKey;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "shiftKey", {
get() {
return this[impl].shiftKey;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "altKey", {
get() {
return this[impl].altKey;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "metaKey", {
get() {
return this[impl].metaKey;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "repeat", {
get() {
return this[impl].repeat;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "isComposing", {
get() {
return this[impl].isComposing;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "charCode", {
get() {
return this[impl].charCode;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "keyCode", {
get() {
return this[impl].keyCode;
},
enumerable: true,
configurable: true
});
Object.defineProperty(KeyboardEvent.prototype, "which", {
get() {
return this[impl].which;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(KeyboardEvent.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: KeyboardEvent,
expose: {
Window: { KeyboardEvent: KeyboardEvent }
}
};

View File

@@ -0,0 +1,90 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const EventModifierInit = require("./EventModifierInit");
module.exports = {
convertInherit(obj, ret) {
EventModifierInit.convertInherit(obj, ret);
let key, value;
key = "charCode";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["unsigned long"](value);
} else {
ret[key] = 0;
}
key = "code";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["DOMString"](value);
} else {
ret[key] = "";
}
key = "isComposing";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "key";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["DOMString"](value);
} else {
ret[key] = "";
}
key = "keyCode";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["unsigned long"](value);
} else {
ret[key] = 0;
}
key = "location";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["unsigned long"](value);
} else {
ret[key] = 0;
}
key = "repeat";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "which";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["unsigned long"](value);
} else {
ret[key] = 0;
}
},
convert(obj) {
if (obj !== undefined && typeof obj !== "object") {
throw new TypeError("Dictionary has to be an object");
}
if (obj instanceof Date || obj instanceof RegExp) {
throw new TypeError("Dictionary may not be a Date or RegExp object");
}
const ret = Object.create(null);
module.exports.convertInherit(obj, ret);
return ret;
}
};

View File

@@ -0,0 +1,111 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../events/MessageEvent-impl.js");
const Event = require("./Event.js");
const impl = utils.implSymbol;
const convertMessageEventInit = require("./MessageEventInit").convert;
function MessageEvent(type) {
if (!this || this[impl] || !(this instanceof MessageEvent)) {
throw new TypeError("Failed to construct 'MessageEvent': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
}
if (arguments.length < 1) {
throw new TypeError("Failed to construct 'MessageEvent': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 2; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = convertMessageEventInit(args[1]);
module.exports.setup(this, args);
}
MessageEvent.prototype = Object.create(Event.interface.prototype);
MessageEvent.prototype.constructor = MessageEvent;
MessageEvent.prototype.initMessageEvent = function initMessageEvent(type, bubbles, cancelable, data, origin, lastEventId, source, ports) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 8) {
throw new TypeError("Failed to execute 'initMessageEvent' on 'MessageEvent': 8 arguments required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 8; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = conversions["boolean"](args[1]);
args[2] = conversions["boolean"](args[2]);
args[4] = conversions["DOMString"](args[4]);
args[5] = conversions["DOMString"](args[5]);
return this[impl].initMessageEvent.apply(this[impl], args);
};
Object.defineProperty(MessageEvent.prototype, "data", {
get() {
return this[impl].data;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MessageEvent.prototype, "origin", {
get() {
return this[impl].origin;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MessageEvent.prototype, "lastEventId", {
get() {
return this[impl].lastEventId;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MessageEvent.prototype, "source", {
get() {
return this[impl].source;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MessageEvent.prototype, "ports", {
get() {
return this[impl].ports;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(MessageEvent.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: MessageEvent,
expose: {
Window: { MessageEvent: MessageEvent },
Worker: { MessageEvent: MessageEvent }
}
};

View File

@@ -0,0 +1,56 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const EventInit = require("./EventInit");
module.exports = {
convertInherit(obj, ret) {
EventInit.convertInherit(obj, ret);
let key, value;
key = "data";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = (value);
}
key = "lastEventId";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["DOMString"](value);
}
key = "origin";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["DOMString"](value);
}
key = "ports";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = (value);
}
key = "source";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = (value);
}
},
convert(obj) {
if (obj !== undefined && typeof obj !== "object") {
throw new TypeError("Dictionary has to be an object");
}
if (obj instanceof Date || obj instanceof RegExp) {
throw new TypeError("Dictionary may not be a Date or RegExp object");
}
const ret = Object.create(null);
module.exports.convertInherit(obj, ret);
return ret;
}
};

View File

@@ -0,0 +1,181 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../events/MouseEvent-impl.js");
const UIEvent = require("./UIEvent.js");
const impl = utils.implSymbol;
const convertMouseEventInit = require("./MouseEventInit").convert;
function MouseEvent(typeArg) {
if (!this || this[impl] || !(this instanceof MouseEvent)) {
throw new TypeError("Failed to construct 'MouseEvent': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
}
if (arguments.length < 1) {
throw new TypeError("Failed to construct 'MouseEvent': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 2; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = convertMouseEventInit(args[1]);
module.exports.setup(this, args);
}
MouseEvent.prototype = Object.create(UIEvent.interface.prototype);
MouseEvent.prototype.constructor = MouseEvent;
MouseEvent.prototype.getModifierState = function getModifierState(keyArg) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 1) {
throw new TypeError("Failed to execute 'getModifierState' on 'MouseEvent': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 1; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
return this[impl].getModifierState.apply(this[impl], args);
};
MouseEvent.prototype.initMouseEvent = function initMouseEvent(typeArg, bubblesArg, cancelableArg, viewArg, detailArg, screenXArg, screenYArg, clientXArg, clientYArg, ctrlKeyArg, altKeyArg, shiftKeyArg, metaKeyArg, buttonArg, relatedTargetArg) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 15) {
throw new TypeError("Failed to execute 'initMouseEvent' on 'MouseEvent': 15 arguments required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 15; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = conversions["boolean"](args[1]);
args[2] = conversions["boolean"](args[2]);
args[4] = conversions["long"](args[4]);
args[5] = conversions["long"](args[5]);
args[6] = conversions["long"](args[6]);
args[7] = conversions["long"](args[7]);
args[8] = conversions["long"](args[8]);
args[9] = conversions["boolean"](args[9]);
args[10] = conversions["boolean"](args[10]);
args[11] = conversions["boolean"](args[11]);
args[12] = conversions["boolean"](args[12]);
args[13] = conversions["short"](args[13]);
return this[impl].initMouseEvent.apply(this[impl], args);
};
Object.defineProperty(MouseEvent.prototype, "screenX", {
get() {
return this[impl].screenX;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MouseEvent.prototype, "screenY", {
get() {
return this[impl].screenY;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MouseEvent.prototype, "clientX", {
get() {
return this[impl].clientX;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MouseEvent.prototype, "clientY", {
get() {
return this[impl].clientY;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MouseEvent.prototype, "ctrlKey", {
get() {
return this[impl].ctrlKey;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MouseEvent.prototype, "shiftKey", {
get() {
return this[impl].shiftKey;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MouseEvent.prototype, "altKey", {
get() {
return this[impl].altKey;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MouseEvent.prototype, "metaKey", {
get() {
return this[impl].metaKey;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MouseEvent.prototype, "button", {
get() {
return this[impl].button;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MouseEvent.prototype, "relatedTarget", {
get() {
return this[impl].relatedTarget;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MouseEvent.prototype, "buttons", {
get() {
return this[impl].buttons;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(MouseEvent.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: MouseEvent,
expose: {
Window: { MouseEvent: MouseEvent }
}
};

View File

@@ -0,0 +1,82 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const EventModifierInit = require("./EventModifierInit");
module.exports = {
convertInherit(obj, ret) {
EventModifierInit.convertInherit(obj, ret);
let key, value;
key = "button";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["short"](value);
} else {
ret[key] = 0;
}
key = "buttons";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["unsigned short"](value);
} else {
ret[key] = 0;
}
key = "clientX";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["long"](value);
} else {
ret[key] = 0;
}
key = "clientY";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["long"](value);
} else {
ret[key] = 0;
}
key = "relatedTarget";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = (value);
} else {
ret[key] = null;
}
key = "screenX";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["long"](value);
} else {
ret[key] = 0;
}
key = "screenY";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["long"](value);
} else {
ret[key] = 0;
}
},
convert(obj) {
if (obj !== undefined && typeof obj !== "object") {
throw new TypeError("Dictionary has to be an object");
}
if (obj instanceof Date || obj instanceof RegExp) {
throw new TypeError("Dictionary may not be a Date or RegExp object");
}
const ret = Object.create(null);
module.exports.convertInherit(obj, ret);
return ret;
}
};

View File

@@ -0,0 +1,125 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../events/MutationEvent-impl.js");
const Event = require("./Event.js");
const impl = utils.implSymbol;
function MutationEvent() {
throw new TypeError("Illegal constructor");
}
MutationEvent.prototype = Object.create(Event.interface.prototype);
MutationEvent.prototype.constructor = MutationEvent;
MutationEvent.prototype.initMutationEvent = function initMutationEvent(typeArg, bubblesArg, cancelableArg, relatedNodeArg, prevValueArg, newValueArg, attrNameArg, attrChangeArg) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 8) {
throw new TypeError("Failed to execute 'initMutationEvent' on 'MutationEvent': 8 arguments required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 8; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = conversions["boolean"](args[1]);
args[2] = conversions["boolean"](args[2]);
args[4] = conversions["DOMString"](args[4]);
args[5] = conversions["DOMString"](args[5]);
args[6] = conversions["DOMString"](args[6]);
args[7] = conversions["unsigned short"](args[7]);
return this[impl].initMutationEvent.apply(this[impl], args);
};
Object.defineProperty(MutationEvent, "MODIFICATION", {
value: 1,
enumerable: true
});
Object.defineProperty(MutationEvent.prototype, "MODIFICATION", {
value: 1,
enumerable: true
});
Object.defineProperty(MutationEvent, "ADDITION", {
value: 2,
enumerable: true
});
Object.defineProperty(MutationEvent.prototype, "ADDITION", {
value: 2,
enumerable: true
});
Object.defineProperty(MutationEvent, "REMOVAL", {
value: 3,
enumerable: true
});
Object.defineProperty(MutationEvent.prototype, "REMOVAL", {
value: 3,
enumerable: true
});
Object.defineProperty(MutationEvent.prototype, "relatedNode", {
get() {
return this[impl].relatedNode;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MutationEvent.prototype, "prevValue", {
get() {
return this[impl].prevValue;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MutationEvent.prototype, "newValue", {
get() {
return this[impl].newValue;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MutationEvent.prototype, "attrName", {
get() {
return this[impl].attrName;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MutationEvent.prototype, "attrChange", {
get() {
return this[impl].attrChange;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(MutationEvent.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: MutationEvent,
expose: {
Window: { MutationEvent: MutationEvent }
}
};

View File

@@ -0,0 +1,77 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../events/ProgressEvent-impl.js");
const Event = require("./Event.js");
const impl = utils.implSymbol;
const convertProgressEventInit = require("./ProgressEventInit").convert;
function ProgressEvent(type) {
if (!this || this[impl] || !(this instanceof ProgressEvent)) {
throw new TypeError("Failed to construct 'ProgressEvent': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
}
if (arguments.length < 1) {
throw new TypeError("Failed to construct 'ProgressEvent': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 2; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = convertProgressEventInit(args[1]);
module.exports.setup(this, args);
}
ProgressEvent.prototype = Object.create(Event.interface.prototype);
ProgressEvent.prototype.constructor = ProgressEvent;
Object.defineProperty(ProgressEvent.prototype, "lengthComputable", {
get() {
return this[impl].lengthComputable;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ProgressEvent.prototype, "loaded", {
get() {
return this[impl].loaded;
},
enumerable: true,
configurable: true
});
Object.defineProperty(ProgressEvent.prototype, "total", {
get() {
return this[impl].total;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(ProgressEvent.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: ProgressEvent,
expose: {
Window: { ProgressEvent: ProgressEvent },
DedicatedWorker: { ProgressEvent: ProgressEvent },
SharedWorker: { ProgressEvent: ProgressEvent }
}
};

View File

@@ -0,0 +1,50 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const EventInit = require("./EventInit");
module.exports = {
convertInherit(obj, ret) {
EventInit.convertInherit(obj, ret);
let key, value;
key = "lengthComputable";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["boolean"](value);
} else {
ret[key] = false;
}
key = "loaded";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["unsigned long long"](value);
} else {
ret[key] = 0;
}
key = "total";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["unsigned long long"](value);
} else {
ret[key] = 0;
}
},
convert(obj) {
if (obj !== undefined && typeof obj !== "object") {
throw new TypeError("Dictionary has to be an object");
}
if (obj instanceof Date || obj instanceof RegExp) {
throw new TypeError("Dictionary may not be a Date or RegExp object");
}
const ret = Object.create(null);
module.exports.convertInherit(obj, ret);
return ret;
}
};

View File

@@ -0,0 +1,93 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../events/TouchEvent-impl.js");
const UIEvent = require("./UIEvent.js");
const impl = utils.implSymbol;
function TouchEvent() {
throw new TypeError("Illegal constructor");
}
TouchEvent.prototype = Object.create(UIEvent.interface.prototype);
TouchEvent.prototype.constructor = TouchEvent;
Object.defineProperty(TouchEvent.prototype, "touches", {
get() {
return this[impl].touches;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TouchEvent.prototype, "targetTouches", {
get() {
return this[impl].targetTouches;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TouchEvent.prototype, "changedTouches", {
get() {
return this[impl].changedTouches;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TouchEvent.prototype, "altKey", {
get() {
return this[impl].altKey;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TouchEvent.prototype, "metaKey", {
get() {
return this[impl].metaKey;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TouchEvent.prototype, "ctrlKey", {
get() {
return this[impl].ctrlKey;
},
enumerable: true,
configurable: true
});
Object.defineProperty(TouchEvent.prototype, "shiftKey", {
get() {
return this[impl].shiftKey;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(TouchEvent.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: TouchEvent,
expose: {
Window: { TouchEvent: TouchEvent }
}
};

View File

@@ -0,0 +1,85 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const Impl = require("../events/UIEvent-impl.js");
const Event = require("./Event.js");
const impl = utils.implSymbol;
const convertUIEventInit = require("./UIEventInit").convert;
function UIEvent(type) {
if (!this || this[impl] || !(this instanceof UIEvent)) {
throw new TypeError("Failed to construct 'UIEvent': Please use the 'new' operator, this DOM object constructor cannot be called as a function.");
}
if (arguments.length < 1) {
throw new TypeError("Failed to construct 'UIEvent': 1 argument required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 2; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = convertUIEventInit(args[1]);
module.exports.setup(this, args);
}
UIEvent.prototype = Object.create(Event.interface.prototype);
UIEvent.prototype.constructor = UIEvent;
UIEvent.prototype.initUIEvent = function initUIEvent(typeArg, bubblesArg, cancelableArg, viewArg, detailArg) {
if (!this || !module.exports.is(this)) {
throw new TypeError("Illegal invocation");
}
if (arguments.length < 5) {
throw new TypeError("Failed to execute 'initUIEvent' on 'UIEvent': 5 arguments required, but only " + arguments.length + " present.");
}
const args = [];
for (let i = 0; i < arguments.length && i < 5; ++i) {
args[i] = arguments[i];
}
args[0] = conversions["DOMString"](args[0]);
args[1] = conversions["boolean"](args[1]);
args[2] = conversions["boolean"](args[2]);
args[4] = conversions["long"](args[4]);
return this[impl].initUIEvent.apply(this[impl], args);
};
Object.defineProperty(UIEvent.prototype, "view", {
get() {
return this[impl].view;
},
enumerable: true,
configurable: true
});
Object.defineProperty(UIEvent.prototype, "detail", {
get() {
return this[impl].detail;
},
enumerable: true,
configurable: true
});
module.exports = {
is(obj) {
return !!obj && obj[impl] instanceof Impl.implementation;
},
create(constructorArgs, privateData) {
let obj = Object.create(UIEvent.prototype);
this.setup(obj, constructorArgs, privateData);
return obj;
},
setup(obj, constructorArgs, privateData) {
if (!privateData) privateData = {};
privateData.wrapper = obj;
obj[impl] = new Impl.implementation(constructorArgs, privateData);
obj[impl][utils.wrapperSymbol] = obj;
},
interface: UIEvent,
expose: {
Window: { UIEvent: UIEvent }
}
};

View File

@@ -0,0 +1,42 @@
"use strict";
const conversions = require("webidl-conversions");
const utils = require("./utils.js");
const EventInit = require("./EventInit");
module.exports = {
convertInherit(obj, ret) {
EventInit.convertInherit(obj, ret);
let key, value;
key = "detail";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = conversions["long"](value);
} else {
ret[key] = 0;
}
key = "view";
value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
ret[key] = (value);
} else {
ret[key] = null;
}
},
convert(obj) {
if (obj !== undefined && typeof obj !== "object") {
throw new TypeError("Dictionary has to be an object");
}
if (obj instanceof Date || obj instanceof RegExp) {
throw new TypeError("Dictionary may not be a Date or RegExp object");
}
const ret = Object.create(null);
module.exports.convertInherit(obj, ret);
return ret;
}
};

View File

@@ -0,0 +1,20 @@
"use strict";
module.exports.mixin = function mixin(target, source) {
const keys = Object.getOwnPropertyNames(source);
for (let i = 0; i < keys.length; ++i) {
Object.defineProperty(target, keys[i], Object.getOwnPropertyDescriptor(source, keys[i]));
}
};
module.exports.wrapperSymbol = Symbol("wrapper");
module.exports.implSymbol = Symbol("impl");
module.exports.wrapperForImpl = function (impl) {
return impl[module.exports.wrapperSymbol];
};
module.exports.implForWrapper = function (wrapper) {
return wrapper[module.exports.implSymbol];
};

20
node_modules/jsdom/lib/jsdom/living/generated/utils.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
"use strict";
module.exports.mixin = function mixin(target, source) {
const keys = Object.getOwnPropertyNames(source);
for (let i = 0; i < keys.length; ++i) {
Object.defineProperty(target, keys[i], Object.getOwnPropertyDescriptor(source, keys[i]));
}
};
module.exports.wrapperSymbol = Symbol("wrapper");
module.exports.implSymbol = Symbol("impl");
module.exports.wrapperForImpl = function (impl) {
return impl[module.exports.wrapperSymbol];
};
module.exports.implForWrapper = function (wrapper) {
return wrapper[module.exports.implSymbol];
};

View File

@@ -0,0 +1,43 @@
"use strict";
const internalQuerySelector = require("../selectors").querySelector;
const internalGetAttr = require("../attributes").getAttributeValue;
const URL = require("../../utils").URL;
exports.documentBaseURL = function (document) {
// https://html.spec.whatwg.org/multipage/infrastructure.html#document-base-url
const firstBase = internalQuerySelector(document, "base[href]");
const fallbackBaseURL = exports.fallbackBaseURL(document);
if (firstBase === null) {
return fallbackBaseURL;
}
return exports.frozenBaseURL(firstBase, fallbackBaseURL);
};
exports.fallbackBaseURL = function (document) {
// https://html.spec.whatwg.org/multipage/infrastructure.html#fallback-base-url
// Unimplemented: <iframe srcdoc>
if (document._URL === "about:blank" && document._defaultView &&
document._defaultView._parent !== document._defaultView) {
return module.exports.documentBaseURL(document._defaultView._parent._document);
}
return document._URL;
};
exports.frozenBaseURL = function (baseElement, fallbackBaseURL) {
// https://html.spec.whatwg.org/multipage/semantics.html#frozen-base-url
// The spec is eager (setting the frozen base URL when things change); we are lazy (getting it when we need to)
const baseHrefAttribute = internalGetAttr(baseElement, "href");
try {
return new URL(baseHrefAttribute, fallbackBaseURL).href;
} catch (e) {
return fallbackBaseURL;
}
};

View File

@@ -0,0 +1,17 @@
"use strict";
const SymbolTree = require("symbol-tree");
exports.cloningSteps = Symbol("cloning steps");
exports.locationInfo = Symbol("location info");
exports.accept = Symbol("accept");
exports.requestManager = Symbol("request manager");
exports.pool = Symbol("pool");
exports.agentOptions = Symbol("agentOptions");
// TODO: the many underscore-prefixed hooks should move here
// E.g. _attrModified (which maybe should be split into its per-spec variants)
/**
* This SymbolTree is used to build the tree for all Node in a document
*/
exports.domSymbolTree = new SymbolTree("DOM SymbolTree");

View File

@@ -0,0 +1,5 @@
"use strict";
module.exports = function orderedSetParser(input) {
return new Set(input.split(/\s+/).filter(Boolean));
};

View File

@@ -0,0 +1,11 @@
"use strict";
// https://html.spec.whatwg.org/multipage/webappapis.html#event-handlers-on-elements,-document-objects,-and-window-objects
module.exports = new Set(["onblur", "onerror", "onfocus", "onload", "onresize", "onscroll", "onafterprint",
"onbeforeprint", "onbeforeunload", "onhashchange", "onlanguagechange", "onmessage", "onoffline", "ononline",
"onpagehide", "onpageshow", "onpopstate", "onstorage", "onunload"]);
// level2/html sets up setters/getters on HTMLBodyElement that proxy to the window (setting data properties there)
// level1/core sets up so that modifying the appropriate attributes on body elements will forward to setting on
// the window, with the appropriate `this`.

View File

@@ -0,0 +1,61 @@
"use strict";
const util = require("util");
const ErrorEvent = require("../generated/ErrorEvent").interface;
const errorReportingMode = Symbol("error reporting mode");
// https://html.spec.whatwg.org/multipage/webappapis.html#report-the-error
// Omits script parameter and any check for muted errors; takes error object, message, and location as params, unlike
// the spec. Returns whether the event was handled or not.
function reportAnError(line, col, target, errorObject, message, location) {
if (errorReportingMode in target) {
return false;
}
target[errorReportingMode] = true;
// TODO Events: use constructor directly, once they are no longer tied to a window.
const event = new ErrorEvent("error", {
bubbles: false,
cancelable: true,
message,
filename: location,
lineno: line,
colno: col,
error: errorObject
});
target.dispatchEvent(event);
delete target[errorReportingMode];
return event.defaultPrevented;
}
module.exports = function reportException(window, error, filenameHint) {
// This function will give good results on real Error objects with stacks; poor ones otherwise
const stack = error && error.stack;
const lines = stack && stack.split("\n");
// Find the first line that matches; important for multi-line messages
let pieces;
if (lines) {
for (let i = 1; i < lines.length && !pieces; ++i) {
pieces = lines[i].match(/at (?:(.+)\s+)?\(?(?:(.+?):(\d+):(\d+)|([^)]+))\)?/);
}
}
const fileName = pieces && pieces[2] || filenameHint || window._document._URL;
const lineNumber = pieces && parseInt(pieces[3]) || 0;
const columnNumber = pieces && parseInt(pieces[4]) || 0;
const handled = reportAnError(lineNumber, columnNumber, window, error, error.message, fileName);
if (!handled) {
const jsdomError = new Error(`Uncaught ${util.inspect(error)}`);
jsdomError.detail = error;
window._virtualConsole.emit("jsdomError", jsdomError);
}
};

View File

@@ -0,0 +1,62 @@
"use strict";
const xnv = require("xml-name-validator");
const DOMException = require("../../web-idl/DOMException");
// https://dom.spec.whatwg.org/#validate
exports.name = function (name) {
const result = xnv.name(name);
if (!result.success) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR,
"\"" + name + "\" did not match the Name production: " + result.error);
}
};
exports.qname = function (qname) {
exports.name(qname);
const result = xnv.qname(qname);
if (!result.success) {
throw new DOMException(DOMException.NAMESPACE_ERR,
"\"" + qname + "\" did not match the QName production: " + result.error);
}
};
exports.validateAndExtract = function (namespace, qualifiedName) {
if (namespace === "") {
namespace = null;
}
exports.qname(qualifiedName);
let prefix = null;
let localName = qualifiedName;
const colonIndex = qualifiedName.indexOf(":");
if (colonIndex !== -1) {
prefix = qualifiedName.substring(0, colonIndex);
localName = qualifiedName.substring(colonIndex + 1);
}
if (prefix !== null && namespace === null) {
throw new DOMException(DOMException.NAMESPACE_ERR,
"A namespace was given but a prefix was also extracted from the qualifiedName");
}
if (prefix === "xml" && namespace !== "http://www.w3.org/XML/1998/namespace") {
throw new DOMException(DOMException.NAMESPACE_ERR,
"A prefix of \"xml\" was given but the namespace was not the XML namespace");
}
if ((qualifiedName === "xmlns" || prefix === "xmlns") && namespace !== "http://www.w3.org/2000/xmlns/") {
throw new DOMException(DOMException.NAMESPACE_ERR,
"A prefix or qualifiedName of \"xmlns\" was given but the namespace was not the XMLNS namespace");
}
if (namespace === "http://www.w3.org/2000/xmlns/" && qualifiedName !== "xmlns" && prefix !== "xmlns") {
throw new DOMException(DOMException.NAMESPACE_ERR,
"The XMLNS namespace was given but neither the prefix nor qualifiedName was \"xmlns\"");
}
return { namespace, prefix, localName };
};

95
node_modules/jsdom/lib/jsdom/living/html-collection.js generated vendored Normal file
View File

@@ -0,0 +1,95 @@
"use strict";
const lengthFromProperties = require("../utils").lengthFromProperties;
const getAttributeValue = require("./attributes").getAttributeValue;
const privates = Symbol("HTMLCollection internal slots");
class HTMLCollection {
constructor(secret, element, query) {
if (secret !== privates) {
throw new TypeError("Invalid constructor");
}
this[privates] = { element, query, snapshot: undefined, keys: [], length: 0, version: -1 };
updateHTMLCollection(this);
}
get length() {
updateHTMLCollection(this);
return this[privates].length;
}
item(index) {
updateHTMLCollection(this);
return this[index] || null;
}
namedItem(name) {
updateHTMLCollection(this);
if (Object.prototype.hasOwnProperty.call(this, name)) {
return this[name];
}
return null;
}
}
function updateHTMLCollection(collection) {
if (collection[privates].version < collection[privates].element._version) {
collection[privates].snapshot = collection[privates].query();
resetHTMLCollectionTo(collection, collection[privates].snapshot);
collection[privates].version = collection[privates].element._version;
}
}
function resetHTMLCollectionTo(collection, els) {
const startingLength = lengthFromProperties(collection);
for (let i = 0; i < startingLength; ++i) {
delete collection[i];
}
for (let i = 0; i < els.length; ++i) {
collection[i] = els[i];
}
collection[privates].length = els.length;
const keys = collection[privates].keys;
for (let i = 0; i < keys.length; ++i) {
delete collection[keys[i]];
}
keys.length = 0;
for (let i = 0; i < els.length; ++i) {
addIfAttrPresent(els[i], "name");
}
for (let i = 0; i < els.length; ++i) {
addIfAttrPresent(els[i], "id");
}
function addIfAttrPresent(el, attr) {
const value = getAttributeValue(el, attr);
if (value === null || value === "") {
return;
}
// Don't overwrite numeric indices with named ones.
const valueAsNumber = Number(value);
if (!Number.isNaN(valueAsNumber) && valueAsNumber >= 0) {
return;
}
collection[value] = el;
keys.push(value);
}
}
module.exports = function (core) {
core.HTMLCollection = HTMLCollection;
};
module.exports.create = function (element, query) {
return new HTMLCollection(privates, element, query);
};
module.exports.update = updateHTMLCollection;

39
node_modules/jsdom/lib/jsdom/living/index.js generated vendored Normal file
View File

@@ -0,0 +1,39 @@
"use strict";
const core = module.exports = require("../level1/core");
// These (because of how they were written) directly include level1/core and modify it.
// ORDER IS IMPORTANT
require("../level2/core");
require("../level2/events");
require("../level2/html");
require("../level2/style");
require("../level3/core");
require("../level3/ls");
require("../level3/xpath");
require("./document-type")(core);
require("./character-data")(core);
require("./processing-instruction")(core);
require("./comment")(core);
require("./text")(core);
require("./dom-implementation")(core);
require("./document")(core);
require("./element")(core);
require("./html-collection")(core);
require("./node-filter")(core);
require("./node-iterator")(core);
require("./node-list")(core);
require("./node")(core);
require("./selectors")(core);
require("./parent-node")(core);
require("./non-document-type-child-node")(core);
require("./url")(core);
require("./blob")(core);
require("./file")(core);
require("./filelist")(core);
require("./form-data")(core);
require("./xmlhttprequest-event-target")(core);
require("./xmlhttprequest-upload")(core);
core.Attr = require("./generated/Attr").interface;
core.DOMTokenList = require("./dom-token-list").DOMTokenList;

View File

@@ -0,0 +1,137 @@
"use strict";
const hasOwnProp = Object.prototype.hasOwnProperty;
const namedPropertiesTracker = require("../named-properties-tracker");
const NODE_TYPE = require("./node-type");
const createHTMLCollection = require("./html-collection").create;
const treeOrderSorter = require("../utils").treeOrderSorter;
function isNamedPropertyElement(element) {
// (for the name attribute)
// use hasOwnProperty to make sure contentWindow comes from the prototype,
// and is not set directly on the node by a script.
if ("contentWindow" in element && !hasOwnProp.call(element, "contentWindow")) {
return true;
}
switch (element.nodeName) {
case "A":
case "APPLET":
case "AREA":
case "EMBED":
case "FORM":
case "FRAMESET":
case "IMG":
case "OBJECT":
return true;
default:
return false;
}
}
function namedPropertyResolver(HTMLCollection, window, name, values) {
function getResult() {
const results = [];
for (const node of values().keys()) {
if (node.nodeType !== NODE_TYPE.ELEMENT_NODE) {
continue;
}
if (node.getAttribute("id") === name) {
results.push(node);
} else if (node.getAttribute("name") === name && isNamedPropertyElement(node)) {
results.push(node);
}
}
results.sort(treeOrderSorter);
return results;
}
const document = window._document;
const objects = createHTMLCollection(document.documentElement, getResult);
const length = objects.length;
for (let i = 0; i < length; ++i) {
const node = objects[i];
if ("contentWindow" in node && !hasOwnProp.call(node, "contentWindow")) {
return node.contentWindow;
}
}
if (length === 0) {
return undefined;
}
if (length === 1) {
return objects[0];
}
return objects;
}
exports.initializeWindow = function (window, HTMLCollection) {
namedPropertiesTracker.create(window, namedPropertyResolver.bind(null, HTMLCollection));
};
exports.elementAttributeModified = function (element, name, value, oldValue) {
if (!element._attached) {
return;
}
const useName = isNamedPropertyElement(element);
if (name === "id" || (name === "name" && useName)) {
const tracker = namedPropertiesTracker.get(element._ownerDocument._global);
// (tracker will be null if the document has no Window)
if (tracker) {
if (name === "id" && (!useName || element.getAttribute("name") !== oldValue)) {
tracker.untrack(oldValue, element);
}
if (name === "name" && element.getAttribute("id") !== oldValue) {
tracker.untrack(oldValue, element);
}
tracker.track(value, element);
}
}
};
exports.nodeAttachedToDocument = function (node) {
if (node.nodeType !== NODE_TYPE.ELEMENT_NODE) {
return;
}
const tracker = namedPropertiesTracker.get(node._ownerDocument._global);
if (!tracker) {
return;
}
tracker.track(node.getAttribute("id"), node);
if (isNamedPropertyElement(node)) {
tracker.track(node.getAttribute("name"), node);
}
};
exports.nodeDetachedFromDocument = function (node) {
if (node.nodeType !== NODE_TYPE.ELEMENT_NODE) {
return;
}
const tracker = namedPropertiesTracker.get(node._ownerDocument._global);
if (!tracker) {
return;
}
tracker.untrack(node.getAttribute("id"), node);
if (isNamedPropertyElement(node)) {
tracker.untrack(node.getAttribute("name"), node);
}
};

47
node_modules/jsdom/lib/jsdom/living/node-filter.js generated vendored Normal file
View File

@@ -0,0 +1,47 @@
"use strict";
const addConstants = require("../utils").addConstants;
module.exports = function (core) {
// https://dom.spec.whatwg.org/#interface-nodefilter
core.NodeFilter = function () {
throw new TypeError("Illegal constructor");
};
/**
* Returns an unsigned short that will be used to tell if a given Node must
* be accepted or not by the NodeIterator or TreeWalker iteration
* algorithm. This method is expected to be written by the user of a
* NodeFilter.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/NodeFilter
* @interface
*
* @param {Node} node DOM Node
* @return {FILTER_ACCEPT|FILTER_REJECT|FILTER_SKIP}
*/
core.NodeFilter.acceptNode = function (/* node */) {
throw new Error("This method is expected to be written by the user of a NodeFilter.");
};
addConstants(core.NodeFilter, {
// Constants for whatToShow
SHOW_ALL: 0xFFFFFFFF,
SHOW_ELEMENT: 0x00000001,
SHOW_ATTRIBUTE: 0x00000002,
SHOW_TEXT: 0x00000004,
SHOW_CDATA_SECTION: 0x00000008,
SHOW_ENTITY_REFERENCE: 0x00000010,
SHOW_ENTITY: 0x00000020,
SHOW_PROCESSING_INSTRUCTION: 0x00000040,
SHOW_COMMENT: 0x00000080,
SHOW_DOCUMENT: 0x00000100,
SHOW_DOCUMENT_TYPE: 0x00000200,
SHOW_DOCUMENT_FRAGMENT: 0x00000400,
SHOW_NOTATION: 0x00000800,
// Constants returned by acceptNode
FILTER_ACCEPT: 1,
FILTER_REJECT: 2,
FILTER_SKIP: 3
});
};

229
node_modules/jsdom/lib/jsdom/living/node-iterator.js generated vendored Normal file
View File

@@ -0,0 +1,229 @@
"use strict";
const domSymbolTree = require("./helpers/internal-constants").domSymbolTree;
const defineGetter = require("../utils").defineGetter;
const INTERNAL = Symbol("NodeIterator internal");
module.exports = function (core) {
// https://dom.spec.whatwg.org/#interface-nodeiterator
function NodeIteratorInternal(document, root, whatToShow, filter) {
this.active = true;
this.document = document;
this.root = root;
this.referenceNode = root;
this.pointerBeforeReferenceNode = true;
this.whatToShow = whatToShow;
this.filter = filter;
}
NodeIteratorInternal.prototype.throwIfNotActive = function () {
// (only thrown for getters/methods that are affected by removing steps)
if (!this.active) {
throw Error("This NodeIterator is no longer active. " +
"More than " + this.document._activeNodeIteratorsMax +
" iterators are being used concurrently. " +
"You can increase the 'concurrentNodeIterators' option to " +
"make this error go away."
);
// Alternatively, you can pester Ecma to add support for weak references,
// the DOM standard assumes the implementor has control over object life cycles.
}
};
NodeIteratorInternal.prototype.traverse = function (next) {
let node = this.referenceNode;
let beforeNode = this.pointerBeforeReferenceNode;
do {
if (next) {
if (!beforeNode) {
node = domSymbolTree.following(node, { root: this.root });
if (!node) {
return null;
}
}
beforeNode = false;
} else { // previous
if (beforeNode) {
node = domSymbolTree.preceding(node, { root: this.root });
if (!node) {
return null;
}
}
beforeNode = true;
}
}
while (this.filterNode(node) !== core.NodeFilter.FILTER_ACCEPT);
this.pointerBeforeReferenceNode = beforeNode;
this.referenceNode = node;
return node;
};
NodeIteratorInternal.prototype.filterNode = function (node) {
const n = node.nodeType - 1;
if (!(this.whatToShow & (1 << n))) {
return core.NodeFilter.FILTER_SKIP;
}
let ret = core.NodeFilter.FILTER_ACCEPT;
const filter = this.filter;
if (typeof filter === "function") {
ret = filter(node);
} else if (filter && typeof filter.acceptNode === "function") {
ret = filter.acceptNode(node);
}
if (ret === true) {
return core.NodeFilter.FILTER_ACCEPT;
} else if (ret === false) {
return core.NodeFilter.FILTER_REJECT;
}
return ret;
};
NodeIteratorInternal.prototype.runRemovingSteps = function (oldNode, oldParent, oldPreviousSibling) {
if (oldNode.contains(this.root)) {
return;
}
// If oldNode is not an inclusive ancestor of the referenceNode
// attribute value, terminate these steps.
if (!oldNode.contains(this.referenceNode)) {
return;
}
if (this.pointerBeforeReferenceNode) {
// Let nextSibling be oldPreviousSiblings next sibling, if oldPreviousSibling is non-null,
// and oldParents first child otherwise.
const nextSibling = oldPreviousSibling ?
oldPreviousSibling.nextSibling :
oldParent.firstChild;
// If nextSibling is non-null, set the referenceNode attribute to nextSibling
// and terminate these steps.
if (nextSibling) {
this.referenceNode = nextSibling;
return;
}
// Let next be the first node following oldParent (excluding any children of oldParent).
const next = domSymbolTree.following(oldParent, { skipChildren: true });
// If root is an inclusive ancestor of next, set the referenceNode
// attribute to next and terminate these steps.
if (this.root.contains(next)) {
this.referenceNode = next;
return;
}
// Otherwise, set the pointerBeforeReferenceNode attribute to false.
this.pointerBeforeReferenceNode = false;
// Note: Steps are not terminated here.
}
// Set the referenceNode attribute to the last inclusive descendant in tree order of oldPreviousSibling,
// if oldPreviousSibling is non-null, and to oldParent otherwise.
this.referenceNode = oldPreviousSibling ?
domSymbolTree.lastInclusiveDescendant(oldPreviousSibling) :
oldParent;
};
core.Document._removingSteps.push((document, oldNode, oldParent, oldPreviousSibling) => {
for (let i = 0; i < document._activeNodeIterators.length; ++i) {
const internal = document._activeNodeIterators[i];
internal.runRemovingSteps(oldNode, oldParent, oldPreviousSibling);
}
});
core.Document.prototype.createNodeIterator = function (root, whatToShow, filter) {
if (!root) {
throw new TypeError("Not enough arguments to Document.createNodeIterator.");
}
if (filter === undefined) {
filter = null;
}
if (filter !== null &&
typeof filter !== "function" &&
typeof filter.acceptNode !== "function") {
throw new TypeError("Argument 3 of Document.createNodeIterator should be a function or implement NodeFilter.");
}
const document = root._ownerDocument;
whatToShow = whatToShow === undefined ?
core.NodeFilter.SHOW_ALL :
(whatToShow & core.NodeFilter.SHOW_ALL) >>> 0; // >>> makes sure the result is unsigned
filter = filter || null;
const it = Object.create(core.NodeIterator.prototype);
const internal = new NodeIteratorInternal(document, root, whatToShow, filter);
it[INTERNAL] = internal;
document._activeNodeIterators.push(internal);
while (document._activeNodeIterators.length > document._activeNodeIteratorsMax) {
const internalOther = document._activeNodeIterators.shift();
internalOther.active = false;
}
return it;
};
core.NodeIterator = function NodeIterator() {
throw new TypeError("Illegal constructor");
};
defineGetter(core.NodeIterator.prototype, "root", function () {
return this[INTERNAL].root;
});
defineGetter(core.NodeIterator.prototype, "referenceNode", function () {
const internal = this[INTERNAL];
internal.throwIfNotActive();
return internal.referenceNode;
});
defineGetter(core.NodeIterator.prototype, "pointerBeforeReferenceNode", function () {
const internal = this[INTERNAL];
internal.throwIfNotActive();
return internal.pointerBeforeReferenceNode;
});
defineGetter(core.NodeIterator.prototype, "whatToShow", function () {
return this[INTERNAL].whatToShow;
});
defineGetter(core.NodeIterator.prototype, "filter", function () {
return this[INTERNAL].filter;
});
core.NodeIterator.prototype.previousNode = function () {
const internal = this[INTERNAL];
internal.throwIfNotActive();
return internal.traverse(false);
};
core.NodeIterator.prototype.nextNode = function () {
const internal = this[INTERNAL];
internal.throwIfNotActive();
return internal.traverse(true);
};
core.NodeIterator.prototype.detach = function () {
// noop
};
core.NodeIterator.prototype.toString = function () {
return "[object NodeIterator]";
};
};

83
node_modules/jsdom/lib/jsdom/living/node-list.js generated vendored Normal file
View File

@@ -0,0 +1,83 @@
"use strict";
const lengthFromProperties = require("../utils").lengthFromProperties;
const privates = Symbol("NodeList internal slots");
class NodeList {
constructor(secret, config) {
if (secret !== privates) {
throw new TypeError("Invalid constructor");
}
if (config.nodes) {
this[privates] = {
isLive: false,
length: config.nodes.length
};
for (let i = 0; i < config.nodes.length; ++i) {
this[i] = config.nodes[i];
}
} else {
this[privates] = {
isLive: true,
element: config.element,
query: config.query,
snapshot: undefined,
length: 0,
version: -1
};
updateNodeList(this);
}
}
get length() {
updateNodeList(this);
return this[privates].length;
}
item(index) {
updateNodeList(this);
return this[index] || null;
}
}
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
function updateNodeList(nodeList) {
if (nodeList[privates].isLive) {
if (nodeList[privates].version < nodeList[privates].element._version) {
nodeList[privates].snapshot = nodeList[privates].query();
resetNodeListTo(nodeList, nodeList[privates].snapshot);
nodeList[privates].version = nodeList[privates].element._version;
}
} else {
nodeList[privates].length = lengthFromProperties(nodeList);
}
}
function resetNodeListTo(nodeList, nodes) {
const startingLength = lengthFromProperties(nodeList);
for (let i = 0; i < startingLength; ++i) {
delete nodeList[i];
}
for (let i = 0; i < nodes.length; ++i) {
nodeList[i] = nodes[i];
}
nodeList[privates].length = nodes.length;
}
module.exports = function (core) {
core.NodeList = NodeList;
};
module.exports.createLive = function (element, query) {
return new NodeList(privates, { element, query });
};
module.exports.createStatic = function (nodes) {
return new NodeList(privates, { nodes });
};
module.exports.update = updateNodeList;

16
node_modules/jsdom/lib/jsdom/living/node-type.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
"use strict";
module.exports = Object.freeze({
ELEMENT_NODE: 1,
ATTRIBUTE_NODE: 2, // historical
TEXT_NODE: 3,
CDATA_SECTION_NODE: 4, // historical
ENTITY_REFERENCE_NODE: 5, // historical
ENTITY_NODE: 6, // historical
PROCESSING_INSTRUCTION_NODE: 7,
COMMENT_NODE: 8,
DOCUMENT_NODE: 9,
DOCUMENT_TYPE_NODE: 10,
DOCUMENT_FRAGMENT_NODE: 11,
NOTATION_NODE: 12 // historical
});

250
node_modules/jsdom/lib/jsdom/living/node.js generated vendored Normal file
View File

@@ -0,0 +1,250 @@
"use strict";
const defineGetter = require("../utils").defineGetter;
const simultaneousIterators = require("../utils").simultaneousIterators;
const attributes = require("./attributes");
const cloneDoctype = require("./document-type").clone;
const cloningSteps = require("./helpers/internal-constants").cloningSteps;
const domSymbolTree = require("./helpers/internal-constants").domSymbolTree;
const NODE_TYPE = require("./node-type");
const documentBaseURL = require("./helpers/document-base-url").documentBaseURL;
const orderedSetParser = require("./helpers/ordered-set-parser");
const createHTMLCollection = require("./html-collection").create;
const domTokenListContains = require("./dom-token-list").contains;
const getDoctypePrivates = require("./document-type").getPrivates;
module.exports = function (core) {
const DOCUMENT_POSITION_DISCONNECTED = core.Node.DOCUMENT_POSITION_DISCONNECTED;
const DOCUMENT_POSITION_FOLLOWING = core.Node.DOCUMENT_POSITION_FOLLOWING;
const DOCUMENT_POSITION_CONTAINED_BY = core.Node.DOCUMENT_POSITION_CONTAINED_BY;
const DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = core.Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
/**
* Return true if node is of a type obsoleted by the WHATWG living standard
* @param {Node} node
* @return {Boolean}
*/
function isObsoleteNodeType(node) {
return node.nodeType === NODE_TYPE.ENTITY_NODE ||
node.nodeType === NODE_TYPE.ENTITY_REFERENCE_NODE ||
node.nodeType === NODE_TYPE.NOTATION_NODE ||
node.nodeType === NODE_TYPE.CDATA_SECTION_NODE;
}
core.Node.prototype.cloneNode = function (deep) {
deep = Boolean(deep);
return module.exports.clone(core, this, undefined, deep);
};
/**
* Returns a bitmask Number composed of DOCUMENT_POSITION constants based upon the rules defined in
* http://dom.spec.whatwg.org/#dom-node-comparedocumentposition
* @param {Node} other
* @return {Number}
*/
core.Node.prototype.compareDocumentPosition = function (other) {
// Let reference be the context object.
const reference = this;
if (!(other instanceof core.Node)) {
throw new Error("Comparing position against non-Node values is not allowed");
}
if (isObsoleteNodeType(reference) || isObsoleteNodeType(other)) {
throw new Error("Obsolete node type");
}
const result = domSymbolTree.compareTreePosition(reference, other);
// “If other and reference are not in the same tree, return the result of adding DOCUMENT_POSITION_DISCONNECTED,
// DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, and either DOCUMENT_POSITION_PRECEDING or
// DOCUMENT_POSITION_FOLLOWING, with the constraint that this is to be consistent, together.”
if (result === DOCUMENT_POSITION_DISCONNECTED) {
// symbol-tree does not add these bits required by the spec:
return DOCUMENT_POSITION_DISCONNECTED | DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | DOCUMENT_POSITION_FOLLOWING;
}
return result;
};
/**
* The contains(other) method returns true if other is an inclusive descendant of the context object,
* and false otherwise (including when other is null).
* @param {[Node]} other [the node to test]
* @return {[boolean]} [whether other is an inclusive descendant of this]
*/
core.Node.prototype.contains = function (other) {
return Boolean(other instanceof core.Node &&
(this === other || this.compareDocumentPosition(other) & DOCUMENT_POSITION_CONTAINED_BY)
);
};
// http://dom.spec.whatwg.org/#dom-node-parentelement
defineGetter(core.Node.prototype, "parentElement", function () {
const parentNode = domSymbolTree.parent(this);
return parentNode !== null && parentNode.nodeType === NODE_TYPE.ELEMENT_NODE ? parentNode : null;
});
// https://dom.spec.whatwg.org/#dom-node-baseuri
defineGetter(core.Node.prototype, "baseURI", function () {
return documentBaseURL(this._ownerDocument);
});
function nodeEquals(a, b) {
if (a.nodeType !== b.nodeType) {
return false;
}
switch (a.nodeType) {
case NODE_TYPE.DOCUMENT_TYPE_NODE:
const privatesA = getDoctypePrivates(a);
const privatesB = getDoctypePrivates(b);
if (privatesA.name !== privatesB.name || privatesA.publicId !== privatesB.publicId ||
privatesA.systemId !== privatesB.systemId) {
return false;
}
break;
case NODE_TYPE.ELEMENT_NODE:
if (a._namespaceURI !== b._namespaceURI || a._prefix !== b._prefix || a._localName !== b._localName ||
a._attributes.length !== b._attributes.length) {
return false;
}
break;
case NODE_TYPE.PROCESSING_INSTRUCTION_NODE:
if (a._target !== b._target || a._data !== b._data) {
return false;
}
break;
case NODE_TYPE.TEXT_NODE:
case NODE_TYPE.COMMENT_NODE:
if (a._data !== b._data) {
return false;
}
break;
}
if (a.nodeType === NODE_TYPE.ELEMENT_NODE && !attributes.attributeListsEqual(a, b)) {
return false;
}
for (const nodes of simultaneousIterators(domSymbolTree.childrenIterator(a), domSymbolTree.childrenIterator(b))) {
if (!nodes[0] || !nodes[1]) {
// mismatch in the amount of childNodes
return false;
}
if (!nodeEquals(nodes[0], nodes[1])) {
return false;
}
}
return true;
}
// https://dom.spec.whatwg.org/#dom-node-isequalnode
core.Node.prototype.isEqualNode = function (node) {
if (node === undefined) {
// this is what Node? means in the IDL
node = null;
}
if (node === null) {
return false;
}
// Fast-path, not in the spec
if (this === node) {
return true;
}
return nodeEquals(this, node);
};
};
module.exports.clone = function (core, node, document, cloneChildren) {
if (document === undefined) {
document = node._ownerDocument;
}
let copy;
switch (node.nodeType) {
case NODE_TYPE.DOCUMENT_NODE:
// TODO: just use Document when we eliminate the difference between Document and HTMLDocument.
copy = new node.constructor({
contentType: node._contentType,
url: node._URL,
parsingMode: node._parsingMode
});
document = copy;
break;
case NODE_TYPE.DOCUMENT_TYPE_NODE:
copy = cloneDoctype(core, node);
break;
case NODE_TYPE.ELEMENT_NODE:
copy = document._createElementWithCorrectElementInterface(node._localName, node._namespaceURI);
copy._namespaceURI = node._namespaceURI;
copy._prefix = node._prefix;
copy._localName = node._localName;
attributes.copyAttributeList(node, copy);
break;
case NODE_TYPE.TEXT_NODE:
copy = new core.Text(document, node._data);
break;
case NODE_TYPE.COMMENT_NODE:
copy = new core.Comment(document, node._data);
break;
case NODE_TYPE.PROCESSING_INSTRUCTION_NODE:
copy = new core.ProcessingInstruction(document, node._target, node._data);
break;
case NODE_TYPE.DOCUMENT_FRAGMENT_NODE:
copy = new core.DocumentFragment(document);
break;
}
if (node[cloningSteps]) {
node[cloningSteps](copy, node, document, cloneChildren);
}
if (cloneChildren) {
for (const child of domSymbolTree.childrenIterator(node)) {
const childCopy = module.exports.clone(core, child, document, true);
copy.appendChild(childCopy);
}
}
return copy;
};
module.exports.listOfElementsWithClassNames = function (classNames, root) {
// https://dom.spec.whatwg.org/#concept-getElementsByClassName
const classes = orderedSetParser(classNames);
if (classes.size === 0) {
return createHTMLCollection(root, () => false);
}
return createHTMLCollection(root, () => {
const isQuirksMode = root._ownerDocument.compatMode === "BackCompat";
return domSymbolTree.treeToArray(root, { filter(node) {
if (node.nodeType !== NODE_TYPE.ELEMENT_NODE || node === root) {
return false;
}
for (const className of classes) {
if (!domTokenListContains(node.classList, className, { caseInsensitive: isQuirksMode })) {
return false;
}
}
return true;
} });
});
};

View File

@@ -0,0 +1,29 @@
"use strict";
const defineGetter = require("../utils").defineGetter;
const domSymbolTree = require("./helpers/internal-constants").domSymbolTree;
const NODE_TYPE = require("./node-type");
module.exports = function (core) {
// https://dom.spec.whatwg.org/#nondocumenttypechildnode
for (const Constructor of [core.Element, core.CharacterData]) {
defineGetter(Constructor.prototype, "nextElementSibling", function () {
for (const sibling of domSymbolTree.nextSiblingsIterator(this)) {
if (sibling.nodeType === NODE_TYPE.ELEMENT_NODE) {
return sibling;
}
}
return null;
});
defineGetter(Constructor.prototype, "previousElementSibling", function () {
for (const sibling of domSymbolTree.previousSiblingsIterator(this)) {
if (sibling.nodeType === NODE_TYPE.ELEMENT_NODE) {
return sibling;
}
}
return null;
});
}
};

50
node_modules/jsdom/lib/jsdom/living/parent-node.js generated vendored Normal file
View File

@@ -0,0 +1,50 @@
"use strict";
const defineGetter = require("../utils").defineGetter;
const domSymbolTree = require("./helpers/internal-constants").domSymbolTree;
const NODE_TYPE = require("./node-type");
const createHTMLCollection = require("./html-collection").create;
const updateHTMLCollection = require("./html-collection").update;
module.exports = function (core) {
// https://dom.spec.whatwg.org/#interface-parentnode
// Note that ParentNode is a "NoInterfaceObject"
for (const Constructor of [core.Document, core.DocumentFragment, core.Element]) {
defineGetter(Constructor.prototype, "children", function () {
if (!this._childrenList) {
this._childrenList = createHTMLCollection(this, () => {
return domSymbolTree.childrenToArray(this, { filter(node) {
return node.nodeType === NODE_TYPE.ELEMENT_NODE;
} });
});
} else {
updateHTMLCollection(this._childrenList);
}
return this._childrenList;
});
defineGetter(Constructor.prototype, "firstElementChild", function () {
for (const child of domSymbolTree.childrenIterator(this)) {
if (child.nodeType === NODE_TYPE.ELEMENT_NODE) {
return child;
}
}
return null;
});
defineGetter(Constructor.prototype, "lastElementChild", function () {
for (const child of domSymbolTree.childrenIterator(this, { reverse: true })) {
if (child.nodeType === NODE_TYPE.ELEMENT_NODE) {
return child;
}
}
return null;
});
defineGetter(Constructor.prototype, "childElementCount", function () {
return this.children.length;
});
}
};

36
node_modules/jsdom/lib/jsdom/living/post-message.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
"use strict";
const isValidTargetOrigin = require("../utils").isValidTargetOrigin;
const DOMException = require("../web-idl/DOMException");
module.exports = function (message, targetOrigin) {
if (arguments.length < 2) {
throw new TypeError("'postMessage' requires 2 arguments: 'message' and 'targetOrigin'");
}
targetOrigin = String(targetOrigin);
if (!isValidTargetOrigin(targetOrigin)) {
throw new DOMException(DOMException.SYNTAX_ERR, "Failed to execute 'postMessage' on 'Window': " +
"Invalid target origin '" + targetOrigin + "' in a call to 'postMessage'.");
}
// TODO: targetOrigin === '/' - requires reference to source window
// See https://github.com/tmpvar/jsdom/pull/1140#issuecomment-111587499
if (targetOrigin !== "*" && targetOrigin !== this.origin) {
return;
}
// TODO: event.source - requires reference to source window
// TODO: event.origin - requires reference to source window
// TODO: event.ports
// TODO: event.data - structured clone message - requires cloning DOM nodes
const event = new this.MessageEvent("message", {
data: message
});
event.initEvent("message", false, false);
setTimeout(() => {
this.dispatchEvent(event);
}, 0);
};

View File

@@ -0,0 +1,18 @@
"use strict";
const inheritFrom = require("../utils").inheritFrom;
const NODE_TYPE = require("../living/node-type");
module.exports = function (core) {
core.ProcessingInstruction = function ProcessingInstruction(ownerDocument, target, data) {
core.CharacterData.call(this, ownerDocument, data);
this._target = target;
};
inheritFrom(core.CharacterData, core.ProcessingInstruction, {
nodeType: NODE_TYPE.PROCESSING_INSTRUCTION_NODE, // TODO should be on prototype, not here
get target() {
return this._target;
}
});
};

71
node_modules/jsdom/lib/jsdom/living/selectors.js generated vendored Normal file
View File

@@ -0,0 +1,71 @@
"use strict";
const nwmatcher = require("nwmatcher/src/nwmatcher-noqsa");
const memoizeQuery = require("../utils").memoizeQuery;
const domSymbolTree = require("./helpers/internal-constants").domSymbolTree;
const createStaticNodeList = require("../living/node-list").createStatic;
const DOMException = require("../web-idl/DOMException");
module.exports = function (core) {
for (const Class of [core.Document, core.DocumentFragment, core.Element]) {
Class.prototype.querySelector = memoizeQuery(function (selectors) {
selectors = String(selectors);
const matcher = addNwmatcher(this);
try {
return matcher.first(selectors, this);
} catch (e) {
throw new DOMException(DOMException.SYNTAX_ERR, e.message);
}
});
Class.prototype.querySelectorAll = memoizeQuery(function (selectors) {
selectors = String(selectors);
const matcher = addNwmatcher(this);
let list;
try {
list = matcher.select(selectors, this);
} catch (e) {
throw new DOMException(DOMException.SYNTAX_ERR, e.message);
}
return createStaticNodeList(list);
});
}
core.Element.prototype.matches = memoizeQuery(function (selectors) {
selectors = String(selectors);
const matcher = addNwmatcher(this);
try {
return matcher.match(this, selectors);
} catch (e) {
throw new DOMException(DOMException.SYNTAX_ERR, e.message);
}
});
};
// Internal method so you don't have to go through the public API
module.exports.querySelector = function (parentNode, selectors) {
if (!domSymbolTree.hasChildren(parentNode) ||
(parentNode === parentNode._ownerDocument && !parentNode._documentElement)) {
// This allows us to avoid the explosion that occurs if you try to add nwmatcher to a document that is not yet
// initialized.
return null;
}
return addNwmatcher(parentNode).first(selectors, parentNode);
};
// nwmatcher gets `document.documentElement` at creation-time, so we have to initialize lazily, since in the initial
// stages of Document initialization, there is no documentElement present yet.
function addNwmatcher(parentNode) {
const document = parentNode._ownerDocument;
if (!document._nwmatcher) {
document._nwmatcher = nwmatcher({ document });
document._nwmatcher.configure({ UNIQUE_ID: false });
}
return document._nwmatcher;
}

43
node_modules/jsdom/lib/jsdom/living/text.js generated vendored Normal file
View File

@@ -0,0 +1,43 @@
"use strict";
const inheritFrom = require("../utils").inheritFrom;
const domSymbolTree = require("./helpers/internal-constants").domSymbolTree;
const NODE_TYPE = require("../living/node-type");
module.exports = function (core) {
// TODO: constructor should not take ownerDocument
core.Text = function Text(ownerDocument, data) {
core.CharacterData.call(this, ownerDocument, data);
};
inheritFrom(core.CharacterData, core.Text, {
nodeType: NODE_TYPE.TEXT_NODE, // TODO should be on prototype, not here
splitText(offset) {
offset >>>= 0;
const length = this.length;
if (offset > length) {
throw new core.DOMException(core.DOMException.INDEX_SIZE_ERR);
}
const count = length - offset;
const newData = this.substringData(offset, count);
const newNode = this._ownerDocument.createTextNode(newData);
const parent = domSymbolTree.parent(this);
if (parent !== null) {
parent.insertBefore(newNode, this.nextSibling);
}
this.replaceData(offset, count, "");
return newNode;
// TODO: range stuff
}
// TODO: wholeText property
});
};

7
node_modules/jsdom/lib/jsdom/living/url.js generated vendored Normal file
View File

@@ -0,0 +1,7 @@
"use strict";
const URL = require("whatwg-url-compat");
module.exports = function (core) {
core.URL = URL.createURLConstructor();
};

45
node_modules/jsdom/lib/jsdom/living/xhr-sync-worker.js generated vendored Normal file
View File

@@ -0,0 +1,45 @@
"use strict";
const util = require("util");
const jsdom = require("../../jsdom");
const xhrSymbols = require("./xmlhttprequest-symbols");
const chunks = [];
process.stdin.on("data", chunk => {
chunks.push(chunk);
});
process.stdin.on("end", () => {
const buffer = Buffer.concat(chunks);
const doc = jsdom.jsdom();
const xhr = new doc.defaultView.XMLHttpRequest();
const flag = JSON.parse(buffer.toString(), (k, v) => {
if (v && v.type === "Buffer" && v.data) {
return new Buffer(v.data);
}
return v;
});
flag.synchronous = false;
xhr[xhrSymbols.flag] = flag;
const properties = xhr[xhrSymbols.properties];
properties.readyState = doc.defaultView.XMLHttpRequest.OPENED;
try {
xhr.addEventListener("load", () => {
process.stdout.write(JSON.stringify({ properties }), () => {
process.exit(0);
});
}, false);
xhr.addEventListener("error", error => {
process.stdout.write(JSON.stringify({ properties, error: error.stack || util.inspect(error) }), () => {
process.exit(0);
});
}, false);
xhr.send(flag.body);
} catch (error) {
process.stdout.write(JSON.stringify({ properties, error: error.stack || util.inspect(error) }), () => {
process.exit(0);
});
}
});

213
node_modules/jsdom/lib/jsdom/living/xhr-utils.js generated vendored Normal file
View File

@@ -0,0 +1,213 @@
"use strict";
const request = require("request");
const EventEmitter = require("events").EventEmitter;
const fs = require("fs");
const utils = require("../utils");
const xhrSymbols = require("./xmlhttprequest-symbols");
const internalConstants = require("./helpers/internal-constants");
function wrapCookieJarForRequest(cookieJar) {
const jarWrapper = request.jar();
jarWrapper._jar = cookieJar;
return jarWrapper;
}
function getRequestHeader(requestHeaders, header) {
const keys = Object.keys(requestHeaders);
let n = keys.length;
while (n--) {
const key = keys[n];
if (key.toLowerCase() === header.toLowerCase()) {
return requestHeaders[key];
}
}
return null;
}
exports.getRequestHeader = getRequestHeader;
// return a "request" client object or an event emitter matching the same behaviour for unsupported protocols
// the callback should be called with a "request" response object or an event emitter matching the same behaviour too
exports.createClient = function createClient(xhr, callback) {
const flag = xhr[xhrSymbols.flag];
const urlObj = new utils.URL(flag.uri);
const uri = urlObj.href;
const requestManager = xhr._ownerDocument[internalConstants.requestManager];
if (urlObj.protocol === "file:") {
const response = new EventEmitter();
response.statusCode = 200;
response.rawHeaders = [];
response.headers = {};
const filePath = urlObj.pathname
.replace(/^file:\/\//, "")
.replace(/^\/([a-z]):\//i, "$1:/")
.replace(/%20/g, " ");
const client = new EventEmitter();
const readableStream = fs.createReadStream(filePath, { encoding: "utf8" });
readableStream.on("data", chunk => {
response.emit("data", new Buffer(chunk));
client.emit("data", new Buffer(chunk));
});
readableStream.on("end", () => {
response.emit("end");
client.emit("end");
});
readableStream.on("error", err => {
response.emit("error", err);
client.emit("error", err);
});
client.abort = function () {
readableStream.destroy();
client.emit("abort");
};
if (requestManager) {
const req = {
abort() {
xhr.abort();
}
};
requestManager.add(req);
const rmReq = requestManager.remove.bind(requestManager, req);
client.on("abort", rmReq);
client.on("error", rmReq);
client.on("end", rmReq);
}
process.nextTick(() => callback(null, response));
return client;
}
if (urlObj.protocol === "data:") {
const response = new EventEmitter();
let buffer;
if (flag.method === "GET") {
try {
const dataUrlContent = utils.parseDataUrl(decodeURI(uri));
buffer = dataUrlContent.buffer;
response.statusCode = 200;
response.rawHeaders = dataUrlContent.type ? ["Content-Type", dataUrlContent.type] : [];
response.headers = dataUrlContent.type ? { "content-type": dataUrlContent.type } : {};
} catch (err) {
process.nextTick(() => callback(err, null));
return null;
}
} else {
buffer = new Buffer("");
response.statusCode = 0;
response.rawHeaders = {};
response.headers = {};
}
const client = new EventEmitter();
client.abort = function () {};
process.nextTick(() => {
callback(null, response);
process.nextTick(() => {
response.emit("data", buffer);
client.emit("data", buffer);
response.emit("end");
client.emit("end");
});
});
return client;
}
const requestHeaders = {};
for (const header in flag.requestHeaders) {
requestHeaders[header] = flag.requestHeaders[header];
}
if (!getRequestHeader(flag.requestHeaders, "Referer")) {
requestHeaders.Referer = flag.baseUrl;
}
if (!getRequestHeader(flag.requestHeaders, "User-Agent")) {
requestHeaders["User-Agent"] = flag.userAgent;
}
if (!getRequestHeader(flag.requestHeaders, "Accept-Language")) {
requestHeaders["Accept-Language"] = "en";
}
if (!getRequestHeader(flag.requestHeaders, "Accept")) {
requestHeaders.Accept = "*/*";
}
const options = {
uri,
method: flag.method,
headers: requestHeaders,
gzip: true,
maxRedirects: 21,
followAllRedirects: true
};
if (flag.auth) {
options.auth = {
user: flag.auth.user || "",
pass: flag.auth.pass || "",
sendImmediately: false
};
}
if (xhr._ownerDocument._cookieJar) {
options.jar = wrapCookieJarForRequest(xhr._ownerDocument._cookieJar);
}
options.pool = xhr._ownerDocument[internalConstants.pool];
options.agentOptions = xhr._ownerDocument[internalConstants.agentOptions];
const body = flag.body;
const hasBody = body !== undefined &&
body !== null &&
body !== "" &&
!(flag.method === "HEAD" || flag.method === "GET");
if (hasBody && !flag.formData) {
options.body = body;
}
try {
const client = request(options)
.on("response", response => callback(null, response))
.on("error", callback);
if (hasBody && flag.formData) {
const form = client.form();
for (const entry of body) {
form.append(entry.name, entry.value, entry.options);
}
}
if (requestManager) {
const req = {
abort() {
xhr.abort();
}
};
requestManager.add(req);
const rmReq = requestManager.remove.bind(requestManager, req);
client.on("abort", rmReq);
client.on("error", rmReq);
client.on("end", rmReq);
}
return client;
} catch (e) {
process.nextTick(() => callback(e));
return null;
}
};

View File

@@ -0,0 +1,23 @@
"use strict";
const EventTarget = require("./generated/EventTarget");
function XMLHttpRequestEventTarget() {
if (!(this instanceof XMLHttpRequestEventTarget)) {
throw new TypeError("DOM object constructor cannot be called as a function.");
}
EventTarget.setup(this);
this.onabort = null;
this.onerror = null;
this.onload = null;
this.onloadend = null;
this.onloadstart = null;
this.onprogress = null;
this.ontimeout = null;
}
XMLHttpRequestEventTarget.prototype = Object.create(EventTarget.interface.prototype);
module.exports = function (core) {
core.XMLHttpRequestEventTarget = XMLHttpRequestEventTarget;
};

View File

@@ -0,0 +1,4 @@
"use strict";
exports.flag = Symbol("flag");
exports.properties = Symbol("properties");

View File

@@ -0,0 +1,17 @@
"use strict";
module.exports = function (core) {
const XMLHttpRequestEventTarget = core.XMLHttpRequestEventTarget;
class XMLHttpRequestUpload extends XMLHttpRequestEventTarget {
constructor() {
super();
if (!(this instanceof XMLHttpRequestUpload)) {
throw new TypeError("DOM object constructor cannot be called as a function.");
}
}
}
core.XMLHttpRequestUpload = XMLHttpRequestUpload;
};

692
node_modules/jsdom/lib/jsdom/living/xmlhttprequest.js generated vendored Normal file
View File

@@ -0,0 +1,692 @@
"use strict";
const HTTP_STATUS_CODES = require("http").STATUS_CODES;
const spawnSync = require("child_process").spawnSync;
const xhrUtils = require("./xhr-utils");
const DOMException = require("../web-idl/DOMException");
const xhrSymbols = require("./xmlhttprequest-symbols");
const blobSymbols = require("./blob-symbols");
const formDataSymbols = require("./form-data-symbols");
const utils = require("../utils");
const documentBaseURLHelper = require("./helpers/document-base-url");
const forbiddenRequestHeaders = new RegExp("^(?:" + [
"Accept-Charset",
"Accept-Encoding",
"Access-Control-Request-Headers",
"Access-Control-Request-Method",
"Connection",
"Content-Length",
"Cookie",
"Cookie2",
"Date",
"DNT",
"Expect",
"Host",
"Keep-Alive",
"Origin",
"Referer",
"TE",
"Trailer",
"Transfer-Encoding",
"Upgrade",
"User-Agent",
"Via",
"Sec-.*",
"Proxy-.*"
].join("|") + ")$", "i");
const uniqueResponseHeaders = new RegExp("^(?:" + [
"content-type",
"content-length",
"user-agent",
"referer",
"host",
"authorization",
"proxy-authorization",
"if-modified-since",
"if-unmodified-since",
"from",
"location",
"max-forwards"
].join("|") + ")$", "i");
const allowedRequestMethods = ["OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE"];
const forbiddenRequestMethods = ["TRACK", "TRACE", "CONNECT"];
const tokenRegexp = /^(?:(?![\x00-\x1F\x7F \t\(\)<>@,;:\\"\/\[\]?={}])[\x00-\x7F])+$/;
const fieldValueRegexp = /^(?:(?![\x00-\x1F\x7F])[\x00-\xFF])*$/;
const XMLHttpRequestResponseType = [
"",
"arraybuffer",
"blob",
"document",
"json",
"text"
];
module.exports = function createXMLHttpRequest(window) {
const Event = window.Event;
const ProgressEvent = window.ProgressEvent;
const Blob = window.Blob;
const FormData = window.FormData;
const XMLHttpRequestEventTarget = window.XMLHttpRequestEventTarget;
const XMLHttpRequestUpload = window.XMLHttpRequestUpload;
class XMLHttpRequest extends XMLHttpRequestEventTarget {
constructor() {
super();
if (!(this instanceof XMLHttpRequest)) {
throw new TypeError("DOM object constructor cannot be called as a function.");
}
this.upload = new XMLHttpRequestUpload();
this.upload._ownerDocument = window.document;
this[xhrSymbols.flag] = {
synchronous: false,
withCredentials: false,
mimeType: null,
auth: null,
method: undefined,
responseType: "",
requestHeaders: {},
baseUrl: "",
uri: "",
userAgent: "",
timeout: 0,
body: undefined,
formData: false
};
this[xhrSymbols.properties] = {
send: false,
timeoutStart: 0,
timeoutId: 0,
timeoutFn: null,
client: null,
responseHeaders: {},
responseBuffer: null,
responseCache: null,
responseTextCache: null,
responseXMLCache: null,
readyState: XMLHttpRequest.UNSENT,
status: 0,
statusText: ""
};
this.onreadystatechange = null;
}
get readyState() {
return this[xhrSymbols.properties].readyState;
}
get status() {
return this[xhrSymbols.properties].status;
}
get statusText() {
return this[xhrSymbols.properties].statusText;
}
get responseType() {
return this[xhrSymbols.flag].responseType;
}
set responseType(responseType) {
const flag = this[xhrSymbols.flag];
if (this.readyState === XMLHttpRequest.LOADING || this.readyState === XMLHttpRequest.DONE) {
throw new DOMException(DOMException.INVALID_STATE_ERR);
}
if (this.readyState === XMLHttpRequest.OPENED && flag.synchronous) {
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
if (XMLHttpRequestResponseType.indexOf(responseType) === -1) {
responseType = "";
}
flag.responseType = responseType;
}
get response() {
const properties = this[xhrSymbols.properties];
if (properties.responseCache) {
return properties.responseCache;
}
let res = "";
switch (this.responseType) {
case "":
case "text":
res = this.responseText;
break;
case "arraybuffer":
if (!properties.responseBuffer) {
return null;
}
res = (new Uint8Array(properties.responseBuffer)).buffer;
break;
case "blob":
if (!properties.responseBuffer) {
return null;
}
res = new Blob([(new Uint8Array(properties.responseBuffer)).buffer]);
break;
case "document":
res = this.responseXML;
break;
case "json":
if (this.readyState !== XMLHttpRequest.DONE || !properties.responseBuffer) {
res = null;
}
try {
res = JSON.parse(properties.responseBuffer.toString());
} catch (e) {
res = null;
}
break;
}
properties.responseCache = res;
return res;
}
get responseText() {
const properties = this[xhrSymbols.properties];
if (this.responseType !== "" && this.responseType !== "text") {
throw new DOMException(DOMException.INVALID_STATE_ERR);
}
if (this.readyState !== XMLHttpRequest.LOADING && this.readyState !== XMLHttpRequest.DONE) {
return "";
}
if (properties.responseTextCache) {
return properties.responseTextCache;
}
const responseBuffer = properties.responseBuffer;
if (!responseBuffer) {
return "";
}
const res = responseBuffer.toString();
properties.responseTextCache = res;
return res;
}
get responseXML() {
const flag = this[xhrSymbols.flag];
const properties = this[xhrSymbols.properties];
if (this.responseType !== "" && this.responseType !== "document") {
throw new DOMException(DOMException.INVALID_STATE_ERR);
}
if (this.readyState !== XMLHttpRequest.DONE) {
return null;
}
if (properties.responseXMLCache) {
return properties.responseXMLCache;
}
const contentType = flag.mimeType || this.getResponseHeader("Content-Type");
if (contentType && !contentType.match(/^(?:text\/html|text\/xml|application\/xml|.*?\+xml)(?:;.*)*$/)) {
return null;
}
const responseBuffer = properties.responseBuffer;
if (!responseBuffer) {
return null;
}
const resText = responseBuffer.toString();
const res = new window.Document({ parsingMode: "xml" });
res._htmlToDom.appendHtmlToDocument(resText, res);
properties.responseXMLCache = res;
return res;
}
get timeout() {
return this[xhrSymbols.flag].timeout;
}
set timeout(val) {
const flag = this[xhrSymbols.flag];
const properties = this[xhrSymbols.properties];
if (flag.synchronous) {
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
flag.timeout = val;
clearTimeout(properties.timeoutId);
if (val > 0 && properties.timeoutFn) {
properties.timeoutId = setTimeout(
properties.timeoutFn,
Math.max(0, val - ((new Date()).getTime() - properties.timeoutStart))
);
} else {
properties.timeoutFn = null;
properties.timeoutStart = 0;
}
}
get withCredentials() {
return this[xhrSymbols.flag].withCredentials;
}
set withCredentials(val) {
const flag = this[xhrSymbols.flag];
const properties = this[xhrSymbols.properties];
if (!(this.readyState === XMLHttpRequest.UNSENT || this.readyState === XMLHttpRequest.OPENED)) {
throw new DOMException(DOMException.INVALID_STATE_ERR);
}
if (properties.send) {
throw new DOMException(DOMException.INVALID_STATE_ERR);
}
if (flag.synchronous) {
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
flag.withCredentials = val;
}
abort() {
const flag = this[xhrSymbols.flag];
const properties = this[xhrSymbols.properties];
clearTimeout(properties.timeoutId);
properties.timeoutFn = null;
properties.timeoutStart = 0;
const client = properties.client;
if (client) {
client.abort();
}
if (!(this.readyState === XMLHttpRequest.UNSENT ||
(this.readyState === XMLHttpRequest.OPENED && !properties.send) ||
this.readyState === XMLHttpRequest.DONE)) {
properties.send = false;
readyStateChange(this, XMLHttpRequest.DONE);
if (!(flag.method === "HEAD" || flag.method === "GET")) {
this.upload.dispatchEvent(new ProgressEvent("progress"));
this.upload.dispatchEvent(new ProgressEvent("abort"));
this.upload.dispatchEvent(new ProgressEvent("loadend"));
}
this.dispatchEvent(new ProgressEvent("progress"));
this.dispatchEvent(new ProgressEvent("abort"));
this.dispatchEvent(new ProgressEvent("loadend"));
}
properties.readyState = XMLHttpRequest.UNSENT;
}
getAllResponseHeaders() {
const properties = this[xhrSymbols.properties];
const readyState = this.readyState;
if ([XMLHttpRequest.UNSENT, XMLHttpRequest.OPENED].indexOf(readyState) >= 0) {
return "";
}
return Object.keys(properties.responseHeaders)
.filter(key => {
const keyLc = key.toLowerCase();
return keyLc !== "set-cookie" && keyLc !== "set-cookie2";
})
.map(key => {
return [key, properties.responseHeaders[key]].join(": ");
}, this).join("\r\n");
}
getResponseHeader(header) {
const properties = this[xhrSymbols.properties];
const readyState = this.readyState;
if ([XMLHttpRequest.UNSENT, XMLHttpRequest.OPENED].indexOf(readyState) >= 0) {
return null;
}
const keys = Object.keys(properties.responseHeaders);
let n = keys.length;
const responseHeaders = {};
while (n--) {
const key = keys[n];
responseHeaders[key.toLowerCase()] = properties.responseHeaders[key];
}
const key = header.toLowerCase();
if (key === "set-cookie" || key === "set-cookie2") {
return null;
}
const value = responseHeaders[key];
return typeof value !== "undefined" ? String(value) : null;
}
open(method, uri, async, user, password) {
const flag = this[xhrSymbols.flag];
const properties = this[xhrSymbols.properties];
const argumentCount = arguments.length;
if (argumentCount < 2) {
throw new TypeError("Not enought arguments");
}
if (!tokenRegexp.test(method)) {
throw new DOMException(DOMException.SYNTAX_ERR);
}
const upperCaseMethod = method.toUpperCase();
if (forbiddenRequestMethods.indexOf(upperCaseMethod) !== -1) {
throw new DOMException(DOMException.SECURITY_ERR);
}
const client = properties.client;
if (client && typeof client.abort === "function") {
client.abort();
}
if (allowedRequestMethods.indexOf(upperCaseMethod) !== -1) {
method = upperCaseMethod;
}
if (typeof async !== "undefined") {
flag.synchronous = !async;
} else {
flag.synchronous = false;
}
if (flag.responseType && flag.synchronous) {
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
if (flag.synchronous && flag.timeout) {
throw new DOMException(DOMException.INVALID_ACCESS_ERR);
}
flag.method = method;
const baseUrl = documentBaseURLHelper.documentBaseURL(this._ownerDocument).toString();
flag.baseUrl = baseUrl;
const urlObj = new utils.URL(uri, baseUrl);
flag.uri = urlObj.href;
flag.userAgent = this._ownerDocument._defaultView.navigator.userAgent;
if (argumentCount >= 4 && (user || password)) {
flag.auth = {
user,
pass: password
};
}
flag.requestHeaders = {};
properties.send = false;
properties.requestBuffer = null;
properties.requestCache = null;
readyStateChange(this, XMLHttpRequest.OPENED);
}
overrideMimeType(mime) {
if ([XMLHttpRequest.LOADING, XMLHttpRequest.DONE].indexOf(this.readyState) >= 0) {
throw new DOMException(DOMException.INVALID_STATE_ERR);
}
this[xhrSymbols.flag].mimeType = mime;
}
send(body) {
const flag = this[xhrSymbols.flag];
const properties = this[xhrSymbols.properties];
const self = this;
if (this.readyState !== XMLHttpRequest.OPENED || properties.send) {
throw new DOMException(DOMException.INVALID_STATE_ERR);
}
if (!flag.body &&
body !== undefined &&
body !== null &&
body !== "" &&
!(flag.method === "HEAD" || flag.method === "GET")) {
if (body instanceof FormData) {
flag.formData = true;
const formData = [];
for (const entry of body[formDataSymbols.entries]) {
let val;
if (entry.value instanceof Blob) {
const blob = entry.value;
val = {
name: entry.name,
value: blob[blobSymbols.buffer],
options: {
filename: blob.name,
contentType: blob.type,
knownLength: blob.size
}
};
} else {
val = entry;
}
formData.push(val);
}
flag.body = formData;
} else if (body instanceof Blob) {
flag.body = body[blobSymbols.buffer];
} else if (body instanceof ArrayBuffer) {
flag.body = new Buffer(new Uint8Array(body));
} else if (typeof body !== "string") {
flag.body = String(body);
} else {
flag.body = body;
}
}
if (flag.synchronous) {
const flagStr = JSON.stringify(flag);
const res = spawnSync(
process.execPath,
[require.resolve("./xhr-sync-worker.js")],
{
input: flagStr
}
);
if (res.status !== 0) {
throw new Error(res.stderr.toString());
}
if (res.error) {
if (typeof res.error === "string") {
res.error = new Error(res.error);
}
throw res.error;
}
const response = JSON.parse(res.stdout.toString(), (k, v) => {
if (k === "responseBuffer" && v && v.data) {
return new Buffer(v.data);
}
return v;
});
response.properties.readyState = XMLHttpRequest.LOADING;
this[xhrSymbols.properties] = response.properties;
readyStateChange(self, XMLHttpRequest.DONE);
if (response.error) {
this.dispatchEvent(new ProgressEvent("error"));
this.dispatchEvent(new ProgressEvent("loadend"));
throw new DOMException(DOMException.NETWORK_ERR, response.error);
} else {
const responseBuffer = this[xhrSymbols.properties].responseBuffer;
const contentLength = this.getResponseHeader("content-length") || "0";
const bufferLength = parseInt(contentLength, 10) || responseBuffer.length;
const progressObj = { lengthComputable: false };
if (bufferLength !== 0) {
progressObj.total = bufferLength;
progressObj.loaded = bufferLength;
progressObj.lengthComputable = true;
}
this.dispatchEvent(new ProgressEvent("load"));
this.dispatchEvent(new ProgressEvent("loadend", progressObj));
}
} else {
properties.send = true;
this.dispatchEvent(new ProgressEvent("loadstart"));
const client = xhrUtils.createClient(this,
(err, response) => {
if (err) {
if (client) {
client.removeAllListeners();
}
readyStateChange(self, XMLHttpRequest.DONE);
if (!(flag.method === "HEAD" || flag.method === "GET")) {
self.upload.dispatchEvent(new ProgressEvent("error", err));
self.upload.dispatchEvent(new ProgressEvent("loadend"));
}
self.dispatchEvent(new ProgressEvent("error", err));
self.dispatchEvent(new ProgressEvent("loadend"));
return;
}
receiveResponse(self, response);
}
);
properties.client = client;
if (client) {
if (body !== undefined &&
body !== null &&
body !== "" &&
!(flag.method === "HEAD" || flag.method === "GET")) {
setDispatchProgressEvents(this);
}
if (this.timeout > 0) {
properties.timeoutStart = (new Date()).getTime();
properties.timeoutFn = function () {
client.abort();
if (!(self.readyState === XMLHttpRequest.UNSENT ||
(self.readyState === XMLHttpRequest.OPENED && !properties.send) ||
self.readyState === XMLHttpRequest.DONE)) {
properties.send = false;
readyStateChange(self, XMLHttpRequest.DONE);
if (!(flag.method === "HEAD" || flag.method === "GET")) {
self.upload.dispatchEvent(new ProgressEvent("progress"));
self.upload.dispatchEvent(new ProgressEvent("timeout"));
self.upload.dispatchEvent(new ProgressEvent("loadend"));
}
self.dispatchEvent(new ProgressEvent("progress"));
self.dispatchEvent(new ProgressEvent("timeout"));
self.dispatchEvent(new ProgressEvent("loadend"));
}
properties.readyState = XMLHttpRequest.UNSENT;
};
properties.timeoutId = setTimeout(properties.timeoutFn, this.timeout);
}
}
}
flag.body = undefined;
flag.formData = false;
}
setRequestHeader(header, value) {
const flag = this[xhrSymbols.flag];
const properties = this[xhrSymbols.properties];
if (arguments.length !== 2) {
throw new TypeError();
}
value = String(value);
if (!tokenRegexp.test(header) || !fieldValueRegexp.test(value)) {
throw new DOMException(DOMException.SYNTAX_ERR);
}
if (this.readyState !== XMLHttpRequest.OPENED || properties.send) {
throw new DOMException(DOMException.INVALID_STATE_ERR);
}
if (forbiddenRequestHeaders.test(header)) {
return;
}
const keys = Object.keys(flag.requestHeaders);
let n = keys.length;
while (n--) {
const key = keys[n];
if (key.toLowerCase() === header.toLowerCase()) {
flag.requestHeaders[key] += ", " + value;
return;
}
}
flag.requestHeaders[header] = value;
}
toString() {
return "[object XMLHttpRequest]";
}
get _ownerDocument() {
return window.document;
}
}
utils.addConstants(XMLHttpRequest, {
UNSENT: 0,
OPENED: 1,
HEADERS_RECEIVED: 2,
LOADING: 3,
DONE: 4
});
function readyStateChange(xhr, readyState) {
if (xhr.readyState !== readyState) {
const readyStateChangeEvent = new Event("readystatechange");
const properties = xhr[xhrSymbols.properties];
properties.readyState = readyState;
xhr.dispatchEvent(readyStateChangeEvent);
}
}
function receiveResponse(xhr, response) {
const properties = xhr[xhrSymbols.properties];
let byteOffset = 0;
const statusCode = response.statusCode;
properties.status = statusCode;
properties.statusText = response.statusMessage || HTTP_STATUS_CODES[statusCode] || "OK";
const headers = {};
const headerMap = {};
const rawHeaders = response.rawHeaders;
const n = Number(rawHeaders.length);
for (let i = 0; i < n; i += 2) {
const k = rawHeaders[i];
const kl = k.toLowerCase();
const v = rawHeaders[i + 1];
if (k.match(uniqueResponseHeaders)) {
if (headerMap[kl] !== undefined) {
delete headers[headerMap[kl]];
}
headers[k] = v;
} else if (headerMap[kl] !== undefined) {
headers[headerMap[kl]] += ", " + v;
} else {
headers[k] = v;
}
headerMap[kl] = k;
}
properties.responseHeaders = headers;
const contentLength = xhr.getResponseHeader("content-length") || "0";
const bufferLength = parseInt(contentLength, 10) || 0;
const progressObj = { lengthComputable: false };
if (bufferLength !== 0) {
progressObj.total = bufferLength;
progressObj.loaded = 0;
progressObj.lengthComputable = true;
}
properties.responseBuffer = new Buffer(0);
properties.responseCache = null;
properties.responseTextCache = null;
properties.responseXMLCache = null;
readyStateChange(xhr, XMLHttpRequest.HEADERS_RECEIVED);
properties.client.on("data", chunk => {
properties.responseBuffer = Buffer.concat([properties.responseBuffer, chunk]);
properties.responseCache = null;
properties.responseTextCache = null;
properties.responseXMLCache = null;
});
response.on("data", chunk => {
byteOffset += chunk.length;
progressObj.loaded = byteOffset;
readyStateChange(xhr, XMLHttpRequest.LOADING);
if (progressObj.total !== progressObj.loaded) {
xhr.dispatchEvent(new ProgressEvent("progress", progressObj));
}
});
properties.client.on("end", () => {
clearTimeout(properties.timeoutId);
properties.timeoutFn = null;
properties.timeoutStart = 0;
properties.client = null;
readyStateChange(xhr, XMLHttpRequest.DONE);
xhr.dispatchEvent(new ProgressEvent("load"));
xhr.dispatchEvent(new ProgressEvent("loadend", progressObj));
});
}
function setDispatchProgressEvents(xhr) {
const client = xhr[xhrSymbols.properties].client;
client.on("request", req => {
xhr.upload.dispatchEvent(new ProgressEvent("loadstart"));
req.on("response", () => {
let total = 0;
let lengthComputable = false;
const length = parseInt(xhrUtils.getRequestHeader(client.headers, "content-length"), 10);
if (length) {
total = length;
lengthComputable = true;
}
const progress = {
lengthComputable,
total,
loaded: total
};
xhr.upload.dispatchEvent(new ProgressEvent("progress", progress));
xhr.upload.dispatchEvent(new ProgressEvent("load"));
xhr.upload.dispatchEvent(new ProgressEvent("loadend"));
});
});
}
return XMLHttpRequest;
};