-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdummy.js
39 lines (34 loc) · 895 Bytes
/
dummy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { io, stdio } from './_io.js';
const registry = new Map;
const type = 'dummy';
// REQUIRES INTEGRATION TEST
/* c8 ignore start */
const require = name => registry.get(name);
const run = (interpreter, code) => {
try {
return Function('require', code)(require);
}
catch (error) {
io.get(interpreter).stderr(error);
}
};
export default {
type,
module: () => 'data:application/javascript,',
engine: module => stdio().get(module),
registerJSModule(_, name, value) {
registry.set(name, value);
},
run,
runAsync: run,
runEvent: async (interpreter, code, event) => {
try {
await Function('require', 'e', `return ${code}(e)`)(require, event);
}
catch (error) {
io.get(interpreter).stderr(error);
}
},
transform: (_, value) => value,
writeFile() {},
};