Skip to content

Commit

Permalink
add a workaround in Object.{ entries, values } for some IE versions…
Browse files Browse the repository at this point in the history
… bug with invisible integer keys on `null`-prototype objects
  • Loading branch information
zloirock committed Jun 11, 2023
1 parent 38592f4 commit c22285c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Fixed some cases of increasing buffer size in `ArrayBuffer.prototype.{ transfer, transferToFixedLength }` polyfills
- Fixed awaiting async `AsyncDisposableStack.prototype.adopt` callback, [#1258](https://github.com/zloirock/core-js/issues/1258)
- Fixed `URLSearchParams#size` in ES3 engines (IE8-)
- Added a workaround in `Object.{ entries, values }` for some IE versions bug with invisible integer keys on `null`-prototype objects
- Added TypeScript definitions to `core-js-compat`, [#1235](https://github.com/zloirock/core-js/issues/1235), thanks [@susnux](https://github.com/susnux)
- Compat data improvements:
- [`Set.prototype.difference`](https://github.com/tc39/proposal-set-methods) that was missed in Bun because of [a bug](https://github.com/oven-sh/bun/issues/2309) added in 0.6.0
Expand Down
14 changes: 13 additions & 1 deletion packages/core-js/internals/object-to-array.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
var DESCRIPTORS = require('../internals/descriptors');
var fails = require('../internals/fails');
var uncurryThis = require('../internals/function-uncurry-this');
var objectGetPrototypeOf = require('../internals/object-get-prototype-of');
var objectKeys = require('../internals/object-keys');
var toIndexedObject = require('../internals/to-indexed-object');
var $propertyIsEnumerable = require('../internals/object-property-is-enumerable').f;

var propertyIsEnumerable = uncurryThis($propertyIsEnumerable);
var push = uncurryThis([].push);

// in some IE versions, `propertyIsEnumerable` returns incorrect result on integer keys
// of `null` prototype objects
var IE_BUG = fails(function () {
// eslint-disable-next-line es/no-object-create -- safe
var O = Object.create(null);
O[2] = 2;
return !propertyIsEnumerable(O, 2);
});

// `Object.{ entries, values }` methods implementation
var createMethod = function (TO_ENTRIES) {
return function (it) {
var O = toIndexedObject(it);
var keys = objectKeys(O);
var IE_WORKAROUND = IE_BUG && objectGetPrototypeOf(O) === null;
var length = keys.length;
var i = 0;
var result = [];
var key;
while (length > i) {
key = keys[i++];
if (!DESCRIPTORS || propertyIsEnumerable(O, key)) {
if (!DESCRIPTORS || (IE_WORKAROUND ? key in O : propertyIsEnumerable(O, key))) {
push(result, TO_ENTRIES ? [key, O[key]] : O[key]);
}
}
Expand Down

0 comments on commit c22285c

Please sign in to comment.