Skip to content

Commit c22285c

Browse files
committed
add a workaround in Object.{ entries, values } for some IE versions bug with invisible integer keys on null-prototype objects
1 parent 38592f4 commit c22285c

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
- Fixed some cases of increasing buffer size in `ArrayBuffer.prototype.{ transfer, transferToFixedLength }` polyfills
2929
- Fixed awaiting async `AsyncDisposableStack.prototype.adopt` callback, [#1258](https://github.com/zloirock/core-js/issues/1258)
3030
- Fixed `URLSearchParams#size` in ES3 engines (IE8-)
31+
- Added a workaround in `Object.{ entries, values }` for some IE versions bug with invisible integer keys on `null`-prototype objects
3132
- Added TypeScript definitions to `core-js-compat`, [#1235](https://github.com/zloirock/core-js/issues/1235), thanks [@susnux](https://github.com/susnux)
3233
- Compat data improvements:
3334
- [`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

packages/core-js/internals/object-to-array.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
11
var DESCRIPTORS = require('../internals/descriptors');
2+
var fails = require('../internals/fails');
23
var uncurryThis = require('../internals/function-uncurry-this');
4+
var objectGetPrototypeOf = require('../internals/object-get-prototype-of');
35
var objectKeys = require('../internals/object-keys');
46
var toIndexedObject = require('../internals/to-indexed-object');
57
var $propertyIsEnumerable = require('../internals/object-property-is-enumerable').f;
68

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

12+
// in some IE versions, `propertyIsEnumerable` returns incorrect result on integer keys
13+
// of `null` prototype objects
14+
var IE_BUG = fails(function () {
15+
// eslint-disable-next-line es/no-object-create -- safe
16+
var O = Object.create(null);
17+
O[2] = 2;
18+
return !propertyIsEnumerable(O, 2);
19+
});
20+
1021
// `Object.{ entries, values }` methods implementation
1122
var createMethod = function (TO_ENTRIES) {
1223
return function (it) {
1324
var O = toIndexedObject(it);
1425
var keys = objectKeys(O);
26+
var IE_WORKAROUND = IE_BUG && objectGetPrototypeOf(O) === null;
1527
var length = keys.length;
1628
var i = 0;
1729
var result = [];
1830
var key;
1931
while (length > i) {
2032
key = keys[i++];
21-
if (!DESCRIPTORS || propertyIsEnumerable(O, key)) {
33+
if (!DESCRIPTORS || (IE_WORKAROUND ? key in O : propertyIsEnumerable(O, key))) {
2234
push(result, TO_ENTRIES ? [key, O[key]] : O[key]);
2335
}
2436
}

0 commit comments

Comments
 (0)