summaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-03-04 11:25:11 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-03-04 11:28:03 -0800
commite82c6e77e2fa2a2443fd3cc4ef4f4c9c0ba0ca62 (patch)
tree9056de7846a197669da39bbcb9f867d8dc94d9ba /src/js
parent7b604a383873b0042056cf9b78f9cb6ab466953c (diff)
downloadbinaryen-e82c6e77e2fa2a2443fd3cc4ef4f4c9c0ba0ca62.tar.gz
binaryen-e82c6e77e2fa2a2443fd3cc4ef4f4c9c0ba0ca62.tar.bz2
binaryen-e82c6e77e2fa2a2443fd3cc4ef4f4c9c0ba0ca62.zip
support memory segments in wasm modules, which we get if the wasm backend was used
Diffstat (limited to 'src/js')
-rw-r--r--src/js/wasm.js-post.js6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js
index 605621b4b..84ae825d9 100644
--- a/src/js/wasm.js-post.js
+++ b/src/js/wasm.js-post.js
@@ -56,14 +56,16 @@ function integrateWasmJS(Module) {
function mergeMemory(newBuffer) {
// The wasm instance creates its memory. But static init code might have written to
// 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');
var oldView = new Int8Array(oldBuffer);
var newView = new Int8Array(newBuffer);
+ if ({{{ WASM_BACKEND }}}) {
+ // memory segments arrived in the wast, do not trample them
+ oldView.set(newView.subarray(STATIC_BASE, STATIC_BASE + STATIC_BUMP), STATIC_BASE);
+ }
newView.set(oldView);
updateGlobalBuffer(newBuffer);
updateGlobalBufferViews();