2080
2080

Reputation: 1417

WebAssembly: Reconstructing the stack from scratch

By transforming .wasm source files or interacting with a suitable debugger with Javascript it should be possible to serialize the full Wasm execution state (mainly the stack, call frames, local variables etc.).

I wonder if it is possible to reconstruct it using this serialized representation and continue running the program where it was stopped on another machine.

Could current browser runtimes support this?

Upvotes: 0

Views: 120

Answers (1)

Andreas Rossberg
Andreas Rossberg

Reputation: 36078

Not sure what transformation or debugger you have in mind, but your premise that it is possible to serialise JavaScript execution state is false. It would in fact be extremely difficult to implement such a mechanism in browser engines. No production JS engine I'm aware of can even serialise its heap in the general case (even though some, like V8, have a very limited snapshot mechanism for the start-up heap). Let alone the call stack and live function state, which may be in one of many optimisation modes, arbitrarily intermixed with C or assembly stack frames from the runtime or the embedder, and generally is super tricky.

The mechanisation you have in mind would require general serialisation on top of first-class undelimited continuations. TC39, the JavaScript committee, discarded the idea of adding full-blown continuations to the language many years ago because it was deemed too hard and too expensive to implement in most engines (which is why ES6 instead introduced generators as a much more limited mechanism). Edit: Generic serialisation wasn't even ever considered, since it would actually break encapsulation via closures or proxies, and thus all existing security patterns of the language.

Upvotes: 1

Related Questions