You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment, the JS API specifies that, when calling a host function, undefined is always passed as the receiver. With the addition of externref, it would otherwise be possible to directly call built-in functions without an intermediate JS glue code function, so it's unfortunate to require a glue code function of the form:
when calling a method (which is almost every function defined by Web IDL).
As an explicit, configurable way to coerce a JS (including Web IDL) function into a wasm function, I think WebAssembly.Function gives us a nice potential solution to this problem: add an optional dictionary parameter with an optional method field (default false) that indicates that the first wasm parameter should be rerouted to the receiver, as in the glue code above. So, for example, you could convert the DOM appendChild method into something wasm could call via:
An aesthetic question is whether "method:true" (or whatever that property should be named) should be merged with the first parameter. It'd look nice, but technically this first parameter is supposed to be describing a wasm function type, so I'm guessing "no".
The text was updated successfully, but these errors were encountered:
That sounds great, but is there any particular reason that it has to be the first parameter?
Could it be left to the code author to decide which parameter is the JS this value?
Maybe a number instead?
constfunc=newWebAssembly.Function({parameters: ["externref","externref"]},Node.prototype.appendChild,{this: 1});// starting at 0; 1 is the second parameterfunc(child,this_element);constfunc2=newWebAssembly.Function({parameters: ["externref","externref"]},Node.prototype.appendChild,{this: 2});// RangeError: function only has 2 parameters, index 2 is out of bounds
I'm personally more interested in calling Wasm functions by passing JS this values to them.
At the moment, the JS API specifies that, when calling a host function,
undefined
is always passed as the receiver. With the addition ofexternref
, it would otherwise be possible to directly call built-in functions without an intermediate JS glue code function, so it's unfortunate to require a glue code function of the form:when calling a method (which is almost every function defined by Web IDL).
As an explicit, configurable way to coerce a JS (including Web IDL) function into a wasm function, I think
WebAssembly.Function
gives us a nice potential solution to this problem: add an optional dictionary parameter with an optionalmethod
field (defaultfalse
) that indicates that the first wasm parameter should be rerouted to the receiver, as in the glue code above. So, for example, you could convert the DOMappendChild
method into something wasm could call via:An aesthetic question is whether "method:true" (or whatever that property should be named) should be merged with the first parameter. It'd look nice, but technically this first parameter is supposed to be describing a wasm function type, so I'm guessing "no".
The text was updated successfully, but these errors were encountered: