Inside the instance there are wasm globals (emscripten doesn't make heavy
use of them but they exist) and the indirect function table.

On the JS there are a lot of potential things... but it sounds like you are
planning to avoid them so maybe it won't be an issue for you.

On Sat, Dec 17, 2022 at 1:58 PM Steve Dekorte <st...@dekorte.com> wrote:

>
> For my use case, I only want to use HTML/JS to start WASM and hand it a
> canvas and events. Things like i/o contexts would have to be reconstructed
> if possible. Is there anything else?
>
> On Dec 17, 2022, at 1:40 PM, 'Sam Clegg' via emscripten-discuss <
> emscripten-discuss@googlegroups.com> wrote:
>
> 
> Neat!  That might work for the linear memory, but as I said in an earlier
> reply there is more to the state of a running module than just its memory.
>
> On Sat, Dec 17, 2022 at 10:40 AM Steve Dekorte <st...@dekorte.com> wrote:
>
>>
>> Just for fun, I tried asking ChatGPT:
>>
>> [[Please write some Javascript code which stores the state of a
>> WebAssembly instance to a byte array.]]
>>
>> // First, create a WebAssembly instance and obtain a reference to its
>> memory object
>> const wasmInstance = new WebAssembly.Instance(wasmModule);
>> const memory = wasmInstance.exports.memory;
>>
>> // Next, create a JavaScript typed array to hold the contents of the
>> memory object
>> const memoryArray = new Uint8Array(memory.buffer);
>>
>> // Finally, use the copy method to copy the contents of the memory object
>> to the typed array
>> memory.copy(memoryArray);
>>
>> [[Thanks. Could you also write some Javascript code which creates a new
>> WebAssembly instance and uses this byte array to restore the previous
>> state?]]
>>
>> // First, create a WebAssembly module using the WebAssembly.compile
>> function
>> const wasmModule = await WebAssembly.compile(wasmCode);
>>
>> // Next, create a new WebAssembly instance and obtain a reference to its
>> memory object
>> const wasmInstance = new WebAssembly.Instance(wasmModule);
>> const memory = wasmInstance.exports.memory;
>>
>> // Use the copy method to copy the contents of the byte array into the
>> memory object of the WebAssembly instance
>> memory.copy(byteArray);
>>
>> // Now, the WebAssembly instance has been restored to the previous state
>>
>> //...It is important to note that the byte array must be the same size as
>> the memory object of the WebAssembly instance, and it must contain a valid
>> snapshot of the state of the WebAssembly instance. If the byte array is not
>> the correct size or does not contain a valid snapshot, the WebAssembly
>> instance may not be restored correctly.
>>
>> I haven’t had a chance to give it a try yet. Does it look reasonable?
>>
>> Steve
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to emscripten-discuss+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/emscripten-discuss/f1967bf2cf0d44dc90bd7557a64839f4%40smtp.hushmail.com
>> .
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "emscripten-discuss" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/emscripten-discuss/-b2JbVbsfo4/unsubscribe
> .
> To unsubscribe from this group and all its topics, send an email to
> emscripten-discuss+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/CAL_va28VFRxNwFGv2R6f2rDhYpTie0e8Pie%3Dt5hb4y2G5%3Dgzzw%40mail.gmail.com
> <https://groups.google.com/d/msgid/emscripten-discuss/CAL_va28VFRxNwFGv2R6f2rDhYpTie0e8Pie%3Dt5hb4y2G5%3Dgzzw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to emscripten-discuss+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/305a50dba3817de2b1b876b9ca9a1a58%40smtp.hushmail.com
> <https://groups.google.com/d/msgid/emscripten-discuss/305a50dba3817de2b1b876b9ca9a1a58%40smtp.hushmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2_Uu4Ec6UdnnS2EBRUTEDbpu4%3Dk2VUUPq8d3mYTN6zcBg%40mail.gmail.com.

Reply via email to