source: imaps-frontend/node_modules/es-abstract/2020/AbstractEqualityComparison.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.9 KB
RevLine 
[d565449]1'use strict';
2
3var StrictEqualityComparison = require('./StrictEqualityComparison');
4var StringToBigInt = require('./StringToBigInt');
5var ToNumber = require('./ToNumber');
6var ToPrimitive = require('./ToPrimitive');
7var Type = require('./Type');
8
[79a0317]9var isNaN = require('math-intrinsics/isNaN');
10var isObject = require('../helpers/isObject');
[d565449]11
12// https://262.ecma-international.org/11.0/#sec-abstract-equality-comparison
13
14module.exports = function AbstractEqualityComparison(x, y) {
[79a0317]15 if (Type(x) === Type(y)) {
[d565449]16 return StrictEqualityComparison(x, y);
17 }
18 if (x == null && y == null) {
19 return true;
20 }
[79a0317]21 if (typeof x === 'number' && typeof y === 'string') {
[d565449]22 return AbstractEqualityComparison(x, ToNumber(y));
23 }
[79a0317]24 if (typeof x === 'string' && typeof y === 'number') {
[d565449]25 return AbstractEqualityComparison(ToNumber(x), y);
26 }
[79a0317]27 if (typeof x === 'bigint' && typeof y === 'string') {
[d565449]28 var n = StringToBigInt(y);
29 if (isNaN(n)) {
30 return false;
31 }
32 return AbstractEqualityComparison(x, n);
33 }
[79a0317]34 if (typeof x === 'string' && typeof y === 'bigint') {
[d565449]35 return AbstractEqualityComparison(y, x);
36 }
[79a0317]37 if (typeof x === 'boolean') {
[d565449]38 return AbstractEqualityComparison(ToNumber(x), y);
39 }
[79a0317]40 if (typeof y === 'boolean') {
[d565449]41 return AbstractEqualityComparison(x, ToNumber(y));
42 }
[79a0317]43 if ((typeof x === 'string' || typeof x === 'number' || typeof x === 'bigint' || typeof x === 'symbol') && isObject(y)) {
[d565449]44 return AbstractEqualityComparison(x, ToPrimitive(y));
45 }
[79a0317]46 if (isObject(x) && (typeof y === 'string' || typeof y === 'number' || typeof y === 'bigint' || typeof y === 'symbol')) {
[d565449]47 return AbstractEqualityComparison(ToPrimitive(x), y);
48 }
[79a0317]49 if ((typeof x === 'bigint' && typeof y === 'number') || (typeof x === 'number' && typeof y === 'bigint')) {
[d565449]50 if (isNaN(x) || isNaN(y) || x === Infinity || y === Infinity || x === -Infinity || y === -Infinity) {
51 return false;
52 }
53 return x == y; // eslint-disable-line eqeqeq
54 }
55 return false;
56};
Note: See TracBrowser for help on using the repository browser.