tor-browser

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

bigint.js (6532B)


      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: Bitwise OR for BigInt values
      6 esid: sec-bitwise-op
      7 info: |
      8  BitwiseOp(op, x, y)
      9 
     10  1. Let result be 0.
     11  2. Let shift be 0.
     12  3. Repeat, until (x = 0 or x = -1) and (y = 0 or y = -1),
     13    a. Let xDigit be x modulo 2.
     14    b. Let yDigit be y modulo 2.
     15    c. Let result be result + 2**shift * op(xDigit, yDigit)
     16    d. Let shift be shift + 1.
     17    e. Let x be (x - xDigit) / 2.
     18    f. Let y be (y - yDigit) / 2.
     19  4. If op(x modulo 2, y modulo 2) ≠ 0,
     20    a. Let result be result - 2**shift. NOTE: This extends the sign.
     21  5. Return result.
     22 
     23 features: [BigInt]
     24 ---*/
     25 
     26 assert.sameValue(0b00n | 0b00n, 0b00n, "0b00n | 0b00n === 0b00n");
     27 assert.sameValue(0b00n | 0b01n, 0b01n, "0b00n | 0b01n === 0b01n");
     28 assert.sameValue(0b01n | 0b00n, 0b01n, "0b01n | 0b00n === 0b01n");
     29 assert.sameValue(0b00n | 0b10n, 0b10n, "0b00n | 0b10n === 0b10n");
     30 assert.sameValue(0b10n | 0b00n, 0b10n, "0b10n | 0b00n === 0b10n");
     31 assert.sameValue(0b00n | 0b11n, 0b11n, "0b00n | 0b11n === 0b11n");
     32 assert.sameValue(0b11n | 0b00n, 0b11n, "0b11n | 0b00n === 0b11n");
     33 assert.sameValue(0b01n | 0b01n, 0b01n, "0b01n | 0b01n === 0b01n");
     34 assert.sameValue(0b01n | 0b10n, 0b11n, "0b01n | 0b10n === 0b11n");
     35 assert.sameValue(0b10n | 0b01n, 0b11n, "0b10n | 0b01n === 0b11n");
     36 assert.sameValue(0b01n | 0b11n, 0b11n, "0b01n | 0b11n === 0b11n");
     37 assert.sameValue(0b11n | 0b01n, 0b11n, "0b11n | 0b01n === 0b11n");
     38 assert.sameValue(0b10n | 0b10n, 0b10n, "0b10n | 0b10n === 0b10n");
     39 assert.sameValue(0b10n | 0b11n, 0b11n, "0b10n | 0b11n === 0b11n");
     40 assert.sameValue(0b11n | 0b10n, 0b11n, "0b11n | 0b10n === 0b11n");
     41 assert.sameValue(0xffffffffn | 0n, 0xffffffffn, "0xffffffffn | 0n === 0xffffffffn");
     42 assert.sameValue(0n | 0xffffffffn, 0xffffffffn, "0n | 0xffffffffn === 0xffffffffn");
     43 assert.sameValue(0xffffffffn | 0xffffffffn, 0xffffffffn, "0xffffffffn | 0xffffffffn === 0xffffffffn");
     44 assert.sameValue(0xffffffffffffffffn | 0n, 0xffffffffffffffffn, "0xffffffffffffffffn | 0n === 0xffffffffffffffffn");
     45 assert.sameValue(0n | 0xffffffffffffffffn, 0xffffffffffffffffn, "0n | 0xffffffffffffffffn === 0xffffffffffffffffn");
     46 assert.sameValue(0xffffffffffffffffn | 0xffffffffn, 0xffffffffffffffffn, "0xffffffffffffffffn | 0xffffffffn === 0xffffffffffffffffn");
     47 assert.sameValue(0xffffffffn | 0xffffffffffffffffn, 0xffffffffffffffffn, "0xffffffffn | 0xffffffffffffffffn === 0xffffffffffffffffn");
     48 assert.sameValue(
     49  0xffffffffffffffffn | 0xffffffffffffffffn, 0xffffffffffffffffn,
     50  "0xffffffffffffffffn | 0xffffffffffffffffn === 0xffffffffffffffffn");
     51 assert.sameValue(
     52  0xbf2ed51ff75d380fd3be813ec6185780n | 0x4aabef2324cedff5387f1f65n, 0xbf2ed51fffffff2ff7fedffffe7f5fe5n,
     53  "0xbf2ed51ff75d380fd3be813ec6185780n | 0x4aabef2324cedff5387f1f65n === 0xbf2ed51fffffff2ff7fedffffe7f5fe5n");
     54 assert.sameValue(
     55  0x4aabef2324cedff5387f1f65n | 0xbf2ed51ff75d380fd3be813ec6185780n, 0xbf2ed51fffffff2ff7fedffffe7f5fe5n,
     56  "0x4aabef2324cedff5387f1f65n | 0xbf2ed51ff75d380fd3be813ec6185780n === 0xbf2ed51fffffff2ff7fedffffe7f5fe5n");
     57 assert.sameValue(0n | -1n, -1n, "0n | -1n === -1n");
     58 assert.sameValue(-1n | 0n, -1n, "-1n | 0n === -1n");
     59 assert.sameValue(0n | -2n, -2n, "0n | -2n === -2n");
     60 assert.sameValue(-2n | 0n, -2n, "-2n | 0n === -2n");
     61 assert.sameValue(1n | -2n, -1n, "1n | -2n === -1n");
     62 assert.sameValue(-2n | 1n, -1n, "-2n | 1n === -1n");
     63 assert.sameValue(2n | -2n, -2n, "2n | -2n === -2n");
     64 assert.sameValue(-2n | 2n, -2n, "-2n | 2n === -2n");
     65 assert.sameValue(2n | -3n, -1n, "2n | -3n === -1n");
     66 assert.sameValue(-3n | 2n, -1n, "-3n | 2n === -1n");
     67 assert.sameValue(-1n | -2n, -1n, "-1n | -2n === -1n");
     68 assert.sameValue(-2n | -1n, -1n, "-2n | -1n === -1n");
     69 assert.sameValue(-2n | -2n, -2n, "-2n | -2n === -2n");
     70 assert.sameValue(-2n | -3n, -1n, "-2n | -3n === -1n");
     71 assert.sameValue(-3n | -2n, -1n, "-3n | -2n === -1n");
     72 assert.sameValue(0xffffffffn | -1n, -1n, "0xffffffffn | -1n === -1n");
     73 assert.sameValue(-1n | 0xffffffffn, -1n, "-1n | 0xffffffffn === -1n");
     74 assert.sameValue(0xffffffffffffffffn | -1n, -1n, "0xffffffffffffffffn | -1n === -1n");
     75 assert.sameValue(-1n | 0xffffffffffffffffn, -1n, "-1n | 0xffffffffffffffffn === -1n");
     76 assert.sameValue(
     77  0xbf2ed51ff75d380fd3be813ec6185780n | -0x4aabef2324cedff5387f1f65n, -0x8a2c72024405ec138670865n,
     78  "0xbf2ed51ff75d380fd3be813ec6185780n | -0x4aabef2324cedff5387f1f65n === -0x8a2c72024405ec138670865n");
     79 assert.sameValue(
     80  -0x4aabef2324cedff5387f1f65n | 0xbf2ed51ff75d380fd3be813ec6185780n, -0x8a2c72024405ec138670865n,
     81  "-0x4aabef2324cedff5387f1f65n | 0xbf2ed51ff75d380fd3be813ec6185780n === -0x8a2c72024405ec138670865n");
     82 assert.sameValue(
     83  -0xbf2ed51ff75d380fd3be813ec6185780n | 0x4aabef2324cedff5387f1f65n, -0xbf2ed51fb554100cd330000ac600401bn,
     84  "-0xbf2ed51ff75d380fd3be813ec6185780n | 0x4aabef2324cedff5387f1f65n === -0xbf2ed51fb554100cd330000ac600401bn");
     85 assert.sameValue(
     86  0x4aabef2324cedff5387f1f65n | -0xbf2ed51ff75d380fd3be813ec6185780n, -0xbf2ed51fb554100cd330000ac600401bn,
     87  "0x4aabef2324cedff5387f1f65n | -0xbf2ed51ff75d380fd3be813ec6185780n === -0xbf2ed51fb554100cd330000ac600401bn");
     88 assert.sameValue(
     89  -0xbf2ed51ff75d380fd3be813ec6185780n | -0x4aabef2324cedff5387f1f65n, -0x42092803008e813400181765n,
     90  "-0xbf2ed51ff75d380fd3be813ec6185780n | -0x4aabef2324cedff5387f1f65n === -0x42092803008e813400181765n");
     91 assert.sameValue(
     92  -0x4aabef2324cedff5387f1f65n | -0xbf2ed51ff75d380fd3be813ec6185780n, -0x42092803008e813400181765n,
     93  "-0x4aabef2324cedff5387f1f65n | -0xbf2ed51ff75d380fd3be813ec6185780n === -0x42092803008e813400181765n");
     94 assert.sameValue(-0xffffffffn | 0n, -0xffffffffn, "-0xffffffffn | 0n === -0xffffffffn");
     95 assert.sameValue(0n | -0xffffffffn, -0xffffffffn, "0n | -0xffffffffn === -0xffffffffn");
     96 assert.sameValue(
     97  -0xffffffffffffffffn | 0x10000000000000000n, -0xffffffffffffffffn,
     98  "-0xffffffffffffffffn | 0x10000000000000000n === -0xffffffffffffffffn");
     99 assert.sameValue(
    100  0x10000000000000000n | -0xffffffffffffffffn, -0xffffffffffffffffn,
    101  "0x10000000000000000n | -0xffffffffffffffffn === -0xffffffffffffffffn");
    102 assert.sameValue(
    103  -0xffffffffffffffffffffffffn | 0x10000000000000000n, -0xfffffffeffffffffffffffffn,
    104  "-0xffffffffffffffffffffffffn | 0x10000000000000000n === -0xfffffffeffffffffffffffffn");
    105 assert.sameValue(
    106  0x10000000000000000n | -0xffffffffffffffffffffffffn, -0xfffffffeffffffffffffffffn,
    107  "0x10000000000000000n | -0xffffffffffffffffffffffffn === -0xfffffffeffffffffffffffffn");
    108 
    109 reportCompare(0, 0);