diff options
Diffstat (limited to 'test/wasm2js/dynamicLibrary.2asm.js.opt')
-rw-r--r-- | test/wasm2js/dynamicLibrary.2asm.js.opt | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/test/wasm2js/dynamicLibrary.2asm.js.opt b/test/wasm2js/dynamicLibrary.2asm.js.opt index 61669987f..28c547fb4 100644 --- a/test/wasm2js/dynamicLibrary.2asm.js.opt +++ b/test/wasm2js/dynamicLibrary.2asm.js.opt @@ -42,23 +42,27 @@ function asmFunc(global, env, buffer) { } var memasmFunc = new ArrayBuffer(16777216); -var assignasmFunc = ( - function(mem) { - var _mem = new Uint8Array(mem); - return function(offset, s) { - var bytes, i; - if (typeof Buffer === 'undefined') { - bytes = atob(s); - for (i = 0; i < bytes.length; i++) - _mem[offset + i] = bytes.charCodeAt(i); - } else { - bytes = Buffer.from(s, 'base64'); - for (i = 0; i < bytes.length; i++) - _mem[offset + i] = bytes[i]; - } - } +for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i) { + base64ReverseLookup[48+i] = 52+i; // '0-9' + base64ReverseLookup[65+i] = i; // 'A-Z' + base64ReverseLookup[97+i] = 26+i; // 'a-z' + } + base64ReverseLookup[43] = 62; // '+' + base64ReverseLookup[47] = 63; // '/' + /** @noinline Inlining this function would mean expanding the base64 string 4x times in the source code, which Closure seems to be happy to do. */ + function base64DecodeToExistingUint8Array(uint8Array, offset, b64) { + var b1, b2, i = 0, j = offset, bLength = b64.length, end = offset + (bLength*3>>2); + if (b64[bLength-2] == '=') --end; + if (b64[bLength-1] == '=') --end; + for (; i < bLength; i += 4, j += 3) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j+1 < end) uint8Array[j+1] = b1 << 4 | b2 >> 2; + if (j+2 < end) uint8Array[j+2] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; } - )(memasmFunc); -assignasmFunc(memoryBase, "ZHluYW1pYyBkYXRh"); + } +var bufferView = new Uint8Array(memasmFunc); +base64DecodeToExistingUint8Array(bufferView, memoryBase, "ZHluYW1pYyBkYXRh"); var retasmFunc = asmFunc({Math,Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,NaN,Infinity}, {abort:function() { throw new Error('abort'); }},memasmFunc); export var baz = retasmFunc.baz; |