source: imaps-frontend/node_modules/es-abstract/2023/SortIndexedProperties.js@ d565449

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.5 KB
Line 
1'use strict';
2
3var callBound = require('call-bind/callBound');
4
5var $TypeError = require('es-errors/type');
6
7var Get = require('./Get');
8var HasProperty = require('./HasProperty');
9var ToString = require('./ToString');
10var Type = require('./Type');
11
12var isAbstractClosure = require('../helpers/isAbstractClosure');
13var isInteger = require('../helpers/isInteger');
14
15var $push = callBound('Array.prototype.push');
16var $sort = callBound('Array.prototype.sort');
17
18// https://262.ecma-international.org/14.0/#sec-sortindexedproperties
19
20module.exports = function SortIndexedProperties(obj, len, SortCompare, holes) {
21 if (Type(obj) !== 'Object') {
22 throw new $TypeError('Assertion failed: Type(obj) is not Object');
23 }
24 if (!isInteger(len) || len < 0) {
25 throw new $TypeError('Assertion failed: `len` must be an integer >= 0');
26 }
27 if (!isAbstractClosure(SortCompare) || SortCompare.length !== 2) {
28 throw new $TypeError('Assertion failed: `SortCompare` must be an abstract closure taking 2 arguments');
29 }
30 if (holes !== 'skip-holes' && holes !== 'read-through-holes') {
31 throw new $TypeError('Assertion failed: `holes` must be either `skip-holes` or `read-through-holes`');
32 }
33
34 var items = []; // step 1
35
36 var k = 0; // step 2
37
38 while (k < len) { // step 3
39 var Pk = ToString(k);
40 var kRead = holes === 'skip-holes' ? HasProperty(obj, Pk) : true; // step 3.b - 3.c
41 if (kRead) { // step 3.d
42 var kValue = Get(obj, Pk);
43 $push(items, kValue);
44 }
45 k += 1; // step 3.e
46 }
47
48 $sort(items, SortCompare); // step 4
49
50 return items; // step 5
51};
Note: See TracBrowser for help on using the repository browser.