Files: b4f2286715e5d94ee25ada50027f1690079cca1b / codeHandler.js
610 bytesRaw
1 | const Wasm = require('./wasmAgent.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 | 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 | |
22 | let codeHandlers = exports.handlers = { |
23 | default: defaultHandler, |
24 | wasm: wasm |
25 | } |
26 | |
27 | exports.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