Skip to content

Commit

Permalink
process: introduce process.availableV8flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Trott committed Jun 8, 2022
1 parent aba2cd7 commit 1bc7e60
Show file tree
Hide file tree
Showing 4 changed files with 821 additions and 82 deletions.
57 changes: 56 additions & 1 deletion doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ return `true` in the following cases:
* Flags may omit leading single (`-`) or double (`--`) dashes; e.g.,
`inspect-brk` for `--inspect-brk`, or `r` for `-r`.
* Flags passed through to V8 (as listed in `--v8-options`) may replace
one or more _non-leading_ dashes for an underscore, or vice-versa;
one or more _non-leading_ dashes for an underscore, or vice versa;
e.g., `--perf_basic_prof`, `--perf-basic-prof`, `--perf_basic-prof`,
etc.
* Flags may contain one or more equals (`=`) characters; all
Expand Down Expand Up @@ -955,6 +955,61 @@ $ bash -c 'exec -a customArgv0 ./node'
'customArgv0'
```

## `process.availableV8Flags`

<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental
* {Set}

The `process.availableV8Flags` property is a special, read-only `Set` of
command-line flags. If a user supplies one or more of these flags, Node.js will
pass the flags through to V8. These flags are not supported by Node.js. Avoid
using these flags if at all possible. They may or may not work correctly, and
their behavior can change in breaking ways in any Node.js release.

`process.availableV8Flags` extends `Set`, but overrides `Set.prototype.has` to
recognize several different possible flag representations.
`process.availableV8Flags.has()` will return `true` in the following cases:

* Flags may omit leading single (`-`) or double (`--`) dashes.
* Flags may replace one or more non-leading dashes for an underscore, or vice
versa.
* Flags may contain one or more equals (`=`) characters and all
characters after and including the first equals will be ignored.

When iterating over `process.availableV8Flags`, flags will appear only once.
Each will begin with one or more dashes. Flags will contain underscores instead
of non-leading dashes.

```mjs
import { availableV8Flags } from 'process';

availableV8Flags.forEach((flag) => {
// --abort-on-contradictory-flags
// --abort-on-uncaught-exception
// --adjust-os-scheduling-parameters
// ...
});
```

```cjs
const { availableV8Flags } = require('process');

availableV8Flags.forEach((flag) => {
// --abort-on-contradictory-flags
// --abort-on-uncaught-exception
// --adjust-os-scheduling-parameters
// ...
});
```

The methods `add()`, `clear()`, and `delete()` of `process.availableV8Flags` do
nothing.

## `process.channel`

<!-- YAML
Expand Down
21 changes: 21 additions & 0 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,27 @@ ObjectDefineProperty(process, 'allowedNodeEnvironmentFlags', {
configurable: true
});

// process.availableV8Flags
ObjectDefineProperty(process, 'availableV8Flags', {
get() {
const flags = perThreadSetup.buildAvailableV8Flags();
process.availableV8Flags = flags;
return process.availableV8Flags;
},
// If the user tries to set this to another value, override
// this completely to that value.
set(value) {
ObjectDefineProperty(this, 'availableV8Flags', {
value,
configurable: true,
enumerable: true,
writable: true
});
},
enumerable: true,
configurable: true
});

// process.assert
process.assert = deprecate(
perThreadSetup.assert,
Expand Down
Loading

0 comments on commit 1bc7e60

Please sign in to comment.