tor-browser

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

testCrossCompartmentTransparency.js (8590B)


      1 // |jit-test| error: done
      2 
      3 var g1 = newGlobal('same-compartment');
      4 var g2 = newGlobal();
      5 var proxyStr = "new Proxy({},                              "+
      6 "  { getOwnPropertyDescriptor: () =>assertEq(true,false),  "+
      7 "    ownKeys: () =>assertEq(true,false),                   "+
      8 "    defineProperty: () =>assertEq(true,false),            "+
      9 "    deleteProperty: () =>assertEq(true,false),            "+
     10 "    get: () =>assertEq(true,false),                       "+
     11 "    set: () =>assertEq(true,false),                       "+
     12 "});                                                       ";
     13 var proxy1 = g1.eval(proxyStr);
     14 var proxy2 = g2.eval(proxyStr);
     15 
     16 var test = (function() {
     17 "use strict";
     18 return function test(str, f, isGeneric = false) {
     19 
     20    var x = f(eval(str));
     21    assertEq(x, f(g1.eval(str)));
     22    assertEq(x, f(g2.eval(str)));
     23 
     24    var threw = false;
     25    try {
     26        f(g1.eval("new Object()"));
     27    } catch (e) {
     28        assertEq(Object.prototype.toString.call(e), "[object Error]");
     29        threw = true;
     30    }
     31    assertEq(threw, !isGeneric);
     32    threw = false;
     33    try {
     34        f(g2.eval("new Object()"));
     35    } catch (e) {
     36        assertEq(Object.prototype.toString.call(e), "[object Error]");
     37        threw = true;
     38    }
     39    assertEq(threw, !isGeneric);
     40    threw = false;
     41    try {
     42        f(proxy1);
     43    } catch (e) {
     44        assertEq(Object.prototype.toString.call(e), "[object Error]");
     45        threw = true;
     46    }
     47    assertEq(threw, !isGeneric);
     48    threw = false;
     49    try {
     50        f(proxy2);
     51    } catch (e) {
     52        assertEq(Object.prototype.toString.call(e), "[object Error]");
     53        threw = true;
     54    }
     55    assertEq(threw, !isGeneric);
     56 }
     57 })();
     58 
     59 if (Boolean.prototype.toSource) {
     60    test("new Boolean(true)", b => Boolean.prototype.toSource.call(b));
     61 }
     62 test("new Boolean(true)", b => Boolean.prototype.toString.call(b));
     63 test("new Boolean(true)", b => Boolean.prototype.valueOf.call(b));
     64 if (Number.prototype.toSource) {
     65    test("new Number(1)", n => Number.prototype.toSource.call(n));
     66 }
     67 test("new Number(1)", n => Number.prototype.toString.call(n));
     68 test("new Number(1)", n => Number.prototype.valueOf.call(n));
     69 test("new Number(1)", n => Number.prototype.toFixed.call(n));
     70 test("new Number(1)", n => Number.prototype.toExponential.call(n));
     71 test("new Number(1)", n => Number.prototype.toPrecision.call(n));
     72 test("(function*(){yield 1})()", i => (function*(){yield})().next.call(i).toString());
     73 if (String.prototype.toSource) {
     74    test("new String('one')", s => String.prototype.toSource.call(s));
     75 }
     76 test("new String('one')", s => String.prototype.toString.call(s));
     77 test("new RegExp('1')", r => RegExp.prototype.exec.call(r, '1').toString());
     78 test("new RegExp('1')", r => RegExp.prototype.test.call(r, '1'));
     79 test("new RegExp('1')", r => assertEq("a1".search(r), 1));
     80 test("new RegExp('1')", r => assertEq("a1".match(r)[0], '1'));
     81 test("new RegExp('1')", r => assertEq("a1".replace(r, 'A'), 'aA'));
     82 test("new RegExp('1')", r => assertEq(String("a1b".split(r)), "a,b"));
     83 test("new RegExp('1')", r => assertEq(String(new RegExp(r)), String(r)));
     84 test("new RegExp('1')", r => assertEq(String(/x/.compile(r)), String(r)));
     85 test("new WeakMap()", w => WeakMap.prototype.has.call(w, {}));
     86 test("new WeakMap()", w => WeakMap.prototype.get.call(w, {}));
     87 test("new WeakMap()", w => WeakMap.prototype.delete.call(w, {}));
     88 test("new WeakMap()", w => WeakMap.prototype.set.call(w, {}).toString());
     89 test("new Map()", w => Map.prototype.has.call(w, {}));
     90 test("new Map()", w => Map.prototype.get.call(w, {}));
     91 test("new Map()", w => Map.prototype.delete.call(w, {}));
     92 test("new Map()", w => Map.prototype.set.call(w, {}).toString());
     93 test("new Set()", w => Set.prototype.has.call(w, {}));
     94 test("new Set()", w => Set.prototype.add.call(w, {}).toString());
     95 test("new Set()", w => Set.prototype.delete.call(w, {}));
     96 
     97 test("new Int8Array(1)", a => Int8Array.prototype.subarray.call(a).toString());
     98 test("new Uint8Array(1)", a => Uint8Array.prototype.subarray.call(a).toString());
     99 test("new Int16Array(1)", a => Int16Array.prototype.subarray.call(a).toString());
    100 test("new Uint16Array(1)", a => Uint16Array.prototype.subarray.call(a).toString());
    101 test("new Int32Array(1)", a => Int32Array.prototype.subarray.call(a).toString());
    102 test("new Uint32Array(1)", a => Uint32Array.prototype.subarray.call(a).toString());
    103 test("new Float32Array(1)", a => Float32Array.prototype.subarray.call(a).toString());
    104 test("new Float64Array(1)", a => Float64Array.prototype.subarray.call(a).toString());
    105 test("new Uint8ClampedArray(1)", a => Uint8ClampedArray.prototype.subarray.call(a).toString());
    106 
    107 test("new Int8Array(1)", a => Int8Array.prototype.set.call(a, []));
    108 test("new Uint8Array(1)", a => Uint8Array.prototype.set.call(a, []));
    109 test("new Int16Array(1)", a => Int16Array.prototype.set.call(a, []));
    110 test("new Uint16Array(1)", a => Uint16Array.prototype.set.call(a, []));
    111 test("new Int32Array(1)", a => Int32Array.prototype.set.call(a, []));
    112 test("new Uint32Array(1)", a => Uint32Array.prototype.set.call(a, []));
    113 test("new Float32Array(1)", a => Float32Array.prototype.set.call(a, []));
    114 test("new Float64Array(1)", a => Float64Array.prototype.set.call(a, []));
    115 test("new Uint8ClampedArray(1)", a => Uint8ClampedArray.prototype.set.call(a, []));
    116 
    117 function justDontThrow() {}
    118 test("new Date()", d => justDontThrow(Date.prototype.getTime.call(d)));
    119 test("new Date()", d => justDontThrow(Date.prototype.getYear.call(d)));
    120 test("new Date()", d => justDontThrow(Date.prototype.getFullYear.call(d)));
    121 test("new Date()", d => justDontThrow(Date.prototype.getUTCFullYear.call(d)));
    122 test("new Date()", d => justDontThrow(Date.prototype.getMonth.call(d)));
    123 test("new Date()", d => justDontThrow(Date.prototype.getUTCMonth.call(d)));
    124 test("new Date()", d => justDontThrow(Date.prototype.getDate.call(d)));
    125 test("new Date()", d => justDontThrow(Date.prototype.getUTCDate.call(d)));
    126 test("new Date()", d => justDontThrow(Date.prototype.getDay.call(d)));
    127 test("new Date()", d => justDontThrow(Date.prototype.getUTCDay.call(d)));
    128 test("new Date()", d => justDontThrow(Date.prototype.getHours.call(d)));
    129 test("new Date()", d => justDontThrow(Date.prototype.getUTCHours.call(d)));
    130 test("new Date()", d => justDontThrow(Date.prototype.getMinutes.call(d)));
    131 test("new Date()", d => justDontThrow(Date.prototype.getUTCMinutes.call(d)));
    132 test("new Date()", d => justDontThrow(Date.prototype.getSeconds.call(d)));
    133 test("new Date()", d => justDontThrow(Date.prototype.getUTCSeconds.call(d)));
    134 test("new Date()", d => justDontThrow(Date.prototype.getTimezoneOffset.call(d)));
    135 test("new Date()", d => justDontThrow(Date.prototype.setTime.call(d)));
    136 test("new Date()", d => justDontThrow(Date.prototype.setMilliseconds.call(d)));
    137 test("new Date()", d => justDontThrow(Date.prototype.setUTCMilliseconds.call(d)));
    138 test("new Date()", d => justDontThrow(Date.prototype.setSeconds.call(d)));
    139 test("new Date()", d => justDontThrow(Date.prototype.setUTCSeconds.call(d)));
    140 test("new Date()", d => justDontThrow(Date.prototype.setMinutes.call(d)));
    141 test("new Date()", d => justDontThrow(Date.prototype.setUTCMinutes.call(d)));
    142 test("new Date()", d => justDontThrow(Date.prototype.setHours.call(d)));
    143 test("new Date()", d => justDontThrow(Date.prototype.setUTCHours.call(d)));
    144 test("new Date()", d => justDontThrow(Date.prototype.setDate.call(d)));
    145 test("new Date()", d => justDontThrow(Date.prototype.setUTCDate.call(d)));
    146 test("new Date()", d => justDontThrow(Date.prototype.setMonth.call(d)));
    147 test("new Date()", d => justDontThrow(Date.prototype.setUTCMonth.call(d)));
    148 test("new Date()", d => justDontThrow(Date.prototype.setFullYear.call(d)));
    149 test("new Date()", d => justDontThrow(Date.prototype.setUTCFullYear.call(d)));
    150 test("new Date()", d => justDontThrow(Date.prototype.setYear.call(d)));
    151 test("new Date()", d => justDontThrow(Date.prototype.toGMTString.call(d)));
    152 test("new Date()", d => justDontThrow(Date.prototype.toISOString.call(d)));
    153 test("new Date()", d => justDontThrow(Date.prototype.toLocaleString.call(d)));
    154 test("new Date()", d => justDontThrow(Date.prototype.toLocaleDateString.call(d)));
    155 test("new Date()", d => justDontThrow(Date.prototype.toLocaleTimeString.call(d)));
    156 test("new Date()", d => justDontThrow(Date.prototype.toTimeString.call(d)));
    157 test("new Date()", d => justDontThrow(Date.prototype.toDateString.call(d)));
    158 if (Date.prototype.toSource) {
    159    test("new Date()", d => justDontThrow(Date.prototype.toSource.call(d)));
    160 }
    161 test("new Date()", d => justDontThrow(Date.prototype.toString.call(d)));
    162 test("new Date()", d => justDontThrow(Date.prototype.valueOf.call(d)));
    163 
    164 throw "done";