summaryrefslogtreecommitdiff
path: root/src/js/wasm.js-post.js
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-03-07 13:10:44 -0800
committerAlon Zakai <alonzakai@gmail.com>2016-03-07 13:10:44 -0800
commitb65a994c24e83694f27cb835845b3b281207fc2f (patch)
tree86ba8aa07f966d22742150551791732248cb4f84 /src/js/wasm.js-post.js
parenta96bf5cbb71ee5923f4f534db49cedeccf6d51d0 (diff)
parent91008b47488fe87943b7c2b66c3f362907d37bee (diff)
downloadbinaryen-b65a994c24e83694f27cb835845b3b281207fc2f.tar.gz
binaryen-b65a994c24e83694f27cb835845b3b281207fc2f.tar.bz2
binaryen-b65a994c24e83694f27cb835845b3b281207fc2f.zip
Merge pull request #229 from WebAssembly/integrate-wasm-fixes
Integrate wasm fixes
Diffstat (limited to 'src/js/wasm.js-post.js')
-rw-r--r--src/js/wasm.js-post.js15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js
index b2ec40b00..4071ace46 100644
--- a/src/js/wasm.js-post.js
+++ b/src/js/wasm.js-post.js
@@ -71,7 +71,9 @@ function integrateWasmJS(Module) {
// 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');
+ if (newBuffer.byteLength < oldBuffer.byteLength) {
+ Module['printErr']('the new buffer in mergeMemory is smaller than the previous one. in native wasm, we should grow memory here');
+ }
var oldView = new Int8Array(oldBuffer);
var newView = new Int8Array(newBuffer);
if ({{{ WASM_BACKEND }}}) {
@@ -122,13 +124,20 @@ function integrateWasmJS(Module) {
// doesn't need to care that it is wasm and not asm.
Module['asm'] = function(global, env, providedBuffer) {
// Load the wasm module
- var binary = Module['readBinary'](Module['wasmCodeFile']);
+ var binary;
+ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
+ binary = Module['wasmBinary'];
+ assert(binary, "on the web, we need the wasm binary to be preloaded and set on Module['wasmBinary']. emcc.py will do that for you when generating HTML (but not JS)");
+ binary = new Uint8Array(binary);
+ } else {
+ binary = Module['readBinary'](Module['wasmCodeFile']);
+ }
// Create an instance of the module using native support in the JS engine.
info['global'] = {
- 'Math': global.Math,
'NaN': NaN,
'Infinity': Infinity
};
+ info['global.Math'] = global.Math;
info['env'] = env;
var instance;
instance = Wasm.instantiateModule(binary, info);