Skip to content

Commit 3f78d4e

Browse files
juanarboltargos
authored andcommittedSep 21, 2024
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 <soyjuanarbol@gmail.com> PR-URL: #53078 Reviewed-By: Tierney Cyren <hello@bnb.im> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 272484b commit 3f78d4e

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
@@ -687,6 +687,23 @@ Make built-in language features like `eval` and `new Function` that generate
687687
code from strings throw an exception instead. This does not affect the Node.js
688688
`node:vm` module.
689689

690+
### `--expose-gc`
691+
692+
<!-- YAML
693+
added: REPLACEME
694+
-->
695+
696+
> Stability: 1 - Experimental. This flag is inherited from V8 and is subject to
697+
> change upstream.
698+
699+
This flag will expose the gc extension from V8.
700+
701+
```js
702+
if (globalThis.gc) {
703+
globalThis.gc();
704+
}
705+
```
706+
690707
### `--dns-result-order=order`
691708

692709
<!-- YAML
@@ -2819,6 +2836,7 @@ V8 options that are allowed are:
28192836
* `--abort-on-uncaught-exception`
28202837
* `--disallow-code-generation-from-strings`
28212838
* `--enable-etw-stack-walking`
2839+
* `--expose-gc`
28222840
* `--huge-max-old-generation-size`
28232841
* `--interpreted-frames-native-stack`
28242842
* `--jitless`
@@ -3148,6 +3166,8 @@ documented here:
31483166

31493167
### `--enable-etw-stack-walking`
31503168

3169+
### `--expose-gc`
3170+
31513171
### `--harmony-shadow-realm`
31523172

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

‎src/node_options.cc

+1
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
506506
AddOption("--experimental-report", "", NoOp{}, kAllowedInEnvvar);
507507
AddOption(
508508
"--experimental-wasi-unstable-preview1", "", NoOp{}, kAllowedInEnvvar);
509+
AddOption("--expose-gc", "expose gc extension", V8Option{}, kAllowedInEnvvar);
509510
AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
510511
AddOption("--frozen-intrinsics",
511512
"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)
Please sign in to comment.