[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var StrictEqualityComparison = require('./StrictEqualityComparison');
|
---|
| 4 | var StringToBigInt = require('./StringToBigInt');
|
---|
| 5 | var ToNumber = require('./ToNumber');
|
---|
| 6 | var ToPrimitive = require('./ToPrimitive');
|
---|
| 7 | var Type = require('./Type');
|
---|
| 8 |
|
---|
[79a0317] | 9 | var isNaN = require('math-intrinsics/isNaN');
|
---|
| 10 | var isObject = require('../helpers/isObject');
|
---|
[d565449] | 11 |
|
---|
| 12 | // https://262.ecma-international.org/11.0/#sec-abstract-equality-comparison
|
---|
| 13 |
|
---|
| 14 | module.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 | };
|
---|