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
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var GetIntrinsic = require('get-intrinsic');
|
---|
| 4 |
|
---|
| 5 | var $TypeError = require('es-errors/type');
|
---|
| 6 |
|
---|
| 7 | var objectKeys = require('object-keys');
|
---|
| 8 |
|
---|
| 9 | var callBound = require('call-bind/callBound');
|
---|
| 10 |
|
---|
| 11 | var callBind = require('call-bind');
|
---|
| 12 |
|
---|
| 13 | var $isEnumerable = callBound('Object.prototype.propertyIsEnumerable');
|
---|
| 14 | var $pushApply = callBind.apply(GetIntrinsic('%Array.prototype.push%'));
|
---|
| 15 |
|
---|
| 16 | var forEach = require('../helpers/forEach');
|
---|
| 17 |
|
---|
| 18 | var Type = require('./Type');
|
---|
| 19 |
|
---|
| 20 | // https://262.ecma-international.org/8.0/#sec-enumerableownproperties
|
---|
| 21 |
|
---|
| 22 | module.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.