diff options
author | Sam Clegg <sbc@chromium.org> | 2020-11-11 15:50:33 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-11 15:50:33 -0800 |
commit | f0d6b089960e089bcc5c1794003585ebbd91d33a (patch) | |
tree | 25e44d01fb2343f3152abeceed593986d1a0998b /test/wasm2js | |
parent | d0d96a815fb2e6c397dce76fb1b74b803fd431f4 (diff) | |
download | binaryen-f0d6b089960e089bcc5c1794003585ebbd91d33a.tar.gz binaryen-f0d6b089960e089bcc5c1794003585ebbd91d33a.tar.bz2 binaryen-f0d6b089960e089bcc5c1794003585ebbd91d33a.zip |
wasm2js: Declare data segments before calling asmFunc (#3337)
This is because we maybe need to reference the segments
during the start function. For example in the case of
pthreads we conditionally load passive segments during
start.
Tested in emscripten with: tests/runner.py wasm2js1
Diffstat (limited to 'test/wasm2js')
29 files changed, 383 insertions, 380 deletions
diff --git a/test/wasm2js/atomic_fence.2asm.js b/test/wasm2js/atomic_fence.2asm.js index 7f35ea3ef..2caca85e6 100644 --- a/test/wasm2js/atomic_fence.2asm.js +++ b/test/wasm2js/atomic_fence.2asm.js @@ -9,7 +9,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -48,7 +47,6 @@ function asmFunc(env) { HEAPF32 = new Float32Array(newBuffer); HEAPF64 = new Float64Array(newBuffer); buffer = newBuffer; - bufferView = HEAPU8; } return oldPages; } @@ -58,7 +56,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); export var atomic_fence = retasmFunc.atomic_fence; diff --git a/test/wasm2js/atomics_32.2asm.js b/test/wasm2js/atomics_32.2asm.js index 99fc06a63..1b09d634d 100644 --- a/test/wasm2js/atomics_32.2asm.js +++ b/test/wasm2js/atomics_32.2asm.js @@ -1,4 +1,28 @@ + var bufferView; + var memorySegments = {}; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + } + return uint8Array; + } +memorySegments[0] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "aGVsbG8s"); +memorySegments[1] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "d29ybGQh"); var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -65,8 +89,6 @@ bufferView.set(memorySegments[segment].subarray(offset, offset + size), dest); } - var memorySegments = {}; - function asmFunc(env) { var buffer = new ArrayBuffer(16777216); var HEAP8 = new Int8Array(buffer); @@ -77,7 +99,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -122,6 +143,7 @@ function asmFunc(env) { i64toi32_i32$0 = wasm2js_get_stashed_bits() | 0; } + bufferView = HEAPU8; function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -131,28 +153,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); -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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); - for (; i < bLength; i += 4) { - b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; - b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; - if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; - } - return uint8Array; - } - memorySegments[0] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "aGVsbG8s"); -memorySegments[1] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "d29ybGQh"); export var test = retasmFunc.test; diff --git a/test/wasm2js/atomics_32.2asm.js.opt b/test/wasm2js/atomics_32.2asm.js.opt index 24c75a1aa..1b62f99b3 100644 --- a/test/wasm2js/atomics_32.2asm.js.opt +++ b/test/wasm2js/atomics_32.2asm.js.opt @@ -1,4 +1,28 @@ + var bufferView; + var memorySegments = {}; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + } + return uint8Array; + } +memorySegments[0] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "aGVsbG8s"); +memorySegments[1] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "d29ybGQh"); var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -65,8 +89,6 @@ bufferView.set(memorySegments[segment].subarray(offset, offset + size), dest); } - var memorySegments = {}; - function asmFunc(env) { var buffer = new ArrayBuffer(16777216); var HEAP8 = new Int8Array(buffer); @@ -77,7 +99,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -118,6 +139,7 @@ function asmFunc(env) { wasm2js_get_stashed_bits() | 0; } + bufferView = HEAPU8; function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -127,28 +149,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); -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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); - for (; i < bLength; i += 4) { - b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; - b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; - if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; - } - return uint8Array; - } - memorySegments[0] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "aGVsbG8s"); -memorySegments[1] = base64DecodeToExistingUint8Array(new Uint8Array(6), 0, "d29ybGQh"); export var test = retasmFunc.test; diff --git a/test/wasm2js/bulk-memory.2asm.js b/test/wasm2js/bulk-memory.2asm.js index b87b52d3c..a517931fb 100644 --- a/test/wasm2js/bulk-memory.2asm.js +++ b/test/wasm2js/bulk-memory.2asm.js @@ -21,6 +21,7 @@ function asmFunc(env) { var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); + var bufferView; var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -44,7 +45,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -70,6 +70,7 @@ function asmFunc(env) { return HEAPU8[$0_1 >> 0] | 0 | 0; } + bufferView = HEAPU8; function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -102,12 +103,35 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); export var fill = retasmFunc.fill; export var load8_u = retasmFunc.load8_u; + var bufferView; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + } + return uint8Array; + } +function initActiveSegments(imports) { + base64DecodeToExistingUint8Array(bufferView, 0, "qrvM3Q=="); +} var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -129,7 +153,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -155,6 +178,8 @@ function asmFunc(env) { return HEAPU8[$0_1 >> 0] | 0 | 0; } + bufferView = HEAPU8; + initActiveSegments(env); function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -165,10 +190,15 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); -for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i) { +export var copy = retasmFunc.copy; +export var load8_u = retasmFunc.load8_u; + + var bufferView; + var memorySegments = {}; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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' @@ -187,10 +217,7 @@ for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i } return uint8Array; } - base64DecodeToExistingUint8Array(bufferView, 0, "qrvM3Q=="); -export var copy = retasmFunc.copy; -export var load8_u = retasmFunc.load8_u; - +memorySegments[0] = base64DecodeToExistingUint8Array(new Uint8Array(4), 0, "qrvM3Q=="); var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -202,8 +229,6 @@ export var load8_u = retasmFunc.load8_u; bufferView.set(memorySegments[segment].subarray(offset, offset + size), dest); } - var memorySegments = {}; - function asmFunc(env) { var buffer = new ArrayBuffer(65536); var HEAP8 = new Int8Array(buffer); @@ -214,7 +239,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -240,6 +264,7 @@ function asmFunc(env) { return HEAPU8[$0_1 >> 0] | 0 | 0; } + bufferView = HEAPU8; function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -272,10 +297,15 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); -for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i) { +export var init = retasmFunc.init; +export var load8_u = retasmFunc.load8_u; + + var bufferView; + var memorySegments = {}; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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' @@ -294,10 +324,10 @@ for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i } return uint8Array; } - memorySegments[0] = base64DecodeToExistingUint8Array(new Uint8Array(4), 0, "qrvM3Q=="); -export var init = retasmFunc.init; -export var load8_u = retasmFunc.load8_u; - +memorySegments[0] = base64DecodeToExistingUint8Array(new Uint8Array(0), 0, ""); +function initActiveSegments(imports) { + base64DecodeToExistingUint8Array(bufferView, 0, ""); +} var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -314,8 +344,6 @@ export var load8_u = retasmFunc.load8_u; bufferView.set(memorySegments[segment].subarray(offset, offset + size), dest); } - var memorySegments = {}; - function asmFunc(env) { var buffer = new ArrayBuffer(65536); var HEAP8 = new Int8Array(buffer); @@ -326,7 +354,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -356,6 +383,8 @@ function asmFunc(env) { wasm2js_memory_init(1, 0, 0, 0); } + bufferView = HEAPU8; + initActiveSegments(env); function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -390,30 +419,8 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); -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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); - for (; i < bLength; i += 4) { - b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; - b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; - if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; - } - return uint8Array; - } - memorySegments[0] = base64DecodeToExistingUint8Array(new Uint8Array(0), 0, ""); -base64DecodeToExistingUint8Array(bufferView, 0, ""); export var drop_passive = retasmFunc.drop_passive; export var init_passive = retasmFunc.init_passive; export var drop_active = retasmFunc.drop_active; diff --git a/test/wasm2js/bulk-memory.2asm.js.opt b/test/wasm2js/bulk-memory.2asm.js.opt index 45914eaec..4febf1a84 100644 --- a/test/wasm2js/bulk-memory.2asm.js.opt +++ b/test/wasm2js/bulk-memory.2asm.js.opt @@ -21,6 +21,7 @@ function asmFunc(env) { var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); + var bufferView; var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -44,7 +45,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -70,6 +70,7 @@ function asmFunc(env) { return HEAPU8[$0_1 | 0]; } + bufferView = HEAPU8; function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -102,12 +103,35 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); export var fill = retasmFunc.fill; export var load8_u = retasmFunc.load8_u; + var bufferView; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + } + return uint8Array; + } +function initActiveSegments(imports) { + base64DecodeToExistingUint8Array(bufferView, 0, "qrvM3Q=="); +} var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -129,7 +153,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -155,6 +178,8 @@ function asmFunc(env) { return HEAPU8[$0_1 | 0]; } + bufferView = HEAPU8; + initActiveSegments(env); function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -165,10 +190,15 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); -for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i) { +export var copy = retasmFunc.copy; +export var load8_u = retasmFunc.load8_u; + + var bufferView; + var memorySegments = {}; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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' @@ -187,10 +217,7 @@ for (var base64ReverseLookup = new Uint8Array(123/*'z'+1*/), i = 25; i >= 0; --i } return uint8Array; } - base64DecodeToExistingUint8Array(bufferView, 0, "qrvM3Q=="); -export var copy = retasmFunc.copy; -export var load8_u = retasmFunc.load8_u; - +memorySegments[0] = base64DecodeToExistingUint8Array(new Uint8Array(4), 0, "qrvM3Q=="); var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -202,8 +229,6 @@ export var load8_u = retasmFunc.load8_u; bufferView.set(memorySegments[segment].subarray(offset, offset + size), dest); } - var memorySegments = {}; - function asmFunc(env) { var buffer = new ArrayBuffer(65536); var HEAP8 = new Int8Array(buffer); @@ -214,7 +239,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -240,6 +264,7 @@ function asmFunc(env) { return HEAPU8[$0_1 | 0]; } + bufferView = HEAPU8; function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -272,29 +297,8 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); -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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); - for (; i < bLength; i += 4) { - b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; - b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; - if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; - } - return uint8Array; - } - memorySegments[0] = base64DecodeToExistingUint8Array(new Uint8Array(4), 0, "qrvM3Q=="); export var init = retasmFunc.init; export var load8_u = retasmFunc.load8_u; @@ -308,7 +312,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -353,7 +356,6 @@ function asmFunc(env) { HEAPF32 = new Float32Array(newBuffer); HEAPF64 = new Float64Array(newBuffer); buffer = newBuffer; - bufferView = HEAPU8; } return oldPages; } @@ -366,7 +368,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); export var drop_passive = retasmFunc.drop_passive; diff --git a/test/wasm2js/deterministic.2asm.js b/test/wasm2js/deterministic.2asm.js index 6ab4739ac..8049c3f63 100644 --- a/test/wasm2js/deterministic.2asm.js +++ b/test/wasm2js/deterministic.2asm.js @@ -10,7 +10,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -41,7 +40,6 @@ function asmFunc(env) { }; } -var bufferView; var memasmFunc = new ArrayBuffer(65536); var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); }, memory: { buffer : memasmFunc } diff --git a/test/wasm2js/deterministic.2asm.js.opt b/test/wasm2js/deterministic.2asm.js.opt index 4f222ed42..b6b137d71 100644 --- a/test/wasm2js/deterministic.2asm.js.opt +++ b/test/wasm2js/deterministic.2asm.js.opt @@ -10,7 +10,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -40,7 +39,6 @@ function asmFunc(env) { }; } -var bufferView; var memasmFunc = new ArrayBuffer(65536); var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); }, memory: { buffer : memasmFunc } diff --git a/test/wasm2js/dynamicLibrary.2asm.js b/test/wasm2js/dynamicLibrary.2asm.js index 5e743768d..03f8b79ed 100644 --- a/test/wasm2js/dynamicLibrary.2asm.js +++ b/test/wasm2js/dynamicLibrary.2asm.js @@ -12,6 +12,30 @@ function Table(ret) { return ret; } + var bufferView; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + } + return uint8Array; + } +function initActiveSegments(imports) { + base64DecodeToExistingUint8Array(bufferView, imports[memoryBase], "ZHluYW1pYyBkYXRh"); +} function asmFunc(env) { var memory = env.memory; var buffer = memory.buffer; @@ -23,7 +47,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -51,6 +74,8 @@ function asmFunc(env) { } + bufferView = HEAPU8; + initActiveSegments(env); var FUNCTION_TABLE = Table(new Array(10)); FUNCTION_TABLE[import$tableBase + 0] = foo; FUNCTION_TABLE[import$tableBase + 1] = bar; @@ -64,29 +89,8 @@ function asmFunc(env) { }; } -var bufferView; var memasmFunc = new ArrayBuffer(16777216); var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); }, memory: { buffer : memasmFunc } }); -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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); - for (; i < bLength; i += 4) { - b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; - b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; - if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; - } - return uint8Array; - } - base64DecodeToExistingUint8Array(bufferView, memoryBase, "ZHluYW1pYyBkYXRh"); export var baz = retasmFunc.baz; diff --git a/test/wasm2js/dynamicLibrary.2asm.js.opt b/test/wasm2js/dynamicLibrary.2asm.js.opt index 6c310360c..c86293805 100644 --- a/test/wasm2js/dynamicLibrary.2asm.js.opt +++ b/test/wasm2js/dynamicLibrary.2asm.js.opt @@ -12,6 +12,30 @@ function Table(ret) { return ret; } + var bufferView; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + } + return uint8Array; + } +function initActiveSegments(imports) { + base64DecodeToExistingUint8Array(bufferView, imports[memoryBase], "ZHluYW1pYyBkYXRh"); +} function asmFunc(env) { var memory = env.memory; var buffer = memory.buffer; @@ -23,7 +47,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -43,6 +66,8 @@ function asmFunc(env) { } + bufferView = HEAPU8; + initActiveSegments(env); var FUNCTION_TABLE = Table(new Array(10)); FUNCTION_TABLE[import$tableBase + 0] = foo; FUNCTION_TABLE[import$tableBase + 1] = foo; @@ -56,29 +81,8 @@ function asmFunc(env) { }; } -var bufferView; var memasmFunc = new ArrayBuffer(16777216); var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); }, memory: { buffer : memasmFunc } }); -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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); - for (; i < bLength; i += 4) { - b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; - b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; - if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; - } - return uint8Array; - } - base64DecodeToExistingUint8Array(bufferView, memoryBase, "ZHluYW1pYyBkYXRh"); export var baz = retasmFunc.baz; diff --git a/test/wasm2js/emscripten-grow-no.2asm.js b/test/wasm2js/emscripten-grow-no.2asm.js index 898faa539..d349b622a 100644 --- a/test/wasm2js/emscripten-grow-no.2asm.js +++ b/test/wasm2js/emscripten-grow-no.2asm.js @@ -1,4 +1,28 @@ function instantiate(asmLibraryArg) { + var bufferView; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + } + return uint8Array; + } +function initActiveSegments(imports) { + base64DecodeToExistingUint8Array(bufferView, 1600, "YWJj"); +} function asmFunc(env) { var memory = env.memory; var buffer = memory.buffer; @@ -10,7 +34,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -28,6 +51,8 @@ function asmFunc(env) { ; // EMSCRIPTEN_END_FUNCS ; + bufferView = HEAPU8; + initActiveSegments(env); function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -47,27 +72,5 @@ function asmFunc(env) { }; } -var bufferView; -var exports = asmFunc(asmLibraryArg); -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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); - for (; i < bLength; i += 4) { - b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; - b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; - if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; - } - return uint8Array; - } - base64DecodeToExistingUint8Array(bufferView, 1600, "YWJj"); -return exports; -}
\ No newline at end of file + return asmFunc(asmLibraryArg); +} diff --git a/test/wasm2js/emscripten-grow-no.2asm.js.opt b/test/wasm2js/emscripten-grow-no.2asm.js.opt index 898faa539..d349b622a 100644 --- a/test/wasm2js/emscripten-grow-no.2asm.js.opt +++ b/test/wasm2js/emscripten-grow-no.2asm.js.opt @@ -1,4 +1,28 @@ function instantiate(asmLibraryArg) { + var bufferView; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + } + return uint8Array; + } +function initActiveSegments(imports) { + base64DecodeToExistingUint8Array(bufferView, 1600, "YWJj"); +} function asmFunc(env) { var memory = env.memory; var buffer = memory.buffer; @@ -10,7 +34,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -28,6 +51,8 @@ function asmFunc(env) { ; // EMSCRIPTEN_END_FUNCS ; + bufferView = HEAPU8; + initActiveSegments(env); function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -47,27 +72,5 @@ function asmFunc(env) { }; } -var bufferView; -var exports = asmFunc(asmLibraryArg); -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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); - for (; i < bLength; i += 4) { - b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; - b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; - if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; - } - return uint8Array; - } - base64DecodeToExistingUint8Array(bufferView, 1600, "YWJj"); -return exports; -}
\ No newline at end of file + return asmFunc(asmLibraryArg); +} diff --git a/test/wasm2js/emscripten-grow-yes.2asm.js b/test/wasm2js/emscripten-grow-yes.2asm.js index 7fce8936a..fb0ca4d8e 100644 --- a/test/wasm2js/emscripten-grow-yes.2asm.js +++ b/test/wasm2js/emscripten-grow-yes.2asm.js @@ -1,4 +1,28 @@ function instantiate(asmLibraryArg) { + var bufferView; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + } + return uint8Array; + } +function initActiveSegments(imports) { + base64DecodeToExistingUint8Array(bufferView, 1600, "YWJj"); +} function asmFunc(env) { var memory = env.memory; var buffer = memory.buffer; @@ -11,7 +35,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -29,6 +52,8 @@ function asmFunc(env) { ; // EMSCRIPTEN_END_FUNCS ; + bufferView = HEAPU8; + initActiveSegments(env); function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -71,27 +96,5 @@ function asmFunc(env) { }; } -var bufferView; -var exports = asmFunc(asmLibraryArg); -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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); - for (; i < bLength; i += 4) { - b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; - b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; - if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; - } - return uint8Array; - } - base64DecodeToExistingUint8Array(bufferView, 1600, "YWJj"); -return exports; -}
\ No newline at end of file + return asmFunc(asmLibraryArg); +} diff --git a/test/wasm2js/emscripten-grow-yes.2asm.js.opt b/test/wasm2js/emscripten-grow-yes.2asm.js.opt index 7fce8936a..fb0ca4d8e 100644 --- a/test/wasm2js/emscripten-grow-yes.2asm.js.opt +++ b/test/wasm2js/emscripten-grow-yes.2asm.js.opt @@ -1,4 +1,28 @@ function instantiate(asmLibraryArg) { + var bufferView; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + } + return uint8Array; + } +function initActiveSegments(imports) { + base64DecodeToExistingUint8Array(bufferView, 1600, "YWJj"); +} function asmFunc(env) { var memory = env.memory; var buffer = memory.buffer; @@ -11,7 +35,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -29,6 +52,8 @@ function asmFunc(env) { ; // EMSCRIPTEN_END_FUNCS ; + bufferView = HEAPU8; + initActiveSegments(env); function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -71,27 +96,5 @@ function asmFunc(env) { }; } -var bufferView; -var exports = asmFunc(asmLibraryArg); -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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); - for (; i < bLength; i += 4) { - b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; - b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; - if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; - } - return uint8Array; - } - base64DecodeToExistingUint8Array(bufferView, 1600, "YWJj"); -return exports; -}
\ No newline at end of file + return asmFunc(asmLibraryArg); +} diff --git a/test/wasm2js/emscripten.2asm.js b/test/wasm2js/emscripten.2asm.js index 6d8a1c357..d411b62a9 100644 --- a/test/wasm2js/emscripten.2asm.js +++ b/test/wasm2js/emscripten.2asm.js @@ -1,4 +1,29 @@ function instantiate(asmLibraryArg) { + var bufferView; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + } + return uint8Array; + } +function initActiveSegments(imports) { + base64DecodeToExistingUint8Array(bufferView, 1024, "aGVsbG8sIHdvcmxkIQoAAJwMAAAtKyAgIDBYMHgAKG51bGwpAAAAAAAAAAAAAAAAEQAKABEREQAAAAAFAAAAAAAACQAAAAALAAAAAAAAAAARAA8KERERAwoHAAETCQsLAAAJBgsAAAsABhEAAAAREREAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAEQAKChEREQAKAAACAAkLAAAACQALAAALAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAADAAAAAAJDAAAAAAADAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAANAAAABA0AAAAACQ4AAAAAAA4AAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAADwAAAAAPAAAAAAkQAAAAAAAQAAAQAAASAAAAEhISAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAASEhIAAAAAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="); +} function asmFunc(env) { var buffer = new ArrayBuffer(16777216); var FUNCTION_TABLE = env.table; @@ -10,7 +35,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -187,6 +211,8 @@ function asmFunc(env) { // EMSCRIPTEN_END_FUNCS ; + bufferView = HEAPU8; + initActiveSegments(env); FUNCTION_TABLE[1] = foo; FUNCTION_TABLE[2] = bar; FUNCTION_TABLE[3] = tabled; @@ -205,28 +231,5 @@ function asmFunc(env) { }; } -var bufferView; -var exports = asmFunc(asmLibraryArg); -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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); - for (; i < bLength; i += 4) { - b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; - b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; - if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; - } - return uint8Array; - } - base64DecodeToExistingUint8Array(bufferView, 1024, "aGVsbG8sIHdvcmxkIQoAAJwMAAAtKyAgIDBYMHgAKG51bGwpAAAAAAAAAAAAAAAAEQAKABEREQAAAAAFAAAAAAAACQAAAAALAAAAAAAAAAARAA8KERERAwoHAAETCQsLAAAJBgsAAAsABhEAAAAREREAAAAAAAAAAAAAAAAAAAAACwAAAAAAAAAAEQAKChEREQAKAAACAAkLAAAACQALAAALAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAwAAAAAAAAAAAAAAAwAAAAADAAAAAAJDAAAAAAADAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAANAAAABA0AAAAACQ4AAAAAAA4AAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAADwAAAAAPAAAAAAkQAAAAAAAQAAAQAAASAAAAEhISAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAASEhIAAAAAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAALAAAAAAAAAAAAAAAKAAAAAAoAAAAACQsAAAAAAAsAAAsAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADAAAAAAAAAAAAAAADAAAAAAMAAAAAAkMAAAAAAAMAAAMAAAwMTIzNDU2Nzg5QUJDREVGLTBYKzBYIDBYLTB4KzB4IDB4AGluZgBJTkYAbmFuAE5BTgAuAA=="); -base64DecodeToExistingUint8Array(bufferView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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="); -return exports; -}
\ No newline at end of file + return asmFunc(asmLibraryArg); +} diff --git a/test/wasm2js/emscripten.2asm.js.opt b/test/wasm2js/emscripten.2asm.js.opt index e01e4e462..5d14ea4b3 100644 --- a/test/wasm2js/emscripten.2asm.js.opt +++ b/test/wasm2js/emscripten.2asm.js.opt @@ -1,4 +1,41 @@ function instantiate(asmLibraryArg) { + var bufferView; + var base64ReverseLookup = new Uint8Array(123/*'z'+1*/); + for (var 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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); + for (; i < bLength; i += 4) { + b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; + b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; + uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; + if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; + if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; + } + return uint8Array; + } +function initActiveSegments(imports) { + base64DecodeToExistingUint8Array(bufferView, 1024, "aGVsbG8sIHdvcmxkIQoAAJwMAAAtKyAgIDBYMHgAKG51bGwp"); + base64DecodeToExistingUint8Array(bufferView, 1072, "EQAKABEREQAAAAAFAAAAAAAACQAAAAALAAAAAAAAAAARAA8KERERAwoHAAETCQsLAAAJBgsAAAsABhEAAAARERE="); + base64DecodeToExistingUint8Array(bufferView, 1153, "CwAAAAAAAAAAEQAKChEREQAKAAACAAkLAAAACQALAAAL"); + base64DecodeToExistingUint8Array(bufferView, 1211, "DA=="); + base64DecodeToExistingUint8Array(bufferView, 1223, "DAAAAAAMAAAAAAkMAAAAAAAMAAAM"); + base64DecodeToExistingUint8Array(bufferView, 1269, "Dg=="); + base64DecodeToExistingUint8Array(bufferView, 1281, "DQAAAAQNAAAAAAkOAAAAAAAOAAAO"); + base64DecodeToExistingUint8Array(bufferView, 1327, "EA=="); + base64DecodeToExistingUint8Array(bufferView, 1339, "DwAAAAAPAAAAAAkQAAAAAAAQAAAQAAASAAAAEhIS"); + base64DecodeToExistingUint8Array(bufferView, 1394, "EgAAABISEgAAAAAAAAk="); + base64DecodeToExistingUint8Array(bufferView, 1443, "Cw=="); + base64DecodeToExistingUint8Array(bufferView, 1455, "CgAAAAAKAAAAAAkLAAAAAAALAAAL"); + base64DecodeToExistingUint8Array(bufferView, 1501, "DA=="); + base64DecodeToExistingUint8Array(bufferView, 1513, "DAAAAAAMAAAAAAkMAAAAAAAMAAAMAAAwMTIzNDU2Nzg5QUJDREVGLTBYKzBYIDBYLTB4KzB4IDB4AGluZgBJTkYAbmFuAE5BTgAu"); +} function asmFunc(env) { var buffer = new ArrayBuffer(16777216); var FUNCTION_TABLE = env.table; @@ -10,7 +47,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -168,6 +204,8 @@ function asmFunc(env) { // EMSCRIPTEN_END_FUNCS ; + bufferView = HEAPU8; + initActiveSegments(env); FUNCTION_TABLE[1] = foo; FUNCTION_TABLE[2] = bar; FUNCTION_TABLE[3] = internal; @@ -186,40 +224,5 @@ function asmFunc(env) { }; } -var bufferView; -var exports = asmFunc(asmLibraryArg); -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) - (b64[bLength-2] == '=') - (b64[bLength-1] == '='); - for (; i < bLength; i += 4) { - b1 = base64ReverseLookup[b64.charCodeAt(i+1)]; - b2 = base64ReverseLookup[b64.charCodeAt(i+2)]; - uint8Array[j++] = base64ReverseLookup[b64.charCodeAt(i)] << 2 | b1 >> 4; - if (j < end) uint8Array[j++] = b1 << 4 | b2 >> 2; - if (j < end) uint8Array[j++] = b2 << 6 | base64ReverseLookup[b64.charCodeAt(i+3)]; - } - return uint8Array; - } - base64DecodeToExistingUint8Array(bufferView, 1024, "aGVsbG8sIHdvcmxkIQoAAJwMAAAtKyAgIDBYMHgAKG51bGwp"); -base64DecodeToExistingUint8Array(bufferView, 1072, "EQAKABEREQAAAAAFAAAAAAAACQAAAAALAAAAAAAAAAARAA8KERERAwoHAAETCQsLAAAJBgsAAAsABhEAAAARERE="); -base64DecodeToExistingUint8Array(bufferView, 1153, "CwAAAAAAAAAAEQAKChEREQAKAAACAAkLAAAACQALAAAL"); -base64DecodeToExistingUint8Array(bufferView, 1211, "DA=="); -base64DecodeToExistingUint8Array(bufferView, 1223, "DAAAAAAMAAAAAAkMAAAAAAAMAAAM"); -base64DecodeToExistingUint8Array(bufferView, 1269, "Dg=="); -base64DecodeToExistingUint8Array(bufferView, 1281, "DQAAAAQNAAAAAAkOAAAAAAAOAAAO"); -base64DecodeToExistingUint8Array(bufferView, 1327, "EA=="); -base64DecodeToExistingUint8Array(bufferView, 1339, "DwAAAAAPAAAAAAkQAAAAAAAQAAAQAAASAAAAEhIS"); -base64DecodeToExistingUint8Array(bufferView, 1394, "EgAAABISEgAAAAAAAAk="); -base64DecodeToExistingUint8Array(bufferView, 1443, "Cw=="); -base64DecodeToExistingUint8Array(bufferView, 1455, "CgAAAAAKAAAAAAkLAAAAAAALAAAL"); -base64DecodeToExistingUint8Array(bufferView, 1501, "DA=="); -base64DecodeToExistingUint8Array(bufferView, 1513, "DAAAAAAMAAAAAAkMAAAAAAAMAAAMAAAwMTIzNDU2Nzg5QUJDREVGLTBYKzBYIDBYLTB4KzB4IDB4AGluZgBJTkYAbmFuAE5BTgAu"); -return exports; -}
\ No newline at end of file + return asmFunc(asmLibraryArg); +} diff --git a/test/wasm2js/endianness.2asm.js b/test/wasm2js/endianness.2asm.js index c203eab2c..5d32183cb 100644 --- a/test/wasm2js/endianness.2asm.js +++ b/test/wasm2js/endianness.2asm.js @@ -1,5 +1,6 @@ import { setTempRet0 } from 'env'; + var bufferView; var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -40,7 +41,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -652,6 +652,7 @@ function asmFunc(env) { return $2 | 0; } + bufferView = HEAPU8; function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -699,7 +700,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); }, setTempRet0 }); diff --git a/test/wasm2js/grow-memory-tricky.2asm.js b/test/wasm2js/grow-memory-tricky.2asm.js index a2049364d..44e7d816f 100644 --- a/test/wasm2js/grow-memory-tricky.2asm.js +++ b/test/wasm2js/grow-memory-tricky.2asm.js @@ -9,7 +9,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -60,7 +59,6 @@ function asmFunc(env) { HEAPF32 = new Float32Array(newBuffer); HEAPF64 = new Float64Array(newBuffer); buffer = newBuffer; - bufferView = HEAPU8; } return oldPages; } @@ -82,7 +80,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); export var memory = retasmFunc.memory; diff --git a/test/wasm2js/grow-memory-tricky.2asm.js.opt b/test/wasm2js/grow-memory-tricky.2asm.js.opt index e1e2d8476..793feef27 100644 --- a/test/wasm2js/grow-memory-tricky.2asm.js.opt +++ b/test/wasm2js/grow-memory-tricky.2asm.js.opt @@ -9,7 +9,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -50,7 +49,6 @@ function asmFunc(env) { HEAPF32 = new Float32Array(newBuffer); HEAPF64 = new Float64Array(newBuffer); buffer = newBuffer; - bufferView = HEAPU8; } return oldPages; } @@ -72,7 +70,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); export var memory = retasmFunc.memory; diff --git a/test/wasm2js/grow_memory.2asm.js b/test/wasm2js/grow_memory.2asm.js index 11c5fe3b7..62de4bb90 100644 --- a/test/wasm2js/grow_memory.2asm.js +++ b/test/wasm2js/grow_memory.2asm.js @@ -9,7 +9,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -53,7 +52,6 @@ function asmFunc(env) { HEAPF32 = new Float32Array(newBuffer); HEAPF64 = new Float64Array(newBuffer); buffer = newBuffer; - bufferView = HEAPU8; } return oldPages; } @@ -75,7 +73,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); export var memory = retasmFunc.memory; diff --git a/test/wasm2js/left-to-right.2asm.js b/test/wasm2js/left-to-right.2asm.js index 7e066030d..8027956cb 100644 --- a/test/wasm2js/left-to-right.2asm.js +++ b/test/wasm2js/left-to-right.2asm.js @@ -1,4 +1,5 @@ + var bufferView; var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -35,7 +36,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -2040,6 +2040,7 @@ function asmFunc(env) { return 32 | 0; } + bufferView = HEAPU8; var FUNCTION_TABLE = [i32_t0, i32_t1, i64_t0, i64_t1, f32_t0, f32_t1, f64_t0, f64_t1]; function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; @@ -2166,7 +2167,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); export var i32_add = retasmFunc.i32_add; diff --git a/test/wasm2js/minified-memory.2asm.js b/test/wasm2js/minified-memory.2asm.js index bfb5fb75c..657ef011b 100644 --- a/test/wasm2js/minified-memory.2asm.js +++ b/test/wasm2js/minified-memory.2asm.js @@ -11,7 +11,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -51,7 +50,6 @@ function asmFunc(env) { HEAPF64 = new Float64Array(newBuffer); buffer = newBuffer; memory.buffer = buffer; - bufferView = HEAPU8; } return oldPages; } @@ -61,7 +59,6 @@ function asmFunc(env) { }; } -var bufferView; var memasmFunc = new ArrayBuffer(65536); var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); }, a: { buffer : memasmFunc } diff --git a/test/wasm2js/minified-memory.2asm.js.opt b/test/wasm2js/minified-memory.2asm.js.opt index 9819e879a..6a3e3a5d9 100644 --- a/test/wasm2js/minified-memory.2asm.js.opt +++ b/test/wasm2js/minified-memory.2asm.js.opt @@ -11,7 +11,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -51,7 +50,6 @@ function asmFunc(env) { HEAPF64 = new Float64Array(newBuffer); buffer = newBuffer; memory.buffer = buffer; - bufferView = HEAPU8; } return oldPages; } @@ -61,7 +59,6 @@ function asmFunc(env) { }; } -var bufferView; var memasmFunc = new ArrayBuffer(65536); var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); }, a: { buffer : memasmFunc } diff --git a/test/wasm2js/reinterpret_scratch.2asm.js b/test/wasm2js/reinterpret_scratch.2asm.js index 1d71d6613..b2c2a741b 100644 --- a/test/wasm2js/reinterpret_scratch.2asm.js +++ b/test/wasm2js/reinterpret_scratch.2asm.js @@ -1,4 +1,5 @@ + var bufferView; var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -27,7 +28,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -51,6 +51,7 @@ function asmFunc(env) { return HEAP32[0 >> 2] | 0 | 0; } + bufferView = HEAPU8; function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -60,7 +61,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); export var foo = retasmFunc.foo; diff --git a/test/wasm2js/reinterpret_scratch.2asm.js.opt b/test/wasm2js/reinterpret_scratch.2asm.js.opt index 749279140..cf0bb9a04 100644 --- a/test/wasm2js/reinterpret_scratch.2asm.js.opt +++ b/test/wasm2js/reinterpret_scratch.2asm.js.opt @@ -1,4 +1,5 @@ + var bufferView; var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -23,7 +24,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -46,6 +46,7 @@ function asmFunc(env) { return HEAP32[0]; } + bufferView = HEAPU8; function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -55,7 +56,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); export var foo = retasmFunc.foo; diff --git a/test/wasm2js/start_func.2asm.js b/test/wasm2js/start_func.2asm.js index 70b3458fe..f3694708a 100644 --- a/test/wasm2js/start_func.2asm.js +++ b/test/wasm2js/start_func.2asm.js @@ -9,7 +9,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -49,7 +48,6 @@ function asmFunc(env) { HEAPF32 = new Float32Array(newBuffer); HEAPF64 = new Float64Array(newBuffer); buffer = newBuffer; - bufferView = HEAPU8; } return oldPages; } @@ -59,6 +57,5 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); diff --git a/test/wasm2js/start_func.2asm.js.opt b/test/wasm2js/start_func.2asm.js.opt index 1c624c8aa..17e43c880 100644 --- a/test/wasm2js/start_func.2asm.js.opt +++ b/test/wasm2js/start_func.2asm.js.opt @@ -9,7 +9,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -49,7 +48,6 @@ function asmFunc(env) { HEAPF32 = new Float32Array(newBuffer); HEAPF64 = new Float64Array(newBuffer); buffer = newBuffer; - bufferView = HEAPU8; } return oldPages; } @@ -59,6 +57,5 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); diff --git a/test/wasm2js/traps.2asm.js b/test/wasm2js/traps.2asm.js index cca067d1c..5ca565d0e 100644 --- a/test/wasm2js/traps.2asm.js +++ b/test/wasm2js/traps.2asm.js @@ -1590,7 +1590,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -1701,7 +1700,6 @@ function asmFunc(env) { HEAPF32 = new Float32Array(newBuffer); HEAPF64 = new Float64Array(newBuffer); buffer = newBuffer; - bufferView = HEAPU8; } return oldPages; } @@ -1724,7 +1722,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); } }); export var no_dce_i32_load = retasmFunc.no_dce_i32_load; diff --git a/test/wasm2js/unaligned.2asm.js b/test/wasm2js/unaligned.2asm.js index fd6018450..8f8f3673b 100644 --- a/test/wasm2js/unaligned.2asm.js +++ b/test/wasm2js/unaligned.2asm.js @@ -1,5 +1,6 @@ import { setTempRet0 } from 'env'; + var bufferView; var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -40,7 +41,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -160,6 +160,7 @@ function asmFunc(env) { return $0_1 | 0; } + bufferView = HEAPU8; function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -176,7 +177,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); }, setTempRet0 }); diff --git a/test/wasm2js/unaligned.2asm.js.opt b/test/wasm2js/unaligned.2asm.js.opt index 0eb08a4c7..e5005fef5 100644 --- a/test/wasm2js/unaligned.2asm.js.opt +++ b/test/wasm2js/unaligned.2asm.js.opt @@ -1,5 +1,6 @@ import { setTempRet0 } from 'env'; + var bufferView; var scratchBuffer = new ArrayBuffer(16); var i32ScratchView = new Int32Array(scratchBuffer); @@ -36,7 +37,6 @@ function asmFunc(env) { var HEAPU32 = new Uint32Array(buffer); var HEAPF32 = new Float32Array(buffer); var HEAPF64 = new Float64Array(buffer); - bufferView = HEAPU8; var Math_imul = Math.imul; var Math_fround = Math.fround; var Math_abs = Math.abs; @@ -113,6 +113,7 @@ function asmFunc(env) { return $0_1; } + bufferView = HEAPU8; function __wasm_memory_size() { return buffer.byteLength / 65536 | 0; } @@ -129,7 +130,6 @@ function asmFunc(env) { }; } -var bufferView; var retasmFunc = asmFunc( { abort: function() { throw new Error('abort'); }, setTempRet0 }); |