-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37c33b9
commit c16868b
Showing
2 changed files
with
5 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,12 @@ | ||
import { WASI } from "wasi"; | ||
import fs from "fs/promises"; | ||
import path from "path"; | ||
import { RubyVM } from "../dist/index.umd.js"; | ||
import { DefaultRubyVM } from "../dist/default/node.cjs"; | ||
|
||
const rubyModule = (async () => { | ||
const binary = await fs.readFile(path.join(__dirname, "./../dist/ruby.wasm")); | ||
return await WebAssembly.compile(binary.buffer); | ||
})(); | ||
|
||
export const initRubyVM = async () => { | ||
const wasi = new WASI(); | ||
const vm = new RubyVM(); | ||
const imports = { | ||
wasi_snapshot_preview1: wasi.wasiImport, | ||
}; | ||
vm.addToImports(imports); | ||
|
||
const instance = await WebAssembly.instantiate(await rubyModule, imports); | ||
await vm.setInstance(instance); | ||
wasi.initialize(instance); | ||
vm.initialize(); | ||
return vm; | ||
return DefaultRubyVM(await rubyModule); | ||
}; |