Skip to content

Commit

Permalink
test: use checkIfCollectableByCounting in SourceTextModule leak test
Browse files Browse the repository at this point in the history
...which may be more reliable than than checkIfCollectable().
  • Loading branch information
joyeecheung committed Jan 18, 2024
1 parent 32ce183 commit 1aea2e6
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions test/es-module/test-vm-source-text-module-leak.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
// Flags: --experimental-vm-modules --max-old-space-size=16 --trace-gc
// Flags: --expose-internals --experimental-vm-modules --max-old-space-size=16 --trace-gc
'use strict';

// This tests that vm.SourceTextModule() does not leak.
// See: https://github.com/nodejs/node/issues/33439
require('../common');
const { checkIfCollectable } = require('../common/gc');
const common = require('../common');
const { checkIfCollectableByCounting } = require('../common/gc');
const vm = require('vm');

async function createSourceTextModule() {
// Try to reach the maximum old space size.
const m = new vm.SourceTextModule(`
const bar = new Array(512).fill("----");
export { bar };
`);
await m.link(() => {});
await m.evaluate();
return m;
}
const outer = 32;
const inner = 128;

checkIfCollectable(createSourceTextModule, 4096, 1024);
checkIfCollectableByCounting(async (i) => {
for (let j = 0; j < inner; j++) {
// Try to reach the maximum old space size.
const m = new vm.SourceTextModule(`
const bar = new Array(512).fill("----");
export { bar };
`);
await m.link(() => {});
await m.evaluate();
}
return inner;
}, vm.SourceTextModule, outer).then(common.mustCall());

0 comments on commit 1aea2e6

Please sign in to comment.