Skip to content

Commit

Permalink
Fix Node v10 and Node v11 support
Browse files Browse the repository at this point in the history
Closes #2795.
  • Loading branch information
domenic committed Jan 20, 2020
1 parent 16c9856 commit 6472db4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/jsdom/browser/Window.js
Expand Up @@ -37,21 +37,23 @@ const WindowEventHandlersImpl = require("../living/nodes/WindowEventHandlers-imp
module.exports = Window;
const { installInterfaces } = require("../living/interfaces");

const jsGlobalEntriesToInstall = Object.entries(jsGlobals).filter(([name]) => name in global);

// https://html.spec.whatwg.org/#the-window-object
function setupWindow(windowInstance, { runScripts }) {
if (runScripts === "outside-only" || runScripts === "dangerously") {
contextifyWindow(windowInstance);

// Without this, these globals will only appear to scripts running inside the context using vm.runScript; they will
// not appear to scripts running from the outside, including to JSDOM implementation code.
for (const [globalName, globalPropDesc] of Object.entries(jsGlobals)) {
for (const [globalName, globalPropDesc] of jsGlobalEntriesToInstall) {
const propDesc = { ...globalPropDesc, value: vm.runInContext(globalName, windowInstance) };
Object.defineProperty(windowInstance, globalName, propDesc);
}
} else {
// Without contextifying the window, none of the globals will exist. So, let's at least alias them from the Node.js
// context. See https://github.com/jsdom/jsdom/issues/2727 for more background and discussion.
for (const [globalName, globalPropDesc] of Object.entries(jsGlobals)) {
for (const [globalName, globalPropDesc] of jsGlobalEntriesToInstall) {
const propDesc = { ...globalPropDesc, value: global[globalName] };
Object.defineProperty(windowInstance, globalName, propDesc);
}
Expand Down

0 comments on commit 6472db4

Please sign in to comment.