Skip to content

Commit cf4d3c8

Browse files
juanarboleliphazbouye
authored andcommitted
cli: add --expose-gc flag available to NODE_OPTIONS
This commits allows users to send `--expose-gc` via `NODE_OPTIONS` environment variable. Using `node --expose-gc` is possible but via `NODE_OPTIONS` won't work. ```sh NODE_OPTIONS='--expose-gc' node node: --expose-gc is not allowed in NODE_OPTIONS ``` Signed-off-by: Juan José Arboleda <[email protected]> PR-URL: nodejs#53078 Reviewed-By: Tierney Cyren <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent 5432b04 commit cf4d3c8

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

doc/api/cli.md

+20
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,23 @@ Make built-in language features like `eval` and `new Function` that generate
673673
code from strings throw an exception instead. This does not affect the Node.js
674674
`node:vm` module.
675675

676+
### `--expose-gc`
677+
678+
<!-- YAML
679+
added: REPLACEME
680+
-->
681+
682+
> Stability: 1 - Experimental. This flag is inherited from V8 and is subject to
683+
> change upstream.
684+
685+
This flag will expose the gc extension from V8.
686+
687+
```js
688+
if (globalThis.gc) {
689+
globalThis.gc();
690+
}
691+
```
692+
676693
### `--dns-result-order=order`
677694

678695
<!-- YAML
@@ -2864,6 +2881,7 @@ V8 options that are allowed are:
28642881
* `--abort-on-uncaught-exception`
28652882
* `--disallow-code-generation-from-strings`
28662883
* `--enable-etw-stack-walking`
2884+
* `--expose-gc`
28672885
* `--huge-max-old-generation-size`
28682886
* `--interpreted-frames-native-stack`
28692887
* `--jitless`
@@ -3193,6 +3211,8 @@ documented here:
31933211

31943212
### `--enable-etw-stack-walking`
31953213

3214+
### `--expose-gc`
3215+
31963216
### `--harmony-shadow-realm`
31973217

31983218
### `--huge-max-old-generation-size`

src/node_options.cc

+1
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
477477
AddOption("--experimental-report", "", NoOp{}, kAllowedInEnvvar);
478478
AddOption(
479479
"--experimental-wasi-unstable-preview1", "", NoOp{}, kAllowedInEnvvar);
480+
AddOption("--expose-gc", "expose gc extension", V8Option{}, kAllowedInEnvvar);
480481
AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
481482
AddOption("--frozen-intrinsics",
482483
"experimental frozen intrinsics support",

test/parallel/test-cli-node-options.js

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ if (common.hasCrypto) {
6969
// V8 options
7070
expect('--abort_on-uncaught_exception', 'B\n');
7171
expect('--disallow-code-generation-from-strings', 'B\n');
72+
expect('--expose-gc', 'B\n');
7273
expect('--huge-max-old-generation-size', 'B\n');
7374
expect('--jitless', 'B\n');
7475
expect('--max-old-space-size=0', 'B\n');

0 commit comments

Comments
 (0)