tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

bigint-and-object.js (5314B)


      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 description: Non-strict equality comparison of BigInt values and non-primitive objects
      5 esid: sec-abstract-equality-comparison
      6 info: |
      7  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).
      8  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.
      9 
     10  then after the recursion:
     11 
     12  1. If Type(x) is the same as Type(y), then
     13    a. Return the result of performing Strict Equality Comparison x === y.
     14  ...
     15  6. If Type(x) is BigInt and Type(y) is String,
     16    a. Let n be StringToBigInt(y).
     17    b. If n is NaN, return false.
     18    c. Return the result of x == n.
     19  7. If Type(x) is String and Type(y) is BigInt, return the result of y == x.
     20 
     21 features: [BigInt]
     22 ---*/
     23 assert.sameValue(0n == Object(0n), true, 'The result of (0n == Object(0n)) is true');
     24 assert.sameValue(Object(0n) == 0n, true, 'The result of (Object(0n) == 0n) is true');
     25 assert.sameValue(0n == Object(1n), false, 'The result of (0n == Object(1n)) is false');
     26 assert.sameValue(Object(1n) == 0n, false, 'The result of (Object(1n) == 0n) is false');
     27 assert.sameValue(1n == Object(0n), false, 'The result of (1n == Object(0n)) is false');
     28 assert.sameValue(Object(0n) == 1n, false, 'The result of (Object(0n) == 1n) is false');
     29 assert.sameValue(1n == Object(1n), true, 'The result of (1n == Object(1n)) is true');
     30 assert.sameValue(Object(1n) == 1n, true, 'The result of (Object(1n) == 1n) is true');
     31 assert.sameValue(2n == Object(0n), false, 'The result of (2n == Object(0n)) is false');
     32 assert.sameValue(Object(0n) == 2n, false, 'The result of (Object(0n) == 2n) is false');
     33 assert.sameValue(2n == Object(1n), false, 'The result of (2n == Object(1n)) is false');
     34 assert.sameValue(Object(1n) == 2n, false, 'The result of (Object(1n) == 2n) is false');
     35 assert.sameValue(2n == Object(2n), true, 'The result of (2n == Object(2n)) is true');
     36 assert.sameValue(Object(2n) == 2n, true, 'The result of (Object(2n) == 2n) is true');
     37 assert.sameValue(0n == {}, false, 'The result of (0n == {}) is false');
     38 assert.sameValue({} == 0n, false, 'The result of (({}) == 0n) is false');
     39 
     40 assert.sameValue(0n == {
     41  valueOf: function() {
     42    return 0n;
     43  }
     44 }, true, 'The result of (0n == {valueOf: function() {return 0n;}}) is true');
     45 
     46 assert.sameValue({
     47  valueOf: function() {
     48    return 0n;
     49  }
     50 } == 0n, true, 'The result of (({valueOf: function() {return 0n;}}) == 0n) is true');
     51 
     52 assert.sameValue(0n == {
     53  valueOf: function() {
     54    return 1n;
     55  }
     56 }, false, 'The result of (0n == {valueOf: function() {return 1n;}}) is false');
     57 
     58 assert.sameValue({
     59  valueOf: function() {
     60    return 1n;
     61  }
     62 } == 0n, false, 'The result of (({valueOf: function() {return 1n;}}) == 0n) is false');
     63 
     64 assert.sameValue(0n == {
     65  toString: function() {
     66    return '0';
     67  }
     68 }, true, 'The result of (0n == {toString: function() {return "0";}}) is true');
     69 
     70 assert.sameValue({
     71  toString: function() {
     72    return '0';
     73  }
     74 } == 0n, true, 'The result of (({toString: function() {return "0";}}) == 0n) is true');
     75 
     76 assert.sameValue(0n == {
     77  toString: function() {
     78    return '1';
     79  }
     80 }, false, 'The result of (0n == {toString: function() {return "1";}}) is false');
     81 
     82 assert.sameValue({
     83  toString: function() {
     84    return '1';
     85  }
     86 } == 0n, false, 'The result of (({toString: function() {return "1";}}) == 0n) is false');
     87 
     88 assert.sameValue(900719925474099101n == {
     89  valueOf: function() {
     90    return 900719925474099101n;
     91  }
     92 }, true, 'The result of (900719925474099101n == {valueOf: function() {return 900719925474099101n;}}) is true');
     93 
     94 assert.sameValue({
     95  valueOf: function() {
     96    return 900719925474099101n;
     97  }
     98 } == 900719925474099101n, true, 'The result of (({valueOf: function() {return 900719925474099101n;}}) == 900719925474099101n) is true');
     99 
    100 assert.sameValue(900719925474099101n == {
    101  valueOf: function() {
    102    return 900719925474099102n;
    103  }
    104 }, false, 'The result of (900719925474099101n == {valueOf: function() {return 900719925474099102n;}}) is false');
    105 
    106 assert.sameValue({
    107  valueOf: function() {
    108    return 900719925474099102n;
    109  }
    110 } == 900719925474099101n, false, 'The result of (({valueOf: function() {return 900719925474099102n;}}) == 900719925474099101n) is false');
    111 
    112 assert.sameValue(900719925474099101n == {
    113  toString: function() {
    114    return '900719925474099101';
    115  }
    116 }, true, 'The result of (900719925474099101n == {toString: function() {return "900719925474099101";}}) is true');
    117 
    118 assert.sameValue({
    119  toString: function() {
    120    return '900719925474099101';
    121  }
    122 } == 900719925474099101n, true, 'The result of (({toString: function() {return "900719925474099101";}}) == 900719925474099101n) is true');
    123 
    124 assert.sameValue(900719925474099101n == {
    125  toString: function() {
    126    return '900719925474099102';
    127  }
    128 }, false, 'The result of (900719925474099101n == {toString: function() {return "900719925474099102";}}) is false');
    129 
    130 assert.sameValue({
    131  toString: function() {
    132    return '900719925474099102';
    133  }
    134 } == 900719925474099101n, false, 'The result of (({toString: function() {return "900719925474099102";}}) == 900719925474099101n) is false');
    135 
    136 reportCompare(0, 0);