Tim van der Lippe | bc3a0b7 | 2021-11-08 15:22:37 | [diff] [blame] | 1 | 'use strict'; |
| 2 | |
| 3 | var GetIntrinsic = require('get-intrinsic'); |
| 4 | |
| 5 | var $TypeError = GetIntrinsic('%TypeError%'); |
| 6 | |
| 7 | var objectKeys = require('object-keys'); |
| 8 | |
| 9 | var callBound = require('call-bind/callBound'); |
| 10 | |
| 11 | var callBind = require('call-bind'); |
| 12 | |
| 13 | var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable'); |
| 14 | var $pushApply = callBind.apply(GetIntrinsic('%Array.prototype.push%')); |
| 15 | |
| 16 | var forEach = require('../helpers/forEach'); |
| 17 | |
| 18 | var Type = require('./Type'); |
| 19 | |
| 20 | // https://262.ecma-international.org/8.0/#sec-enumerableownproperties |
| 21 | |
| 22 | module.exports = function EnumerableOwnProperties(O, kind) { |
| 23 | if (Type(O) !== 'Object') { |
| 24 | throw new $TypeError('Assertion failed: Type(O) is not Object'); |
| 25 | } |
| 26 | |
| 27 | var keys = objectKeys(O); |
| 28 | if (kind === 'key') { |
| 29 | return keys; |
| 30 | } |
| 31 | if (kind === 'value' || kind === 'key+value') { |
| 32 | var results = []; |
| 33 | forEach(keys, function (key) { |
| 34 | if ($isEnumerable(O, key)) { |
| 35 | $pushApply(results, [ |
| 36 | kind === 'value' ? O[key] : [key, O[key]] |
| 37 | ]); |
| 38 | } |
| 39 | }); |
| 40 | return results; |
| 41 | } |
| 42 | throw new $TypeError('Assertion failed: "kind" is not "key", "value", or "key+value": ' + kind); |
| 43 | }; |