forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
process: add allowedNodeEnvironmentFlags property
`process.allowedNodeEnvironmentFlags` provides an API to validate and list flags as specified in `NODE_OPTIONS` from user code. Refs: nodejs#17740 Signed-off-by: Christopher Hiller <[email protected]> PR-URL: nodejs#19335 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Sam Ruby <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
- Loading branch information
Showing
7 changed files
with
299 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
require('../common'); | ||
|
||
// assert legit flags are allowed, and bogus flags are disallowed | ||
{ | ||
const goodFlags = [ | ||
'--inspect-brk', | ||
'inspect-brk', | ||
'--perf_basic_prof', | ||
'--perf-basic-prof', | ||
'perf-basic-prof', | ||
'--perf_basic-prof', | ||
'perf_basic-prof', | ||
'perf_basic_prof', | ||
'-r', | ||
'r', | ||
'--stack-trace-limit=100', | ||
'--stack-trace-limit=-=xX_nodejs_Xx=-' | ||
]; | ||
|
||
const badFlags = [ | ||
'--inspect_brk', | ||
'INSPECT-BRK', | ||
'--INSPECT-BRK', | ||
'--r', | ||
'-R', | ||
'---inspect-brk', | ||
'--cheeseburgers' | ||
]; | ||
|
||
goodFlags.forEach((flag) => { | ||
assert.strictEqual( | ||
process.allowedNodeEnvironmentFlags.has(flag), | ||
true, | ||
`flag should be in set: ${flag}` | ||
); | ||
}); | ||
|
||
badFlags.forEach((flag) => { | ||
assert.strictEqual( | ||
process.allowedNodeEnvironmentFlags.has(flag), | ||
false, | ||
`flag should not be in set: ${flag}` | ||
); | ||
}); | ||
} | ||
|
||
// assert all "canonical" flags begin with dash(es) | ||
{ | ||
process.allowedNodeEnvironmentFlags.forEach((flag) => { | ||
assert.strictEqual(/^--?[a-z8_-]+$/.test(flag), true); | ||
}); | ||
} | ||
|
||
// assert immutability of process.allowedNodeEnvironmentFlags | ||
{ | ||
assert.strictEqual(Object.isFrozen(process.allowedNodeEnvironmentFlags), | ||
true); | ||
|
||
process.allowedNodeEnvironmentFlags.add('foo'); | ||
assert.strictEqual(process.allowedNodeEnvironmentFlags.has('foo'), false); | ||
process.allowedNodeEnvironmentFlags.forEach((flag) => { | ||
assert.strictEqual(flag === 'foo', false); | ||
}); | ||
|
||
process.allowedNodeEnvironmentFlags.clear(); | ||
assert.strictEqual(process.allowedNodeEnvironmentFlags.size > 0, true); | ||
|
||
const size = process.allowedNodeEnvironmentFlags.size; | ||
process.allowedNodeEnvironmentFlags.delete('-r'); | ||
assert.strictEqual(process.allowedNodeEnvironmentFlags.size, size); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters