git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 8ced6c46cc8f744d128a65d00c117a79e68918b8

Files: 8ced6c46cc8f744d128a65d00c117a79e68918b8 / codeHandler.js

798 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
22const javascript = {
23 test: (code) => {
24 return typeof code === 'object'
25 },
26 init: (code) => {
27 return code
28 }
29}
30
31let codeHandlers = exports.handlers = {
32 default: defaultHandler,
33 wasm: wasm,
34 javascript: javascript
35}
36
37exports.init = (code) => {
38 for (let name in codeHandlers) {
39 try {
40 const handler = codeHandlers[name]
41 if (handler.test(code)) {
42 return handler.init(code)
43 }
44 } catch (e) {}
45 }
46}
47

Built with git-ssb-web