browser-env icon indicating copy to clipboard operation
browser-env copied to clipboard

TypeError: Cannot redefine property: Infinity

Open niftylettuce opened this issue 5 years ago • 3 comments

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)

niftylettuce avatar Jun 17 '19 06:06 niftylettuce

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.

lukechilds avatar Jun 17 '19 08:06 lukechilds

Hi @lukechilds could you merge my last pull request?

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

bitliner avatar Feb 02 '20 00:02 bitliner

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.

OktarinTentakel avatar Dec 02 '21 13:12 OktarinTentakel