v8/test/inspector/debugger/set-breakpoint.js
Alexey Kozyatinskiy c31bb8a4e4 [debug] retire ScriptWrapper
- rewritten couple tests,
- migrated JSMessageObject to real Script instead of wrapper,
- removed wrapper.

R=yangguo@chromium.org
TBR=ulan@chromium.org

Bug: v8:5530
Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ia95492344c7b5978a940e2ab007b389384537148
Reviewed-on: https://chromium-review.googlesource.com/1112851
Reviewed-by: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54274}
2018-07-05 21:33:03 +00:00

125 lines
4.3 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('Check different set breakpoint cases.');
contextGroup.addScript(
`function f() {
a=1;
};
function g() {
// Comment.
f();
}
eval('function h(){}');
eval('function sourceUrlFunc() { a = 2; }\\n//# sourceURL=sourceUrlScript');`);
(async function test() {
session.setupScriptMap();
Protocol.Debugger.enable();
{
InspectorTest.log('Set breakpoint at function g..');
const location = await functionLocation('g');
const {result} = await Protocol.Debugger.setBreakpoint({location});
InspectorTest.log('Breakpoint set at:');
await session.logSourceLocation(result.actualLocation);
InspectorTest.log('Call g..');
Protocol.Runtime.evaluate({expression: 'g()'});
const {params:{
callFrames:[topFrame],
hitBreakpoints
}} = await Protocol.Debugger.oncePaused();
InspectorTest.log('Breakpoint hit at:');
await session.logSourceLocation(topFrame.location);
const hitBreakpoint = hitBreakpoints[0] === result.breakpointId;
InspectorTest.log(`hitBreakpoints contains breakpoint: ${hitBreakpoint}\n`);
}
{
InspectorTest.log('Set breakpoint at function f when we on pause..');
const {result} = await Protocol.Debugger.setBreakpoint({
location: await functionLocation('f')
});
InspectorTest.log('Breakpoint set at:');
await session.logSourceLocation(result.actualLocation);
InspectorTest.log('Resume..');
Protocol.Debugger.resume();
const {params:{
callFrames:[topFrame],
hitBreakpoints
}} = await Protocol.Debugger.oncePaused();
InspectorTest.log('Breakpoint hit at:');
await session.logSourceLocation(topFrame.location);
const hitBreakpoint = hitBreakpoints[0] === result.breakpointId;
InspectorTest.log(`hitBreakpoints contains breakpoint: ${hitBreakpoint}\n`);
await Protocol.Debugger.resume();
}
{
InspectorTest.log('Set breakpoint by url at sourceUrlFunc..');
const {lineNumber, columnNumber} = await functionLocation('sourceUrlFunc');
const {result} = await Protocol.Debugger.setBreakpointByUrl({
url: 'sourceUrlScript',
lineNumber,
columnNumber
});
InspectorTest.log('Breakpoint set at:');
await session.logSourceLocation(result.locations[0]);
InspectorTest.log('Call sourceUrlFunc..');
Protocol.Runtime.evaluate({expression: 'sourceUrlFunc()'});
const {params:{
callFrames:[topFrame],
hitBreakpoints
}} = await Protocol.Debugger.oncePaused();
InspectorTest.log('Breakpoint hit at:');
await session.logSourceLocation(topFrame.location);
const hitBreakpoint = hitBreakpoints[0] === result.breakpointId;
InspectorTest.log(`hitBreakpoints contains breakpoint: ${hitBreakpoint}\n`);
await Protocol.Debugger.resume();
}
{
InspectorTest.log(
'Set breakpoint at empty line by url in top level function..');
const {result:{breakpointId}} = await Protocol.Debugger.setBreakpointByUrl({
url: 'test-script',
lineNumber: 4,
columnNumber: 0
});
Protocol.Runtime.evaluate({
expression: `//# sourceURL=test-script\nfunction i1(){};\n\n\n\n\nfunction i2(){}\n// last line`
});
const [{
params:{location}
}, {
params:{
callFrames:[topFrame],
hitBreakpoints
}
}] = await Promise.all([
Protocol.Debugger.onceBreakpointResolved(),
Protocol.Debugger.oncePaused()]);
InspectorTest.log('Breakpoint resolved at:');
await session.logSourceLocation(location);
InspectorTest.log('Breakpoint hit at:');
await session.logSourceLocation(topFrame.location);
const hitBreakpoint = hitBreakpoints[0] === breakpointId;
InspectorTest.log(`hitBreakpoints contains breakpoint: ${hitBreakpoint}\n`);
}
await Protocol.Debugger.disable();
InspectorTest.completeTest();
})();
async function functionLocation(name) {
const {result:{result}} = await Protocol.Runtime.evaluate({expression: name});
const {result:{internalProperties}} = await Protocol.Runtime.getProperties({
objectId: result.objectId
});
const {value:{value}} = internalProperties.find(
prop => prop.name === '[[FunctionLocation]]');
return value;
}