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

[feature-request] Object.keys should coerce primitive values in IE11 #294

Closed
neenhouse opened this issue Aug 17, 2019 · 0 comments · Fixed by #317
Closed

[feature-request] Object.keys should coerce primitive values in IE11 #294

neenhouse opened this issue Aug 17, 2019 · 0 comments · Fixed by #317

Comments

@neenhouse
Copy link
Contributor

neenhouse commented Aug 17, 2019

Overview

In IE11, running the following causes a uncontrolled exception to occur:

Object.keys(50);

This is problematic for applications written with modern JS, babel is typically used to allow statements like:

const myData = {...dataA, ...dataB}

Babel will transpile that line and implement a function called _objectSpread: https://github.com/babel/babel/blob/a112be2fa0b2abab7fd9a845b3a76b273c506449/packages/babel-helpers/src/helpers.js#L393, which implements Object.keys:

...
var ownKeys = Object.keys(source);
...

This is a highly traveled path in UI apps that implement object spread syntax (which is pretty common these days). Spreading non object type data is a pretty easy mistake to make, and modern browsers forgive.

To prevent exception in IE11 with string and number, we should use the polyfill provided from this lib which already follows the ECMA-262 ed 6 spec (http://ecma-international.org/ecma-262/6.0/index.html#sec-object.keys).

Why does this matter

Companies who are trying to optimize their polyfill payload can very likely run into this issue when they try to swap out core-js Object APIs for polyfill-library with apps that implement object spread. This issue can cause complete failure in apps and prevent adoption of polyfill-library.

Browsers impacted

  • IE11
  • Others?

I should be able to prepare a PR pretty soon to address this issue.

neenhouse added a commit to neenhouse/polyfill-library that referenced this issue Aug 17, 2019
@neenhouse neenhouse changed the title [feature-request] Object.keys should coerce non-object values in IE11 [feature-request] Object.keys should coerce primitive values in IE11 Aug 17, 2019
JakeChampion pushed a commit to neenhouse/polyfill-library that referenced this issue Aug 20, 2019
JakeChampion pushed a commit to neenhouse/polyfill-library that referenced this issue Sep 27, 2019
JakeChampion pushed a commit to neenhouse/polyfill-library that referenced this issue Feb 7, 2020
JakeChampion pushed a commit to neenhouse/polyfill-library that referenced this issue Feb 7, 2020
JakeChampion pushed a commit to neenhouse/polyfill-library that referenced this issue Feb 7, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
1 participant