blob: 44171b9eb4d3e152a143e3f903d572c807a72f0a [file] [log] [blame]
Tim van der Lippebc3a0b72021-11-08 15:22:371'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $TypeError = GetIntrinsic('%TypeError%');
6
7var objectKeys = require('object-keys');
8
9var callBound = require('call-bind/callBound');
10
11var callBind = require('call-bind');
12
13var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
14var $pushApply = callBind.apply(GetIntrinsic('%Array.prototype.push%'));
15
16var forEach = require('../helpers/forEach');
17
18var Type = require('./Type');
19
20// https://262.ecma-international.org/8.0/#sec-enumerableownproperties
21
22module.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};