From 9445c4900b120455583fbf48c8a08666a050bc5a Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sat, 5 Mar 2016 15:21:45 -0800 Subject: fix global.Math imports --- src/js/wasm.js-post.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/js/wasm.js-post.js') diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js index b2ec40b00..762c1bd30 100644 --- a/src/js/wasm.js-post.js +++ b/src/js/wasm.js-post.js @@ -125,10 +125,10 @@ function integrateWasmJS(Module) { var 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); -- cgit v1.2.3 From 69b457cd2da748175f8fc46312c8f7b40e368205 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sat, 5 Mar 2016 16:45:22 -0800 Subject: warn when we should grow wasm memory in mergeMemory --- src/js/wasm.js-post.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/js/wasm.js-post.js') diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js index 762c1bd30..de1ee2752 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 }}}) { -- cgit v1.2.3 From 573aa7adf10858b0bf8f566f72142be2775076c4 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 6 Mar 2016 16:19:21 -0800 Subject: assume wasm binaries were preloaded on the web, where we lack sync binary reads --- src/js/wasm.js-post.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/js/wasm.js-post.js') diff --git a/src/js/wasm.js-post.js b/src/js/wasm.js-post.js index de1ee2752..4071ace46 100644 --- a/src/js/wasm.js-post.js +++ b/src/js/wasm.js-post.js @@ -124,7 +124,14 @@ 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'] = { 'NaN': NaN, -- cgit v1.2.3