Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/es-abstract/2019/AbstractEqualityComparison.js')
-rw-r--r--node_modules/es-abstract/2019/AbstractEqualityComparison.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/node_modules/es-abstract/2019/AbstractEqualityComparison.js b/node_modules/es-abstract/2019/AbstractEqualityComparison.js
new file mode 100644
index 000000000..40b390986
--- /dev/null
+++ b/node_modules/es-abstract/2019/AbstractEqualityComparison.js
@@ -0,0 +1,37 @@
+'use strict';
+
+var ToNumber = require('./ToNumber');
+var ToPrimitive = require('./ToPrimitive');
+var Type = require('./Type');
+
+// https://www.ecma-international.org/ecma-262/6.0/#sec-abstract-equality-comparison
+
+module.exports = function AbstractEqualityComparison(x, y) {
+ var xType = Type(x);
+ var yType = Type(y);
+ if (xType === yType) {
+ return x === y; // ES6+ specified this shortcut anyways.
+ }
+ if (x == null && y == null) {
+ return true;
+ }
+ if (xType === 'Number' && yType === 'String') {
+ return AbstractEqualityComparison(x, ToNumber(y));
+ }
+ if (xType === 'String' && yType === 'Number') {
+ return AbstractEqualityComparison(ToNumber(x), y);
+ }
+ if (xType === 'Boolean') {
+ return AbstractEqualityComparison(ToNumber(x), y);
+ }
+ if (yType === 'Boolean') {
+ return AbstractEqualityComparison(x, ToNumber(y));
+ }
+ if ((xType === 'String' || xType === 'Number' || xType === 'Symbol') && yType === 'Object') {
+ return AbstractEqualityComparison(x, ToPrimitive(y));
+ }
+ if (xType === 'Object' && (yType === 'String' || yType === 'Number' || yType === 'Symbol')) {
+ return AbstractEqualityComparison(ToPrimitive(x), y);
+ }
+ return false;
+};