1 |
3a515b92
|
cagy
|
'use strict';
|
2 |
|
|
|
3 |
|
|
var GetIntrinsic = require('../GetIntrinsic');
|
4 |
|
|
|
5 |
|
|
var hasSymbols = require('has-symbols')();
|
6 |
|
|
|
7 |
|
|
var $TypeError = GetIntrinsic('%TypeError%');
|
8 |
|
|
|
9 |
|
|
var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%');
|
10 |
|
|
var $gOPS = hasSymbols && GetIntrinsic('%Object.getOwnPropertySymbols%');
|
11 |
|
|
var keys = require('object-keys');
|
12 |
|
|
|
13 |
|
|
var esType = require('./Type');
|
14 |
|
|
|
15 |
|
|
// https://www.ecma-international.org/ecma-262/6.0/#sec-getownpropertykeys
|
16 |
|
|
|
17 |
|
|
module.exports = function GetOwnPropertyKeys(O, Type) {
|
18 |
|
|
if (esType(O) !== 'Object') {
|
19 |
|
|
throw new $TypeError('Assertion failed: Type(O) is not Object');
|
20 |
|
|
}
|
21 |
|
|
if (Type === 'Symbol') {
|
22 |
|
|
return $gOPS ? $gOPS(O) : [];
|
23 |
|
|
}
|
24 |
|
|
if (Type === 'String') {
|
25 |
|
|
if (!$gOPN) {
|
26 |
|
|
return keys(O);
|
27 |
|
|
}
|
28 |
|
|
return $gOPN(O);
|
29 |
|
|
}
|
30 |
|
|
throw new $TypeError('Assertion failed: `Type` must be `"String"` or `"Symbol"`');
|
31 |
|
|
};
|