Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /* See https://bugzilla.mozilla.org/show_bug.cgi?id=813901 */ |
michael@0 | 6 | |
michael@0 | 7 | const Cu = Components.utils; |
michael@0 | 8 | const TypedArrays = [ Int8Array, Uint8Array, Int16Array, Uint16Array, |
michael@0 | 9 | Int32Array, Uint32Array, Float32Array, Float64Array, |
michael@0 | 10 | Uint8ClampedArray ]; |
michael@0 | 11 | |
michael@0 | 12 | // Make sure that the correct nativecall-y stuff is denied on security wrappers. |
michael@0 | 13 | |
michael@0 | 14 | function run_test() { |
michael@0 | 15 | |
michael@0 | 16 | var sb = new Cu.Sandbox('http://www.example.org'); |
michael@0 | 17 | sb.obj = {foo: 2}; |
michael@0 | 18 | |
michael@0 | 19 | /* Set up some typed arrays. */ |
michael@0 | 20 | sb.ab = new ArrayBuffer(8); |
michael@0 | 21 | for (var i = 0; i < 8; ++i) |
michael@0 | 22 | new Uint8Array(sb.ab)[i] = i * 10; |
michael@0 | 23 | sb.ta = []; |
michael@0 | 24 | TypedArrays.forEach(function(f) sb.ta.push(new f(sb.ab))); |
michael@0 | 25 | sb.dv = new DataView(sb.ab); |
michael@0 | 26 | |
michael@0 | 27 | /* Things that should throw. */ |
michael@0 | 28 | checkThrows("Object.prototype.__lookupSetter__('__proto__').call(obj, {});", sb); |
michael@0 | 29 | sb.re = /f/; |
michael@0 | 30 | checkThrows("RegExp.prototype.exec.call(re, 'abcdefg').index", sb); |
michael@0 | 31 | sb.d = new Date(); |
michael@0 | 32 | checkThrows("Date.prototype.setYear.call(d, 2011)", sb); |
michael@0 | 33 | sb.m = new Map(); |
michael@0 | 34 | checkThrows("(new Map()).clear.call(m)", sb); |
michael@0 | 35 | checkThrows("ArrayBuffer.prototype.__lookupGetter__('byteLength').call(ab);", sb); |
michael@0 | 36 | checkThrows("ArrayBuffer.prototype.slice.call(ab, 0);", sb); |
michael@0 | 37 | checkThrows("DataView.prototype.getInt8.call(dv, 0);", sb); |
michael@0 | 38 | |
michael@0 | 39 | /* Now that Date is on Xrays, these should all throw. */ |
michael@0 | 40 | checkThrows("Date.prototype.getYear.call(d)", sb); |
michael@0 | 41 | checkThrows("Date.prototype.valueOf.call(d)", sb); |
michael@0 | 42 | checkThrows("d.valueOf()", sb); |
michael@0 | 43 | checkThrows("Date.prototype.toString.call(d)", sb); |
michael@0 | 44 | checkThrows("d.toString()", sb); |
michael@0 | 45 | |
michael@0 | 46 | /* Typed arrays. */ |
michael@0 | 47 | function testForTypedArray(t) { |
michael@0 | 48 | sb.curr = t; |
michael@0 | 49 | do_check_eq(Cu.evalInSandbox("this[curr.constructor.name].prototype.subarray.call(curr, 0)[0]", sb), t[0]); |
michael@0 | 50 | do_check_eq(Cu.evalInSandbox("(new this[curr.constructor.name]).__lookupGetter__('length').call(curr)", sb), t.length); |
michael@0 | 51 | do_check_eq(Cu.evalInSandbox("(new this[curr.constructor.name]).__lookupGetter__('buffer').call(curr)", sb), sb.ab); |
michael@0 | 52 | do_check_eq(Cu.evalInSandbox("(new this[curr.constructor.name]).__lookupGetter__('byteOffset').call(curr)", sb), t.byteOffset); |
michael@0 | 53 | do_check_eq(Cu.evalInSandbox("(new this[curr.constructor.name]).__lookupGetter__('byteLength').call(curr)", sb), t.byteLength); |
michael@0 | 54 | } |
michael@0 | 55 | sb.ta.forEach(testForTypedArray); |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | function checkThrows(expression, sb) { |
michael@0 | 59 | var result = Cu.evalInSandbox('(function() { try { ' + expression + '; return "allowed"; } catch (e) { return e.toString(); }})();', sb); |
michael@0 | 60 | dump('result: ' + result + '\n\n\n'); |
michael@0 | 61 | do_check_true(!!/denied/.exec(result)); |
michael@0 | 62 | } |
michael@0 | 63 |