Skip to content

Commit

Permalink
[interpreter] Return instance wrapper from instance() (WebAssembly#126)
Browse files Browse the repository at this point in the history
This doesn't change much currently, but the instance wrapper can be used in the future to send messages to worker threads, so they can remain in sync with the main thread.
  • Loading branch information
binji authored Feb 12, 2019
1 parent 27bae12 commit 059fcf4
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions interpreter/script/js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ let handler = {
};
let registry = new Proxy({spectest}, handler);

function register(name, instance) {
registry[name] = instance.exports;
function register(name, instanceObj) {
registry[name] = instanceObj.instance.exports;
}

function module(bytes, valid = true) {
Expand All @@ -53,20 +53,22 @@ function module(bytes, valid = true) {
}

function instance(bytes, imports = registry) {
return new WebAssembly.Instance(module(bytes), imports);
const mod = module(bytes);
const instance = new WebAssembly.Instance(mod, imports);
return {module: mod, instance};
}

function call(instance, name, args) {
return instance.exports[name](...args);
function call(instanceObj, name, args) {
return instanceObj.instance.exports[name](...args);
}

function get(instance, name) {
let v = instance.exports[name];
function get(instanceObj, name) {
let v = instanceObj.instance.exports[name];
return (v instanceof WebAssembly.Global) ? v.value : v;
}

function exports(name, instance) {
return {[name]: instance.exports};
function exports(name, instanceObj) {
return {[name]: instanceObj.instance.exports};
}

function run(action) {
Expand Down

0 comments on commit 059fcf4

Please sign in to comment.