Skip to content

Commit

Permalink
cli: add --expose-gc flag available to NODE_OPTIONS
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
juanarbol authored and targos committed Sep 21, 2024
1 parent 272484b commit 3f78d4e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,23 @@ Make built-in language features like `eval` and `new Function` that generate
code from strings throw an exception instead. This does not affect the Node.js
`node:vm` module.

### `--expose-gc`

<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental. This flag is inherited from V8 and is subject to
> change upstream.
This flag will expose the gc extension from V8.

```js
if (globalThis.gc) {
globalThis.gc();
}
```

### `--dns-result-order=order`

<!-- YAML
Expand Down Expand Up @@ -2819,6 +2836,7 @@ V8 options that are allowed are:
* `--abort-on-uncaught-exception`
* `--disallow-code-generation-from-strings`
* `--enable-etw-stack-walking`
* `--expose-gc`
* `--huge-max-old-generation-size`
* `--interpreted-frames-native-stack`
* `--jitless`
Expand Down Expand Up @@ -3148,6 +3166,8 @@ documented here:

### `--enable-etw-stack-walking`

### `--expose-gc`

### `--harmony-shadow-realm`

### `--huge-max-old-generation-size`
Expand Down
1 change: 1 addition & 0 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
AddOption("--experimental-report", "", NoOp{}, kAllowedInEnvvar);
AddOption(
"--experimental-wasi-unstable-preview1", "", NoOp{}, kAllowedInEnvvar);
AddOption("--expose-gc", "expose gc extension", V8Option{}, kAllowedInEnvvar);
AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
AddOption("--frozen-intrinsics",
"experimental frozen intrinsics support",
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-cli-node-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ if (common.hasCrypto) {
// V8 options
expect('--abort_on-uncaught_exception', 'B\n');
expect('--disallow-code-generation-from-strings', 'B\n');
expect('--expose-gc', 'B\n');
expect('--huge-max-old-generation-size', 'B\n');
expect('--jitless', 'B\n');
expect('--max-old-space-size=0', 'B\n');
Expand Down

0 comments on commit 3f78d4e

Please sign in to comment.