Skip to content

Conversation

kripken
Copy link
Member

@kripken kripken commented Mar 9, 2017

Fixes #5005. Specifically, this

  • Adds readBinary support in web workers, as they can do sync binary xhrs after all, so that fixes emscripten_create_worker with -s WASM=1 #5005.
  • Refactor a getBinaryPromise method that gets a promise, no matter which platform we are on. In particular, on a worker (which lacks the Fetch API), it can use that readBinary method.

@kripken
Copy link
Member Author

kripken commented Mar 9, 2017

I realized as a nice benefit of this refactoring that we can get rid of the ugly preloading of the wasm binary into Module.wasmBinary in emcc. (And that made me notice some bugs in this PR, since it was just using the preloaded binary... fixed).

WebAssembly.instantiate(getBinary(), info).then(function(output) {
getBinaryPromise().then(function(binary) {
return WebAssembly.instantiate(binary, info)
}).then(function(output) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, since working on this, can you change the #if #endif in here to a #if #else #endif to avoid the "unreachable code" console warnings below?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, fixing.

Module['printErr']('asynchronously preparing wasm');
addRunDependency('wasm-instantiate'); // we can't run yet
WebAssembly.instantiate(getBinary(), info).then(function(output) {
getBinaryPromise().then(function(binary) {
Copy link
Collaborator

@juj juj Mar 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main .html file is supposed to download the .wasm file. At this point, is it not possible that the .wasm file download is still in progress, but has not finished yet, and therefore getBinaryPromise() will kick off a second parallel download redundantly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not as it currently works - the html downloads the wasm binary before starting to do anything else. Another reason it's good to get rid of that thing ;)

return ret;
}

function getBinary() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this getBinary() function as well, or could we just have one getBinaryPromise() function that also contains the content of this function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use it when we need synchronous access to it - for the interpreter, or when async compilation is off. Also, I think it's nice it's separate, conceptually.

@kripken
Copy link
Member Author

kripken commented Mar 15, 2017

ping @juj, see responses to comments above, i think this is good to go unless you have further issues.

Copy link
Member

@dschuff dschuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine to me for now. I filed #5047 to talk about supporting both wasm and asm together well.

@kripken
Copy link
Member Author

kripken commented Mar 20, 2017

re-ping @juj

@juj
Copy link
Collaborator

juj commented Mar 20, 2017

Looks alright to me - the use of the fetch api will preclude iOS Safari (http://caniuse.com/#search=fetch), oddly desktop Safari has that already. Though hopefully by the time Webkit adds wasm support, they'd have fetch as well.

@kripken
Copy link
Member Author

kripken commented Mar 20, 2017

Good to know about fetch, when they ship wasm on iOS we'll need to track that.

@kripken kripken merged commit c2f2fe6 into incoming Mar 20, 2017
@kripken kripken deleted the wasm-worker branch March 20, 2017 20:22
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

Successfully merging this pull request may close these issues.

emscripten_create_worker with -s WASM=1
3 participants