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 | load(libdir + "asm.js"); |
michael@0 | 2 | load(libdir + "asserts.js"); |
michael@0 | 3 | |
michael@0 | 4 | assertAsmTypeFail(USE_ASM); |
michael@0 | 5 | assertAsmTypeFail(USE_ASM + 'return'); |
michael@0 | 6 | assertAsmTypeFail(USE_ASM + 'function f() 0'); |
michael@0 | 7 | assertAsmTypeFail(USE_ASM + 'function f(){}'); |
michael@0 | 8 | assertAsmTypeFail(USE_ASM + 'function f(){} return 0'); |
michael@0 | 9 | assertAsmTypeFail(USE_ASM + 'function f() 0; return 0'); |
michael@0 | 10 | assertAsmTypeFail(USE_ASM + 'function f(){} return g'); |
michael@0 | 11 | assertAsmTypeFail(USE_ASM + 'function f(){} function f(){} return f'); |
michael@0 | 12 | assertAsmTypeFail(USE_ASM + 'var f=0; function f(){} return f'); |
michael@0 | 13 | assertAsmTypeFail('glob', USE_ASM + 'var f=glob.Math.imul; function f(){} return f'); |
michael@0 | 14 | assertAsmTypeFail('glob','foreign', USE_ASM + 'var f=foreign.foo; function f(){} return f'); |
michael@0 | 15 | assertAsmTypeFail(USE_ASM + 'function f(){} var f=[f,f]; return f'); |
michael@0 | 16 | assertAsmTypeFail(USE_ASM + 'function f() 0; return f'); |
michael@0 | 17 | assertAsmTypeFail('"use strict";' + USE_ASM + 'function f() {} return f'); |
michael@0 | 18 | assertAsmTypeFail(USE_ASM + '"use strict"; function f() {} return f'); |
michael@0 | 19 | assertEq(asmLink(asmCompile(USE_ASM + 'function f(){} return f'))(), undefined); |
michael@0 | 20 | assertEq(asmLink(asmCompile(USE_ASM + 'function f(){;} return f'))(), undefined); |
michael@0 | 21 | assertAsmTypeFail(USE_ASM + 'function f(i,j){;} return f'); |
michael@0 | 22 | assertEq(asmLink(asmCompile('"use asm";; function f(){};;; return f;;'))(), undefined); |
michael@0 | 23 | assertAsmTypeFail(USE_ASM + 'function f(x){} return f'); |
michael@0 | 24 | assertAsmTypeFail(USE_ASM + 'function f(){return; return 1} return f'); |
michael@0 | 25 | assertEq(asmLink(asmCompile(USE_ASM + 'function f(x){x=x|0} return f'))(42), undefined); |
michael@0 | 26 | assertEq(asmLink(asmCompile(USE_ASM + 'function f(x){x=x|0; return x|0} return f'))(42), 42); |
michael@0 | 27 | assertEq(asmLink(asmCompile(USE_ASM + 'function f(x){x=x|0; return x|0;;;} return f'))(42), 42); |
michael@0 | 28 | assertEq(asmLink(asmCompile(USE_ASM + 'function f(x,y){x=x|0;y=y|0; return (x+y)|0} return f'))(44, -2), 42); |
michael@0 | 29 | assertAsmTypeFail('a', USE_ASM + 'function a(){} return a'); |
michael@0 | 30 | assertAsmTypeFail('a','b','c', USE_ASM + 'var c'); |
michael@0 | 31 | assertAsmTypeFail('a','b','c', USE_ASM + 'var c=0'); |
michael@0 | 32 | assertAsmTypeFail(USE_ASM + 'c=0;return {}'); |
michael@0 | 33 | assertAsmTypeFail('x','x', USE_ASM + 'function a(){} return a'); |
michael@0 | 34 | assertAsmTypeFail('x','y','x', USE_ASM + 'function a(){} return a'); |
michael@0 | 35 | assertEq(asmLink(asmCompile('x', USE_ASM + 'function a(){} return a'))(), undefined); |
michael@0 | 36 | assertEq(asmLink(asmCompile('x','y', USE_ASM + 'function a(){} return a'))(), undefined); |
michael@0 | 37 | assertEq(asmLink(asmCompile('x','y','z', USE_ASM + 'function a(){} return a'))(), undefined); |
michael@0 | 38 | assertAsmTypeFail('x','y', USE_ASM + 'function y(){} return f'); |
michael@0 | 39 | assertEq(asmLink(asmCompile('x', USE_ASM + 'function f(){} return f'), 1, 2, 3)(), undefined); |
michael@0 | 40 | assertEq(asmLink(asmCompile('x', USE_ASM + 'function f(){} return f'), 1)(), undefined); |
michael@0 | 41 | assertEq(asmLink(asmCompile('x','y', USE_ASM + 'function f(){} return f'), 1, 2)(), undefined); |
michael@0 | 42 | |
michael@0 | 43 | assertEq(asmLink(asmCompile(USE_ASM + 'function f(i) {i=i|0} return f'))(42), undefined); |
michael@0 | 44 | assertEq(asmLink(asmCompile(USE_ASM + 'function f() {var i=0;; var j=1;} return f'))(), undefined); // bug 877965 second part |
michael@0 | 45 | assertAsmTypeFail(USE_ASM + 'function f(i) {i=i|0;var i} return f'); |
michael@0 | 46 | assertAsmTypeFail(USE_ASM + 'function f(i) {i=i|0;var i=0} return f'); |
michael@0 | 47 | |
michael@0 | 48 | assertAsmTypeFail('glob', USE_ASM + 'var im=glob.imul; function f() {} return f'); |
michael@0 | 49 | assertAsmLinkAlwaysFail(asmCompile('glob', USE_ASM + 'var im=glob.Math.imul; function f(i,j) {i=i|0;j=j|0; return im(i,j)|0} return f'), null); |
michael@0 | 50 | assertAsmLinkAlwaysFail(asmCompile('glob', USE_ASM + 'var im=glob.Math.imul; function f(i,j) {i=i|0;j=j|0; return im(i,j)|0} return f'), {}); |
michael@0 | 51 | assertAsmLinkAlwaysFail(asmCompile('glob', USE_ASM + 'var im=glob.Math.imul; function f(i,j) {i=i|0;j=j|0; return im(i,j)|0} return f'), {imul:Math.imul}); |
michael@0 | 52 | assertEq(asmLink(asmCompile('glob', USE_ASM + 'var im=glob.Math.imul; function f(i,j) {i=i|0;j=j|0; return im(i,j)|0} return f'), {Math:{imul:Math.imul}})(2,3), 6); |
michael@0 | 53 | assertEq(asmLink(asmCompile('glob', USE_ASM + 'var im=glob.Math.imul; function f(i,j) {i=i|0;j=j|0; return im(i,j)|0} return f'), this)(8,4), 32); |
michael@0 | 54 | |
michael@0 | 55 | assertAsmLinkAlwaysFail(asmCompile('glob','i','b', USE_ASM + 'var i32=new glob.Int32Array(b); function f(){} return f'), null, null); |
michael@0 | 56 | assertAsmLinkAlwaysFail(asmCompile('glob','i','b', USE_ASM + 'var i32=new glob.Int32Array(b); function f(){} return f'), this, null, null); |
michael@0 | 57 | assertAsmLinkAlwaysFail(asmCompile('glob','i','b', USE_ASM + 'var i32=new glob.Int32Array(b); function f(){} return f'), this, null, null); |
michael@0 | 58 | assertAsmLinkAlwaysFail(asmCompile('glob','i','b', USE_ASM + 'var i32=new glob.Int32Array(b); function f(){} return f'), this, null, new ArrayBuffer(1)); |
michael@0 | 59 | assertAsmLinkFail(asmCompile('glob','i','b', USE_ASM + 'var i32=new glob.Int32Array(b); function f(){} return f'), this, null, new ArrayBuffer(100)); |
michael@0 | 60 | assertAsmLinkFail(asmCompile('glob','i','b', USE_ASM + 'var i32=new glob.Int32Array(b); function f(){} return f'), this, null, new ArrayBuffer(4000)); |
michael@0 | 61 | assertEq(asmLink(asmCompile('glob','i','b', USE_ASM + 'var i32=new glob.Int32Array(b); function f(){} return f'), this, null, new ArrayBuffer(4096))(), undefined); |
michael@0 | 62 | assertEq(asmLink(asmCompile('glob','i','b', USE_ASM + 'var i32=new glob.Int32Array(b); function f(){} return f'), this, null, new ArrayBuffer(2*4096))(), undefined); |
michael@0 | 63 | |
michael@0 | 64 | assertAsmTypeFail('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i) {i=i|0; i = i32[i]|0; return i|0}; return f'); |
michael@0 | 65 | assertAsmTypeFail('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i) {i=i|0; i = i32[i>>1]|0; return i|0}; return f'); |
michael@0 | 66 | assertAsmTypeFail('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i) {i=i|0; i = i32[i>>1]|0; return i|0}; return f'); |
michael@0 | 67 | assertAsmLinkAlwaysFail(asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i) {i=i|0; i = i32[i>>2]|0; return i|0}; return f'), this, null, new ArrayBuffer(4095)); |
michael@0 | 68 | assertEq(asmCompile('glob', 'imp', 'b', USE_ASM + HEAP_IMPORTS + 'function f(i) {i=i|0; i = i32[i>>2]|0; return i|0}; return f')(this, null, new ArrayBuffer(4096))(), 0); |
michael@0 | 69 | |
michael@0 | 70 | var exp = asmLink(asmCompile(USE_ASM + "return {}")); |
michael@0 | 71 | assertEq(Object.keys(exp).length, 0); |
michael@0 | 72 | |
michael@0 | 73 | var exp = asmLink(asmCompile(USE_ASM + "function f() { return 3 } return {f:f,f:f}")); |
michael@0 | 74 | assertEq(exp.f(), 3); |
michael@0 | 75 | assertEq(Object.keys(exp).join(), 'f'); |
michael@0 | 76 | |
michael@0 | 77 | assertAsmTypeFail(USE_ASM + "function f() { return 3 } return {1:f}"); |
michael@0 | 78 | assertAsmTypeFail(USE_ASM + "function f() { return 3 } return {__proto__:f}"); |
michael@0 | 79 | assertAsmTypeFail(USE_ASM + "function f() { return 3 } return {get x() {} }"); |
michael@0 | 80 | |
michael@0 | 81 | var exp = asmLink(asmCompile(USE_ASM + 'function internal() { return ((g()|0)+2)|0 } function f() { return 1 } function g() { return 2 } function h() { return internal()|0 } return {f:f,g1:g,h1:h}')); |
michael@0 | 82 | assertEq(exp.f(), 1); |
michael@0 | 83 | assertEq(exp.g1(), 2); |
michael@0 | 84 | assertEq(exp.h1(), 4); |
michael@0 | 85 | assertEq(Object.keys(exp).join(), 'f,g1,h1'); |
michael@0 | 86 | |
michael@0 | 87 | // can't test destructuring args with Function constructor |
michael@0 | 88 | function assertTypeFailInEval(str) |
michael@0 | 89 | { |
michael@0 | 90 | if (!isAsmJSCompilationAvailable()) |
michael@0 | 91 | return; |
michael@0 | 92 | |
michael@0 | 93 | var caught = false; |
michael@0 | 94 | var oldOpts = options("werror"); |
michael@0 | 95 | assertEq(oldOpts.indexOf("werror"), -1); |
michael@0 | 96 | try { |
michael@0 | 97 | eval(str); |
michael@0 | 98 | } catch (e) { |
michael@0 | 99 | assertEq((''+e).indexOf(ASM_TYPE_FAIL_STRING) == -1, false); |
michael@0 | 100 | caught = true; |
michael@0 | 101 | } |
michael@0 | 102 | assertEq(caught, true); |
michael@0 | 103 | options("werror"); |
michael@0 | 104 | } |
michael@0 | 105 | assertTypeFailInEval('function f({}) { "use asm"; function g() {} return g }'); |
michael@0 | 106 | assertTypeFailInEval('function f({global}) { "use asm"; function g() {} return g }'); |
michael@0 | 107 | assertTypeFailInEval('function f(global, {imports}) { "use asm"; function g() {} return g }'); |
michael@0 | 108 | assertTypeFailInEval('function f(g = 2) { "use asm"; function g() {} return g }'); |
michael@0 | 109 | assertTypeFailInEval('function *f() { "use asm"; function g() {} return g }'); |
michael@0 | 110 | assertTypeFailInEval('f => { "use asm"; function g() {} return g }'); |
michael@0 | 111 | |
michael@0 | 112 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'var)') }, SyntaxError); |
michael@0 | 113 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'return)') }, SyntaxError); |
michael@0 | 114 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'var z=-2w') }, SyntaxError); |
michael@0 | 115 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'var z=-2w;') }, SyntaxError); |
michael@0 | 116 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'function') }, SyntaxError); |
michael@0 | 117 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'function f') }, SyntaxError); |
michael@0 | 118 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'function f(') }, SyntaxError); |
michael@0 | 119 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'function f()') }, SyntaxError); |
michael@0 | 120 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'function f() {') }, SyntaxError); |
michael@0 | 121 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'function f() {} var') }, SyntaxError); |
michael@0 | 122 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'function f() {} var TBL=-2w; return f') }, SyntaxError); |
michael@0 | 123 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'function f() {} var TBL=-2w return f') }, SyntaxError); |
michael@0 | 124 | assertThrowsInstanceOf(function() { new Function(USE_ASM + 'function () {}') }, SyntaxError); |
michael@0 | 125 | assertNoWarning(function() { parse("function f() { 'use asm'; function g() {} return g }") }); |