bootstrap: add exception handling for profiler bootstrap

Add exception handling for the case when profile is
not bootstrapped when coverage is enabled.

Fixes: https://github.com/nodejs/node/issues/29542

PR-URL: https://github.com/nodejs/node/pull/29552
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Shobhit Chittora 2019-09-14 05:39:46 +05:30 committed by Anna Henningsen
parent 4ef3ccbbe0
commit fdd5d4ad4a
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
3 changed files with 41 additions and 2 deletions

View File

@ -120,8 +120,16 @@ function setupCoverageHooks(dir) {
const { resolve } = require('path');
const coverageDirectory = resolve(cwd, dir);
const { sourceMapCacheToObject } = require('internal/source_map');
internalBinding('profiler').setCoverageDirectory(coverageDirectory);
internalBinding('profiler').setSourceMapCacheGetter(sourceMapCacheToObject);
if (process.features.inspector) {
internalBinding('profiler').setCoverageDirectory(coverageDirectory);
internalBinding('profiler').setSourceMapCacheGetter(sourceMapCacheToObject);
} else {
process.emitWarning('The inspector is disabled, ' +
'coverage could not be collected',
'Warning');
return '';
}
return coverageDirectory;
}

View File

@ -651,6 +651,12 @@ function skipIfInspectorDisabled() {
}
}
function skipIfInspectorEnabled() {
if (process.features.inspector) {
skip('V8 inspector is enabled');
}
}
function skipIfReportDisabled() {
if (!process.config.variables.node_report) {
skip('Diagnostic reporting is disabled');
@ -783,6 +789,7 @@ module.exports = {
skipIf32Bits,
skipIfEslintMissing,
skipIfInspectorDisabled,
skipIfInspectorEnabled,
skipIfReportDisabled,
skipIfWorker,

View File

@ -0,0 +1,24 @@
'use strict';
const common = require('../common');
common.skipIfInspectorEnabled();
const fixtures = require('../common/fixtures');
const assert = require('assert');
const { spawnSync } = require('child_process');
const env = { ...process.env, NODE_V8_COVERAGE: '/foo/bar' };
const childPath = fixtures.path('v8-coverage/subprocess');
const { status, stderr } = spawnSync(
process.execPath,
[childPath],
{ env }
);
const warningMessage = 'The inspector is disabled, ' +
'coverage could not be collected';
assert.strictEqual(status, 0);
assert.strictEqual(
stderr.toString().includes(`Warning: ${warningMessage}`),
true
);