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
TLDR: bind should be overrided for WebAssembly.Function to return regular JS Function.
According to the proposal WebAssembly.Function is a subclass of regular JS Function and Function.prototype in its prototype chain. It makes possible to call Function.prototype.bind on WebAssembly.Function object. It returns Bound Function exotic object with its [[Prototype]] internal field set to a prototype of target - WebAssembly.Function.prototype in our case. After that we get an object indistinguishable from WebAssembly.Function using instanceof machinery, but it couldn't be used as an argument for Table.set.
letwafn=newWebAssembly.Function({parameters: ['i32'],results:[]},_=>0)letpseudo_wafn=wafn.bind(null)console.log(pseudo_wafninstanceofWebAssembly.Function)// true in current state of thingsconsole.log(pseudo_wafn.type().parameters)// ['i32']? []? but Function.prototype.bind knows nothing about WebAssembly.Functionlettable=newWebAssembly.Table({initial: 1,element: "anyfunc"})table.set(0,pseudo_wafn)// throws an exception. pseudo_wafn is not a real WebAssembly.Function
To keep it consistent and predictable I propose to override bind on the level of WebAssembly.Function.prototype to behave exactly like original one, but return BoundFunctionObject with a regular function prototype. It allows to keep ergonomic on JS side without changing ecma262 spec.
The text was updated successfully, but these errors were encountered:
No, I'm not familiar with such precedence. Other function objects(AsyncFunction, AsyncGeneratorFunction) behave the same way as their BoundFunctionObject in any applications. So there is no such problem with them.
TLDR:
bind
should be overrided for WebAssembly.Function to return regular JS Function.According to the proposal
WebAssembly.Function
is a subclass of regular JS Function andFunction.prototype
in its prototype chain. It makes possible to call Function.prototype.bind onWebAssembly.Function
object. It returns Bound Function exotic object with its[[Prototype]]
internal field set to a prototype of target -WebAssembly.Function.prototype
in our case. After that we get an object indistinguishable fromWebAssembly.Function
usinginstanceof
machinery, but it couldn't be used as an argument forTable.set
.To keep it consistent and predictable I propose to override
bind
on the level ofWebAssembly.Function.prototype
to behave exactly like original one, but returnBoundFunctionObject
with a regular function prototype. It allows to keep ergonomic on JS side without changingecma262
spec.The text was updated successfully, but these errors were encountered: