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

Missing ES6 methods which were optional in ES5 #336

Closed
chocolateboy opened this issue Sep 19, 2017 · 1 comment
Closed

Missing ES6 methods which were optional in ES5 #336

chocolateboy opened this issue Sep 19, 2017 · 1 comment
Labels

Comments

@chocolateboy
Copy link

chocolateboy commented Sep 19, 2017

💡 Some implementations of ECMAScript have included additional properties for some of the standard native objects. This non-normative annex suggests uniform semantics for such properties without making the properties or their semantics part of this standard. -- ECMA-262 Edition 5.1 / Annex B / B.2 Additional Properties

String.prototype.substr is optional in ES3 and ES5 but required in ES6. While all browsers appear to have implemented it before the semantics became normative — incorrectly in at least some version(s) of IE — its optional status is not just hypothetical. It's behind a build-time flag in Duktape and missing from e.g. MuJS:

The scripting backend which mpv currently uses is MuJS - a compatible minimal ES5 interpreter. As such, String.substring is implemented for instance, while the common but non-standard String.substr is not. -- mpv manual

Other missing methods that are optional in ES5 and required in ES6 include:

  • global.escape
  • global.unescape
  • Date.prototype.getYear
  • Date.prototype.setYear
  • Date.prototype.toGMTString
@loganfsmyth
Copy link
Contributor

optional in ES3 and ES5 but required in ES6

I feel like this varies depending on how you look at it. These are all defined in Annex B, https://www.ecma-international.org/ecma-262/8.0/#sec-additional-ecmascript-features-for-web-browsers, which says

The ECMAScript language syntax and semantics defined in this annex are required when the ECMAScript host is a web browser. The content of this annex is normative but optional if the ECMAScript host is not a web browser.

You specifically mention DukTape and MuJS, but these seem perfectly spec compliant to me because they are indeed not "web browser" environments.

So the question is, is it core-js's job to polyfill things that are not required in all ES6 environments. core-js is also used in many non-browser contexts, and it has no 100%-guaranteed way to know whether something is a browser. I could see an argument that these could be implemented as an optional opt-in alongside the normal core-js entry points, but on the other hand the fact that these are optional in some environments means that they should essentially never be used in any code written today.

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

No branches or pull requests

3 participants