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().

PR-URL: #51512
Refs: #51362
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
joyeecheung authored and targos committed Feb 15, 2024
1 parent 9dfb36f commit c88f0b6
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 c88f0b6

Please sign in to comment.