Experimental JS API based on tracking values #2013
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR upstreams API we're using in Popcorn.
It doesn't have tests or extended docs. I'd gladly take some instructions about testing Wasm. Docs will be added after first round of review – I need to know if approach is sane at all.
Design notes
We needed some API to track values in JS with their lifetime in the VM. This was achieved by using new type of resource –
TrackedValue. Popcorn also wants to customize JS behavior without maintaining custom Emscripten hooks in.cfiles – we extracted them to functions inatomvm.pre.js. You can see our implementation in Popcorn repo.We also need JS to have access to DOM. We hardcoded thread executing JS to be main thread (or in our case, iframe thread).
We were thinking about relaxing that constraint but it'd need
js_tracked_evalto forward script to it's destination JS context (e.g.postMessage()to iframe).js_get_tracked_objectsworks by batchingTrackedObjects and their status (missing, bad type, etc). This allows to reduce communication overhead between JS and Wasm.We also needed to use ES modules instead of current, IIFE format. It makes it easier to load in iframes and to use in modern JS projects.
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later