summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/js/wasm.js-post.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js
index 75a91d4d4..526d10455 100644
--- a/src/js/wasm.js-post.js
+++ b/src/js/wasm.js-post.js
@@ -55,14 +55,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) {