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

Strict mode errors in file(s) which overwrite constructor #820

Closed
ckisielius opened this issue May 5, 2020 · 1 comment
Closed

Strict mode errors in file(s) which overwrite constructor #820

ckisielius opened this issue May 5, 2020 · 1 comment

Comments

@ckisielius
Copy link

There's an issue with a couple of versions of chromium (list below) browser's Map implementation. I can't reproduce the error on browserstack with an identical useragent, so I don't trust the userAgent in my logs. But I can tell from splunk logging that it's failing for them at this line:

NativePrototype.constructor = Constructor;

With this message: TypeError: Cannot modify readonly property: constructor.

My question is, what do you think about removing the "use strict" from any file which overwrites a constructor? IE11 doesn't care either way, and since isForced defaults to true core-js will inevitably see more cases like this one where it tries and fails to overwrite.

Reproduce the error by running this code (taken from the file above) in chrome or most modern browsers:

(function() {
'use strict';
 try {
   var NativeConstructor = window['Map'];
   var NativePrototype = NativeConstructor && NativeConstructor.prototype;
   var Constructor = NativeConstructor;
   Constructor.prototype = NativePrototype;
   NativePrototype.constructor = function() { }
 } catch(e) {
   console.log(e);
 }
})();

User Agents which log the error (again, I can't reproduce it but in case someone else is seeing the same thing):

"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36"

Please let me know your thoughts. Thank you so much for maintaining this repo. It makes using babel an amazing experience for those of us who still need to support IE11.

@zloirock
Copy link
Owner

Sorry, but I can't reproduce it.

Your example has a mistake:

+(function() {
+'use strict';
+ try {
+   var NativeConstructor = window['Map'];
+   var NativePrototype = NativeConstructor && NativeConstructor.prototype;
-   var Constructor = NativeConstructor;
-   Constructor.prototype = NativePrototype;
+   NativePrototype.constructor = function() { }
+ } catch(e) {
+   console.log(e);
+ }
+})();

In core-js, Constructor is just a new function and have { writable: true } prototype descriptor, but in your code, it's Map and descriptor is { writable: false }, so your example should throw an error anyway, but with another error message:

-TypeError: Cannot modify readonly property: constructor.
+TypeError: Cannot modify readonly property: prototype.

I checked this case in mentioned browsers - and they work properly, Map.prototype.constructor has { configurable: true, writable: true } descriptor and redefinition of this property can't throw an error.

This issue looks like a conflict with another, incorrect, polyfill, which set Map.prototype.constructor as non-writable like #746 or #702.

If you could add a reproducible example - please, add it here.

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

No branches or pull requests

2 participants