Skip to content

Commit 0368161

Browse files
committed
process: introduce process.availableV8flags
1 parent a9b2d85 commit 0368161

File tree

4 files changed

+818
-79
lines changed

4 files changed

+818
-79
lines changed

doc/api/process.md

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ return `true` in the following cases:
807807
* Flags may omit leading single (`-`) or double (`--`) dashes; e.g.,
808808
`inspect-brk` for `--inspect-brk`, or `r` for `-r`.
809809
* Flags passed through to V8 (as listed in `--v8-options`) may replace
810-
one or more _non-leading_ dashes for an underscore, or vice-versa;
810+
one or more _non-leading_ dashes for an underscore, or vice versa;
811811
e.g., `--perf_basic_prof`, `--perf-basic-prof`, `--perf_basic-prof`,
812812
etc.
813813
* Flags may contain one or more equals (`=`) characters; all
@@ -944,6 +944,61 @@ $ bash -c 'exec -a customArgv0 ./node'
944944
'customArgv0'
945945
```
946946

947+
## `process.availableV8Flags`
948+
949+
<!-- YAML
950+
added: REPLACEME
951+
-->
952+
953+
> Stability: 1 - Experimental
954+
955+
* {Set}
956+
957+
The `process.availableV8Flags` property is a special, read-only `Set` of
958+
command-line flags. If a user supplies one or more of these flags, Node.js will
959+
pass the flags through to V8. These flags are not supported by Node.js. Avoid
960+
using these flags if at all possible. They may or may not work correctly, and
961+
their behavior can change in breaking ways in any Node.js release.
962+
963+
`process.availableV8lags` extends `Set`, but overrides `Set.prototype.has` to
964+
recognize several different possible flag representations.
965+
`process.availableV8Flags.has()` will return `true` in the following cases:
966+
967+
* Flags may omit leading single (`-`) or double (`--`) dashes.
968+
* Flags may replace one or more non-leading dashes for an underscore, or vice
969+
versa.
970+
* Flags may contain one or more equals (`=`) characters and all
971+
characters after and including the first equals will be ignored.
972+
973+
When iterating over `process.availableV8Flags`, flags will appear only once.
974+
Each will begin with one or more dashes. Flags will contain underscores instead
975+
of non-leading dashes.
976+
977+
```mjs
978+
import { availableV8Flags } from 'process';
979+
980+
availableV8Flags.forEach((flag) => {
981+
// -r
982+
// --inspect-brk
983+
// --abort_on_uncaught_exception
984+
// ...
985+
});
986+
```
987+
988+
```cjs
989+
const { availableV8Flags } = require('process');
990+
991+
availableV8Flags.forEach((flag) => {
992+
// -r
993+
// --inspect-brk
994+
// --abort_on_uncaught_exception
995+
// ...
996+
});
997+
```
998+
999+
The methods `add()`, `clear()`, and `delete()` of `process.availableV8Flags` do
1000+
nothing.
1001+
9471002
## `process.channel`
9481003

9491004
<!-- YAML

lib/internal/bootstrap/node.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,27 @@ ObjectDefineProperty(process, 'allowedNodeEnvironmentFlags', {
289289
configurable: true
290290
});
291291

292+
// process.availableV8Flags
293+
ObjectDefineProperty(process, 'availableV8Flags', {
294+
get() {
295+
const flags = perThreadSetup.buildAvailableV8Flags();
296+
process.availableV8Flags = flags;
297+
return process.availableV8Flags;
298+
},
299+
// If the user tries to set this to another value, override
300+
// this completely to that value.
301+
set(value) {
302+
ObjectDefineProperty(this, 'availableV8Flags', {
303+
value,
304+
configurable: true,
305+
enumerable: true,
306+
writable: true
307+
});
308+
},
309+
enumerable: true,
310+
configurable: true
311+
});
312+
292313
// process.assert
293314
process.assert = deprecate(
294315
perThreadSetup.assert,

0 commit comments

Comments
 (0)