Remove dependance on global window and document (#2897)

* Remove dependance on global window and document

* Use any available document, prioritising parent.ownerDocument

* Fix mockDom for DocumentFragment, revert to better ownerDocument implementation

* Simplify activeElement usage
This commit is contained in:
Kory Nunn 2024-07-30 01:26:51 +10:00 committed by Claudia Meadows
parent 5488953436
commit 8e7ef427e0
No known key found for this signature in database
GPG key ID: C86B594396786760
2 changed files with 22 additions and 17 deletions

View file

@ -307,6 +307,7 @@ module.exports = function(options) {
parentNode: null,
childNodes: [],
attributes: {},
ownerDocument: $window.document,
contains: function(child) {
while (child != null) {
if (child === this) return true
@ -717,6 +718,7 @@ module.exports = function(options) {
},
createDocumentFragment: function() {
return {
ownerDocument: $window.document,
nodeType: 11,
nodeName: "#document-fragment",
appendChild: appendChild,
@ -738,6 +740,7 @@ module.exports = function(options) {
get activeElement() {return activeElement},
},
}
$window.document.defaultView = $window
$window.document.documentElement = $window.document.createElement("html")
appendChild.call($window.document.documentElement, $window.document.createElement("head"))
$window.document.body = $window.document.createElement("body")