-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
50 lines (42 loc) · 1.14 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
import {SourceTextModule, SyntheticModule, createContext} from 'vm';
async function link() {
// Having a shared context leaks nodejs memory
let context = createContext()
const module = new SourceTextModule(`
import foo from 'foo';
export default {a: new Array(100000).fill('-')};
`, {
context,
identifier: ''
});
const subModule = new SourceTextModule(`
import asd from 'asd.json';
export default asd;
`, {
context,
identifier: 'foo'
})
const jsonModule = new SyntheticModule(
['default'],
function () {
// mimic some large file
this.setExport('default', {a: new Array(100000).fill('-')});
},
{
context,
identifier: 'asd.json'
}
)
await subModule.link(() => jsonModule)
await module.link(() => subModule)
await module.evaluate();
// UN-COMMENT THIS LINE TO FIX THE LEAK?? wtf...
context = null
return module;
}
for (let i = 0; i < 100000; i++) {
if (i % 100 === 0) {
console.log("iterations" + i)
}
await link();
}