source: imaps-frontend/node_modules/es-abstract/2020/AbstractRelationalComparison.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: 2.0 KB
RevLine 
[d565449]1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $Number = GetIntrinsic('%Number%');
6var $TypeError = require('es-errors/type');
7
[79a0317]8var $isNaN = require('math-intrinsics/isNaN');
[d565449]9
10var IsStringPrefix = require('./IsStringPrefix');
11var StringToBigInt = require('./StringToBigInt');
12var ToNumeric = require('./ToNumeric');
13var ToPrimitive = require('./ToPrimitive');
14var Type = require('./Type');
15
16var BigIntLessThan = require('./BigInt/lessThan');
17var NumberLessThan = require('./Number/lessThan');
18
19// https://262.ecma-international.org/9.0/#sec-abstract-relational-comparison
20
21// eslint-disable-next-line max-statements, max-lines-per-function
22module.exports = function AbstractRelationalComparison(x, y, LeftFirst) {
23 if (typeof LeftFirst !== 'boolean') {
24 throw new $TypeError('Assertion failed: LeftFirst argument must be a Boolean');
25 }
26 var px;
27 var py;
28 if (LeftFirst) {
29 px = ToPrimitive(x, $Number);
30 py = ToPrimitive(y, $Number);
31 } else {
32 py = ToPrimitive(y, $Number);
33 px = ToPrimitive(x, $Number);
34 }
35 if (typeof px === 'string' && typeof py === 'string') {
36 if (IsStringPrefix(py, px)) {
37 return false;
38 }
39 if (IsStringPrefix(px, py)) {
40 return true;
41 }
42 return px < py; // both strings, neither a prefix of the other. shortcut for steps 3 c-f
43 }
44
45 var nx;
46 var ny;
[79a0317]47 if (typeof px === 'bigint' && typeof py === 'string') {
[d565449]48 ny = StringToBigInt(py);
49 if ($isNaN(ny)) {
50 return void undefined;
51 }
52 return BigIntLessThan(px, ny);
53 }
[79a0317]54 if (typeof px === 'string' && typeof py === 'bigint') {
[d565449]55 nx = StringToBigInt(px);
56 if ($isNaN(nx)) {
57 return void undefined;
58 }
59 return BigIntLessThan(nx, py);
60 }
61
62 nx = ToNumeric(px);
63 ny = ToNumeric(py);
[79a0317]64 if (Type(nx) === Type(ny)) {
65 return typeof nx === 'number' ? NumberLessThan(nx, ny) : BigIntLessThan(nx, ny);
[d565449]66 }
67
68 if ($isNaN(nx) || $isNaN(ny)) {
69 return void undefined;
70 }
71 if (nx === -Infinity || ny === Infinity) {
72 return true;
73 }
74 if (nx === Infinity || ny === -Infinity) {
75 return false;
76 }
77
78 return nx < ny; // by now, these are both nonzero, finite, and not equal
79};
Note: See TracBrowser for help on using the repository browser.