-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpen322-tester.js
37 lines (34 loc) · 970 Bytes
/
cpen322-tester.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
// This module is INSECURE
const Module = require('module');
const http = require('http');
const path = require('path');
const exported = new Map();
let initialized = false;
module.exports = {
connect: async (url) => {
if (!initialized){
let cpen322 = await new Promise((resolve, reject) => http.get(url, res => {
let filename = 'cpen322.js';
let data = '';
res.setEncoding('utf8');
res.on('data', chunk => data += chunk);
res.on('end', () => {
let cpen322 = new Module('', module.parent);
cpen322.filename = filename;
cpen322.paths = Module._nodeModulePaths(path.dirname(filename));
cpen322._compile(data, filename);
resolve(cpen322.exports);
});
}));
cpen322.initialize({
exported: exported
});
}
initialized = true;
},
export: (filename, dict) => {
let scope = path.basename(filename);
if (!exported.has(scope)) exported.set(scope, {});
Object.assign(exported.get(scope), dict);
}
}