zloirock / core-js

Standard Library
MIT License
24.61k stars 1.66k forks source link

Uncaught TypeError: Cannot define property iterateEntries, object is not extensible #1321

Closed tmackay-cenet closed 10 months ago

tmackay-cenet commented 10 months ago

I've come across a browser environment where the built-in Object() is not extensible (MS Remote Help client using WebView2).

This leads to the following error (when logging in using Okta Signin Widget v7, standard CDN bundle) define-built-in.js:20 Uncaught TypeError: Cannot define property iterateEntries, object is not extensible

Similarly, the following modules attempt to extend target 'Object' and subsequently define-built-in.js does not check Object.isExtensible() before attempting to extend.

esnext.object.iterate-entries.js esnext.object.iterate-keys.js esnext.object.iterate-values.js

Granted Okta probably doesn't need to include these modules but the implementation could be made a little more robust and not prevent further execution with an unhandled error in similar cases by the addition of this check.

zloirock commented 10 months ago

Non-extensible Object is a case of a broken environment, so it's not a core-js issue. Obviously, polyfills can't work in this case. If a polyfill can't be defined, an error should be thrown - silent errors are a bad practice. If for some reason you want to freeze / prevent the extension of JS built-ins, you should apply polyfills before that.