Debian Codegraph @

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

raw
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 => RegExp.prototype.compile.call(r, '1').toString());
80 test("new RegExp('1')", r => assertEq("a1".search(r), 1));
81 test("new RegExp('1')", r => assertEq("a1".match(r)[0], '1'));
82 test("new RegExp('1')", r => assertEq("a1".replace(r, 'A'), 'aA'));
83 test("new RegExp('1')", r => assertEq(String("a1b".split(r)), "a,b"));
84 test("new RegExp('1')", r => assertEq(String(new RegExp(r)), String(r)));
85 test("new RegExp('1')", r => assertEq(String(/x/.compile(r)), String(r)));
86 test("new WeakMap()", w => WeakMap.prototype.has.call(w, {}));
87 test("new WeakMap()", w => WeakMap.prototype.get.call(w, {}));
88 test("new WeakMap()", w => WeakMap.prototype.delete.call(w, {}));
89 test("new WeakMap()", w => WeakMap.prototype.set.call(w, {}).toString());
90 test("new Map()", w => Map.prototype.has.call(w, {}));
91 test("new Map()", w => Map.prototype.get.call(w, {}));
92 test("new Map()", w => Map.prototype.delete.call(w, {}));
93 test("new Map()", w => Map.prototype.set.call(w, {}).toString());
94 test("new Set()", w => Set.prototype.has.call(w, {}));
95 test("new Set()", w => Set.prototype.add.call(w, {}).toString());
96 test("new Set()", w => Set.prototype.delete.call(w, {}));
97
98 test("new Int8Array(1)", a => Int8Array.prototype.subarray.call(a).toString());
99 test("new Uint8Array(1)", a => Uint8Array.prototype.subarray.call(a).toString());
100 test("new Int16Array(1)", a => Int16Array.prototype.subarray.call(a).toString());
101 test("new Uint16Array(1)", a => Uint16Array.prototype.subarray.call(a).toString());
102 test("new Int32Array(1)", a => Int32Array.prototype.subarray.call(a).toString());
103 test("new Uint32Array(1)", a => Uint32Array.prototype.subarray.call(a).toString());
104 test("new Float32Array(1)", a => Float32Array.prototype.subarray.call(a).toString());
105 test("new Float64Array(1)", a => Float64Array.prototype.subarray.call(a).toString());
106 test("new Uint8ClampedArray(1)", a => Uint8ClampedArray.prototype.subarray.call(a).toString());
107
108 test("new Int8Array(1)", a => Int8Array.prototype.set.call(a, []));
109 test("new Uint8Array(1)", a => Uint8Array.prototype.set.call(a, []));
110 test("new Int16Array(1)", a => Int16Array.prototype.set.call(a, []));
111 test("new Uint16Array(1)", a => Uint16Array.prototype.set.call(a, []));
112 test("new Int32Array(1)", a => Int32Array.prototype.set.call(a, []));
113 test("new Uint32Array(1)", a => Uint32Array.prototype.set.call(a, []));
114 test("new Float32Array(1)", a => Float32Array.prototype.set.call(a, []));
115 test("new Float64Array(1)", a => Float64Array.prototype.set.call(a, []));
116 test("new Uint8ClampedArray(1)", a => Uint8ClampedArray.prototype.set.call(a, []));
117
118 function justDontThrow() {}
119 test("new Date()", d => justDontThrow(Date.prototype.getTime.call(d)));
120 test("new Date()", d => justDontThrow(Date.prototype.getYear.call(d)));
121 test("new Date()", d => justDontThrow(Date.prototype.getFullYear.call(d)));
122 test("new Date()", d => justDontThrow(Date.prototype.getUTCFullYear.call(d)));
123 test("new Date()", d => justDontThrow(Date.prototype.getMonth.call(d)));
124 test("new Date()", d => justDontThrow(Date.prototype.getUTCMonth.call(d)));
125 test("new Date()", d => justDontThrow(Date.prototype.getDate.call(d)));
126 test("new Date()", d => justDontThrow(Date.prototype.getUTCDate.call(d)));
127 test("new Date()", d => justDontThrow(Date.prototype.getDay.call(d)));
128 test("new Date()", d => justDontThrow(Date.prototype.getUTCDay.call(d)));
129 test("new Date()", d => justDontThrow(Date.prototype.getHours.call(d)));
130 test("new Date()", d => justDontThrow(Date.prototype.getUTCHours.call(d)));
131 test("new Date()", d => justDontThrow(Date.prototype.getMinutes.call(d)));
132 test("new Date()", d => justDontThrow(Date.prototype.getUTCMinutes.call(d)));
133 test("new Date()", d => justDontThrow(Date.prototype.getSeconds.call(d)));
134 test("new Date()", d => justDontThrow(Date.prototype.getUTCSeconds.call(d)));
135 test("new Date()", d => justDontThrow(Date.prototype.getTimezoneOffset.call(d)));
136 test("new Date()", d => justDontThrow(Date.prototype.setTime.call(d)));
137 test("new Date()", d => justDontThrow(Date.prototype.setMilliseconds.call(d)));
138 test("new Date()", d => justDontThrow(Date.prototype.setUTCMilliseconds.call(d)));
139 test("new Date()", d => justDontThrow(Date.prototype.setSeconds.call(d)));
140 test("new Date()", d => justDontThrow(Date.prototype.setUTCSeconds.call(d)));
141 test("new Date()", d => justDontThrow(Date.prototype.setMinutes.call(d)));
142 test("new Date()", d => justDontThrow(Date.prototype.setUTCMinutes.call(d)));
143 test("new Date()", d => justDontThrow(Date.prototype.setHours.call(d)));
144 test("new Date()", d => justDontThrow(Date.prototype.setUTCHours.call(d)));
145 test("new Date()", d => justDontThrow(Date.prototype.setDate.call(d)));
146 test("new Date()", d => justDontThrow(Date.prototype.setUTCDate.call(d)));
147 test("new Date()", d => justDontThrow(Date.prototype.setMonth.call(d)));
148 test("new Date()", d => justDontThrow(Date.prototype.setUTCMonth.call(d)));
149 test("new Date()", d => justDontThrow(Date.prototype.setFullYear.call(d)));
150 test("new Date()", d => justDontThrow(Date.prototype.setUTCFullYear.call(d)));
151 test("new Date()", d => justDontThrow(Date.prototype.setYear.call(d)));
152 test("new Date()", d => justDontThrow(Date.prototype.toGMTString.call(d)));
153 test("new Date()", d => justDontThrow(Date.prototype.toISOString.call(d)));
154 test("new Date()", d => justDontThrow(Date.prototype.toLocaleString.call(d)));
155 test("new Date()", d => justDontThrow(Date.prototype.toLocaleDateString.call(d)));
156 test("new Date()", d => justDontThrow(Date.prototype.toLocaleTimeString.call(d)));
157 test("new Date()", d => justDontThrow(Date.prototype.toTimeString.call(d)));
158 test("new Date()", d => justDontThrow(Date.prototype.toDateString.call(d)));
159 if (Date.prototype.toSource) {
160 test("new Date()", d => justDontThrow(Date.prototype.toSource.call(d)));
161 }
162 test("new Date()", d => justDontThrow(Date.prototype.toString.call(d)));
163 test("new Date()", d => justDontThrow(Date.prototype.valueOf.call(d)));
164
165 throw "done";