| 1 |
// TODO(Babel 8): Remove this file. |
| 2 |
// We run these tests as far back as Node 6, so we need these there. |
| 3 |
|
| 4 |
if (!Object.entries) { |
| 5 |
Object.entries = object => Object.keys(object).map(key => [key, object[key]]); |
| 6 |
} |
| 7 |
|
| 8 |
// From: https://github.com/tc39/proposal-object-from-entries/blob/main/polyfill.js |
| 9 |
if (!Object.fromEntries) { |
| 10 |
Object.fromEntries = function (entries) { |
| 11 |
const obj = {}; |
| 12 |
|
| 13 |
for (const pair of entries) { |
| 14 |
if (Object(pair) !== pair) { |
| 15 |
throw new TypeError("iterable for fromEntries should yield objects"); |
| 16 |
} |
| 17 |
|
| 18 |
// Consistency with Map: contract is that entry has "0" and "1" keys, not |
| 19 |
// that it is an array or iterable. |
| 20 |
|
| 21 |
const { 0: key, 1: val } = pair; |
| 22 |
|
| 23 |
Object.defineProperty(obj, key, { |
| 24 |
configurable: true, |
| 25 |
enumerable: true, |
| 26 |
writable: true, |
| 27 |
value: val, |
| 28 |
}); |
| 29 |
} |
| 30 |
|
| 31 |
return obj; |
| 32 |
}; |
| 33 |
} |