1 | 'use strict';
|
---|
2 |
|
---|
3 | var ToNumber = require('./ToNumber');
|
---|
4 | var ToPrimitive = require('./ToPrimitive');
|
---|
5 | var Type = require('./Type');
|
---|
6 |
|
---|
7 | var isObject = require('../helpers/isObject');
|
---|
8 |
|
---|
9 | // https://262.ecma-international.org/5.1/#sec-11.9.3
|
---|
10 |
|
---|
11 | module.exports = function AbstractEqualityComparison(x, y) {
|
---|
12 | if (Type(x) === Type(y)) {
|
---|
13 | return x === y; // ES6+ specified this shortcut anyways.
|
---|
14 | }
|
---|
15 | if (x == null && y == null) {
|
---|
16 | return true;
|
---|
17 | }
|
---|
18 | if (typeof x === 'number' && typeof y === 'string') {
|
---|
19 | return AbstractEqualityComparison(x, ToNumber(y));
|
---|
20 | }
|
---|
21 | if (typeof x === 'string' && typeof y === 'number') {
|
---|
22 | return AbstractEqualityComparison(ToNumber(x), y);
|
---|
23 | }
|
---|
24 | if (typeof x === 'boolean') {
|
---|
25 | return AbstractEqualityComparison(ToNumber(x), y);
|
---|
26 | }
|
---|
27 | if (typeof y === 'boolean') {
|
---|
28 | return AbstractEqualityComparison(x, ToNumber(y));
|
---|
29 | }
|
---|
30 | if ((typeof x === 'string' || typeof x === 'number') && isObject(y)) {
|
---|
31 | return AbstractEqualityComparison(x, ToPrimitive(y));
|
---|
32 | }
|
---|
33 | if (isObject(x) && (typeof y === 'string' || typeof y === 'number')) {
|
---|
34 | return AbstractEqualityComparison(ToPrimitive(x), y);
|
---|
35 | }
|
---|
36 | return false;
|
---|
37 | };
|
---|