Projekt

Obecné

Profil

Stáhnout (1.13 KB) Statistiky
| Větev: | Revize:
1
'use strict';
2

    
3
var ToNumber = require('./ToNumber');
4
var ToPrimitive = require('./ToPrimitive');
5
var Type = require('./Type');
6

    
7
// https://www.ecma-international.org/ecma-262/6.0/#sec-abstract-equality-comparison
8

    
9
module.exports = function AbstractEqualityComparison(x, y) {
10
	var xType = Type(x);
11
	var yType = Type(y);
12
	if (xType === yType) {
13
		return x === y; // ES6+ specified this shortcut anyways.
14
	}
15
	if (x == null && y == null) {
16
		return true;
17
	}
18
	if (xType === 'Number' && yType === 'String') {
19
		return AbstractEqualityComparison(x, ToNumber(y));
20
	}
21
	if (xType === 'String' && yType === 'Number') {
22
		return AbstractEqualityComparison(ToNumber(x), y);
23
	}
24
	if (xType === 'Boolean') {
25
		return AbstractEqualityComparison(ToNumber(x), y);
26
	}
27
	if (yType === 'Boolean') {
28
		return AbstractEqualityComparison(x, ToNumber(y));
29
	}
30
	if ((xType === 'String' || xType === 'Number' || xType === 'Symbol') && yType === 'Object') {
31
		return AbstractEqualityComparison(x, ToPrimitive(y));
32
	}
33
	if (xType === 'Object' && (yType === 'String' || yType === 'Number' || yType === 'Symbol')) {
34
		return AbstractEqualityComparison(ToPrimitive(x), y);
35
	}
36
	return false;
37
};
(1-1/112)