WebAssembly / interface-types

Other
641 stars 57 forks source link

Need a `get-receiver` incoming binding operator? #45

Closed fitzgen closed 5 years ago

fitzgen commented 5 years ago

Say I have this Web IDL interface:

interface Foo {
    void myMethod();
}

And I am implementing my_method in Wasm with the following function:

(func $myMethod (param anyref)
  ;; ...
  )

For the bindings between Foo#myMethod and $myMethod, we need an incoming binding expression similar to get, but which gets the this receiver rather than an indexed parameter.

Note that this need comes up not just for methods on interfaces, but also for various callbacks on the Web where this is used to pass extra contextual information (e.g. event listeners).

Or alternatively, is the this receiver intended to always the first element of the incoming Web IDL values? If so, then we should make this more clear and provide an example of using the this receiver from Wasm.

lukewagner commented 5 years ago

This isn't super-clearly documented, but the idea, in the explainer, is if the function is declared to be a "method" (via (method any)), then the receiver is taken/provided as the first argument.

fitzgen commented 5 years ago

Ah yeah, I missed that when looking at the explainer again. I think clarifying this further is unnecessary for the explainer, and should instead be in the actual standard, so I'm going to close this issue.