| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent db7459b commit 26a06b0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,7 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | + const wait = require('timers/promises').setTimeout; | ||
| 4 | + | ||
| 3 | 5 | // TODO(joyeecheung): merge ongc.js and gcUntil from common/index.js | |
| 4 | 6 | // into this. | |
| 5 | 7 | ||
@@ -65,6 +67,15 @@ async function checkIfCollectable( | |||
| 65 | 67 | createObject(); | |
| 66 | 68 | } | |
| 67 | 69 | ||
| 70 | + // Repeat an operation and give GC some breathing room at every iteration. | ||
| 71 | + async function runAndBreathe(fn, repeat, waitTime = 20) { | ||
| 72 | + for (let i = 0; i < repeat; i++) { | ||
| 73 | + await fn(); | ||
| 74 | + await wait(waitTime); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + | ||
| 68 | 78 | module.exports = { | |
| 69 | 79 | checkIfCollectable, | |
| 80 | + runAndBreathe, | ||
| 70 | 81 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,13 +8,11 @@ | |||
| 8 | 8 | ||
| 9 | 9 | const common = require('../common'); | |
| 10 | 10 | const fixtures = require('../common/fixtures'); | |
| 11 | + const { runAndBreathe } = require('../common/gc'); | ||
| 11 | 12 | ||
| 12 | - async function main() { | ||
| 13 | - const mod = fixtures.fileURL('es-module-shadow-realm', 'state-counter.mjs'); | ||
| 14 | - for (let i = 0; i < 100; i++) { | ||
| 15 | - const realm = new ShadowRealm(); | ||
| 16 | - await realm.importValue(mod, 'getCounter'); | ||
| 17 | - } | ||
| 18 | - } | ||
| 13 | + const mod = fixtures.fileURL('es-module-shadow-realm', 'state-counter.mjs'); | ||
| 19 | 14 | ||
| 20 | - main().then(common.mustCall()); | ||
| 15 | + runAndBreathe(async () => { | ||
| 16 | + const realm = new ShadowRealm(); | ||
| 17 | + await realm.importValue(mod, 'getCounter'); | ||
| 18 | + }, 100).then(common.mustCall()); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,14 +6,16 @@ | |||
| 6 | 6 | */ | |
| 7 | 7 | ||
| 8 | 8 | const common = require('../common'); | |
| 9 | + const { runAndBreathe } = require('../common/gc'); | ||
| 9 | 10 | const assert = require('assert'); | |
| 10 | 11 | const { isMainThread, Worker } = require('worker_threads'); | |
| 11 | 12 | ||
| 12 | - for (let i = 0; i < 100; i++) { | ||
| 13 | + runAndBreathe(() => { | ||
| 13 | 14 | const realm = new ShadowRealm(); | |
| 14 | 15 | realm.evaluate('new TextEncoder(); 1;'); | |
| 15 | - } | ||
| 16 | + }, 100).then(common.mustCall()); | ||
| 16 | 17 | ||
| 18 | + // Test it in worker too. | ||
| 17 | 19 | if (isMainThread) { | |
| 18 | 20 | const worker = new Worker(__filename); | |
| 19 | 21 | worker.on('exit', common.mustCall((code) => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments