summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-10-11 18:24:14 -0700
committerGitHub <noreply@github.com>2016-10-11 18:24:14 -0700
commit7e543286b099d7f78816e087c230c2ef23f34beb (patch)
tree1355152a3fbc698a0a2cd224c99e415f08ba4a83 /src
parent85900965a12a3f07c9cca8ef620d4bee039f16fc (diff)
parent0f42a9d1d43dcffc76cd816725f278ed8cf28702 (diff)
downloadbinaryen-7e543286b099d7f78816e087c230c2ef23f34beb.tar.gz
binaryen-7e543286b099d7f78816e087c230c2ef23f34beb.tar.bz2
binaryen-7e543286b099d7f78816e087c230c2ef23f34beb.zip
Merge pull request #759 from WebAssembly/js-api
memory growth fixes
Diffstat (limited to 'src')
-rw-r--r--src/asm2wasm.h1
-rw-r--r--src/js/wasm.js-post.js14
2 files changed, 13 insertions, 2 deletions
diff --git a/src/asm2wasm.h b/src/asm2wasm.h
index 9b503c84d..9bf677e6f 100644
--- a/src/asm2wasm.h
+++ b/src/asm2wasm.h
@@ -981,6 +981,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
// apply memory growth, if relevant
if (memoryGrowth) {
emscripten::generateMemoryGrowthFunction(wasm);
+ wasm.memory.max = Memory::kMaxSize;
}
#if 0
diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js
index f093ff64d..a4bc35f97 100644
--- a/src/js/wasm.js-post.js
+++ b/src/js/wasm.js-post.js
@@ -269,8 +269,18 @@ function integrateWasmJS(Module) {
Module['reallocBuffer'] = function(size) {
size = Math.ceil(size / wasmPageSize) * wasmPageSize; // round up to wasm page size
var old = Module['buffer'];
- exports['__growWasmMemory'](size / wasmPageSize); // tiny wasm method that just does grow_memory
- return Module['buffer'] !== old ? Module['buffer'] : null; // if it was reallocated, it changed
+ var result = exports['__growWasmMemory'](size / wasmPageSize); // tiny wasm method that just does grow_memory
+ if (Module["usingWasm"]) {
+ if (result !== (-1 | 0)) {
+ // success in native wasm memory growth, get the buffer from the memory
+ return Module['buffer'] = Module['wasmMemory'].buffer;
+ } else {
+ return null;
+ }
+ } else {
+ // in interpreter, we replace Module.buffer if we allocate
+ return Module['buffer'] !== old ? Module['buffer'] : null; // if it was reallocated, it changed
+ }
};
// Provide an "asm.js function" for the application, called to "link" the asm.js module. We instantiate