| 1 |
// Copyright (C) 2017 Josh Wolfe. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
description: Non-strict equality comparison of BigInt values and non-primitive objects |
| 6 |
esid: sec-abstract-equality-comparison |
| 7 |
info: | |
| 8 |
10. If Type(x) is either String, Number, BigInt, or Symbol and Type(y) is Object, return the result of the comparison x == ? ToPrimitive(y). |
| 9 |
11. If Type(x) is Object and Type(y) is either String, Number, BigInt, or Symbol, return the result of the comparison ? ToPrimitive(x) == y. |
| 10 |
|
| 11 |
then after the recursion: |
| 12 |
|
| 13 |
1. If Type(x) is the same as Type(y), then |
| 14 |
a. Return the result of performing Strict Equality Comparison x === y. |
| 15 |
... |
| 16 |
6. If Type(x) is BigInt and Type(y) is String, |
| 17 |
a. Let n be StringToBigInt(y). |
| 18 |
b. If n is NaN, return false. |
| 19 |
c. Return the result of x == n. |
| 20 |
7. If Type(x) is String and Type(y) is BigInt, return the result of y == x. |
| 21 |
|
| 22 |
features: [BigInt] |
| 23 |
---*/ |
| 24 |
|
| 25 |
assert.sameValue(0n == Object(0n), true, "0n == Object(0n)"); |
| 26 |
assert.sameValue(Object(0n) == 0n, true, "Object(0n) == 0n"); |
| 27 |
assert.sameValue(0n == Object(1n), false, "0n == Object(1n)"); |
| 28 |
assert.sameValue(Object(1n) == 0n, false, "Object(1n) == 0n"); |
| 29 |
assert.sameValue(1n == Object(0n), false, "1n == Object(0n)"); |
| 30 |
assert.sameValue(Object(0n) == 1n, false, "Object(0n) == 1n"); |
| 31 |
assert.sameValue(1n == Object(1n), true, "1n == Object(1n)"); |
| 32 |
assert.sameValue(Object(1n) == 1n, true, "Object(1n) == 1n"); |
| 33 |
assert.sameValue(2n == Object(0n), false, "2n == Object(0n)"); |
| 34 |
assert.sameValue(Object(0n) == 2n, false, "Object(0n) == 2n"); |
| 35 |
assert.sameValue(2n == Object(1n), false, "2n == Object(1n)"); |
| 36 |
assert.sameValue(Object(1n) == 2n, false, "Object(1n) == 2n"); |
| 37 |
assert.sameValue(2n == Object(2n), true, "2n == Object(2n)"); |
| 38 |
assert.sameValue(Object(2n) == 2n, true, "Object(2n) == 2n"); |
| 39 |
assert.sameValue(0n == {}, false, "0n == {}"); |
| 40 |
assert.sameValue({} == 0n, false, "{} == 0n"); |
| 41 |
assert.sameValue(0n == {valueOf: function() { return 0n; }}, true, "0n == {valueOf: function() { return 0n; }}"); |
| 42 |
assert.sameValue({valueOf: function() { return 0n; }} == 0n, true, "{valueOf: function() { return 0n; }} == 0n"); |
| 43 |
assert.sameValue(0n == {valueOf: function() { return 1n; }}, false, "0n == {valueOf: function() { return 1n; }}"); |
| 44 |
assert.sameValue({valueOf: function() { return 1n; }} == 0n, false, "{valueOf: function() { return 1n; }} == 0n"); |
| 45 |
assert.sameValue(0n == {toString: function() { return "0"; }}, true, '0n == {toString: function() { return "0"; }}'); |
| 46 |
assert.sameValue({toString: function() { return "0"; }} == 0n, true, '{toString: function() { return "0"; }} == 0n'); |
| 47 |
assert.sameValue(0n == {toString: function() { return "1"; }}, false, '0n == {toString: function() { return "1"; }}'); |
| 48 |
assert.sameValue({toString: function() { return "1"; }} == 0n, false, '{toString: function() { return "1"; }} == 0n'); |
| 49 |
assert.sameValue(900719925474099101n == {valueOf: function() { return 900719925474099101n; }}, true, "900719925474099101n == {valueOf: function() { return 900719925474099101n; }}"); |
| 50 |
assert.sameValue({valueOf: function() { return 900719925474099101n; }} == 900719925474099101n, true, "{valueOf: function() { return 900719925474099101n; }} == 900719925474099101n"); |
| 51 |
assert.sameValue(900719925474099101n == {valueOf: function() { return 900719925474099102n; }}, false, "900719925474099101n == {valueOf: function() { return 900719925474099102n; }}"); |
| 52 |
assert.sameValue({valueOf: function() { return 900719925474099102n; }} == 900719925474099101n, false, "{valueOf: function() { return 900719925474099102n; }} == 900719925474099101n"); |
| 53 |
assert.sameValue(900719925474099101n == {toString: function() { return "900719925474099101"; }}, true, '900719925474099101n == {toString: function() { return "900719925474099101"; }}'); |
| 54 |
assert.sameValue({toString: function() { return "900719925474099101"; }} == 900719925474099101n, true, '{toString: function() { return "900719925474099101"; }} == 900719925474099101n'); |
| 55 |
assert.sameValue(900719925474099101n == {toString: function() { return "900719925474099102"; }}, false, '900719925474099101n == {toString: function() { return "900719925474099102"; }}'); |
| 56 |
assert.sameValue({toString: function() { return "900719925474099102"; }} == 900719925474099101n, false, '{toString: function() { return "900719925474099102"; }} == 900719925474099101n'); |