-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Issue: This proposal was designed with the intention that eventually the "suspending" and "promising" functions it produces would be implementable using just WebAssembly extended with some core stack-switching design (and some JS imports or manipulating JS Suspender objects and testing for and adding listeners to JS Promises). However, as an unintended consequence of semantic corner cases, the current semantics makes this impossible without also adding support for catching traps in wasm. In particular, given a wasm function "foo", you can use simple wasm modules and WebAssembly.Function with "suspending" and "promising" options (and no JS code beyond simple linking) to build a WebAssembly.Function that behaves just like "foo" except it throws a wasm exception (with your choice of tag of type externref) instead of trapping.
Cause: The issue is caused by the fact that a "promising" function both calls the wrapped function immediately and returns a rejected promise immediately if that call traps before suspending.
Fix: The simplest and most flexible way to resolve the issue is to have the "promising" function also trap if that call traps before suspending. (We might also consider taking the change a step further to make "promising" symmetric with "suspending" and have the "promising" function return a promise only if a corresponding suspend occurs, and have it otherwise simply return the tuple of values coerced into an externref.)