source: frontend/node_modules/es-abstract/2024/SortIndexedProperties.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 13 days ago

Fix frontend appearance

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