source: imaps-frontend/node_modules/es-abstract/5/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
RevLine 
[d565449]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');
10var isPrefixOf = require('../helpers/isPrefixOf');
11
12var ToNumber = require('./ToNumber');
13var ToPrimitive = require('./ToPrimitive');
14
15// https://262.ecma-international.org/5.1/#sec-11.8.5
16
17// eslint-disable-next-line max-statements
18module.exports = function AbstractRelationalComparison(x, y, LeftFirst) {
19 if (typeof LeftFirst !== 'boolean') {
20 throw new $TypeError('Assertion failed: LeftFirst argument must be a Boolean');
21 }
22 var px;
23 var py;
24 if (LeftFirst) {
25 px = ToPrimitive(x, $Number);
26 py = ToPrimitive(y, $Number);
27 } else {
28 py = ToPrimitive(y, $Number);
29 px = ToPrimitive(x, $Number);
30 }
31 var bothStrings = typeof px === 'string' && typeof py === 'string';
32 if (!bothStrings) {
33 var nx = ToNumber(px);
34 var ny = ToNumber(py);
35 if ($isNaN(nx) || $isNaN(ny)) {
36 return undefined;
37 }
38 if ($isFinite(nx) && $isFinite(ny) && nx === ny) {
39 return false;
40 }
41 if (nx === Infinity) {
42 return false;
43 }
44 if (ny === Infinity) {
45 return true;
46 }
47 if (ny === -Infinity) {
48 return false;
49 }
50 if (nx === -Infinity) {
51 return true;
52 }
53 return nx < ny; // by now, these are both nonzero, finite, and not equal
54 }
55 if (isPrefixOf(py, px)) {
56 return false;
57 }
58 if (isPrefixOf(px, py)) {
59 return true;
60 }
61 return px < py; // both strings, neither a prefix of the other. shortcut for steps c-f
62};
Note: See TracBrowser for help on using the repository browser.