stevefan1999-personal opened issue #7724:
I'm trying to implement the JS interface to WebAssembly using wasmtime with my own little JS engine project but I came across this
A Memory object represents a single memory instance which can be simultaneously referenced by multiple Instance objects. Each Memory object has the following internal slots:
[[Memory]] : a memory address
[[BufferObject]] : an ArrayBuffer whose Data Block is identified with the above memory address
(https://webassembly.github.io/spec/js-api/#memories)
But if you look closely at https://docs.wasmtime.dev/api/wasmtime/struct.Memory.html#impl-Memory, you can see that the only way to create a
Memory
is by handing it aStore
, but to get aStore
you must first create it from anEngine
and so I think there is currently no way to implement the required semantics the WebAssembly Spec needed me to do.
bjorn3 commented on issue #7724:
An
Engine
is meant to be created once at startup and then used on all threads. (You can still create multipleEngine
s if you need different settings in different places.) The way to model the JS behavior would be to create a singleStore
for every thread running javascript. Be aware however that all things that are part of aStore
can't get deallocated without deallocating the entireStore
. As such you can easily run out of memory if you keep aStore
around for the entire JS execution.
alexcrichton closed issue #7724:
I'm trying to implement the JS interface to WebAssembly using wasmtime with my own little JS engine project but I came across this
A Memory object represents a single memory instance which can be simultaneously referenced by multiple Instance objects. Each Memory object has the following internal slots:
[[Memory]] : a memory address
[[BufferObject]] : an ArrayBuffer whose Data Block is identified with the above memory address
(https://webassembly.github.io/spec/js-api/#memories)
But if you look closely at https://docs.wasmtime.dev/api/wasmtime/struct.Memory.html#impl-Memory, you can see that the only way to create a
Memory
is by handing it aStore
, but to get aStore
you must first create it from anEngine
and so I think there is currently no way to implement the required semantics the WebAssembly Spec needed me to do.
alexcrichton commented on issue #7724:
I don't have much more to add over what @bjorn3 already mentioned (thanks!) other than the Rust API for
wasmtime
is intentionally different from the JS API to better suit Rust idioms and cater to Wasmtime's use cases.Otherwise though given that a
Store
-per-JS-thread should suffice I'm otherwise going to close this. Let us know though if you've got other questions!
Last updated: Nov 22 2024 at 17:03 UTC