git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 2d5edf066ff154d5fc07115a7b1b66bcc2899f57

Files: 2d5edf066ff154d5fc07115a7b1b66bcc2899f57 / 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