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.2 KB
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var ToNumber = require('./ToNumber');
|
---|
| 4 | var ToPrimitive = require('./ToPrimitive');
|
---|
| 5 | var Type = require('./Type');
|
---|
| 6 |
|
---|
[79a0317] | 7 | var isObject = require('../helpers/isObject');
|
---|
| 8 |
|
---|
[d565449] | 9 | // https://262.ecma-international.org/6.0/#sec-abstract-equality-comparison
|
---|
| 10 |
|
---|
| 11 | module.exports = function AbstractEqualityComparison(x, y) {
|
---|
[79a0317] | 12 | if (Type(x) === Type(y)) {
|
---|
[d565449] | 13 | return x === y; // ES6+ specified this shortcut anyways.
|
---|
| 14 | }
|
---|
| 15 | if (x == null && y == null) {
|
---|
| 16 | return true;
|
---|
| 17 | }
|
---|
[79a0317] | 18 | if (typeof x === 'number' && typeof y === 'string') {
|
---|
[d565449] | 19 | return AbstractEqualityComparison(x, ToNumber(y));
|
---|
| 20 | }
|
---|
[79a0317] | 21 | if (typeof x === 'string' && typeof y === 'number') {
|
---|
[d565449] | 22 | return AbstractEqualityComparison(ToNumber(x), y);
|
---|
| 23 | }
|
---|
[79a0317] | 24 | if (typeof x === 'boolean') {
|
---|
[d565449] | 25 | return AbstractEqualityComparison(ToNumber(x), y);
|
---|
| 26 | }
|
---|
[79a0317] | 27 | if (typeof y === 'boolean') {
|
---|
[d565449] | 28 | return AbstractEqualityComparison(x, ToNumber(y));
|
---|
| 29 | }
|
---|
[79a0317] | 30 | if ((typeof x === 'string' || typeof x === 'number' || typeof x === 'symbol') && isObject(y)) {
|
---|
[d565449] | 31 | return AbstractEqualityComparison(x, ToPrimitive(y));
|
---|
| 32 | }
|
---|
[79a0317] | 33 | if (isObject(x) && (typeof y === 'string' || typeof y === 'number' || typeof y === 'symbol')) {
|
---|
[d565449] | 34 | return AbstractEqualityComparison(ToPrimitive(x), y);
|
---|
| 35 | }
|
---|
| 36 | return false;
|
---|
| 37 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.