Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Identification of the window object with the global object #39

Open
vinci-mz opened this issue Jan 16, 2018 · 0 comments
Open

Identification of the window object with the global object #39

vinci-mz opened this issue Jan 16, 2018 · 0 comments

Comments

@vinci-mz
Copy link

vinci-mz commented Jan 16, 2018

First of all, thanks for the interesting and useful solution, which jsdom-global definitely is.
Though let me notice there is still a difference between the real browsers behavior and the environment emulated on the node using jsdom-global. In the real browser:

window.foo=1;
typeof foo; // => 'number'

Unfortunately in the emulated environment on node -r jsdom-global/register:

window.foo=1;
typeof foo; // => 'undefined'

Let me ask - is it possible to fix the above disadvantage?

I have the impression that identifing window with global seems to be easy achievable by changing in the jsdom-global/index.js only the little piece of the existing code:

  KEYS.forEach(function (key) {
    global[key] = window[key]
  })
  
  global.document = window.document  // change
  global.window = window             // change
  window.console = global.console    // change
  document.destroy = cleanup

as follows:

  KEYS.forEach(function (key) {
    global[key] = window[key]
  })
  
  global.window=global    // changed
  document.window=global  // changed
  document.destroy = cleanup

Now in the emulated environment on node -r jsdom-global/register we have

window.foo=1;
typeof foo; // => 'number'

Unfortunately it is not the correct solution - for example after the change the window.DOMParser lost, though DOMException, DOMImplementation or DOMTokenList are available as globally as well as the window members...
(I suppose the cleanup behavior may also require some tuning because after the proposed change it could be the "one way ticket")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant