Allow receiving wasm as a function via wasm_fn (#629)
Allow receiving wasm as a function via wasm_fn (for bundlers)
This commit is contained in:
parent
d1a949d881
commit
f42e204ed3
|
@ -154,6 +154,13 @@ function V86Starter(options)
|
|||
"__indirect_function_table": wasm_table,
|
||||
};
|
||||
|
||||
let wasm_fn = options["wasm_fn"];
|
||||
|
||||
if(!wasm_fn)
|
||||
{
|
||||
wasm_fn = async function(env)
|
||||
{
|
||||
return new Promise(resolve => {
|
||||
let v86_bin = DEBUG ? "v86-debug.wasm" : "v86.wasm";
|
||||
let v86_bin_fallback = "v86-fallback.wasm";
|
||||
|
||||
|
@ -179,32 +186,16 @@ function V86Starter(options)
|
|||
done: bytes =>
|
||||
{
|
||||
WebAssembly
|
||||
.instantiate(bytes, { "env": wasm_shared_funcs })
|
||||
.instantiate(bytes, env)
|
||||
.then(({ instance }) => {
|
||||
const imports = wasm_shared_funcs;
|
||||
const exports = instance["exports"];
|
||||
wasm_memory = exports.memory;
|
||||
exports["rust_init"]();
|
||||
|
||||
const emulator = this.v86 = new v86(this.emulator_bus, { exports, wasm_table });
|
||||
cpu = emulator.cpu;
|
||||
|
||||
this.continue_init(emulator, options);
|
||||
resolve(instance.exports);
|
||||
}, err => {
|
||||
v86util.load_file(v86_bin_fallback, {
|
||||
done: bytes => {
|
||||
WebAssembly
|
||||
.instantiate(bytes, { "env": wasm_shared_funcs })
|
||||
.instantiate(bytes, env)
|
||||
.then(({ instance }) => {
|
||||
const imports = wasm_shared_funcs;
|
||||
const exports = instance["exports"];
|
||||
wasm_memory = exports.memory;
|
||||
exports["rust_init"]();
|
||||
|
||||
const emulator = this.v86 = new v86(this.emulator_bus, { exports, wasm_table });
|
||||
cpu = emulator.cpu;
|
||||
|
||||
this.continue_init(emulator, options);
|
||||
resolve(instance.exports);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
@ -223,6 +214,20 @@ function V86Starter(options)
|
|||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
wasm_fn({ "env": wasm_shared_funcs })
|
||||
.then((exports) => {
|
||||
wasm_memory = exports.memory;
|
||||
exports["rust_init"]();
|
||||
|
||||
const emulator = this.v86 = new v86(this.emulator_bus, { exports, wasm_table });
|
||||
cpu = emulator.cpu;
|
||||
|
||||
this.continue_init(emulator, options);
|
||||
});
|
||||
}
|
||||
|
||||
V86Starter.prototype.continue_init = async function(emulator, options)
|
||||
|
|
Loading…
Reference in a new issue