Skip to content

Exception type for stack overflows #867

Closed

Description

@gahaas

At the moment stack overflows in WebAssembly should throw a WebAssembly.RuntimeError object (see https://github.com/WebAssembly/design/blob/master/Semantics.md#traps and https://github.com/WebAssembly/design/blob/master/JS.md#traps). JavaScript, however, deals with stack overflows by throwing a RangeError in Chrome, or an InternalError in Firefox. I think stack overflows should cause the same exception in JavaScript and in WebAssembly. The reason is that if an application which uses both JavaScript code and WebAssembly code has a stack overflow, then the thrown exception depends on whether the stack overflow happened in a JavaScript function or in a WebAssembly function.

In V8 we have the additional problem that we use the same stack overflow detection for WebAssembly and JavaScript. This makes it difficult for us to throw a different exception for stack overflows in WebAssembly.

For these reasons I think that in the case of stack overflows, being consistent with JavaScript is more important than being consistent within WebAssembly. Since the exception for stack overflows is browser dependent (at the moment), I suggest to leave the exception type of stack overflows undefined.

Activity

  1. jfbastien commented on Nov 10, 2016

    @jfbastien
    Member

    Sounds fine.

  2. lukewagner commented on Nov 10, 2016

    @lukewagner
    Member

    I feel like this might've been discussed recently with @rossberg-chromium in an issue. The resolution though agreed with you: while all traps may throw a RuntimeError, stack overflow isn't a trap.

  3. rossberg commented on Nov 11, 2016

    @rossberg
    Member

    lukewagner, I believe stack overflow only came up in the context of what errors to use for signalling resource exhaustion in the JS API grow methods.

    Anyways, agreed with the conclusion. Since browsers disagree on the exception used for JS SO, the design doc should probably just state that Wasm uses the same exn.

  4. rossberg commented on Nov 16, 2016

    @rossberg
    Member

    Pondering a bit, I guess the actual question here is whether we want future Wasm to be able to handle traps and whether that should include stack overflow. If so, then stack overflow should remain a regular trap/RuntimeError, and moreover any stack overflow caused while calling back from Wasm into JS should also be mapped to a trap.

  5. lukewagner commented on Nov 16, 2016

    @lukewagner
    Member

    From either a wasm or JS perspective, whether a stack overflow occurred in JS vs. wasm probably isn't a meaningful distinction and I think you'd want one way to catch both. One way to achieve this is to say that, to JS, stack overflow is reported using the same exception type as a current JS stack overflow. However, when we allow catching in wasm, we won't specifically refer to WebAssembly.RuntimeError (b/c RuntimeError is a JS API detail from wasm's pov), but rather I would think the catch block would more abstractly refer to wasm traps via a trap code. We could then have a specific stack-overflow trap code that matched both wasm and JS stack overflows.

  6. gahaas commented on Dec 12, 2016

    @gahaas
    ContributorAuthor

    Please take a look at #875

    I changed Semantics.md so that stack overflows are not called traps anymore, and I handle stack overflows explicitly in JS.md. I think this is a clean solution for now.

    When we allow catching in wasm, then we have to define how we deal with stack overflows and exceptions in imported (JS) functions. I think we can define the handling of WebAssembly stack overflow the same as the handling of these exceptions in imported functions.

  7. jfbastien commented on Dec 15, 2016

    @jfbastien
    Member

    This is done, closing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions