From a6397d8582cafa4caf42462f25735c7f65eff73e Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 21 Apr 2020 10:46:29 +0800 Subject: [PATCH] inspector: only write coverage in fully bootstrapped Environments The NODE_V8_COVERAGE folder and the source map computation are setup during pre-execution since they rely on environment variables as well as JS states. Therefore, we need to give up serialization of JS coverage profiles for Environments that have not go through pre-execution. Currently this is only possible for Environments created using the embedder API CreateEnvironment(). As a result we won't have JS coverage data for most cctests, but if that proves to be necessary we could just run lib/internal/main/environment.js for these Environments created for cctests. Fixes: https://github.com/nodejs/node/issues/32912 Refs: https://github.com/nodejs/node/commit/65e18a8e9f912dfa04a804124b6a19514bb45165 Refs: https://github.com/nodejs/node/commit/5bf43729a403b992cc90b5cdbbaaf505769d1107 https://github.com/nodejs/node/commit/8aa7ef7840ef5f7161f3195e51a3fa6783290160 PR-URL: https://github.com/nodejs/node/pull/32960 Refs: https://github.com/nodejs/node/commit/8aa7ef7840ef5f7161f3195e51a3fa6783290160 Reviewed-By: Richard Lau Reviewed-By: David Carlier Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig Reviewed-By: Franziska Hinkelmann Reviewed-By: Anna Henningsen --- src/inspector_profiler.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/inspector_profiler.cc b/src/inspector_profiler.cc index cc4c3091757683..03cf2f6e5ca76b 100644 --- a/src/inspector_profiler.cc +++ b/src/inspector_profiler.cc @@ -209,6 +209,16 @@ void V8CoverageConnection::WriteProfile(Local message) { HandleScope handle_scope(isolate); Context::Scope context_scope(context); + // This is only set up during pre-execution (when the environment variables + // becomes available in the JS land). If it's empty, we don't have coverage + // directory path (which is resolved in JS land at the moment) either, so + // the best we could to is to just discard the profile and do nothing. + // This should only happen in half-baked Environments created using the + // embedder API. + if (env_->source_map_cache_getter().IsEmpty()) { + return; + } + // Get message.result from the response. Local result; if (!ParseProfile(env_, message, type()).ToLocal(&result)) {