-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
When Object.prototype
is polluted, polyfilling can fail
#973
Comments
Could you create a reproducible example for understanding with which subset of the problem we are dealing? |
Sure, for a quick example of something we've actually run into: // third party script does a polyfill like so
Object.defineProperty(Object.prototype, 'includes', {
configurable: false,
writable: false,
value: function(i) { return this.indexOf(i) != -1; }
}); // core-js now does this:
'use strict';
const path = {};
path['String'] = {}
path['String'].includes = () => 'new function';
// ^ Throws: Uncaught TypeError: Cannot assign to read only property 'includes' of object '<Object>' Here's an example of a commit that fixes the error: activeprospect@ef571d6. Note, though, it checks for |
I'm not sure should such workaround be added on the |
I'll add a workaround, but in a little different way. |
Awesome, thanks! I appreciate the help! |
When working on a library that is run on sites with other scripts, we ran into an issue where, while trying to avoid global pollution, we found ourselves polluted by another script.
In essence, another script had modified
Object.prototype
and had defined a propertyincludes
that was not configurable on all new objects. This threw an error for us while trying to polyfill[].includes
.A quick and dirty solution was to replace some references of {} in
core-js/packages/core-js-pure/override/internals/export.js
toObject.create(null)
.I'm trying to submit a proper PR to fix this, but was wondering, is there a proper way to use a polyfill inside this export file?
The text was updated successfully, but these errors were encountered: