diff options
author | Alon Zakai <azakai@google.com> | 2019-07-03 11:36:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-03 11:36:40 -0700 |
commit | 7d1ff56acafae9c769bc8dd8da2c8ef3c66a2aa6 (patch) | |
tree | e7c1a35f12090a09430a5acd6ea0738f4f64e32d /test/wasm2js/emscripten-grow-yes.2asm.js.opt | |
parent | 2d773d6ddfeaefffe7161fdd26b523f16608dce8 (diff) | |
download | binaryen-7d1ff56acafae9c769bc8dd8da2c8ef3c66a2aa6.tar.gz binaryen-7d1ff56acafae9c769bc8dd8da2c8ef3c66a2aa6.tar.bz2 binaryen-7d1ff56acafae9c769bc8dd8da2c8ef3c66a2aa6.zip |
wasm2js: export memory growth function only if memory growth is enabled (#2194)
Previously we tried to export it if the memory was exported, even if growth was not on, which caused an error.
Diffstat (limited to 'test/wasm2js/emscripten-grow-yes.2asm.js.opt')
-rw-r--r-- | test/wasm2js/emscripten-grow-yes.2asm.js.opt | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/test/wasm2js/emscripten-grow-yes.2asm.js.opt b/test/wasm2js/emscripten-grow-yes.2asm.js.opt new file mode 100644 index 000000000..0f0027beb --- /dev/null +++ b/test/wasm2js/emscripten-grow-yes.2asm.js.opt @@ -0,0 +1,106 @@ +function instantiate(asmLibraryArg, wasmMemory, wasmTable) { + +function asmFunc(global, env, buffer) { + "almost asm"; + var memory = env.memory; + var HEAP8 = new global.Int8Array(buffer); + var HEAP16 = new global.Int16Array(buffer); + var HEAP32 = new global.Int32Array(buffer); + var HEAPU8 = new global.Uint8Array(buffer); + var HEAPU16 = new global.Uint16Array(buffer); + var HEAPU32 = new global.Uint32Array(buffer); + var HEAPF32 = new global.Float32Array(buffer); + var HEAPF64 = new global.Float64Array(buffer); + var Math_imul = global.Math.imul; + var Math_fround = global.Math.fround; + var Math_abs = global.Math.abs; + var Math_clz32 = global.Math.clz32; + var Math_min = global.Math.min; + var Math_max = global.Math.max; + var Math_floor = global.Math.floor; + var Math_ceil = global.Math.ceil; + var Math_sqrt = global.Math.sqrt; + var abort = env.abort; + var nan = global.NaN; + var infinity = global.Infinity; + // EMSCRIPTEN_START_FUNCS; + // EMSCRIPTEN_END_FUNCS; + var FUNCTION_TABLE = []; + function __wasm_memory_grow(pagesToAdd) { + pagesToAdd = pagesToAdd | 0; + var oldPages = __wasm_memory_size() | 0; + var newPages = oldPages + pagesToAdd | 0; + if ((oldPages < newPages) && (newPages < 65536)) { + var newBuffer = new ArrayBuffer(Math_imul(newPages, 65536)); + var newHEAP8 = new global.Int8Array(newBuffer); + newHEAP8.set(HEAP8); + HEAP8 = newHEAP8; + HEAP8 = new global.Int8Array(newBuffer); + HEAP16 = new global.Int16Array(newBuffer); + HEAP32 = new global.Int32Array(newBuffer); + HEAPU8 = new global.Uint8Array(newBuffer); + HEAPU16 = new global.Uint16Array(newBuffer); + HEAPU32 = new global.Uint32Array(newBuffer); + HEAPF32 = new global.Float32Array(newBuffer); + HEAPF64 = new global.Float64Array(newBuffer); + buffer = newBuffer; + memory.buffer = newBuffer; + } + return oldPages; + } + + function __wasm_memory_size() { + return buffer.byteLength / 65536 | 0; + } + + return { + "memory": Object.create(Object.prototype, { + "grow": { + "value": __wasm_memory_grow + }, + "buffer": { + "get": function () { + return buffer; + } + + } + }) + }; +} + +var writeSegment = ( + function(mem) { + var _mem = new Uint8Array(mem); + return function(offset, s) { + var bytes; + if (typeof Buffer === 'undefined') { + bytes = atob(s); + for (var i = 0; i < bytes.length; i++) + _mem[offset + i] = bytes.charCodeAt(i); + } else { + bytes = Buffer.from(s, 'base64'); + for (var i = 0; i < bytes.length; i++) + _mem[offset + i] = bytes[i]; + } + } + } + )(wasmMemory.buffer); +writeSegment(1600, "YWJj"); +return asmFunc({ + 'Int8Array': Int8Array, + 'Int16Array': Int16Array, + 'Int32Array': Int32Array, + 'Uint8Array': Uint8Array, + 'Uint16Array': Uint16Array, + 'Uint32Array': Uint32Array, + 'Float32Array': Float32Array, + 'Float64Array': Float64Array, + 'NaN': NaN, + 'Infinity': Infinity, + 'Math': Math + }, + asmLibraryArg, + wasmMemory.buffer +) + +}
\ No newline at end of file |