-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Es6 module global leakage test #16341
Closed
tinybeachthor
wants to merge
6
commits into
nodejs:master
from
tinybeachthor:es6-module-global-leakage-test
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3fff72f
created testing es6 module for global leakage tests
tinybeachthor 01c7033
fixed a couple basic errors (vars -> lets, ...)
tinybeachthor fd0a410
Merge branch 'es6-module-global-leakage-test' into HEAD
tinybeachthor 8caaded
added globals leakage detection to es module tests
tinybeachthor 246a2e0
reversed whitespace change
tinybeachthor 5d7d9ca
whitespace change reversed
tinybeachthor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Flags: --experimental-modules | ||
/* eslint-disable required-modules */ | ||
|
||
import assert from 'assert'; | ||
|
||
let knownGlobals = [ | ||
Buffer, | ||
clearImmediate, | ||
clearInterval, | ||
clearTimeout, | ||
console, | ||
constructor, // Enumerable in V8 3.21. | ||
global, | ||
process, | ||
setImmediate, | ||
setInterval, | ||
setTimeout | ||
]; | ||
|
||
if (process.env.NODE_TEST_KNOWN_GLOBALS) { | ||
const knownFromEnv = process.env.NODE_TEST_KNOWN_GLOBALS.split(','); | ||
allowGlobals(...knownFromEnv); | ||
} | ||
|
||
export function allowGlobals(...whitelist) { | ||
knownGlobals = knownGlobals.concat(whitelist); | ||
} | ||
|
||
export function leakedGlobals() { | ||
//add possible expected globals | ||
if (global.gc) { | ||
knownGlobals.push(global.gc); | ||
} | ||
|
||
if (global.DTRACE_HTTP_SERVER_RESPONSE) { | ||
knownGlobals.push(DTRACE_HTTP_SERVER_RESPONSE); | ||
knownGlobals.push(DTRACE_HTTP_SERVER_REQUEST); | ||
knownGlobals.push(DTRACE_HTTP_CLIENT_RESPONSE); | ||
knownGlobals.push(DTRACE_HTTP_CLIENT_REQUEST); | ||
knownGlobals.push(DTRACE_NET_STREAM_END); | ||
knownGlobals.push(DTRACE_NET_SERVER_CONNECTION); | ||
} | ||
|
||
if (global.COUNTER_NET_SERVER_CONNECTION) { | ||
knownGlobals.push(COUNTER_NET_SERVER_CONNECTION); | ||
knownGlobals.push(COUNTER_NET_SERVER_CONNECTION_CLOSE); | ||
knownGlobals.push(COUNTER_HTTP_SERVER_REQUEST); | ||
knownGlobals.push(COUNTER_HTTP_SERVER_RESPONSE); | ||
knownGlobals.push(COUNTER_HTTP_CLIENT_REQUEST); | ||
knownGlobals.push(COUNTER_HTTP_CLIENT_RESPONSE); | ||
} | ||
|
||
if (global.LTTNG_HTTP_SERVER_RESPONSE) { | ||
knownGlobals.push(LTTNG_HTTP_SERVER_RESPONSE); | ||
knownGlobals.push(LTTNG_HTTP_SERVER_REQUEST); | ||
knownGlobals.push(LTTNG_HTTP_CLIENT_RESPONSE); | ||
knownGlobals.push(LTTNG_HTTP_CLIENT_REQUEST); | ||
knownGlobals.push(LTTNG_NET_STREAM_END); | ||
knownGlobals.push(LTTNG_NET_SERVER_CONNECTION); | ||
} | ||
|
||
if (global.ArrayBuffer) { | ||
knownGlobals.push(ArrayBuffer); | ||
knownGlobals.push(Int8Array); | ||
knownGlobals.push(Uint8Array); | ||
knownGlobals.push(Uint8ClampedArray); | ||
knownGlobals.push(Int16Array); | ||
knownGlobals.push(Uint16Array); | ||
knownGlobals.push(Int32Array); | ||
knownGlobals.push(Uint32Array); | ||
knownGlobals.push(Float32Array); | ||
knownGlobals.push(Float64Array); | ||
knownGlobals.push(DataView); | ||
} | ||
|
||
// Harmony features. | ||
if (global.Proxy) { | ||
knownGlobals.push(Proxy); | ||
} | ||
|
||
if (global.Symbol) { | ||
knownGlobals.push(Symbol); | ||
} | ||
|
||
const leaked = []; | ||
|
||
for (const val in global) { | ||
if (!knownGlobals.includes(global[val])) { | ||
leaked.push(val); | ||
} | ||
} | ||
|
||
if (global.__coverage__) { | ||
return leaked.filter((varname) => !/^(?:cov_|__cov)/.test(varname)); | ||
} else { | ||
return leaked; | ||
} | ||
} | ||
|
||
// Turn this off if the test should not check for global leaks. | ||
export let globalCheck = true; // eslint-disable-line | ||
|
||
process.on('exit', function() { | ||
if (!globalCheck) return; | ||
const leaked = leakedGlobals(); | ||
if (leaked.length > 0) { | ||
assert.fail(`Unexpected global(s) found: ${leaked.join(', ')}`); | ||
} | ||
}); |
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 |
---|---|---|
|
@@ -3,5 +3,6 @@ import '../common'; | |
import '../fixtures/es-module-require-cache/preload.js'; | ||
import '../fixtures/es-module-require-cache/counter.js'; | ||
import assert from 'assert'; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Unrelated whitespace change? |
||
assert.strictEqual(global.counter, 1); | ||
delete global.counter; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please remove the whitespace changes? :D