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 <[email protected]>
PR-URL: #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]>
  • Loading branch information
juanarbol authored and RafaelGSS committed Jun 7, 2024
1 parent 4a17dda commit 638b510
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 @@ -673,6 +673,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 @@ -2913,6 +2930,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 @@ -3242,6 +3260,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 @@ -489,6 +489,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 638b510

Please sign in to comment.