diff --git a/src/preamble.js b/src/preamble.js index 9c5993d98dcb..ab1e5ec3f1b2 100644 --- a/src/preamble.js +++ b/src/preamble.js @@ -640,7 +640,7 @@ if (Module['locateFile']) { } #endif -function getBinary(file) { +function getBinarySync(file) { if (file == wasmBinaryFile && wasmBinary) { return new Uint8Array(wasmBinary); } @@ -677,22 +677,20 @@ function getBinaryPromise(binaryFile) { throw "failed to load wasm binary file at '" + binaryFile + "'"; } return response['arrayBuffer'](); - }).catch(() => getBinary(binaryFile)); + }).catch(() => getBinarySync(binaryFile)); } #if ENVIRONMENT_MAY_BE_WEBVIEW - else { - if (readAsync) { - // fetch is not available or url is file => try XHR (readAsync uses XHR internally) - return new Promise((resolve, reject) => { - readAsync(binaryFile, (response) => resolve(new Uint8Array(/** @type{!ArrayBuffer} */(response))), reject) - }); - } + else if (readAsync) { + // fetch is not available or url is file => try XHR (readAsync uses XHR internally) + return new Promise((resolve, reject) => { + readAsync(binaryFile, (response) => resolve(new Uint8Array(/** @type{!ArrayBuffer} */(response))), reject) + }); } #endif } - // Otherwise, getBinary should be able to get it synchronously - return Promise.resolve().then(() => getBinary(binaryFile)); + // Otherwise, getBinarySync should be able to get it synchronously + return Promise.resolve().then(() => getBinarySync(binaryFile)); } #if LOAD_SOURCE_MAP @@ -742,58 +740,46 @@ function receiveSourceMapJSON(sourceMap) { #if SPLIT_MODULE || !WASM_ASYNC_COMPILATION function instantiateSync(file, info) { - var instance; var module; - var binary; - try { - binary = getBinary(file); + var binary = getBinarySync(file); #if NODE_CODE_CACHING - if (ENVIRONMENT_IS_NODE) { - var v8 = require('v8'); - // Include the V8 version in the cache name, so that we don't try to - // load cached code from another version, which fails silently (it seems - // to load ok, but we do actually recompile the binary every time). - var cachedCodeFile = '{{{ WASM_BINARY_FILE }}}.' + v8.cachedDataVersionTag() + '.cached'; - cachedCodeFile = locateFile(cachedCodeFile); - var hasCached = fs.existsSync(cachedCodeFile); - if (hasCached) { + if (ENVIRONMENT_IS_NODE) { + var v8 = require('v8'); + // Include the V8 version in the cache name, so that we don't try to + // load cached code from another version, which fails silently (it seems + // to load ok, but we do actually recompile the binary every time). + var cachedCodeFile = '{{{ WASM_BINARY_FILE }}}.' + v8.cachedDataVersionTag() + '.cached'; + cachedCodeFile = locateFile(cachedCodeFile); + var hasCached = fs.existsSync(cachedCodeFile); + if (hasCached) { #if RUNTIME_DEBUG - dbg('NODE_CODE_CACHING: loading module'); -#endif - try { - module = v8.deserialize(fs.readFileSync(cachedCodeFile)); - } catch (e) { - err('NODE_CODE_CACHING: failed to deserialize, bad cache file? (' + cachedCodeFile + ')'); - // Save the new compiled code when we have it. - hasCached = false; - } + dbg('NODE_CODE_CACHING: loading module'); +#endif + try { + module = v8.deserialize(fs.readFileSync(cachedCodeFile)); + } catch (e) { + err('NODE_CODE_CACHING: failed to deserialize, bad cache file? (' + cachedCodeFile + ')'); + // Save the new compiled code when we have it. + hasCached = false; } } - if (!module) { - module = new WebAssembly.Module(binary); - } - if (ENVIRONMENT_IS_NODE && !hasCached) { + } + if (!module) { + module = new WebAssembly.Module(binary); + } + if (ENVIRONMENT_IS_NODE && !hasCached) { #if RUNTIME_DEBUG - dbg('NODE_CODE_CACHING: saving module'); + dbg('NODE_CODE_CACHING: saving module'); #endif - fs.writeFileSync(cachedCodeFile, v8.serialize(module)); - } + fs.writeFileSync(cachedCodeFile, v8.serialize(module)); + } #else // NODE_CODE_CACHING - module = new WebAssembly.Module(binary); + module = new WebAssembly.Module(binary); #endif // NODE_CODE_CACHING - instance = new WebAssembly.Instance(module, info); + var instance = new WebAssembly.Instance(module, info); #if USE_OFFSET_CONVERTER - wasmOffsetConverter = new WasmOffsetConverter(binary, module); -#endif - } catch (e) { - var str = e.toString(); - err('failed to compile wasm module: ' + str); - if (str.includes('imported Memory') || - str.includes('memory import')) { - err('Memory size incompatibility issues may be due to changing INITIAL_MEMORY at runtime to something too large. Use ALLOW_MEMORY_GROWTH to allow any size memory (and also make sure not to set INITIAL_MEMORY at runtime to something smaller than it was at compile time).'); - } - throw e; - } + wasmOffsetConverter = new WasmOffsetConverter(binary, module); +#endif #if LOAD_SOURCE_MAP receiveSourceMapJSON(getSourceMap()); #endif diff --git a/test/other/test_unoptimized_code_size.js.size b/test/other/test_unoptimized_code_size.js.size index 96cea596e6a6..5afe2d8d3a19 100644 --- a/test/other/test_unoptimized_code_size.js.size +++ b/test/other/test_unoptimized_code_size.js.size @@ -1 +1 @@ -59177 +59169 diff --git a/test/other/test_unoptimized_code_size_no_asserts.js.size b/test/other/test_unoptimized_code_size_no_asserts.js.size index cd61113e9956..359dc61823c2 100644 --- a/test/other/test_unoptimized_code_size_no_asserts.js.size +++ b/test/other/test_unoptimized_code_size_no_asserts.js.size @@ -1 +1 @@ -32474 +32466 diff --git a/test/other/test_unoptimized_code_size_strict.js.size b/test/other/test_unoptimized_code_size_strict.js.size index b50e813c75cd..23666e30d8e1 100644 --- a/test/other/test_unoptimized_code_size_strict.js.size +++ b/test/other/test_unoptimized_code_size_strict.js.size @@ -1 +1 @@ -58143 +58135 diff --git a/test/test_other.py b/test/test_other.py index f17a99f2e9c6..45b37611fe18 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -7708,7 +7708,7 @@ def test_binaryen_warn_mem(self): self.run_process([EMXX, test_file('hello_world.cpp'), '-sINITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-sWASM_ASYNC_COMPILATION=0', '-sIMPORTED_MEMORY']) out = self.run_js('a.out.js', assert_returncode=NON_ZERO) self.assertContained('LinkError', out) - self.assertContained('Memory size incompatibility issues may be due to changing INITIAL_MEMORY at runtime to something too large. Use ALLOW_MEMORY_GROWTH to allow any size memory (and also make sure not to set INITIAL_MEMORY at runtime to something smaller than it was at compile time).', out) + self.assertContained("memory import 2 has a larger maximum size 800 than the module's declared maximum", out) self.assertNotContained('hello, world!', out) # and with memory growth, all should be good self.run_process([EMXX, test_file('hello_world.cpp'), '-sINITIAL_MEMORY=' + str(16 * 1024 * 1024), '--pre-js', 'pre.js', '-sALLOW_MEMORY_GROWTH', '-sWASM_ASYNC_COMPILATION=0', '-sIMPORTED_MEMORY'])