summaryrefslogtreecommitdiff
path: root/deps/v8/test/inspector/debugger/stepping-with-blackboxed-ranges.js
blob: 740634f68fe9372efd5a258b0c291eec3eb41dc5 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// 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.

InspectorTest.addScript(
`function blackboxedBoo()
{
    var a = 42;
    var b = foo();
    return a + b;
}
//# sourceURL=blackboxed-script.js`);

InspectorTest.addScript(
`function notBlackboxedFoo()
{
    var a = 42;
    var b = blackboxedBoo();
    return a + b;
}

function blackboxedFoo()
{
    var a = 42;
    var b = notBlackboxedFoo();
    return a + b;
}

function notBlackboxedBoo()
{
    var a = 42;
    var b = blackboxedFoo();
    return a + b;
}
//# sourceURL=mixed-source.js`);

InspectorTest.addScript(
`function testFunction()
{
    notBlackboxedBoo(); // for setup ranges and stepOut
    notBlackboxedBoo(); // for stepIn
}

function foo()
{
    debugger;
    return 239;
}`);

Protocol.Debugger.oncePaused().then(setBlackboxedScriptRanges);
Protocol.Debugger.enable().then(callTestFunction);

function callTestFunction(response)
{
  Protocol.Runtime.evaluate({ expression: "setTimeout(testFunction, 0);"});
}

function setBlackboxedScriptRanges(response)
{
  var callFrames = response.params.callFrames;
  printCallFrames(callFrames);
  Protocol.Debugger.setBlackboxedRanges({
    scriptId: callFrames[1].location.scriptId,
    positions: [ { lineNumber: 0, columnNumber: 0 } ] // blackbox ranges for blackboxed.js
  }).then(setIncorrectRanges.bind(null, callFrames[2].location.scriptId));
}

var incorrectPositions = [
    [ { lineNumber: 0, columnNumber: 0 }, { lineNumber: 0, columnNumber: 0 } ],
    [ { lineNumber: 0, columnNumber: 1 }, { lineNumber: 0, columnNumber: 0 } ],
    [ { lineNumber: 0, columnNumber: -1 } ],
];

function setIncorrectRanges(scriptId, response)
{
  if (response.error)
    InspectorTest.log(response.error.message);
  var positions = incorrectPositions.shift();
  if (!positions) {
    setMixedSourceRanges(scriptId);
    return;
  }
  InspectorTest.log("Try to set positions: " + JSON.stringify(positions));
  Protocol.Debugger.setBlackboxedRanges({
    scriptId: scriptId,
    positions: positions
  }).then(setIncorrectRanges.bind(null, scriptId));
}

function setMixedSourceRanges(scriptId)
{
  Protocol.Debugger.onPaused(runAction);
  Protocol.Debugger.setBlackboxedRanges({
    scriptId: scriptId,
    positions: [ { lineNumber: 8, columnNumber: 0 }, { lineNumber: 15, columnNumber: 0 } ] // blackbox ranges for mixed.js
  }).then(runAction);
}

var actions = [ "stepOut", "print", "stepOut", "print", "stepOut", "print",
    "stepInto", "print", "stepOver", "stepInto", "print", "stepOver", "stepInto", "print",
    "stepOver", "stepInto", "print" ];

function runAction(response)
{
  var action = actions.shift();
  if (!action)
    InspectorTest.completeTest();

  if (action === "print") {
    printCallFrames(response.params.callFrames);
    runAction({});
  } else {
    InspectorTest.log("action: " + action);
    Protocol.Debugger[action]();
  }
}

function printCallFrames(callFrames)
{
  var topCallFrame = callFrames[0];
  if (topCallFrame.functionName.startsWith("blackboxed"))
    InspectorTest.log("FAIL: blackboxed function in top call frame");
  for (var callFrame of callFrames)
    InspectorTest.log(callFrame.functionName + ": " + callFrame.location.lineNumber + ":" + callFrame.location.columnNumber);
  InspectorTest.log("");
}