Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/postamble_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ function initRuntime(wasmExports) {

#if SINGLE_FILE && SINGLE_FILE_BINARY_ENCODE && !WASM2JS
Module['wasm'] = binaryDecode("<<< WASM_BINARY_DATA >>>");
#if ASSERTIONS
assert(Module['wasm'].reduce((x,y) => ((x^y)*65599) >>> 0, 2166136261) == "<<< WASM_BINARY_DATA_CHECKSUM >>>", "The checksum of the binary decoded WebAssembly Module code does not match the original data. Double check that this .html/.js file is interpreted with UTF-8 encoding, e.g. by setting <meta charset='utf-8'> inside <head> of the HTML file, or by passing 'Content-Type: application/javascript; charset=utf-8' HTTP header.");
#endif
#elif SINGLE_FILE && WASM == 1 && !WASM2JS
Module['wasm'] = base64Decode('<<< WASM_BINARY_DATA >>>');
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,10 @@ function getWasmImports() {
return exports;
#else
wasmBinaryFile ??= findWasmBinary();
#if SINGLE_FILE && SINGLE_FILE_BINARY_ENCODE && !WASM2JS && ASSERTIONS
assert(wasmBinaryFile.reduce((x,y) => ((x^y)*65599) >>> 0, 2166136261) == "<<< WASM_BINARY_DATA_CHECKSUM >>>", "The checksum of the binary decoded WebAssembly Module code does not match the original data. Double check that this .html/.js file is interpreted with UTF-8 encoding, e.g. by setting <meta charset='utf-8'> inside <head> of the HTML file, or by passing 'Content-Type: application/javascript; charset=utf-8' HTTP header.");
#endif

#if WASM_ASYNC_COMPILATION
#if RUNTIME_DEBUG
dbg('asynchronously preparing wasm');
Expand Down
7 changes: 7 additions & 0 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -2490,6 +2490,13 @@ def phase_binaryen(target, options, wasm_target):

if settings.SINGLE_FILE_BINARY_ENCODE:
js = do_replace(js, '"<<< WASM_BINARY_DATA >>>"', binary_encode(wasm_target))
if settings.ASSERTIONS:
def checksum(a):
h = 2166136261
for b in a:
h = (h ^ b) * 65599 & 0xffffffff
return h
js = do_replace(js, '"<<< WASM_BINARY_DATA_CHECKSUM >>>"', str(checksum(utils.read_binary(wasm_target))))
else:
js = do_replace(js, '<<< WASM_BINARY_DATA >>>', base64_encode(wasm_target))
delete_file(wasm_target)
Expand Down
Loading