tor-browser

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

bigint-and-object.js (5308B)


      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 inequality 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), false, 'The result of (0n != Object(0n)) is false');
     24 assert.sameValue(Object(0n) != 0n, false, 'The result of (Object(0n) != 0n) is false');
     25 assert.sameValue(0n != Object(1n), true, 'The result of (0n != Object(1n)) is true');
     26 assert.sameValue(Object(1n) != 0n, true, 'The result of (Object(1n) != 0n) is true');
     27 assert.sameValue(1n != Object(0n), true, 'The result of (1n != Object(0n)) is true');
     28 assert.sameValue(Object(0n) != 1n, true, 'The result of (Object(0n) != 1n) is true');
     29 assert.sameValue(1n != Object(1n), false, 'The result of (1n != Object(1n)) is false');
     30 assert.sameValue(Object(1n) != 1n, false, 'The result of (Object(1n) != 1n) is false');
     31 assert.sameValue(2n != Object(0n), true, 'The result of (2n != Object(0n)) is true');
     32 assert.sameValue(Object(0n) != 2n, true, 'The result of (Object(0n) != 2n) is true');
     33 assert.sameValue(2n != Object(1n), true, 'The result of (2n != Object(1n)) is true');
     34 assert.sameValue(Object(1n) != 2n, true, 'The result of (Object(1n) != 2n) is true');
     35 assert.sameValue(2n != Object(2n), false, 'The result of (2n != Object(2n)) is false');
     36 assert.sameValue(Object(2n) != 2n, false, 'The result of (Object(2n) != 2n) is false');
     37 assert.sameValue(0n != {}, true, 'The result of (0n != {}) is true');
     38 assert.sameValue({} != 0n, true, 'The result of (({}) != 0n) is true');
     39 
     40 assert.sameValue(0n != {
     41  valueOf: function() {
     42    return 0n;
     43  }
     44 }, false, 'The result of (0n != {valueOf: function() {return 0n;}}) is false');
     45 
     46 assert.sameValue({
     47  valueOf: function() {
     48    return 0n;
     49  }
     50 } != 0n, false, 'The result of (({valueOf: function() {return 0n;}}) != 0n) is false');
     51 
     52 assert.sameValue(0n != {
     53  valueOf: function() {
     54    return 1n;
     55  }
     56 }, true, 'The result of (0n != {valueOf: function() {return 1n;}}) is true');
     57 
     58 assert.sameValue({
     59  valueOf: function() {
     60    return 1n;
     61  }
     62 } != 0n, true, 'The result of (({valueOf: function() {return 1n;}}) != 0n) is true');
     63 
     64 assert.sameValue(0n != {
     65  toString: function() {
     66    return '0';
     67  }
     68 }, false, 'The result of (0n != {toString: function() {return "0";}}) is false');
     69 
     70 assert.sameValue({
     71  toString: function() {
     72    return '0';
     73  }
     74 } != 0n, false, 'The result of (({toString: function() {return "0";}}) != 0n) is false');
     75 
     76 assert.sameValue(0n != {
     77  toString: function() {
     78    return '1';
     79  }
     80 }, true, 'The result of (0n != {toString: function() {return "1";}}) is true');
     81 
     82 assert.sameValue({
     83  toString: function() {
     84    return '1';
     85  }
     86 } != 0n, true, 'The result of (({toString: function() {return "1";}}) != 0n) is true');
     87 
     88 assert.sameValue(900719925474099101n != {
     89  valueOf: function() {
     90    return 900719925474099101n;
     91  }
     92 }, false, 'The result of (900719925474099101n != {valueOf: function() {return 900719925474099101n;}}) is false');
     93 
     94 assert.sameValue({
     95  valueOf: function() {
     96    return 900719925474099101n;
     97  }
     98 } != 900719925474099101n, false, 'The result of (({valueOf: function() {return 900719925474099101n;}}) != 900719925474099101n) is false');
     99 
    100 assert.sameValue(900719925474099101n != {
    101  valueOf: function() {
    102    return 900719925474099102n;
    103  }
    104 }, true, 'The result of (900719925474099101n != {valueOf: function() {return 900719925474099102n;}}) is true');
    105 
    106 assert.sameValue({
    107  valueOf: function() {
    108    return 900719925474099102n;
    109  }
    110 } != 900719925474099101n, true, 'The result of (({valueOf: function() {return 900719925474099102n;}}) != 900719925474099101n) is true');
    111 
    112 assert.sameValue(900719925474099101n != {
    113  toString: function() {
    114    return '900719925474099101';
    115  }
    116 }, false, 'The result of (900719925474099101n != {toString: function() {return "900719925474099101";}}) is false');
    117 
    118 assert.sameValue({
    119  toString: function() {
    120    return '900719925474099101';
    121  }
    122 } != 900719925474099101n, false, 'The result of (({toString: function() {return "900719925474099101";}}) != 900719925474099101n) is false');
    123 
    124 assert.sameValue(900719925474099101n != {
    125  toString: function() {
    126    return '900719925474099102';
    127  }
    128 }, true, 'The result of (900719925474099101n != {toString: function() {return "900719925474099102";}}) is true');
    129 
    130 assert.sameValue({
    131  toString: function() {
    132    return '900719925474099102';
    133  }
    134 } != 900719925474099101n, true, 'The result of (({toString: function() {return "900719925474099102";}}) != 900719925474099101n) is true');
    135 
    136 reportCompare(0, 0);