blob: b8f4167f738fb8326e47360a679383a713177bd4 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var hasSymbols = require('has-symbols')();
6
7var $TypeError = GetIntrinsic('%TypeError%');
8
9var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%');
10var $gOPS = hasSymbols && GetIntrinsic('%Object.getOwnPropertySymbols%');
11var keys = require('object-keys');
12
13var esType = require('./Type');
14
15// https://ecma-international.org/ecma-262/6.0/#sec-getownpropertykeys
16
17module.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};