wasmerio / wasmer-ruby

💎🕸 WebAssembly runtime for Ruby
https://wasmer.io
MIT License
473 stars 18 forks source link

instance.memory may cause a (small) problem in the future #18

Closed edvakf closed 3 years ago

edvakf commented 5 years ago

Summary

At the current version of WebAssembly, an instance has at most one memory instance, but it may not be true in the future.

If there are more than one memory, the interface of instance.memory will not be the best interface.

Additional details

http://webassembly.github.io/spec/core/syntax/modules.html#syntax-mem

In the current version of WebAssembly, at most one memory may be defined or imported in a single module, and all constructs implicitly reference this memory 0. This restriction may be lifted in future versions.

Just for your information, the memory is exposed to the JavaScript API through exportsObject, ie. instance.exports.mem1.

https://webassembly.github.io/spec/js-api/#dom-module-exports

Hywan commented 5 years ago

Yeah I know, the memory API isn't perfect right now, but we are not in the 1.* branch yet, so we are free to change it. Behind the scene, the runtime supports multiple memory, but we only read the first one if any. Using instance.exports.memory is indeed an interesting API.

Hywan commented 3 years ago

The new API proposed in #48 is now the following:

instance.exports.<export name>

<export name> is the name of the export, whatever it is, a Function, a Memory, a Global or a Table. Problem solved then!