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