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

TypeError: Cannot redefine property: Infinity #77

Open
niftylettuce opened this issue Jun 17, 2019 · 3 comments
Open

TypeError: Cannot redefine property: Infinity #77

niftylettuce opened this issue Jun 17, 2019 · 3 comments

Comments

@niftylettuce
Copy link

Setting the jsdom option of runScripts with value of 'dangerously' causes the following exception:

  TypeError: Cannot redefine property: Infinity

  Object.getOwnPropertyNames.filter.filter.forEach.prop (node_modules/browser-env/src/index.js:41:9)
  browserEnv (node_modules/browser-env/src/index.js:40:6)
  Object.browserEnv (test/browser-env.js:9:1)
@lukechilds
Copy link
Owner

Thanks for taking the time to report this but unfortunately I don't have time to look into this right now due to paid work.

PRs are very welcome.

bitliner added a commit to bitliner/browser-env that referenced this issue Feb 2, 2020
@bitliner
Copy link

bitliner commented Feb 2, 2020

Hi @lukechilds could you merge my last pull request?

If you don't have time, please assign write permissions to me.

@OktarinTentakel
Copy link

I think this is simply due to a simple bug in the index.js:

// IIFE executed on import to return an array of global Node.js properties that
// conflict with global browser properties.
const protectedproperties = (() => Object
  .getOwnPropertyNames(new Window(defaultJsdomConfig))
  .filter(prop => typeof global[prop] !== 'undefined')
)();

This works with a window object only based on the default settings, but adding a user JSDOM-config changes the window properties, which is why "Infinity" is not included in the protected properties.

I guess this should rather read:

// IIFE executed on import to return an array of global Node.js properties that
// conflict with global browser properties.
const protectedproperties = (() => Object
  .getOwnPropertyNames(new Window(Object.assign({}, userJsdomConfig, defaultJsdomConfig)))
  .filter(prop => typeof global[prop] !== 'undefined')
)();

And in this case the const needs to be placed inside "browserEnv", below the declaration of "userJsdomConfig".

You could of course also switch to a parametrized function and call that in the filter.

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

4 participants