Files: fe2d3d73d28c55f28860b137e3990bae31fbd26b / codeHandler.js
528 bytesRaw
1 | const Wasm = require('./vm.js') |
2 | |
3 | const defaultHandler = { |
4 | test: (code) => { |
5 | return !code |
6 | }, |
7 | init: () => { |
8 | return require('./defaultAgent.js') |
9 | } |
10 | } |
11 | |
12 | const 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 | |
21 | let codeHandlers = exports.codeHandlers = [ |
22 | defaultHandler, |
23 | wasm |
24 | ] |
25 | |
26 | exports.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