Skip to content
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

New emscripten features #94

Closed
buu700 opened this issue Jul 6, 2017 · 2 comments
Closed

New emscripten features #94

buu700 opened this issue Jul 6, 2017 · 2 comments

Comments

@buu700
Copy link
Contributor

buu700 commented Jul 6, 2017

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.)

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.

@jedisct1
Copy link
Owner

jedisct1 commented Aug 3, 2017

Support for WebAssembly has been added. It's ugly and hacky, so all improvements would be very welcome!

I won't be able to work on this any more in a near future.

@jedisct1 jedisct1 closed this as completed Aug 3, 2017
@buu700
Copy link
Contributor Author

buu700 commented Aug 3, 2017

Awesome! In that case, I'll just test it out with that new SINGLE_FILE emscripten flag and submit a PR if there are no issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants