-
Notifications
You must be signed in to change notification settings - Fork 35
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
[js-api] Mention opaque data requirement #248
Conversation
This basically does the "handwaving" we discussed in WebAssembly#218. I think adding a concept of a backing store through backdoors in the core spec is not very feasible, so this is what we can do practically at this point. Hopefully resolves WebAssembly#242.
I think we need a little more than this. And most importantly we should add tests for these cases; e.g. a test where wasm calls a JS function that creates a new WebAssembly.Exception, adds some properties to it and throws it, then lets it propagate through the wasm frame and catches it, and tests that the same properties are on the caught object. (and one that rethrows inside of wasm rather than letting it just propagate). |
I'm not sure if I understand the motivation. This sounds like, you want If so, I'm not sure what the purpose of this is. Either way we are adding another stuff to be returned ( Also, does this "removing I think I might be misunderstanding your comments, in which case please let me know.
Will do that. Do you mind if I do that as a separate PR? |
Yes, I agree with @dschuff. Stating the existence of opaque data is one piece, but the more important part is to specify that it has identity and how that is preserved. I think that we can model identity (and opacity) itself by assigning an external address to the payload and store it in map. This has to be converted upon entry and exit from Wasm, like regular values. The other piece is to hand-wave somehow that the core rule for executing rethrow preserves this external address. FWIW, this also needs to assign identities to Wasm exceptions itself, i.e., Wasm throw. That identity may be observed in JS, after the exception has been caught and rethrown in JS, passes through another layer of Wasm (which could involve rethrowing it as well), and is caught by JS again. |
Basically yes. The core spec definitions for returning from an exported function and invoking a catch block do not mention any opaque data, and this spec is currently written as if it does. e.g. can't say here that this opaque data is handed to us by the function return (at least not in the way that's written here, where it just lists opaqueData as another return value). I think what @rossberg is suggesting is that we allocate an externaddr associated with the payload when we create a new exception (e.g. in 12.2 of "call an Extported Function"). I tried to make this work using just the extern value cache, but it didn't seem quite right. We basically need to have a map that maps exception payloads (which now need to be somehow unique) to exception objects, so that we can look them up in 12.1. Or alternatively wrap a new exception object around the same payload.
We have to say somewhere that "something" is associated with an exception as it goes into and out of wasm to/from JS. This spec currently says that something is
I think the wrapping/unwrapping I described is still the behavior we want, we just need way to describe that behavior here without relying on the core spec.
Yes, separate PR is fine with me. |
Thanks for the comments! But more questions 😅:
You mean we can treat a payload as a unique extern object, and create a mapping of
As I asked above, would we also need
Can we have the reverse mapping, meaning given the payload, can we find its
You mean, we can't make this work only with |
Yes, I think that's basically what I meant. In the current spec we are extracting the externaddr exception object from opaqueData, (meaning the core machinery is tracking that identity for us). I think @rossberg meant that we can store the externaddr for the JS exception object in Currently we aren't using the map at all because the externaddr for the JS exception object is already getting converted on entry an exit from wasm (i.e. it goes into |
I looked a little harder at the current version and realized that we are already storing the exception's identity (in the form of the JS exception object) in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will close this given that this is not relevant anymore. |
This basically does the "handwaving" we discussed in #218 (comment). I think adding a concept of a backing store through backdoors in the core spec is not very feasible, so this is what we can do practically at this point.
Hopefully resolves #242.