get-possible-breakpoints-restrict-to-function.js 2.99 KB
Newer Older
1 2 3 4
// Copyright 2016 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.

5
let {session, contextGroup, Protocol} = InspectorTest.start('Checks Debugger.getPossibleBreakpoints with ignoreNestedFunctions');
6 7 8 9 10 11 12 13 14 15 16 17 18 19

var source = `
function test() {
  Array.from([1,2]).map(() => 1).filter(() => true);
  function nested1() {
    Array.from([1,2]).map(() => 1).filter(() => true);
  }
  function nested2() {
    Array.from([1,2]).map(() => 1).filter(() => true);
  }
  nested1();
  nested2();
}
//# sourceURL=test.js`;
20
contextGroup.addScript(source);
21 22 23 24 25 26 27

var scriptId;
Protocol.Debugger.onceScriptParsed().then(message => {
  if (message.params.url === 'test.js')
    scriptId = message.params.scriptId;
}).then(() => InspectorTest.runTestSuite(tests));

28
session.setupScriptMap();
29 30 31 32
Protocol.Debugger.onPaused(message => {
  session.logSourceLocation(message.params.callFrames[0].location);
  Protocol.Debugger.resume();
});
33 34 35 36 37

Protocol.Debugger.enable();
var tests = [
  function testWholeFunction(next) {
    Protocol.Debugger.getPossibleBreakpoints({ start: location(1, 18), ignoreNestedFunctions: false })
38
      .then(message => session.logBreakLocations(message.result.locations))
39 40 41 42 43
      .then(next);
  },

  function testWholeFunctionWithoutNested(next) {
    Protocol.Debugger.getPossibleBreakpoints({ start: location(1, 18), ignoreNestedFunctions: true })
44
      .then(message => session.logBreakLocations(message.result.locations))
45 46 47 48 49
      .then(next);
  },

  function testPartOfFunctionWithoutNested(next) {
    Protocol.Debugger.getPossibleBreakpoints({ start: location(1, 18), end: location(2, 18), ignoreNestedFunctions: true })
50
      .then(message => session.logBreakLocations(message.result.locations))
51 52 53 54 55
      .then(next);
  },

  function testNestedFunction(next) {
    Protocol.Debugger.getPossibleBreakpoints({ start: location(4, 0), ignoreNestedFunctions: true })
56
      .then(message => session.logBreakLocations(message.result.locations))
57 58 59 60 61 62 63 64 65 66 67
      .then(setAllBreakpoints)
      .then(() => InspectorTest.log('Run test() to check breakpoints..'))
      .then(() => Protocol.Runtime.evaluate({ expression: 'test()' }))
      .then(next);
  }
];

function location(lineNumber, columnNumber) {
  return { lineNumber: lineNumber, columnNumber: columnNumber, scriptId: scriptId };
}

68
function setAllBreakpoints(locations) {
69
  var promises = [];
70
  for (var location of locations)
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
    promises.push(Protocol.Debugger.setBreakpoint({ location: location }).then(checkBreakpoint));
  return Promise.all(promises);
}

function checkBreakpoint(message) {
  if (message.error) {
    InspectorTest.log('FAIL: error in setBreakpoint');
    InspectorTest.logMessage(message);
    return;
  }
  var id_data = message.result.breakpointId.split(':');
  if (parseInt(id_data[1]) !== message.result.actualLocation.lineNumber || parseInt(id_data[2]) !== message.result.actualLocation.columnNumber) {
    InspectorTest.log('FAIL: possible breakpoint was resolved in another location');
  }
}