You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GetOwnPropertyKeys.js 823B

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