-
Notifications
You must be signed in to change notification settings - Fork 11
/
test.js
104 lines (81 loc) · 2.01 KB
/
test.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const Sandbox = require('./dist').default;
const assert = require('assert');
const sandbox = new Sandbox();
const jsAsync = `
httpRequest({uri: 'https://gist.githubusercontent.com/zhm/39714de5e103126561da5f60e0fe0ce2/raw/46c1114c9f78a75d67dc4100d7e5e4d63ea5c583/gistfile1.txt'}, (err, res, body) => {
setResult(body);
});
`;
const js = `
const [err, res, body] = httpRequest({uri: 'https://gist.githubusercontent.com/zhm/39714de5e103126561da5f60e0fe0ce2/raw/46c1114c9f78a75d67dc4100d7e5e4d63ea5c583/gistfile1.txt'});
const timerId = setTimeout(() => {
console.log('FINISHED!!!!!');
setResult(body);
}, 3000);
console.log('timerid', timerId);
clearTimeout(timerId);
clearTimeout(timerId);
//while(true){};
`;
const jsInfinite1 = `
setTimeout(() => {}, 10000);
let i = 0;
console.log(i++);
const createTimeout = () => {
console.log(i++);
setTimeout(() => {
createTimeout();
}, 1);
};
createTimeout();
`;
const jsInfinite = `
setTimeout(() => {}, 10000);
`;
const jsTest = `
httpRequest({uri: 'https://gist.githubusercontent.com/zhm/39714de5e103126561da5f60e0fe0ce2/raw/46c1114c9f78a75d67dc4100d7e5e4d63ea5c583/gistfile1.txt'}, (err, res, body) => {
setResult({value: body});
});
`;
const jsTest2 = `
setResult(1337);
`;
const jsTest3 = `
while (true) {}
throw new Error('yo');
`;
const jsTest4 = `
setTimeout(() => {
setResult({ value: 1 });
}, 1000);
`;
const jsTest5 = `
function test() {
// xxxxxxx%
throw new Error('wha')
setResult({value: 1});
}
(() => {
test();
})();
`.trim();
const jsTest6 = '}';
// run(jsAsync, (err, result) => {
// assert.equal(result, 'hi there');
// console.log('success!');
// });
// new Sandbox().execute(jsTest, (err, result) => {
// console.log('success!', err, result);
// });
(async () => {
const { error, value } = await sandbox.execute({ code: jsTest5, timeout: 4000 });
if (error && error.isTimeout) {
console.log('TIMEOUT!');
}
if (error) {
console.error(error);
} else {
console.log('success!', value);
}
await sandbox.shutdown();
})();