source: imaps-frontend/node_modules/es-abstract/2019/AbstractEqualityComparison.js@ 79a0317

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
Line 
1'use strict';
2
3var ToNumber = require('./ToNumber');
4var ToPrimitive = require('./ToPrimitive');
5var Type = require('./Type');
6
7var isObject = require('../helpers/isObject');
8
9// https://262.ecma-international.org/6.0/#sec-abstract-equality-comparison
10
11module.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' || typeof x === 'symbol') && isObject(y)) {
31 return AbstractEqualityComparison(x, ToPrimitive(y));
32 }
33 if (isObject(x) && (typeof y === 'string' || typeof y === 'number' || typeof y === 'symbol')) {
34 return AbstractEqualityComparison(ToPrimitive(x), y);
35 }
36 return false;
37};
Note: See TracBrowser for help on using the repository browser.