tor-browser

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

bug1702424.js (5153B)


      1 load(libdir + "asserts.js");
      2 
      3 // Ensure BytecodeGeneration respects stack depth assertions: Private Methods
      4 class a {
      5    b
      6    // original test case below.
      7    #c() {
      8        d.#c ^= 'x'
      9    }
     10 
     11    // Operator list:
     12    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
     13    //
     14    // Compound Assignments
     15    t() {
     16        d.#c = 'x';
     17        d.#c += 'x';
     18        d.#c -= 'x';
     19        d.#c *= 'x';
     20        d.#c /= 'x';
     21        d.#c %= 'x';
     22        d.#c **= 'x';
     23        d.#c <<= 'x';
     24        d.#c >>= 'x';
     25        d.#c >>>= 'x';
     26 
     27        d.#c &= 'x';
     28        d.#c ^= 'x';
     29        d.#c |= 'x';
     30 
     31    }
     32 
     33    // Compound Logical Assignments
     34    e() {
     35        d.#c &&= 'x';
     36        d.#c ??= 'x';
     37        d.#c ||= 'x';
     38    }
     39 
     40    // Destructruring assignment.
     41    ds() {
     42        [d.#c, b] = [1, 2];
     43    }
     44 
     45    // Increment/Decrement
     46    incDec() {
     47        d.#c++;
     48        d.#c--;
     49        ++d.#c;
     50        --d.#c;
     51    }
     52 }
     53 
     54 class b {
     55    b
     56    // original test case below.
     57    #c = 10;
     58 
     59    // Operator list:
     60    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
     61    //
     62    // Compound Assignments
     63    t() {
     64        d.#c = 'x';
     65        d.#c += 'x';
     66        d.#c -= 'x';
     67        d.#c *= 'x';
     68        d.#c /= 'x';
     69        d.#c %= 'x';
     70        d.#c **= 'x';
     71        d.#c <<= 'x';
     72        d.#c >>= 'x';
     73        d.#c >>>= 'x';
     74 
     75        d.#c &= 'x';
     76        d.#c ^= 'x';
     77        d.#c |= 'x';
     78 
     79    }
     80 
     81    // Compound Logical Assignments
     82    e() {
     83        d.#c &&= 'x';
     84        d.#c ??= 'x';
     85        d.#c ||= 'x';
     86    }
     87 
     88    // Destructruring assignment.
     89    ds() {
     90        [d.#c, b] = [1, 2];
     91    }
     92 
     93 
     94    // Increment/Decrement
     95    incDec() {
     96        d.#c++;
     97        d.#c--;
     98        ++d.#c;
     99        --d.#c;
    100    }
    101 }
    102 
    103 // Ensure we correctly throw for all compound private method assignments
    104 class LiveTest {
    105    #c() { }
    106 
    107    test(lambdas) {
    108        for (let func of lambdas) {
    109            assertThrowsInstanceOf(() => func(this), Error);
    110        }
    111    }
    112 
    113    // Operator list:
    114    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
    115    //
    116    // Compound Assignments
    117    compound() {
    118        let tests = [
    119            (d) => d.#c = 'x',
    120            (d) => d.#c += 'x',
    121            (d) => d.#c -= 'x',
    122            (d) => d.#c *= 'x',
    123            (d) => d.#c /= 'x',
    124            (d) => d.#c %= 'x',
    125            (d) => d.#c **= 'x',
    126            (d) => d.#c <<= 'x',
    127            (d) => d.#c >>= 'x',
    128            (d) => d.#c >>>= 'x',
    129            (d) => d.#c &= 'x',
    130            (d) => d.#c ^= 'x',
    131            (d) => d.#c |= 'x',
    132        ];
    133 
    134        this.test(tests);
    135    }
    136 
    137    // Compound Logical Assignments
    138    compoundLogical() {
    139        let tests = [
    140            (d) => d.#c &&= 'x',
    141        ]
    142        this.test(tests);
    143        // These don't throw because they don't
    144        // process the assignment.
    145        this.#c ??= 'x';
    146        this.#c ||= 'x';
    147    }
    148 
    149    // Destructruring assignment.
    150    destructuring() {
    151        let tests = [
    152            (d) => [d.#c, b] = [1, 2],
    153        ]
    154        this.test(tests);
    155    }
    156 
    157 
    158    // Increment/Decrement
    159    incDec() {
    160        let tests = [
    161            (d) => d.#c++,
    162            (d) => d.#c--,
    163            (d) => ++d.#c,
    164            (d) => --d.#c,
    165        ];
    166        this.test(tests);
    167    }
    168 }
    169 
    170 var l = new LiveTest;
    171 l.compound();
    172 l.compoundLogical();
    173 l.destructuring();
    174 l.incDec();
    175 
    176 // Ensure we correctly throw for all compound private method assignments
    177 class LiveTestField {
    178    #c = 0;
    179 
    180    // Operator list:
    181    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators
    182    //
    183    // Compound Assignments
    184    compound() {
    185        assertEq(this.#c = 1, 1);
    186        assertEq(this.#c += 1, 2);
    187        assertEq(this.#c -= 1, 1);
    188        assertEq(this.#c *= 2, 2);
    189        assertEq(this.#c /= 2, 1);
    190        assertEq(this.#c %= 1, 0);
    191        this.#c = 1;
    192        assertEq(this.#c **= 1, 1);
    193        assertEq(this.#c <<= 1, 2);
    194        assertEq(this.#c >>= 1, 1);
    195        assertEq(this.#c >>>= 1, 0);
    196        assertEq(this.#c &= 2, 0);
    197        assertEq(this.#c ^= 2, 2);
    198        assertEq(this.#c |= 1, 3);
    199    }
    200 
    201    // Compound Logical Assignments
    202    compoundLogical() {
    203        this.#c = undefined;
    204        this.#c ||= 10;
    205        assertEq(this.#c, 10);
    206        this.#c ||= 15;
    207        assertEq(this.#c, 10);
    208 
    209        this.#c = false;
    210        this.#c &&= 10;
    211        assertEq(this.#c, false);
    212        this.#c = 10;
    213        this.#c &&= 15;
    214        assertEq(this.#c, 15);
    215 
    216        this.#c = null;
    217        this.#c ??= 10;
    218        assertEq(this.#c, 10);
    219 
    220        this.#c ??= 15
    221        assertEq(this.#c, 10);
    222    }
    223 
    224    // Destructruring assignment.
    225    destructuring() {
    226        [this.#c, b] = [1, 2];
    227 
    228        assertEq(this.#c, 1);
    229    }
    230 
    231 
    232    // Increment/Decrement
    233    incDec() {
    234        this.#c = 0;
    235        assertEq(++this.#c, 1);
    236        assertEq(--this.#c, 0);
    237        this.#c++;
    238        assertEq(this.#c, 1);
    239        this.#c--;
    240        assertEq(this.#c, 0);
    241 
    242    }
    243 }
    244 
    245 var k = new LiveTestField;
    246 k.compound();
    247 k.compoundLogical()
    248 k.destructuring()
    249 k.incDec();