Skip to content

WebAssembly.{compile|instantiate}Streaming: what if embedder doesn't implement it? #1085

Open

Description

@mtrofin

In Chrome, we're implementing the 2 streaming APIs in v8, on the WebAssembly object (as per spec), and inject the actual implementation from Chrome. This is for layering reasons. I'm assuming we're not alone in taking this approach.

What do we want to do if the embedder "forgets" to inject a dependency? This scenario is unlikely, but may happen in non-web embeddings. A developer porting code to node.js, for example, may hit this situation.

Options:

  1. quietly return undefined (weird, no indication of what just happened)
  2. throw RangeError (we did that for browser limits for sync compilation, but it is weird because why "Range" in this case?)
  3. throw Error with a nice description
  4. behave as-if the API didn't exist (that'd be weird, because the API is testably present)
  5. crash (this is also weird, why such drastic measures when calling an API)

Personal preference: option 3.

Thoughts?

Activity

  1. changed the title [-]WebAssembly.{compile|instantiate}Streaming: what if embedder doesn[/-] [+]WebAssembly.{compile|instantiate}Streaming: what if embedder doesn't implement it?[/+] on May 31, 2017
  2. domenic commented on May 31, 2017

    @domenic
    Member

    It seems like it'd be much better if the API didn't exist (and wasn't testably present). Maybe nobody wants to implement that though...

  3. mtrofin commented on May 31, 2017

    @mtrofin
    ContributorAuthor

    Actually... come to think about it, not terribly hard to implement, at least on the chrome/v8 side.

  4. mtrofin commented on May 31, 2017

    @mtrofin
    ContributorAuthor

    Assuming this is how we all go about it, would this need additional specification?

  5. domenic commented on May 31, 2017

    @domenic
    Member

    In my opinion the current spec supports my suggestion, but it could be made clearer by adding a sentence explicitly saying something like "these methods must not exist if they are not supported" or similar.

  6. rossberg commented on Jun 1, 2017

    @rossberg
    Member

    Not sure how this is fundamentally different from other properties that are added by other APIs. For example, the DOM adds plenty of properties to the global object. Ecma-262 explicitly allows adding properties. So I agree that (1) is the natural option (and what is currently implied).

    Also, not returning undefined would break the standard feature detection patterns.

    @domenic, where do you suggest to add this sentence? If it's in the Web API spec, then it won't have any binding consequences, since it wouldn't apply to an embedder that doesn't implement that spec. If it's in the basic JS API spec then it would basically remove the layering. (FWIW, the same question would apply to any of the other suggestions in the OP.)

  7. mtrofin commented on Jun 1, 2017

    @mtrofin
    ContributorAuthor

    @rossberg-chromium for clarity, option 1 was:

    "instantiateStreaming" in WebAssembly === true
    WebAssembly.instantiateStreaming(some_response) === undefined
    

    I think what we're agreeing on, which wasn't on the original list, and was subsequently proposed by @domenic, is:

    "instantiateStreaming" in WebAssembly === false
    

    and, then, WebAssembly.instantiateStreaming throws ("instantiateStreaming not a function")

    We're still on the same page, though, correct? (i.e. we want this latter option, not option "1")

  8. rossberg commented on Jun 1, 2017

    @rossberg
    Member

    @mtrofin, ah, okay, thanks for the clarification. And yes, I agree with the resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions