-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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: #17740 Signed-off-by: Christopher Hiller <boneskull@boneskull.com> PR-URL: #19335 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Sam Ruby <rubys@intertwingly.net> Reviewed-By: Anna Henningsen <anna@addaleax.net>
- 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