[js] Test if setBreakpoint sets breakpoint on first breakable location
Bug: chromium:1105172 Change-Id: I1e683e5040501464ef6c7427d1e1f7923cd23831 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2304587 Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Kim-Anh Tran <kimanh@chromium.org> Cr-Commit-Position: refs/heads/master@{#68941}
This commit is contained in:
parent
0ef08848a7
commit
bad0135180
@ -0,0 +1,13 @@
|
|||||||
|
Tests if breakpoint set is first breakable location
|
||||||
|
Set breakpoint outside of any function: (0, 0).
|
||||||
|
Setting breakpoint for id: 3 at 0, 0.
|
||||||
|
No breakable location inside a function was found
|
||||||
|
Set breakpoint adds a breakpoint at (8, 1).
|
||||||
|
Set breakpoint at a breakable location: (4, 17).
|
||||||
|
Setting breakpoint for id: 3 at 4, 17.
|
||||||
|
Location match for (4, 17).
|
||||||
|
Initial location is expected to be breakable: true.
|
||||||
|
Set breakpoint at non-breakable location: (7, 0).
|
||||||
|
Setting breakpoint for id: 3 at 7, 0.
|
||||||
|
Location match for (7, 2).
|
||||||
|
Initial location is expected to be breakable: false.
|
@ -0,0 +1,111 @@
|
|||||||
|
// Copyright 2020 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 if breakpoint set is first breakable location');
|
||||||
|
|
||||||
|
const source = `
|
||||||
|
// Add a comment to test a break location that is
|
||||||
|
// outside of a function.
|
||||||
|
function foo() {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
function boo() {
|
||||||
|
return Promise.resolve().then(() => 42);
|
||||||
|
}`;
|
||||||
|
|
||||||
|
contextGroup.addScript(source);
|
||||||
|
Protocol.Debugger.enable();
|
||||||
|
|
||||||
|
runTest()
|
||||||
|
.catch(reason => InspectorTest.log(`Failed: ${reason}.`))
|
||||||
|
.then(InspectorTest.completeTest);
|
||||||
|
|
||||||
|
async function runTest() {
|
||||||
|
const {params: script} = await Protocol.Debugger.onceScriptParsed();
|
||||||
|
await checkSetBreakpointForScript(script.scriptId);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkSetBreakpointForScript(scriptId) {
|
||||||
|
// If we try to set a breakpoint that is outside of any function,
|
||||||
|
// setBreakpoint will find the first breakable location outside of any
|
||||||
|
// functions. If there is none, then it sets a breakpoint at the end of the
|
||||||
|
// script.
|
||||||
|
InspectorTest.log('Set breakpoint outside of any function: (0, 0).');
|
||||||
|
await checkSetBreakpointIsFirstBreakableLocation(scriptId, 0, 0, undefined);
|
||||||
|
|
||||||
|
// If we try to set a breakpoint that is inside of a function and
|
||||||
|
// the location is breakable, setBreakpoint is expected to add
|
||||||
|
// a breakpoint at that location.
|
||||||
|
InspectorTest.log('Set breakpoint at a breakable location: (4, 17).');
|
||||||
|
let breakable = true;
|
||||||
|
await checkSetBreakpointIsFirstBreakableLocation(scriptId, 4, 17, breakable);
|
||||||
|
|
||||||
|
// If we try to set a breakpoint that is inside of a function and
|
||||||
|
// the location is not breakable, setBreakpoint is expected to add
|
||||||
|
// a breakpoint at the next breakable location.
|
||||||
|
InspectorTest.log('Set breakpoint at non-breakable location: (7, 0).')
|
||||||
|
breakable = false;
|
||||||
|
await checkSetBreakpointIsFirstBreakableLocation(scriptId, 7, 0, breakable);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkSetBreakpointIsFirstBreakableLocation(
|
||||||
|
scriptId, lineNumber, columnNumber, breakable) {
|
||||||
|
const possibleLocationsMsg = await Protocol.Debugger.getPossibleBreakpoints({
|
||||||
|
start: {
|
||||||
|
lineNumber: lineNumber,
|
||||||
|
columnNumber: columnNumber,
|
||||||
|
scriptId: scriptId
|
||||||
|
},
|
||||||
|
end: {
|
||||||
|
lineNumber: lineNumber + 1,
|
||||||
|
columnNumber: columnNumber,
|
||||||
|
scriptId: scriptId
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const setLocationMsg =
|
||||||
|
await setBreakpoint(scriptId, lineNumber, columnNumber);
|
||||||
|
const setLocation = setLocationMsg.result.actualLocation;
|
||||||
|
|
||||||
|
if (possibleLocationsMsg.result.locations.length === 0) {
|
||||||
|
InspectorTest.log('No breakable location inside a function was found');
|
||||||
|
InspectorTest.log(`Set breakpoint adds a breakpoint at (${
|
||||||
|
setLocation.lineNumber}, ${setLocation.columnNumber}).`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const possibleLocations = possibleLocationsMsg.result.locations;
|
||||||
|
|
||||||
|
// Check that setting a breakpoint at a line actually
|
||||||
|
// sets the breakpoint at the first breakable location.
|
||||||
|
locationIsEqual(setLocation, possibleLocations[0]);
|
||||||
|
|
||||||
|
// Make sure that the selected locations for the test
|
||||||
|
// are breakable/non breakable as expected.
|
||||||
|
if (breakable ===
|
||||||
|
(setLocation.lineNumber === lineNumber &&
|
||||||
|
setLocation.columnNumber === columnNumber)) {
|
||||||
|
InspectorTest.log(
|
||||||
|
`Initial location is expected to be breakable: ${breakable}.`);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function locationIsEqual(locA, locB) {
|
||||||
|
if (locA.lineNumber === locB.lineNumber &&
|
||||||
|
locA.columnNumber === locB.columnNumber) {
|
||||||
|
InspectorTest.log(
|
||||||
|
`Location match for (${locA.lineNumber}, ${locA.columnNumber}).`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function setBreakpoint(id, lineNumber, columnNumber) {
|
||||||
|
InspectorTest.log(
|
||||||
|
`Setting breakpoint for id: ${id} at ${lineNumber}, ${columnNumber}.`);
|
||||||
|
const location = {
|
||||||
|
scriptId: id,
|
||||||
|
lineNumber: lineNumber,
|
||||||
|
columnNumber: columnNumber
|
||||||
|
};
|
||||||
|
const msg = await Protocol.Debugger.setBreakpoint({location: location});
|
||||||
|
return msg;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user