js/src/jit-test/tests/basic/testCrossCompartmentTransparency.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial