2020-08-25 23:57:08 +00:00
|
|
|
'use strict';
|
|
|
|
|
2021-02-26 03:58:33 +00:00
|
|
|
var GetIntrinsic = require('get-intrinsic');
|
2020-08-25 23:57:08 +00:00
|
|
|
|
|
|
|
var hasSymbols = require('has-symbols')();
|
|
|
|
|
|
|
|
var $TypeError = GetIntrinsic('%TypeError%');
|
|
|
|
|
2022-11-10 10:43:16 +00:00
|
|
|
var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%', true);
|
|
|
|
var $gOPS = hasSymbols && GetIntrinsic('%Object.getOwnPropertySymbols%', true);
|
2020-08-25 23:57:08 +00:00
|
|
|
var keys = require('object-keys');
|
|
|
|
|
|
|
|
var esType = require('./Type');
|
|
|
|
|
2021-02-26 03:58:33 +00:00
|
|
|
// https://ecma-international.org/ecma-262/6.0/#sec-getownpropertykeys
|
2020-08-25 23:57:08 +00:00
|
|
|
|
|
|
|
module.exports = function GetOwnPropertyKeys(O, Type) {
|
|
|
|
if (esType(O) !== 'Object') {
|
|
|
|
throw new $TypeError('Assertion failed: Type(O) is not Object');
|
|
|
|
}
|
|
|
|
if (Type === 'Symbol') {
|
|
|
|
return $gOPS ? $gOPS(O) : [];
|
|
|
|
}
|
|
|
|
if (Type === 'String') {
|
|
|
|
if (!$gOPN) {
|
|
|
|
return keys(O);
|
|
|
|
}
|
|
|
|
return $gOPN(O);
|
|
|
|
}
|
|
|
|
throw new $TypeError('Assertion failed: `Type` must be `"String"` or `"Symbol"`');
|
|
|
|
};
|