git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: f51dc0dfc7b37b0d369c1f9a552d6ab0e1129055

Files: f51dc0dfc7b37b0d369c1f9a552d6ab0e1129055 / codeHandler.js

610 bytesRaw
1const Wasm = require('./wasmAgent.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 code = new Buffer(code)
15 return code && code.slice(0, 4).toString() === '\x00asm'
16 },
17 init: (code) => {
18 return new Wasm(code)
19 }
20}
21
22let codeHandlers = exports.handlers = {
23 default: defaultHandler,
24 wasm: wasm
25}
26
27exports.init = (code) => {
28 for (let name in codeHandlers) {
29 const handler = codeHandlers[name]
30 if (handler.test(code)) {
31 return handler.init(code)
32 }
33 }
34}
35

Built with git-ssb-web