From 5fcf10851999aaef849e5db651886f2ac13cae96 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 14 Apr 2018 19:01:37 +0200 Subject: [PATCH 1/2] 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 --- 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..486f42fe0b8e83 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(); From 27d4a91d4ab848a3af0d587e44b7a1a4e3e0e456 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 15 Apr 2018 09:58:53 +0200 Subject: [PATCH 2/2] fixup! lib: fix coverage reporting --- lib/internal/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/util.js b/lib/internal/util.js index 486f42fe0b8e83..953b1ce0f577e5 100644 --- a/lib/internal/util.js +++ b/lib/internal/util.js @@ -390,7 +390,7 @@ 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; };