v8/test/inspector/debugger/terminate-execution-on-pause.js
Yang Guo 7e5cac2cf3 Make termination exception more consistent.
Termination exceptions tear down V8 to the bottom-most V8 call. If there is a
v8::TryCatch scope around that call, it returns true for HasTerminated() and
HasCaught(). However, Isolate::IsExecutionTerminating() returns false and we
can call into V8 from still inside the v8::TryCatch scope.

Changes that this patch introduces:
 - You need to leave the v8::TryCatch scope around the bottom-most call to
   reset the termination state, in order to resume.
 - Explicitly check for termination exception and reporting it through the
   DevTools protocol after Runtime.evaluate and Debugger.evaluateOnCallFrame.

Bug: v8:8455
Change-Id: I1f36f7a365985469813c2619bf16f18ee69aa4b8
Reviewed-on: https://chromium-review.googlesource.com/c/1337582
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Commit-Queue: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57963}
2018-11-30 11:33:07 +00:00

85 lines
2.6 KiB
JavaScript

// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} =
InspectorTest.start('Tests Runtime.terminateExecution on pause');
Protocol.Runtime.enable();
Protocol.Runtime.onConsoleAPICalled(
message => InspectorTest.logMessage(message.params.args[0]));
Protocol.Debugger.enable();
InspectorTest.runAsyncTestSuite([
async function testTerminateOnDebugger() {
Protocol.Runtime.evaluate({expression: `
function callback() {
debugger;
console.log(42);
setTimeout(callback, 0);
}
callback();
//# sourceURL=test.js`});
await Protocol.Debugger.oncePaused();
const terminated = Protocol.Runtime.terminateExecution();
await Protocol.Debugger.resume();
await terminated;
},
async function testTerminateAtBreakpoint() {
Protocol.Debugger.setBreakpointByUrl({url: 'test.js', lineNumber: 2});
const result = Protocol.Runtime.evaluate({expression: `
function callback() {
console.log(42);
setTimeout(callback, 0);
}
callback();
//# sourceURL=test.js`}).then(InspectorTest.logMessage);
await Protocol.Debugger.oncePaused();
const terminated = Protocol.Runtime.terminateExecution();
await Protocol.Debugger.resume();
await terminated;
await result;
},
async function testTerminateRuntimeEvaluate() {
Protocol.Runtime.evaluate({expression: `
function callback() {
debugger;
console.log(42);
debugger;
}
callback();
//# sourceURL=test.js`});
await Protocol.Debugger.oncePaused();
await Promise.all([
Protocol.Runtime.terminateExecution().then(InspectorTest.logMessage),
Protocol.Runtime.evaluate({expression: 'console.log(42)'}).then(InspectorTest.logMessage)
]);
await Protocol.Debugger.resume();
await Protocol.Debugger.oncePaused();
await Protocol.Debugger.resume();
},
async function testTerminateRuntimeEvaluateOnCallFrame() {
Protocol.Runtime.evaluate({expression: `
function callback() {
let a = 1;
debugger;
console.log(43);
}
callback();
//# sourceURL=test.js`});
let message = await Protocol.Debugger.oncePaused();
let topFrameId = message.params.callFrames[0].callFrameId;
await Protocol.Debugger.evaluateOnCallFrame({callFrameId: topFrameId, expression: "a"})
.then(InspectorTest.logMessage)
await Promise.all([
Protocol.Runtime.terminateExecution().then(InspectorTest.logMessage),
Protocol.Debugger.evaluateOnCallFrame({callFrameId: topFrameId, expression: "a"})
.then(InspectorTest.logMessage)
]);
await Protocol.Debugger.resume();
},
]);