summaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/debugger/get-possible-breakpoints-master.js
blob: 07f90e7a251b7350bbaff063538c2d8246da486e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2017 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.

// Flags: --turbo

let {session, contextGroup, Protocol} = InspectorTest.start('Checks Debugger.getPossibleBreakpoints');

var source = utils.read('test/inspector/debugger/resources/break-locations.js');
contextGroup.addScript(source);

Protocol.Debugger.onceScriptParsed()
  .then(message => Protocol.Debugger.getPossibleBreakpoints({ start: { lineNumber: 0, columnNumber : 0, scriptId: message.params.scriptId }}))
  .then(dumpAllLocations)
  .then(InspectorTest.completeTest);
Protocol.Debugger.enable();

function dumpAllLocations(message) {
  if (message.error) {
    InspectorTest.logMessage(message);
    return;
  }
  var lines = source.split('\n');
  var locations = message.result.locations.sort((loc1, loc2) => {
    if (loc2.lineNumber !== loc1.lineNumber) return loc2.lineNumber - loc1.lineNumber;
    return loc2.columnNumber - loc1.columnNumber;
  });
  for (var location of locations) {
    var line = lines[location.lineNumber];
    line = line.slice(0, location.columnNumber) + locationMark(location.type) + line.slice(location.columnNumber);
    lines[location.lineNumber] = line;
  }
  lines = lines.filter(line => line.indexOf('//# sourceURL=') === -1);
  InspectorTest.log(lines.join('\n'));
  return message;
}

function locationMark(type) {
  if (type === 'return') return '|R|';
  if (type === 'call') return '|C|';
  if (type === 'debuggerStatement') return '|D|';
  return '|_|';
}