fix: support for v8.setHeapSnapshotNearHeapLimit api (#45632)

* fix: support for v8.setHeapSnapshotNearHeapLimit api

Co-authored-by: deepak1556 <hop2deep@gmail.com>

* docs: add support

Co-authored-by: deepak1556 <hop2deep@gmail.com>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
This commit is contained in:
trop[bot] 2025-02-17 13:23:38 +09:00 committed by GitHub
parent cf85d2d7c1
commit fa0da6f19f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 66 additions and 6 deletions

View file

@ -5,6 +5,8 @@ import { expect } from 'chai';
import * as childProcess from 'node:child_process';
import { once } from 'node:events';
import * as fs from 'node:fs/promises';
import * as os from 'node:os';
import * as path from 'node:path';
import { setImmediate } from 'node:timers/promises';
import { pathToFileURL } from 'node:url';
@ -760,5 +762,26 @@ describe('utilityProcess module', () => {
expect(loginAuthInfo!.realm).to.equal('Foo');
expect(loginAuthInfo!.scheme).to.equal('basic');
});
it('supports generating snapshots via v8.setHeapSnapshotNearHeapLimit', async () => {
const tmpDir = await fs.mkdtemp(path.resolve(os.tmpdir(), 'electron-spec-utility-oom-'));
const child = utilityProcess.fork(path.join(fixturesPath, 'oom-grow.js'), [], {
stdio: 'ignore',
execArgv: [
`--diagnostic-dir=${tmpDir}`,
'--js-flags=--max-old-space-size=50'
],
env: {
NODE_DEBUG_NATIVE: 'diagnostic'
}
});
await once(child, 'spawn');
await once(child, 'exit');
const files = (await fs.readdir(tmpDir)).filter((file) => file.endsWith('.heapsnapshot'));
expect(files.length).to.be.equal(1);
const stat = await fs.stat(path.join(tmpDir, files[0]));
expect(stat.size).to.be.greaterThan(0);
await fs.rm(tmpDir, { recursive: true });
});
});
});