source: imaps-frontend/node_modules/es-abstract/2018/AbstractRelationalComparison.js

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