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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/basic/testCrossCompartmentTransparency.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,172 @@
     1.4 +// |jit-test| error: done
     1.5 +
     1.6 +var g1 = newGlobal('same-compartment');
     1.7 +var g2 = newGlobal();
     1.8 +var proxyStr = "Proxy.create(                                    "+
     1.9 +"  { getOwnPropertyDescriptor: function() assertEq(true,false),  "+
    1.10 +"    getPropertyDescriptor: function() assertEq(true,false),     "+
    1.11 +"    getOwnPropertyNames: function() assertEq(true,false),       "+
    1.12 +"    getPropertyNames: function() assertEq(true,false),          "+
    1.13 +"    defineProperty: function() assertEq(true,false),            "+
    1.14 +"    delete: function() assertEq(true,false),                    "+
    1.15 +"    fix: function() assertEq(true,false), },                    "+
    1.16 +"  Object.prototype                                              "+
    1.17 +");                                                              ";
    1.18 +var proxy1 = g1.eval(proxyStr);
    1.19 +var proxy2 = g2.eval(proxyStr);
    1.20 +
    1.21 +function test(str, f) {
    1.22 +    "use strict";
    1.23 +
    1.24 +    var x = f(eval(str));
    1.25 +    assertEq(x, f(g1.eval(str)));
    1.26 +    assertEq(x, f(g2.eval(str)));
    1.27 +
    1.28 +    var threw = false;
    1.29 +    try {
    1.30 +        f(g1.eval("new Object()"));
    1.31 +    } catch (e) {
    1.32 +        assertEq(Object.prototype.toString.call(e), "[object Error]");
    1.33 +        threw = true;
    1.34 +    }
    1.35 +    assertEq(threw, true);
    1.36 +    threw = false;
    1.37 +    try {
    1.38 +        f(g2.eval("new Object()"));
    1.39 +    } catch (e) {
    1.40 +        assertEq(Object.prototype.toString.call(e), "[object Error]");
    1.41 +        threw = true;
    1.42 +    }
    1.43 +    assertEq(threw, true);
    1.44 +    threw = false;
    1.45 +    try {
    1.46 +        f(proxy1);
    1.47 +    } catch (e) {
    1.48 +        assertEq(Object.prototype.toString.call(e), "[object Error]");
    1.49 +        threw = true;
    1.50 +    }
    1.51 +    assertEq(threw, true);
    1.52 +    threw = false;
    1.53 +    try {
    1.54 +        f(proxy2);
    1.55 +    } catch (e) {
    1.56 +        assertEq(Object.prototype.toString.call(e), "[object Error]");
    1.57 +        threw = true;
    1.58 +    }
    1.59 +    assertEq(threw, true);
    1.60 +}
    1.61 +
    1.62 +test("new Array(1,2,3)", function(a) Array.prototype.toSource.call(a));
    1.63 +test("new Boolean(true)", function(b) Boolean.prototype.toSource.call(b));
    1.64 +test("new Boolean(true)", function(b) Boolean.prototype.toString.call(b));
    1.65 +test("new Boolean(true)", function(b) Boolean.prototype.valueOf.call(b));
    1.66 +test("new Number(1)", function(n) Number.prototype.toSource.call(n));
    1.67 +test("new Number(1)", function(n) Number.prototype.toString.call(n));
    1.68 +test("new Number(1)", function(n) Number.prototype.valueOf.call(n));
    1.69 +test("new Number(1)", function(n) Number.prototype.toFixed.call(n));
    1.70 +test("new Number(1)", function(n) Number.prototype.toExponential.call(n));
    1.71 +test("new Number(1)", function(n) Number.prototype.toPrecision.call(n));
    1.72 +test("new Iterator({x:1})", function(i) Iterator.prototype.next.call(i).toString());
    1.73 +test("(function(){yield 1})()", function(i) (function(){yield})().next.call(i).toString());
    1.74 +test("new String('one')", function(s) String.prototype.toSource.call(s));
    1.75 +test("new String('one')", function(s) String.prototype.toString.call(s));
    1.76 +test("new RegExp('1')", function(r) RegExp.prototype.toString.call(r));
    1.77 +test("new RegExp('1')", function(r) RegExp.prototype.exec.call(r, '1').toString());
    1.78 +test("new RegExp('1')", function(r) RegExp.prototype.test.call(r, '1'));
    1.79 +test("new RegExp('1')", function(r) RegExp.prototype.compile.call(r, '1').toString());
    1.80 +test("new RegExp('1')", function(r) assertEq("a1".search(r), 1));
    1.81 +test("new RegExp('1')", function(r) assertEq("a1".match(r)[0], '1'));
    1.82 +test("new RegExp('1')", function(r) assertEq("a1".replace(r, 'A'), 'aA'));
    1.83 +test("new RegExp('1')", function(r) assertEq(String("a1b".split(r)), "a,b"));
    1.84 +test("new RegExp('1')", function(r) assertEq(r, RegExp(r)));
    1.85 +test("new RegExp('1')", function(r) assertEq(String(new RegExp(r)), String(r)));
    1.86 +test("new RegExp('1')", function(r) assertEq(String(/x/.compile(r)), String(r)));
    1.87 +test("new WeakMap()", function(w) WeakMap.prototype.has.call(w, {}));
    1.88 +test("new WeakMap()", function(w) WeakMap.prototype.get.call(w, {}));
    1.89 +test("new WeakMap()", function(w) WeakMap.prototype.delete.call(w, {}));
    1.90 +test("new WeakMap()", function(w) WeakMap.prototype.set.call(w, {}));
    1.91 +test("new Map()", function(w) Map.prototype.has.call(w, {}));
    1.92 +test("new Map()", function(w) Map.prototype.get.call(w, {}));
    1.93 +test("new Map()", function(w) Map.prototype.delete.call(w, {}));
    1.94 +test("new Map()", function(w) Map.prototype.set.call(w, {}));
    1.95 +test("new Set()", function(w) Set.prototype.has.call(w, {}));
    1.96 +test("new Set()", function(w) Set.prototype.add.call(w, {}));
    1.97 +test("new Set()", function(w) Set.prototype.delete.call(w, {}));
    1.98 +
    1.99 +test("new Int8Array(1)", function(a) Int8Array.prototype.subarray.call(a).toString());
   1.100 +test("new Uint8Array(1)", function(a) Uint8Array.prototype.subarray.call(a).toString());
   1.101 +test("new Int16Array(1)", function(a) Int16Array.prototype.subarray.call(a).toString());
   1.102 +test("new Uint16Array(1)", function(a) Uint16Array.prototype.subarray.call(a).toString());
   1.103 +test("new Int32Array(1)", function(a) Int32Array.prototype.subarray.call(a).toString());
   1.104 +test("new Uint32Array(1)", function(a) Uint32Array.prototype.subarray.call(a).toString());
   1.105 +test("new Float32Array(1)", function(a) Float32Array.prototype.subarray.call(a).toString());
   1.106 +test("new Float64Array(1)", function(a) Float64Array.prototype.subarray.call(a).toString());
   1.107 +test("new Uint8ClampedArray(1)", function(a) Uint8ClampedArray.prototype.subarray.call(a).toString());
   1.108 +
   1.109 +test("new Int8Array(1)", function(a) Int8Array.subarray(a).toString());
   1.110 +test("new Uint8Array(1)", function(a) Uint8Array.subarray(a).toString());
   1.111 +test("new Int16Array(1)", function(a) Int16Array.subarray(a).toString());
   1.112 +test("new Uint16Array(1)", function(a) Uint16Array.subarray(a).toString());
   1.113 +test("new Int32Array(1)", function(a) Int32Array.subarray(a).toString());
   1.114 +test("new Uint32Array(1)", function(a) Uint32Array.subarray(a).toString());
   1.115 +test("new Float32Array(1)", function(a) Float32Array.subarray(a).toString());
   1.116 +test("new Float64Array(1)", function(a) Float64Array.subarray(a).toString());
   1.117 +test("new Uint8ClampedArray(1)", function(a) Uint8ClampedArray.subarray(a).toString());
   1.118 +
   1.119 +test("new Int8Array(1)", function(a) Int8Array.prototype.set.call(a, []));
   1.120 +test("new Uint8Array(1)", function(a) Uint8Array.prototype.set.call(a, []));
   1.121 +test("new Int16Array(1)", function(a) Int16Array.prototype.set.call(a, []));
   1.122 +test("new Uint16Array(1)", function(a) Uint16Array.prototype.set.call(a, []));
   1.123 +test("new Int32Array(1)", function(a) Int32Array.prototype.set.call(a, []));
   1.124 +test("new Uint32Array(1)", function(a) Uint32Array.prototype.set.call(a, []));
   1.125 +test("new Float32Array(1)", function(a) Float32Array.prototype.set.call(a, []));
   1.126 +test("new Float64Array(1)", function(a) Float64Array.prototype.set.call(a, []));
   1.127 +test("new Uint8ClampedArray(1)", function(a) Uint8ClampedArray.prototype.set.call(a, []));
   1.128 +
   1.129 +function justDontThrow() {}
   1.130 +test("new Date()", function(d) justDontThrow(Date.prototype.getTime.call(d)));
   1.131 +test("new Date()", function(d) justDontThrow(Date.prototype.getYear.call(d)));
   1.132 +test("new Date()", function(d) justDontThrow(Date.prototype.getFullYear.call(d)));
   1.133 +test("new Date()", function(d) justDontThrow(Date.prototype.getUTCFullYear.call(d)));
   1.134 +test("new Date()", function(d) justDontThrow(Date.prototype.getMonth.call(d)));
   1.135 +test("new Date()", function(d) justDontThrow(Date.prototype.getUTCMonth.call(d)));
   1.136 +test("new Date()", function(d) justDontThrow(Date.prototype.getDate.call(d)));
   1.137 +test("new Date()", function(d) justDontThrow(Date.prototype.getUTCDate.call(d)));
   1.138 +test("new Date()", function(d) justDontThrow(Date.prototype.getDay.call(d)));
   1.139 +test("new Date()", function(d) justDontThrow(Date.prototype.getUTCDay.call(d)));
   1.140 +test("new Date()", function(d) justDontThrow(Date.prototype.getHours.call(d)));
   1.141 +test("new Date()", function(d) justDontThrow(Date.prototype.getUTCHours.call(d)));
   1.142 +test("new Date()", function(d) justDontThrow(Date.prototype.getMinutes.call(d)));
   1.143 +test("new Date()", function(d) justDontThrow(Date.prototype.getUTCMinutes.call(d)));
   1.144 +test("new Date()", function(d) justDontThrow(Date.prototype.getSeconds.call(d)));
   1.145 +test("new Date()", function(d) justDontThrow(Date.prototype.getUTCSeconds.call(d)));
   1.146 +test("new Date()", function(d) justDontThrow(Date.prototype.getTimezoneOffset.call(d)));
   1.147 +test("new Date()", function(d) justDontThrow(Date.prototype.setTime.call(d)));
   1.148 +test("new Date()", function(d) justDontThrow(Date.prototype.setMilliseconds.call(d)));
   1.149 +test("new Date()", function(d) justDontThrow(Date.prototype.setUTCMilliseconds.call(d)));
   1.150 +test("new Date()", function(d) justDontThrow(Date.prototype.setSeconds.call(d)));
   1.151 +test("new Date()", function(d) justDontThrow(Date.prototype.setUTCSeconds.call(d)));
   1.152 +test("new Date()", function(d) justDontThrow(Date.prototype.setMinutes.call(d)));
   1.153 +test("new Date()", function(d) justDontThrow(Date.prototype.setUTCMinutes.call(d)));
   1.154 +test("new Date()", function(d) justDontThrow(Date.prototype.setHours.call(d)));
   1.155 +test("new Date()", function(d) justDontThrow(Date.prototype.setUTCHours.call(d)));
   1.156 +test("new Date()", function(d) justDontThrow(Date.prototype.setDate.call(d)));
   1.157 +test("new Date()", function(d) justDontThrow(Date.prototype.setUTCDate.call(d)));
   1.158 +test("new Date()", function(d) justDontThrow(Date.prototype.setMonth.call(d)));
   1.159 +test("new Date()", function(d) justDontThrow(Date.prototype.setUTCMonth.call(d)));
   1.160 +test("new Date()", function(d) justDontThrow(Date.prototype.setFullYear.call(d)));
   1.161 +test("new Date()", function(d) justDontThrow(Date.prototype.setUTCFullYear.call(d)));
   1.162 +test("new Date()", function(d) justDontThrow(Date.prototype.setYear.call(d)));
   1.163 +test("new Date()", function(d) justDontThrow(Date.prototype.toGMTString.call(d)));
   1.164 +test("new Date()", function(d) justDontThrow(Date.prototype.toISOString.call(d)));
   1.165 +test("new Date()", function(d) justDontThrow(Date.prototype.toLocaleString.call(d)));
   1.166 +test("new Date()", function(d) justDontThrow(Date.prototype.toLocaleDateString.call(d)));
   1.167 +test("new Date()", function(d) justDontThrow(Date.prototype.toLocaleTimeString.call(d)));
   1.168 +test("new Date()", function(d) justDontThrow(Date.prototype.toLocaleFormat.call(d)));
   1.169 +test("new Date()", function(d) justDontThrow(Date.prototype.toTimeString.call(d)));
   1.170 +test("new Date()", function(d) justDontThrow(Date.prototype.toDateString.call(d)));
   1.171 +test("new Date()", function(d) justDontThrow(Date.prototype.toSource.call(d)));
   1.172 +test("new Date()", function(d) justDontThrow(Date.prototype.toString.call(d)));
   1.173 +test("new Date()", function(d) justDontThrow(Date.prototype.valueOf.call(d)));
   1.174 +
   1.175 +throw "done";

mercurial