You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With this, the wasm version of libsodium.js can remain as a single JS file just like the asm.js version. (It also replaces the previous --memory-init-file 0 implementation with this more efficient encoding.)
I haven't followed the work that's gone into implementing WebAssembly in libsodium.js up until now, but as far as how I implemented WebAssembly in those libraries, the pattern I used looks more or less like this (not exactly, but same basic idea):
${preJS}
try {
await new Promise((resolve, reject) => {
var Module = {onRuntimeInitialized: resolve, onAbort: reject};
${wasmBuild}
});
}
catch (_) {
${asmjsBuild} // compiled with -Oz, "use asm" stripped to prevent redundant AOT compilation
}
${postJS}
(As a side benefit, with asm.js becoming a second-class citizen, it's also now safe to run the whole output through uglifyjs mangling and compression.)
The other change I had to make to account for wasm compilation being asynchronous was to convert every field and method into a Promise. For libsodium.js, it could alternatively make more sense to keep the existing API surface synchronous and just expose an "is ready" Promise and/or callback.
The text was updated successfully, but these errors were encountered:
I've recently added two features to emscripten that would be useful here, particularly concerning WebAssembly support.
(They aren't specific to wasm, but were needed to implement the pattern I chose to use in upgrading mceliece.js, ntru.js, rlwe.js, sidh.js, sphincs.js, and xkcd-passphrase two weeks ago.)
Module['onRuntimeInitializeFailed'] emscripten-core/emscripten#5357 (just merged): adds a
Module.onAbort
callbackWebAssembly.instantiate
) and falling back to asm.js, since just checking for the availability of wasm functionality isn't sufficient.Add SINGLE_FILE option to embed all subresources into emitted JS emscripten-core/emscripten#5296 (on track to be merged soon): adds an
-s SINGLE_FILE=1
flag that embeds all subresources as base64 strings (mem init file, wasm binary, etc.)--memory-init-file 0
implementation with this more efficient encoding.)I haven't followed the work that's gone into implementing WebAssembly in libsodium.js up until now, but as far as how I implemented WebAssembly in those libraries, the pattern I used looks more or less like this (not exactly, but same basic idea):
(As a side benefit, with asm.js becoming a second-class citizen, it's also now safe to run the whole output through uglifyjs mangling and compression.)
The other change I had to make to account for wasm compilation being asynchronous was to convert every field and method into a Promise. For libsodium.js, it could alternatively make more sense to keep the existing API surface synchronous and just expose an "is ready" Promise and/or callback.
The text was updated successfully, but these errors were encountered: