From 85e1819d8bc8fad398ac0674064a19a691ea0fd7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 14 Apr 2018 19:01:37 +0200 Subject: [PATCH] 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 Reviewed-By: Trivikram Kamat Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater --- lib/internal/util.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/internal/util.js b/lib/internal/util.js index b92e4c5b588479..953b1ce0f577e5 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -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();