12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- 'use strict';
- var GetIntrinsic = require('get-intrinsic');
- var $Number = GetIntrinsic('%Number%');
- var $TypeError = GetIntrinsic('%TypeError%');
- var $isNaN = require('../helpers/isNaN');
- var $isFinite = require('../helpers/isFinite');
- var IsStringPrefix = require('./IsStringPrefix');
- var ToNumber = require('./ToNumber');
- var ToPrimitive = require('./ToPrimitive');
- var Type = require('./Type');
- module.exports = function AbstractRelationalComparison(x, y, LeftFirst) {
- if (Type(LeftFirst) !== 'Boolean') {
- throw new $TypeError('Assertion failed: LeftFirst argument must be a Boolean');
- }
- var px;
- var py;
- if (LeftFirst) {
- px = ToPrimitive(x, $Number);
- py = ToPrimitive(y, $Number);
- } else {
- py = ToPrimitive(y, $Number);
- px = ToPrimitive(x, $Number);
- }
- if (Type(px) === 'String' && Type(py) === 'String') {
- if (IsStringPrefix(py, px)) {
- return false;
- }
- if (IsStringPrefix(px, py)) {
- return true;
- }
- return px < py;
- }
- var nx = ToNumber(px);
- var ny = ToNumber(py);
- if ($isNaN(nx) || $isNaN(ny)) {
- return undefined;
- }
- if ($isFinite(nx) && $isFinite(ny) && nx === ny) {
- return false;
- }
- if (nx === Infinity) {
- return false;
- }
- if (ny === Infinity) {
- return true;
- }
- if (ny === -Infinity) {
- return false;
- }
- if (nx === -Infinity) {
- return true;
- }
- return nx < ny;
- };
|