diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-03-04 10:35:15 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-03-04 10:39:29 -0800 |
commit | 23d0b0a717cd139c27e9127b2a0bdcaf19abf6ec (patch) | |
tree | cc08c37b8e67223560a851a5ff1006ae14301c33 /bin/wasm.js | |
parent | b9443f47b084b1931d459490ecfd465dfcef68d3 (diff) | |
download | binaryen-23d0b0a717cd139c27e9127b2a0bdcaf19abf6ec.tar.gz binaryen-23d0b0a717cd139c27e9127b2a0bdcaf19abf6ec.tar.bz2 binaryen-23d0b0a717cd139c27e9127b2a0bdcaf19abf6ec.zip |
fix mergeMemory
Diffstat (limited to 'bin/wasm.js')
-rw-r--r-- | bin/wasm.js | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/bin/wasm.js b/bin/wasm.js index 41ae5f593..2d0c7c4ec 100644 --- a/bin/wasm.js +++ b/bin/wasm.js @@ -83199,14 +83199,16 @@ function integrateWasmJS(Module) { function mergeMemory(newBuffer) { // The wasm instance creates its memory. But static init code might have written to - // buffer already, and we must copy it over in a proper merge. + // buffer already, including the mem init file, and we must copy it over in a proper merge. + // TODO: support memory segments in the wasm module itself, but even so, we'd still + // have other static init code. but then we could reuse STATIC_BASE..STATIC_BASE+STATIC_BUMP // TODO: avoid this copy, by avoiding such static init writes // TODO: in shorter term, just copy up to the last static init write var oldBuffer = Module['buffer']; assert(newBuffer.byteLength >= oldBuffer.byteLength, 'we might fail if we allocated more than TOTAL_MEMORY'); - // the wasm module does write out the memory initialization, in range STATIC_BASE..STATIC_BUMP, so avoid that - (new Int8Array(newBuffer).subarray(0, STATIC_BASE)).set(new Int8Array(oldBuffer).subarray(0, STATIC_BASE)); - (new Int8Array(newBuffer).subarray(STATIC_BASE + STATIC_BUMP)).set(new Int8Array(oldBuffer).subarray(STATIC_BASE + STATIC_BUMP)); + var oldView = new Int8Array(oldBuffer); + var newView = new Int8Array(newBuffer); + newView.set(oldView); updateGlobalBuffer(newBuffer); updateGlobalBufferViews(); Module['reallocBuffer'] = function(size) { |