process.allowedNodeEnvironmentFlags
process.allowedNodeEnvironmentFlags 属性是 NODE_OPTIONS 环境变量中允许的特殊的只读 Set 标志。
process.allowedNodeEnvironmentFlags 继承了 Set,但覆盖了 Set.prototype.has 以识别几种不同的可能标志表示。
在以下情况下,process.allowedNodeEnvironmentFlags.has() 将返回 true:
- 标志可以省略前导单(
-)或双(--)破折号;例如,inspect-brk代表--inspect-brk,或r代表-r。 - 传给 V8 的标志(如
--v8-options中所列)可能会替换一个或多个_非前导_破折号作为下划线,反之亦然;例如,--perf_basic_prof、--perf-basic-prof、--perf_basic-prof等。 - 标志可能包含一个或多个等于 (
=) 字符;在第一个等号之后并包括在内的所有字符都将被忽略;例如,--stack-trace-limit=100。 - 标志_必须_在
NODE_OPTIONS中是允许的。
在 process.allowedNodeEnvironmentFlags 上迭代时,标志只会出现_一次_;每个都以一个或多个破折号开头。
传给 V8 的标志将包含下划线而不是非前导破折号:
import { allowedNodeEnvironmentFlags } from 'node:process';
allowedNodeEnvironmentFlags.forEach((flag) => {
// -r
// --inspect-brk
// --abort_on_uncaught_exception
// ...
});const { allowedNodeEnvironmentFlags } = require('node:process');
allowedNodeEnvironmentFlags.forEach((flag) => {
// -r
// --inspect-brk
// --abort_on_uncaught_exception
// ...
});process.allowedNodeEnvironmentFlags 的方法 add()、clear() 和 delete() 什么都不做,会静默失败。
如果 Node.js 编译时_没有_ NODE_OPTIONS 支持(显示在 process.config 中),那么 process.allowedNodeEnvironmentFlags 将包含_本来_允许的内容。
The process.allowedNodeEnvironmentFlags property is a special,
read-only Set of flags allowable within the NODE_OPTIONS
environment variable.
process.allowedNodeEnvironmentFlags extends Set, but overrides
Set.prototype.has to recognize several different possible flag
representations. process.allowedNodeEnvironmentFlags.has() will
return true in the following cases:
- Flags may omit leading single (
-) or double (--) dashes; e.g.,inspect-brkfor--inspect-brk, orrfor-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; e.g.,--perf_basic_prof,--perf-basic-prof,--perf_basic-prof, etc. - Flags may contain one or more equals (
=) characters; all characters after and including the first equals will be ignored; e.g.,--stack-trace-limit=100. - Flags must be allowable within
NODE_OPTIONS.
When iterating over process.allowedNodeEnvironmentFlags, flags will
appear only once; each will begin with one or more dashes. Flags
passed through to V8 will contain underscores instead of non-leading
dashes:
import { allowedNodeEnvironmentFlags } from 'node:process';
allowedNodeEnvironmentFlags.forEach((flag) => {
// -r
// --inspect-brk
// --abort_on_uncaught_exception
// ...
});const { allowedNodeEnvironmentFlags } = require('node:process');
allowedNodeEnvironmentFlags.forEach((flag) => {
// -r
// --inspect-brk
// --abort_on_uncaught_exception
// ...
});The methods add(), clear(), and delete() of
process.allowedNodeEnvironmentFlags do nothing, and will fail
silently.
If Node.js was compiled without NODE_OPTIONS support (shown in
process.config), process.allowedNodeEnvironmentFlags will
contain what would have been allowable.