lib: fix coverage reporting
Taking the source code of a function and running it in another context does not play well with coverage instrumentation. For now, do the simple thing and just write the source code as a string literal. Fixes: https://github.com/nodejs/node/issues/19912 Refs: https://github.com/nodejs/node/pull/19524 PR-URL: https://github.com/nodejs/node/pull/20035 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
c974f1bbe8
commit
85e1819d8b
@ -390,17 +390,16 @@ function isInsideNodeModules() {
|
||||
// Use `runInNewContext()` to get something tamper-proof and
|
||||
// side-effect-free. Since this is currently only used for a deprecated API,
|
||||
// the perf implications should be okay.
|
||||
getStructuredStack = runInNewContext('(' + function() {
|
||||
getStructuredStack = runInNewContext(`(function() {
|
||||
Error.prepareStackTrace = function(err, trace) {
|
||||
err.stack = trace;
|
||||
};
|
||||
Error.stackTraceLimit = Infinity;
|
||||
|
||||
return function structuredStack() {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return new Error().stack;
|
||||
};
|
||||
} + ')()', {}, { filename: 'structured-stack' });
|
||||
})()`, {}, { filename: 'structured-stack' });
|
||||
}
|
||||
|
||||
const stack = getStructuredStack();
|
||||
|
Loading…
x
Reference in New Issue
Block a user