-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: use checkIfCollectableByCounting in SourceTextModule leak test
...which may be more reliable than than checkIfCollectable().
- Loading branch information
1 parent
32ce183
commit 1aea2e6
Showing
1 changed file
with
17 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |