diff options
-rw-r--r-- | src/js/wasm.js-post.js | 19 | ||||
-rw-r--r-- | test/grow_memory.cpp | 20 | ||||
-rw-r--r-- | test/grow_memory.emcc | 1 | ||||
-rw-r--r-- | test/grow_memory.txt | 22 |
4 files changed, 52 insertions, 10 deletions
diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js index 0549dbd51..91ca0c4e8 100644 --- a/src/js/wasm.js-post.js +++ b/src/js/wasm.js-post.js @@ -55,6 +55,8 @@ function integrateWasmJS(Module) { parent: Module // Module inside wasm-js.cpp refers to wasm-js.cpp; this allows access to the outside program. }; + var exports = null; + function lookupImport(mod, base) { var lookup = info; if (mod.indexOf('.') < 0) { @@ -93,7 +95,7 @@ function integrateWasmJS(Module) { updateGlobalBufferViews(); Module['reallocBuffer'] = function(size) { var old = Module['buffer']; - wasmJS['asmExports']['__growWasmMemory'](size); // tiny wasm method that just does grow_memory + exports['__growWasmMemory'](size); // tiny wasm method that just does grow_memory return Module['buffer'] !== old ? Module['buffer'] : null; // if it was reallocated, it changed }; } @@ -183,11 +185,12 @@ function integrateWasmJS(Module) { info['env'] = env; var instance; instance = Wasm.instantiateModule(getBinary(), info); - mergeMemory(instance.exports.memory); + exports = instance.exports; + mergeMemory(exports.memory); applyMappedGlobals(wasmBinaryFile); - return instance.exports; + return exports; }; return true; @@ -221,12 +224,6 @@ function integrateWasmJS(Module) { info.global = global; info.env = env; - Module['reallocBuffer'] = function(size) { - var old = Module['buffer']; - wasmJS['asmExports']['__growWasmMemory'](size); // tiny wasm method that just does grow_memory - return Module['buffer'] !== old ? Module['buffer'] : null; // if it was reallocated, it changed - }; - wasmJS['providedTotalMemory'] = Module['buffer'].byteLength; // Prepare to generate wasm, using either asm2wasm or s-exprs @@ -267,7 +264,9 @@ function integrateWasmJS(Module) { applyMappedGlobals(wasmBinaryFile); } - return wasmJS['asmExports']; + exports = wasmJS['asmExports']; + + return exports; }; return true; diff --git a/test/grow_memory.cpp b/test/grow_memory.cpp new file mode 100644 index 000000000..b8f732f7a --- /dev/null +++ b/test/grow_memory.cpp @@ -0,0 +1,20 @@ +#include <stdio.h> +#include <stdlib.h> +#include <emscripten.h> + +volatile int writeOnly; + +int main() { + EM_ASM({ + assert(HEAPU8.length === 16*1024*1024); + }); + for (int i = 0; i < 20; i++) { + printf("alloc 1MB: %d\n", i); + writeOnly = (int)malloc(1024*1024); + } + EM_ASM({ + assert(HEAPU8.length > 16*1024*1024); + }); + printf("ok.\n"); +} + diff --git a/test/grow_memory.emcc b/test/grow_memory.emcc new file mode 100644 index 000000000..5a0c6fea0 --- /dev/null +++ b/test/grow_memory.emcc @@ -0,0 +1 @@ +["-s", "ALLOW_MEMORY_GROWTH=1"] diff --git a/test/grow_memory.txt b/test/grow_memory.txt new file mode 100644 index 000000000..2adc5a8c2 --- /dev/null +++ b/test/grow_memory.txt @@ -0,0 +1,22 @@ +alloc 1MB: 0 +alloc 1MB: 1 +alloc 1MB: 2 +alloc 1MB: 3 +alloc 1MB: 4 +alloc 1MB: 5 +alloc 1MB: 6 +alloc 1MB: 7 +alloc 1MB: 8 +alloc 1MB: 9 +alloc 1MB: 10 +alloc 1MB: 11 +alloc 1MB: 12 +alloc 1MB: 13 +alloc 1MB: 14 +alloc 1MB: 15 +alloc 1MB: 16 +alloc 1MB: 17 +alloc 1MB: 18 +alloc 1MB: 19 +ok. + |