source: imaps-frontend/node_modules/es-abstract/2019/EnumerableOwnPropertyNames.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.1 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $TypeError = require('es-errors/type');
6
7var objectKeys = require('object-keys');
8
9var callBound = require('call-bind/callBound');
10
11var callBind = require('call-bind');
12
13var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
14var $pushApply = callBind.apply(GetIntrinsic('%Array.prototype.push%'));
15
16var forEach = require('../helpers/forEach');
17
18var Type = require('./Type');
19
20// https://262.ecma-international.org/8.0/#sec-enumerableownproperties
21
22module.exports = function EnumerableOwnPropertyNames(O, kind) {
23 if (Type(O) !== 'Object') {
24 throw new $TypeError('Assertion failed: Type(O) is not Object');
25 }
26
27 var keys = objectKeys(O);
28 if (kind === 'key') {
29 return keys;
30 }
31 if (kind === 'value' || kind === 'key+value') {
32 var results = [];
33 forEach(keys, function (key) {
34 if ($isEnumerable(O, key)) {
35 $pushApply(results, [
36 kind === 'value' ? O[key] : [key, O[key]]
37 ]);
38 }
39 });
40 return results;
41 }
42 throw new $TypeError('Assertion failed: "kind" is not "key", "value", or "key+value": ' + kind);
43};
Note: See TracBrowser for help on using the repository browser.