-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Implement -s SINGLE_FILE_BINARY_ENCODE=1 option #25599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
511a59e
e577792
88f3570
543554e
0f8fce3
091f207
a8e4cbf
c3515f3
046c5ba
e9c0d0e
dbb0ed7
0783a62
5f8df5f
f651178
25477b9
1c26859
88cd3e8
8a27910
6ddaa56
bddafdf
a4144de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Prevent Closure from minifying the binaryDecode() function, or otherwise | ||
| // Closure may analyze through the WASM_BINARY_DATA placeholder string into this | ||
| // function, leading into incorrect results. | ||
| /** @noinline */ | ||
| function binaryDecode(bin) { | ||
| for(var i = 0, l = bin.length, o = new Uint8Array(l); i < l; ++i) { | ||
| o[i] = bin.charCodeAt(i) - 1; | ||
| } | ||
| return o; | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is only 5 lines i wonder if its worth creating a completely new flie? Maybe just inline into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -410,6 +410,10 @@ function instrumentWasmTableWithAbort() { | |
| } | ||
| #endif | ||
|
|
||
| #if SINGLE_FILE && SINGLE_FILE_BINARY_ENCODE && !WASM2JS | ||
| #include "binaryDecode.js" | ||
juj marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #endif | ||
|
|
||
| #if !SOURCE_PHASE_IMPORTS && !WASM_ESM_INTEGRATION | ||
| var wasmBinaryFile; | ||
|
|
||
|
|
@@ -423,27 +427,35 @@ function getWasmBinary(file) {} | |
| #else | ||
|
|
||
| function findWasmBinary() { | ||
| #if SINGLE_FILE | ||
| #if SINGLE_FILE && SINGLE_FILE_BINARY_ENCODE && !WASM2JS | ||
| return binaryDecode('<<< WASM_BINARY_DATA >>>'); | ||
| #elif SINGLE_FILE | ||
| return base64Decode('<<< WASM_BINARY_DATA >>>'); | ||
| #elif AUDIO_WORKLET || !EXPORT_ES6 | ||
| // For an Audio Worklet, we cannot use `new URL()`. | ||
|
||
| return locateFile('{{{ WASM_BINARY_FILE }}}'); | ||
| #else | ||
| #if EXPORT_ES6 && !AUDIO_WORKLET | ||
| if (Module['locateFile']) { | ||
| #endif | ||
| return locateFile('{{{ WASM_BINARY_FILE }}}'); | ||
| #if EXPORT_ES6 && !AUDIO_WORKLET // For an Audio Worklet, we cannot use `new URL()`. | ||
| } | ||
|
|
||
| #if ENVIRONMENT_MAY_BE_SHELL | ||
| if (ENVIRONMENT_IS_SHELL) { | ||
| return '{{{ WASM_BINARY_FILE }}}'; | ||
| } | ||
| #endif | ||
|
|
||
| if (Module['locateFile']) { | ||
| return locateFile('{{{ WASM_BINARY_FILE }}}'); | ||
| } | ||
|
|
||
| // Use bundler-friendly `new URL(..., import.meta.url)` pattern; works in browsers too. | ||
| return new URL('{{{ WASM_BINARY_FILE }}}', import.meta.url).href; | ||
| #endif | ||
|
|
||
| #endif | ||
| } | ||
|
|
||
| function getBinarySync(file) { | ||
| #if SINGLE_FILE && SINGLE_FILE_BINARY_ENCODE | ||
| return file; | ||
| #else | ||
| #if SINGLE_FILE | ||
| if (ArrayBuffer.isView(file)) { | ||
| return file; | ||
|
|
@@ -464,6 +476,7 @@ function getBinarySync(file) { | |
| #else | ||
| throw 'sync fetching of the wasm failed: you can preload it to Module["wasmBinary"] manually, or emcc.py will do that for you when generating HTML (but not JS)'; | ||
| #endif | ||
| #endif | ||
| } | ||
|
|
||
| async function getWasmBinary(binaryFile) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.