main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var ToNumber = require('./ToNumber');
|
---|
4 | var ToPrimitive = require('./ToPrimitive');
|
---|
5 | var Type = require('./Type');
|
---|
6 |
|
---|
7 | // https://262.ecma-international.org/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 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.