jsdom v6.0.0 Release Notes
-
🚀 This major release is focused on massive improvements in speed, URL parsing, and error handling. The potential breaking changes are highlighted in bold below; the largest ones are around the
jsdom.env
error-handling paradigm.🚀 This release also welcomes long-time contributer @Joris-van-der-Wel to the core team. You may recognize him from earlier changelogs. We're very happy to have his help in making jsdom awesome!
- io.js 2.0 onward is now required, as we have begun using ES2015 features only present there.
- 👌 Improved performance dramatically, by ~10000x in some cases, due to the following changes:
- Overhauled the named properties tracker to not walk the entire tree, thus greatly speeding up the setting of
id
andname
attributes (including during parsing). - Overhauled everything dealing with tree traversal to use a new library, symbol-tree, to turn many operations that were previously O(n2) or O(n) into O(n) or O(1).
- Sped up
node.compareDocumentPosition
and anything that used it (likenode.contains
) by doing more intelligent tree traversal instead of directly implementing the specced algorithm.
- Overhauled the named properties tracker to not walk the entire tree, thus greatly speeding up the setting of
- Overhauled how error handling works in jsdom:
window.onerror
(orwindow.addEventListener("error", ...)
) now work, and will catch all script errors, similar to in browsers. This also introduces theErrorEvent
class, incidentally.- The virtual console is now the destination for several types of errors from jsdom, using the new event
"jsdomError"
. This includes: errors loading external resources; script execution errors unhandled bywindow.onerror
; and not-implemented warnings resulting from calling methods likewindow.alert
which jsdom explicitly does not support. - Since script errors are now handled by
window.onerror
and the virtual console, they are no longer included in the initialization process. This results in two changes tojsdom.env
and the initialization lifecycle: - The
load(errors, window)
callback was changed toonload(window)
, to reflect that it is now just sugar for setting awindow.onload
handler. - The
done(errors, window)
callback (i.e., the default callback forjsdom.env
) has becomedone(error, window)
, and like every other io.js callback now simply gives you a single error object, instead of an array of them. - Nodes no longer have a nonstandard
errors
array, or araise
method used to put things in that array.
- 📜 URL parsing and resolution was entirely overhauled to follow the URL standard!
- This fixes several long-standing bugs and hacks in the jsdom URL parser, which already had a mess of gross patches on top of the built-in io.js parser to be more web-compatible.
- The new
URL
class has been added towindow
- The interfaces for
HTMLAnchorElement.prototype
anddocument.location
(as well asURL
, of course) are now uniformized to follow theURLUtils
API (minussearchParams
for now). - As part of this change, you may need to start passing in
file:
URLs tojsdom.env
where previously you were able to get away with passing in filenames.
- ➕ Added the
XMLHttpRequest.prototype.response
getter. - 🛠 Fixed
StyleSheetList.prototype.item
to actually work. (chad3814) - 🛠 Fixed the browser
vm
shim to properly add the built-in global properties (Object
,Array
, etc.) to the sandbox. If you were running jsdom inside a web worker and most of your scripts were broken, this should fix that. - 🛠 Fixed the
hashchange
event to correctly fireHashChangeEvent
instances, with correct propertiesnewURL
andoldURL
(instead of the incorrectnewUrl
andoldUrl
used previously). - ✂ Removed usage of the setimmediate library, as it required
eval
and thus did not work in CSP scenarios.
Finally, if you're a loyal jsdom fan whose made it this far into the changelog, I'd urge you to come join us in #1139, where we are brainstorming a modernized jsdom API that could get rid of many of the warts in the current one.