blob: 7cc9781f10ff7acff506c93838c29e0b10d0e8d7 [file] [log] [blame]
Tim van der Lippefdbd42e2020-04-07 14:14:361'use strict';
2
Tim van der Lippe2c891972021-07-29 15:22:503var GetIntrinsic = require('get-intrinsic');
Tim van der Lippefdbd42e2020-04-07 14:14:364
5var hasSymbols = require('has-symbols')();
6
Nikolay Vitkovd76576c2024-12-02 14:10:157var $TypeError = require('es-errors/type');
Tim van der Lippefdbd42e2020-04-07 14:14:368
Nikolay Vitkovd76576c2024-12-02 14:10:159var $gOPN = GetIntrinsic('%Object.getOwnPropertyNames%', true);
10var $gOPS = hasSymbols && GetIntrinsic('%Object.getOwnPropertySymbols%', true);
Tim van der Lippefdbd42e2020-04-07 14:14:3611var keys = require('object-keys');
12
13var esType = require('./Type');
14
Nikolay Vitkovd76576c2024-12-02 14:10:1515// https://262.ecma-international.org/6.0/#sec-getownpropertykeys
Tim van der Lippefdbd42e2020-04-07 14:14:3616
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};