Socket
Socket
Sign inDemoInstall

jsdom

Package Overview
Dependencies
Maintainers
6
Versions
264
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsdom - npm Package Compare versions

Comparing version 19.0.0 to 20.0.0

lib/jsdom/living/crypto/Crypto-impl.js

38

lib/jsdom/browser/parser/html.js

@@ -21,29 +21,3 @@ "use strict";

// Horrible monkey-patch to implement https://github.com/inikulin/parse5/issues/237 and
// https://github.com/inikulin/parse5/issues/285.
const OpenElementStack = require("parse5/lib/parser/open-element-stack");
const openElementStackOriginalPush = OpenElementStack.prototype.push;
OpenElementStack.prototype.push = function (...args) {
openElementStackOriginalPush.apply(this, args);
this.treeAdapter._currentElement = this.current;
const after = this.items[this.stackTop];
if (after._pushedOnStackOfOpenElements) {
after._pushedOnStackOfOpenElements();
}
};
const openElementStackOriginalPop = OpenElementStack.prototype.pop;
OpenElementStack.prototype.pop = function (...args) {
const before = this.items[this.stackTop];
openElementStackOriginalPop.apply(this, args);
this.treeAdapter._currentElement = this.current;
if (before._poppedOffStackOfOpenElements) {
before._poppedOffStackOfOpenElements();
}
};
class JSDOMParse5Adapter {

@@ -56,3 +30,3 @@ constructor(documentImpl, options = {}) {

// Since the createElement hook doesn't provide the parent element, we keep track of this using _currentElement:
// https://github.com/inikulin/parse5/issues/285. See above horrible monkey-patch for how this is maintained.
// https://github.com/inikulin/parse5/issues/285.
this._currentElement = undefined;

@@ -195,2 +169,12 @@ }

}
onItemPush(after) {
this._currentElement = after;
after._pushedOnStackOfOpenElements?.();
}
onItemPop(before, newTop) {
this._currentElement = newTop;
before._poppedOffStackOfOpenElements?.();
}
}

@@ -197,0 +181,0 @@

@@ -28,2 +28,3 @@ "use strict";

const Screen = require("../living/generated/Screen");
const Crypto = require("../living/generated/Crypto");
const Storage = require("../living/generated/Storage");

@@ -343,2 +344,3 @@ const Selection = require("../living/generated/Selection");

const screen = Screen.create(window);
const crypto = Crypto.create(window);
const customElementRegistry = CustomElementRegistry.create(window);

@@ -407,2 +409,5 @@

},
get crypto() {
return crypto;
},
get origin() {

@@ -409,0 +414,0 @@ return window._origin;

@@ -14,2 +14,3 @@ "use strict";

return fragmentSerialization(this, {
outer: false,
requireWellFormed: true,

@@ -16,0 +17,0 @@ globalObject: this._globalObject

@@ -9,3 +9,3 @@ "use strict";

exports.getChildNodes = node => node.childNodesForSerializing || domSymbolTree.childrenToArray(node);
exports.getChildNodes = node => domSymbolTree.childrenToArray(node);

@@ -12,0 +12,0 @@ exports.getParentNode = node => node.parentNode;

@@ -10,24 +10,15 @@ "use strict";

const NODE_TYPE = require("../node-type");
const NAMESPACES = require("../helpers/namespaces");
function htmlSerialization(node) {
if (
node.nodeType === NODE_TYPE.ELEMENT_NODE &&
node.namespaceURI === NAMESPACES.HTML_NS &&
node.tagName === "TEMPLATE"
) {
node = node.content;
}
return parse5.serialize(node, { treeAdapter });
}
module.exports.fragmentSerialization = (node, { requireWellFormed, globalObject }) => {
module.exports.fragmentSerialization = (node, { outer, requireWellFormed, globalObject }) => {
const contextDocument =
node.nodeType === NODE_TYPE.DOCUMENT_NODE ? node : node._ownerDocument;
if (contextDocument._parsingMode === "html") {
return htmlSerialization(node);
const config = {
...contextDocument._parseOptions,
treeAdapter
};
return outer ? parse5.serializeOuter(node, config) : parse5.serialize(node, config);
}
const childNodes = node.childNodesForSerializing || node.childNodes;
const childNodes = outer ? [node] : node.childNodes;

@@ -34,0 +25,0 @@ try {

@@ -30,2 +30,6 @@ "use strict";

if (options.signal !== null && options.signal.aborted) {
return;
}
if (callback === null) {

@@ -53,2 +57,8 @@ return;

});
if (options.signal !== null) {
options.signal._addAlgorithm(() => {
this.removeEventListener(type, callback, options);
});
}
}

@@ -371,3 +381,3 @@

function normalizeEventHandlerOptions(options, defaultBoolKeys) {
const returnValue = {};
const returnValue = { signal: null };

@@ -391,2 +401,6 @@ // no need to go further here

if (options.signal !== undefined) {
returnValue.signal = options.signal;
}
return returnValue;

@@ -393,0 +407,0 @@ }

@@ -6,2 +6,3 @@ "use strict";

const AbortSignal = require("./AbortSignal.js");
const EventListenerOptions = require("./EventListenerOptions.js");

@@ -35,2 +36,12 @@

}
{
const key = "signal";
let value = obj === undefined || obj === null ? undefined : obj[key];
if (value !== undefined) {
value = AbortSignal.convert(globalObject, value, { context: context + " has member 'signal' that" });
ret[key] = value;
}
}
};

@@ -37,0 +48,0 @@

@@ -11,3 +11,3 @@ "use strict";

return nwsapi({
document: _ownerDocument,
document: idlUtils.wrapperForImpl(_ownerDocument),
DOMException: _globalObject.DOMException

@@ -14,0 +14,0 @@ });

@@ -34,2 +34,3 @@ /* eslint-disable global-require */

NodeList: require("./generated/NodeList"),
RadioNodeList: require("./generated/RadioNodeList"),
HTMLCollection: require("./generated/HTMLCollection"),

@@ -113,2 +114,3 @@ HTMLOptionsCollection: require("./generated/HTMLOptionsCollection"),

HTMLTrackElement: require("./generated/HTMLTrackElement.js"),
HTMLFormControlsCollection: require("./generated/HTMLFormControlsCollection.js"),

@@ -151,2 +153,4 @@ SVGElement: require("./generated/SVGElement.js"),

Crypto: require("./generated/Crypto"),
PluginArray: require("./generated/PluginArray"),

@@ -153,0 +157,0 @@ MimeTypeArray: require("./generated/MimeTypeArray"),

@@ -8,3 +8,3 @@ "use strict";

const NODE_TYPE = require("../node-type");
const { hasWeakRefs, mixin, memoizeQuery } = require("../../utils");
const { mixin, memoizeQuery } = require("../../utils");
const { firstChildWithLocalName, firstChildWithLocalNames, firstDescendantWithLocalName } =

@@ -178,7 +178,3 @@ require("../helpers/traversal");

if (hasWeakRefs) {
this._workingNodeIterators = new IterableWeakSet();
} else {
this._workingNodeIterators = [];
}
this._workingNodeIterators = new IterableWeakSet();

@@ -780,13 +776,3 @@ this._referrer = privateData.options.referrer || "";

const nodeIterator = NodeIterator.createImpl(this._globalObject, [], { root, whatToShow, filter });
if (hasWeakRefs) {
this._workingNodeIterators.add(nodeIterator);
} else {
this._workingNodeIterators.push(nodeIterator);
while (this._workingNodeIterators.length > 10) {
const toInactivate = this._workingNodeIterators.shift();
toInactivate._working = false;
}
}
this._workingNodeIterators.add(nodeIterator);
return nodeIterator;

@@ -793,0 +779,0 @@ }

@@ -162,8 +162,4 @@ "use strict";

get outerHTML() {
// TODO: maybe parse5 can give us a hook where it serializes the node itself too:
// https://github.com/inikulin/parse5/issues/230
// Alternatively, if we can create a virtual node in domSymbolTree, that'd also work.
// It's currently prevented by the fact that a node can't be duplicated in the same tree.
// Then we could get rid of all the code for childNodesForSerializing.
return fragmentSerialization({ childNodesForSerializing: [this], _ownerDocument: this._ownerDocument }, {
return fragmentSerialization(this, {
outer: true,
requireWellFormed: true,

@@ -170,0 +166,0 @@ globalObject: this._globalObject

@@ -9,3 +9,3 @@ "use strict";

const { formOwner, isListed, isSubmittable, isSubmitButton } = require("../helpers/form-controls");
const HTMLCollection = require("../generated/HTMLCollection");
const HTMLFormControlsCollection = require("../generated/HTMLFormControlsCollection");
const notImplemented = require("../../browser/not-implemented");

@@ -65,4 +65,3 @@ const { parseURLToResultingURLRecord } = require("../helpers/document-base-url");

get elements() {
// TODO: Return a HTMLFormControlsCollection
return HTMLCollection.createImpl(this._globalObject, [], {
return HTMLFormControlsCollection.createImpl(this._globalObject, [], {
element: this.getRootNode({}),

@@ -69,0 +68,0 @@ query: () => this._getElementNodes()

@@ -150,3 +150,3 @@ "use strict";

if (url === null || url.host === null || url.host === "" || url.cannotBeABaseURL || url.scheme === "file") {
if (url === null || whatwgURL.cannotHaveAUsernamePasswordPort(url)) {
return;

@@ -174,3 +174,3 @@ }

if (url === null || url.host === null || url.host === "" || url.cannotBeABaseURL || url.scheme === "file") {
if (url === null || whatwgURL.cannotHaveAUsernamePasswordPort(url)) {
return;

@@ -202,3 +202,3 @@ }

if (url === null || url.cannotBeABaseURL) {
if (url === null || whatwgURL.hasAnOpaquePath(url)) {
return;

@@ -226,3 +226,3 @@ }

if (url === null || url.cannotBeABaseURL) {
if (url === null || whatwgURL.hasAnOpaquePath(url)) {
return;

@@ -250,3 +250,3 @@ }

if (url === null || url.host === null || url.host === "" || url.cannotBeABaseURL || url.scheme === "file") {
if (url === null || whatwgURL.cannotHaveAUsernamePasswordPort(url)) {
return;

@@ -271,7 +271,3 @@ }

if (url.cannotBeABaseURL) {
return url.path[0];
}
return "/" + url.path.join("/");
return whatwgURL.serializePath(url);
}

@@ -283,3 +279,3 @@

if (url === null || url.cannotBeABaseURL) {
if (url === null || whatwgURL.hasAnOpaquePath(url)) {
return;

@@ -357,3 +353,3 @@ }

function reinitializeURL(hheu) {
if (hheu.url !== null && hheu.url.scheme === "blob" && hheu.url.cannotBeABaseURL) {
if (hheu.url !== null && hheu.url.scheme === "blob" && whatwgURL.hasAnOpaquePath(hheu.url)) {
return;

@@ -360,0 +356,0 @@ }

"use strict";
const { hasWeakRefs } = require("../../utils");
const { domSymbolTree } = require("../helpers/internal-constants");

@@ -16,9 +15,2 @@ const { filter, FILTER_ACCEPT } = require("./helpers");

// This is used to deactivate the NodeIterator if there are too many working in a Document at the same time.
// Without weak references, a JS implementation of NodeIterator will leak, since we can't know when to clean it up.
// This ensures we force a clean up of those beyond some maximum (specified by the Document).
if (!hasWeakRefs) {
this._working = true;
}
this._globalObject = globalObject;

@@ -28,3 +20,2 @@ }

get referenceNode() {
this._throwIfNotWorking();
return this._referenceNode;

@@ -34,3 +25,2 @@ }

get pointerBeforeReferenceNode() {
this._throwIfNotWorking();
return this._pointerBeforeReferenceNode;

@@ -40,3 +30,2 @@ }

nextNode() {
this._throwIfNotWorking();
return this._traverse("next");

@@ -46,3 +35,2 @@ }

previousNode() {
this._throwIfNotWorking();
return this._traverse("previous");

@@ -87,10 +75,2 @@ }

// Only called by getters and methods that are affected by the pre-removing steps
_throwIfNotWorking() {
if (!hasWeakRefs && !this._working) {
throw Error(`This NodeIterator is no longer working. More than 10 iterators are being used concurrently. ` +
`Using more than 10 node iterators requires WeakRef support.`);
}
}
_traverse(direction) {

@@ -97,0 +77,0 @@ let node = this._referenceNode;

@@ -7,4 +7,2 @@ "use strict";

exports.hasWeakRefs = typeof WeakRef === "function";
exports.toFileUrl = function (fileName) {

@@ -11,0 +9,0 @@ // Beyond just the `path.resolve`, this is mostly for the benefit of Windows,

{
"name": "jsdom",
"version": "19.0.0",
"version": "20.0.0",
"description": "A JavaScript implementation of many web standards",

@@ -23,8 +23,8 @@ "keywords": [

"dependencies": {
"abab": "^2.0.5",
"acorn": "^8.5.0",
"abab": "^2.0.6",
"acorn": "^8.7.1",
"acorn-globals": "^6.0.0",
"cssom": "^0.5.0",
"cssstyle": "^2.3.0",
"data-urls": "^3.0.1",
"data-urls": "^3.0.2",
"decimal.js": "^10.3.1",

@@ -36,7 +36,7 @@ "domexception": "^4.0.0",

"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.1",
"is-potential-custom-element-name": "^1.0.1",
"nwsapi": "^2.2.0",
"parse5": "6.0.1",
"saxes": "^5.0.1",
"parse5": "^7.0.0",
"saxes": "^6.0.0",
"symbol-tree": "^3.2.4",

@@ -49,4 +49,4 @@ "tough-cookie": "^4.0.0",

"whatwg-mimetype": "^3.0.0",
"whatwg-url": "^10.0.0",
"ws": "^8.2.3",
"whatwg-url": "^11.0.0",
"ws": "^8.8.0",
"xml-name-validator": "^4.0.0"

@@ -66,17 +66,17 @@ },

"devDependencies": {
"@domenic/eslint-config": "^1.4.0",
"@domenic/eslint-config": "^2.0.0",
"benchmark": "^2.1.4",
"browserify": "^17.0.0",
"chai": "^4.3.4",
"eslint": "^7.32.0",
"chai": "^4.3.6",
"eslint": "^8.17.0",
"eslint-plugin-html": "^6.2.0",
"eslint-plugin-jsdom-internal": "link:./scripts/eslint-plugin",
"js-yaml": "^4.1.0",
"karma": "^6.3.4",
"karma": "^6.3.20",
"karma-browserify": "^8.1.0",
"karma-chrome-launcher": "^3.1.0",
"karma-chrome-launcher": "^3.1.1",
"karma-mocha": "^2.0.1",
"karma-mocha-webworker": "^1.3.0",
"minimatch": "^3.0.4",
"mocha": "^9.1.2",
"minimatch": "^5.1.0",
"mocha": "^10.0.0",
"mocha-sugar-free": "^1.4.0",

@@ -87,4 +87,4 @@ "pngjs": "^6.0.0",

"watchify": "^4.0.0",
"webidl2js": "^17.0.0",
"yargs": "^17.2.1"
"webidl2js": "^17.1.0",
"yargs": "^17.5.1"
},

@@ -119,4 +119,4 @@ "browser": {

"engines": {
"node": ">=12"
"node": ">=14"
}
}

@@ -8,3 +8,3 @@ <h1 align="center">

The latest versions of jsdom require Node.js v12 or newer. (Versions of jsdom below v17 still work with previous Node.js versions, but are unsupported.)
The latest versions of jsdom require Node.js v14 or newer. (Versions of jsdom below v20 still work with previous Node.js versions, but are unsupported.)

@@ -456,3 +456,3 @@ ## Basic usage

jsdom's primary target is still Node.js, and so we use language features that are only present in recent Node.js versions (namely, Node.js v8+). Thus, older browsers will likely not work. (Even transpilation will not help: we use `Proxy`s extensively throughout the jsdom codebase.)
jsdom's primary target is still Node.js, and so we use language features that are only present in recent Node.js versions. Thus, older browsers will likely not work. (Even transpilation will not help: we use `Proxy`s extensively throughout the jsdom codebase.)

@@ -463,5 +463,5 @@ Notably, jsdom works well inside a web worker. The original contributor, [@lawnsea](https://github.com/lawnsea/), who made this possible, has [published a paper](https://pdfs.semanticscholar.org/47f0/6bb6607a975500a30e9e52d7c9fbc0034e27.pdf) about his project which uses this capability.

### Debugging the DOM using Chrome Devtools
### Debugging the DOM using Chrome DevTools
As of Node.js v6 you can debug programs using Chrome Devtools. See the [official documentation](https://nodejs.org/en/docs/inspector/) for how to get started.
In Node.js you can debug programs using Chrome DevTools. See the [official documentation](https://nodejs.org/en/docs/inspector/) for how to get started.

@@ -468,0 +468,0 @@ By default jsdom elements are formatted as plain old JS objects in the console. To make it easier to debug, you can use [jsdom-devtools-formatter](https://github.com/viddo/jsdom-devtools-formatter), which lets you inspect them like real DOM elements.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc