From 6a696d15ff3830318e5ded688eb4e728eeccd14c Mon Sep 17 00:00:00 2001 From: Nikolai Vavilov Date: Sun, 4 Jun 2017 20:15:27 +0300 Subject: [PATCH] inspector: fix crash on exception Fixes: https://github.com/nodejs/node/issues/13438 PR-URL: https://github.com/nodejs/node/pull/13455 Reviewed-By: Anna Henningsen Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig Reviewed-By: Timothy Gu --- src/inspector_agent.cc | 4 +- test/inspector/test-inspector-exception.js | 64 ++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 test/inspector/test-inspector-exception.js diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index 948719ed702c5a..f1acfa64b4ad13 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -371,7 +371,9 @@ void CallAndPauseOnStart( v8::MaybeLocal retval = args[0].As()->Call(env->context(), args[1], call_args.size(), call_args.data()); - args.GetReturnValue().Set(retval.ToLocalChecked()); + if (!retval.IsEmpty()) { + args.GetReturnValue().Set(retval.ToLocalChecked()); + } } // Used in NodeInspectorClient::currentTimeMS() below. diff --git a/test/inspector/test-inspector-exception.js b/test/inspector/test-inspector-exception.js new file mode 100644 index 00000000000000..3f470c94c18f1d --- /dev/null +++ b/test/inspector/test-inspector-exception.js @@ -0,0 +1,64 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const assert = require('assert'); +const helper = require('./inspector-helper.js'); +const path = require('path'); + +const script = path.join(common.fixturesDir, 'throws_error.js'); + + +function setupExpectBreakOnLine(line, url, session) { + return function(message) { + if ('Debugger.paused' === message['method']) { + const callFrame = message['params']['callFrames'][0]; + const location = callFrame['location']; + assert.strictEqual(url, session.scriptUrlForId(location['scriptId'])); + assert.strictEqual(line, location['lineNumber']); + return true; + } + }; +} + +function testBreakpointOnStart(session) { + const commands = [ + { 'method': 'Runtime.enable' }, + { 'method': 'Debugger.enable' }, + { 'method': 'Debugger.setPauseOnExceptions', + 'params': {'state': 'none'} }, + { 'method': 'Debugger.setAsyncCallStackDepth', + 'params': {'maxDepth': 0} }, + { 'method': 'Profiler.enable' }, + { 'method': 'Profiler.setSamplingInterval', + 'params': {'interval': 100} }, + { 'method': 'Debugger.setBlackboxPatterns', + 'params': {'patterns': []} }, + { 'method': 'Runtime.runIfWaitingForDebugger' } + ]; + + session + .sendInspectorCommands(commands) + .expectMessages(setupExpectBreakOnLine(0, script, session)); +} + +function testWaitsForFrontendDisconnect(session, harness) { + console.log('[test]', 'Verify node waits for the frontend to disconnect'); + session.sendInspectorCommands({ 'method': 'Debugger.resume'}) + .expectStderrOutput('Waiting for the debugger to disconnect...') + .disconnect(true); +} + +function runTests(harness) { + harness + .runFrontendSession([ + testBreakpointOnStart, + testWaitsForFrontendDisconnect + ]).expectShutDown(1); +} + +helper.startNodeForInspectorTest(runTests, + undefined, + undefined, + script);