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

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

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