1
|
'use strict';
|
2
|
|
3
|
var GetIntrinsic = require('../GetIntrinsic');
|
4
|
|
5
|
var $TypeError = GetIntrinsic('%TypeError%');
|
6
|
|
7
|
var objectKeys = require('object-keys');
|
8
|
|
9
|
var callBound = require('../helpers/callBound');
|
10
|
|
11
|
var callBind = require('../helpers/callBind');
|
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://www.ecma-international.org/ecma-262/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
|
};
|