From 059fcf4cd790fd45a1464ea10d8c298f1be81faa Mon Sep 17 00:00:00 2001 From: Ben Smith Date: Mon, 11 Feb 2019 16:17:38 -0800 Subject: [PATCH] [interpreter] Return instance wrapper from instance() (#126) 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. --- interpreter/script/js.ml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/interpreter/script/js.ml b/interpreter/script/js.ml index 75480705db..6487ca5a1a 100644 --- a/interpreter/script/js.ml +++ b/interpreter/script/js.ml @@ -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) { @@ -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) {