Skip to content

Commit 97f7532

Browse files
Tjtannal
authored andcommitted
Add documentation and tests
1 parent 285e863 commit 97f7532

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

doc/api/cli.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,6 +3454,7 @@ V8 options that are allowed are:
34543454
* `--expose-gc`
34553455
* `--interpreted-frames-native-stack`
34563456
* `--jitless`
3457+
* `--max-heap-size`
34573458
* `--max-old-space-size`
34583459
* `--max-semi-space-size`
34593460
* `--perf-basic-prof-only-functions`
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const { spawnSync } = require('child_process');
5+
const path = require('path');
6+
const fs = require('fs');
7+
const tmpdir = require('./tmpdir');
8+
9+
const testScript = `
10+
const v8 = require('v8');
11+
const stats = v8.getHeapStatistics();
12+
const maxHeapSizeMB = Math.round(stats.heap_size_limit / 1024 / 1024);
13+
console.log(maxHeapSizeMB);
14+
`;
15+
16+
tmpdir.refresh();
17+
const scriptPath = path.join(tmpdir.path, 'heap-limit-test.js');
18+
fs.writeFileSync(scriptPath, testScript);
19+
20+
const child = spawnSync(
21+
process.execPath,
22+
[scriptPath],
23+
{
24+
encoding: 'utf8',
25+
env: {
26+
...process.env,
27+
NODE_OPTIONS: '--max-heap-size=750'
28+
}
29+
}
30+
);
31+
32+
assert.strictEqual(child.status, 0, 'Child process did not exit cleanly');
33+
const output = child.stdout.trim();
34+
const heapLimit = Number(output);
35+
36+
assert.strictEqual(
37+
heapLimit,
38+
750,
39+
`max heap size is ${heapLimit}MB, expected 750MB`
40+
);
41+

0 commit comments

Comments
 (0)