git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 05c4e2d027ee79f709d87c92e48f83e9cb3489ad

Files: 05c4e2d027ee79f709d87c92e48f83e9cb3489ad / codeHandler.js

528 bytesRaw
1const Wasm = require('./vm.js')
2
3const defaultHandler = {
4 test: (code) => {
5 return !code
6 },
7 init: () => {
8 return require('./defaultAgent.js')
9 }
10}
11
12const wasm = {
13 test: (code) => {
14 return code && code.slice(0, 4).toString() === '\x00asm'
15 },
16 init: (code) => {
17 return new Wasm(code)
18 }
19}
20
21let codeHandlers = exports.codeHandlers = [
22 defaultHandler,
23 wasm
24]
25
26exports.init = (code) => {
27 for (let handler of codeHandlers) {
28 if (handler.test(code)) {
29 return handler.init(code)
30 }
31 }
32}
33

Built with git-ssb-web