diff --git a/CHANGELOG.md b/CHANGELOG.md index 68f5c1dca6ec..14f6b7563040 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/packages/core-js/internals/object-to-array.js b/packages/core-js/internals/object-to-array.js index b280010e370d..b7c1181b84b6 100644 --- a/packages/core-js/internals/object-to-array.js +++ b/packages/core-js/internals/object-to-array.js @@ -1,5 +1,7 @@ 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; @@ -7,18 +9,28 @@ var $propertyIsEnumerable = require('../internals/object-property-is-enumerable' 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]); } }