Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.13.0
22.15.0
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 100,
"quoteProps": "preserve",
"singleQuote": true
}
134 changes: 0 additions & 134 deletions lib/DOMException.js

This file was deleted.

7 changes: 3 additions & 4 deletions lib/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ var Node = require('./Node');
var NodeList = require('./NodeList');
var NodeUtils = require('./NodeUtils');
var FilteredElementList = require('./FilteredElementList');
var DOMException = require('./DOMException');
var DOMTokenList = require('./DOMTokenList');
var select = require('./select');
var ContainerNode = require('./ContainerNode');
Expand Down Expand Up @@ -683,7 +682,7 @@ Element.prototype = Object.create(ContainerNode.prototype, {

setAttributeNode: { value: function setAttributeNode(attr) {
if (attr.ownerElement !== null && attr.ownerElement !== this) {
throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR);
utils.InUseAttributeError();
}
var result = null;
var oldAttrs = this._attrsByQName[attr.name];
Expand All @@ -692,7 +691,7 @@ Element.prototype = Object.create(ContainerNode.prototype, {
if (oldAttrs.some(function(a) { return a===attr; })) {
return attr;
} else if (attr.ownerElement !== null) {
throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR);
utils.InUseAttributeError();
}
oldAttrs.forEach(function(a) { this.removeAttributeNode(a); }, this);
result = oldAttrs[0];
Expand All @@ -703,7 +702,7 @@ Element.prototype = Object.create(ContainerNode.prototype, {

setAttributeNodeNS: { value: function setAttributeNodeNS(attr) {
if (attr.ownerElement !== null) {
throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR);
utils.InUseAttributeError();
}
var ns = attr.namespaceURI;
var key = (ns === null ? '' : ns) + '|' + attr.localName;
Expand Down
1 change: 0 additions & 1 deletion lib/impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ exports = module.exports = {
CSSStyleDeclaration: require('./CSSStyleDeclaration'),
CharacterData: require('./CharacterData'),
Comment: require('./Comment'),
DOMException: require('./DOMException'),
DOMImplementation: require('./DOMImplementation'),
DOMTokenList: require('./DOMTokenList'),
Document: require('./Document'),
Expand Down
163 changes: 118 additions & 45 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,136 @@
"use strict";
var DOMException = require('./DOMException');
var ERR = DOMException;
var isApiWritable = require("./config").isApiWritable;
'use strict';
var isApiWritable = require('./config').isApiWritable;

exports.NAMESPACE = {
HTML: 'http://www.w3.org/1999/xhtml',
XML: 'http://www.w3.org/XML/1998/namespace',
XMLNS: 'http://www.w3.org/2000/xmlns/',
MATHML: 'http://www.w3.org/1998/Math/MathML',
SVG: 'http://www.w3.org/2000/svg',
XLINK: 'http://www.w3.org/1999/xlink'
XLINK: 'http://www.w3.org/1999/xlink',
};

//
// Shortcut functions for throwing errors of various types.
//
exports.IndexSizeError = function() { throw new DOMException(ERR.INDEX_SIZE_ERR); };
exports.HierarchyRequestError = function() { throw new DOMException(ERR.HIERARCHY_REQUEST_ERR); };
exports.WrongDocumentError = function() { throw new DOMException(ERR.WRONG_DOCUMENT_ERR); };
exports.InvalidCharacterError = function() { throw new DOMException(ERR.INVALID_CHARACTER_ERR); };
exports.NoModificationAllowedError = function() { throw new DOMException(ERR.NO_MODIFICATION_ALLOWED_ERR); };
exports.NotFoundError = function() { throw new DOMException(ERR.NOT_FOUND_ERR); };
exports.NotSupportedError = function() { throw new DOMException(ERR.NOT_SUPPORTED_ERR); };
exports.InvalidStateError = function() { throw new DOMException(ERR.INVALID_STATE_ERR); };
exports.SyntaxError = function() { throw new DOMException(ERR.SYNTAX_ERR); };
exports.InvalidModificationError = function() { throw new DOMException(ERR.INVALID_MODIFICATION_ERR); };
exports.NamespaceError = function() { throw new DOMException(ERR.NAMESPACE_ERR); };
exports.InvalidAccessError = function() { throw new DOMException(ERR.INVALID_ACCESS_ERR); };
exports.TypeMismatchError = function() { throw new DOMException(ERR.TYPE_MISMATCH_ERR); };
exports.SecurityError = function() { throw new DOMException(ERR.SECURITY_ERR); };
exports.NetworkError = function() { throw new DOMException(ERR.NETWORK_ERR); };
exports.AbortError = function() { throw new DOMException(ERR.ABORT_ERR); };
exports.UrlMismatchError = function() { throw new DOMException(ERR.URL_MISMATCH_ERR); };
exports.QuotaExceededError = function() { throw new DOMException(ERR.QUOTA_EXCEEDED_ERR); };
exports.TimeoutError = function() { throw new DOMException(ERR.TIMEOUT_ERR); };
exports.InvalidNodeTypeError = function() { throw new DOMException(ERR.INVALID_NODE_TYPE_ERR); };
exports.DataCloneError = function() { throw new DOMException(ERR.DATA_CLONE_ERR); };

exports.nyi = function() {
throw new Error("NotYetImplemented");
};

exports.shouldOverride = function() {
throw new Error("Abstract function; should be overriding in subclass.");
};

exports.assert = function(expr, msg) {
exports.IndexSizeError = () => {
throw new DOMException('The index is not in the allowed range', 'IndexSizeError');
};

exports.HierarchyRequestError = () => {
throw new DOMException('The node tree hierarchy is not correct', 'HierarchyRequestError');
};

exports.WrongDocumentError = () => {
throw new DOMException('The object is in the wrong Document', 'WrongDocumentError');
};

exports.InvalidCharacterError = () => {
throw new DOMException('The string contains invalid characters', 'InvalidCharacterError');
};

exports.NoModificationAllowedError = () => {
throw new DOMException('The object cannot be modified', 'NoModificationAllowedError');
};

exports.NotFoundError = () => {
throw new DOMException('The object can not be found here', 'NotFoundError');
};

exports.NotSupportedError = () => {
throw new DOMException('The operation is not supported', 'NotSupportedError');
};

exports.InvalidStateError = () => {
throw new DOMException('The object is in an invalid state', 'InvalidStateError');
};

exports.SyntaxError = () => {
throw new DOMException('The string did not match the expected pattern', 'SyntaxError');
};

exports.InvalidModificationError = () => {
throw new DOMException('The object can not be modified in this way', 'InvalidModificationError');
};

exports.NamespaceError = () => {
throw new DOMException('The operation is not allowed by Namespaces in XML', 'NamespaceError');
};

exports.InvalidAccessError = () => {
throw new DOMException(
'The object does not support the operation or argument',
'InvalidAccessError'
);
};

exports.TypeMismatchError = () => {
throw new DOMException(
'The type of the object does not match the expected type',
'TypeMismatchError'
);
};

exports.SecurityError = () => {
throw new DOMException('The operation is insecure', 'SecurityError');
};

exports.NetworkError = () => {
throw new DOMException('A network error occurred', 'NetworkError');
};

exports.AbortError = () => {
throw new DOMException('The operation was aborted', 'AbortError');
};

exports.UrlMismatchError = () => {
throw new DOMException('The given URL does not match another URL', 'URLMismatchError');
};

exports.QuotaExceededError = () => {
throw new DOMException('The quota has been exceeded', 'QuotaExceededError');
};

exports.TimeoutError = () => {
throw new DOMException('The operation timed out', 'TimeoutError');
};

exports.InvalidNodeTypeError = () => {
throw new DOMException('The node is of an invalid type', 'InvalidNodeTypeError');
};

exports.DataCloneError = () => {
throw new DOMException('The object can not be cloned', 'DataCloneError');
};

exports.InUseAttributeError = () => {
throw new DOMException('The attribute is already in use', 'InUseAttributeError');
};

exports.nyi = function () {
throw new Error('NotYetImplemented');
};

exports.shouldOverride = function () {
throw new Error('Abstract function; should be overriding in subclass.');
};

exports.assert = function (expr, msg) {
if (!expr) {
throw new Error("Assertion failed: " + (msg || "") + "\n" + new Error().stack);
throw new Error('Assertion failed: ' + (msg || '') + '\n' + new Error().stack);
}
};

exports.expose = function(src, c) {
exports.expose = function (src, c) {
for (var n in src) {
Object.defineProperty(c.prototype, n, { value: src[n], writable: isApiWritable });
Object.defineProperty(c.prototype, n, {
value: src[n],
writable: isApiWritable,
});
}
};

exports.merge = function(a, b) {
exports.merge = function (a, b) {
for (var n in b) {
a[n] = b[n];
}
Expand All @@ -67,19 +140,19 @@ exports.merge = function(a, b) {
// to be passed to sort(). Assumes that the array being sorted does not
// contain duplicates. And that all nodes are connected and comparable.
// Clever code by ppk via jeresig.
exports.documentOrder = function(n,m) {
exports.documentOrder = function (n, m) {
/* jshint bitwise: false */
return 3 - (n.compareDocumentPosition(m) & 6);
};

exports.toASCIILowerCase = function(s) {
return s.replace(/[A-Z]+/g, function(c) {
exports.toASCIILowerCase = function (s) {
return s.replace(/[A-Z]+/g, function (c) {
return c.toLowerCase();
});
};

exports.toASCIIUpperCase = function(s) {
return s.replace(/[a-z]+/g, function(c) {
exports.toASCIIUpperCase = function (s) {
return s.replace(/[a-z]+/g, function (c) {
return c.toUpperCase();
});
};
2 changes: 1 addition & 1 deletion test/xss.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let browser;
let incognito;

exports.before = async function() {
browser = await puppeteer.launch({headless:"new"});
browser = await puppeteer.launch({headless:"new", args: ['--no-sandbox', '--disable-gpu']});
incognito = await browser.createIncognitoBrowserContext();
}

Expand Down