step-over-caught-exception.js 2.22 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 6 7
let {session, contextGroup, Protocol} = InspectorTest.start('Tests that stepping over caught exception will pause when asked for');

contextGroup.addScript(
8 9 10 11 12 13 14 15 16 17 18 19 20 21
`function testFunction()
{
  function foo()
  {
    try {
      throw new Error();
    } catch (e) {
    }
  }
  debugger;
  foo();
  console.log("completed");
}`);

22 23
Protocol.Debugger.enable();
Protocol.Runtime.enable();
24 25 26 27
step1();

function step1()
{
28
  Protocol.Runtime.evaluate({ "expression": "setTimeout(testFunction, 0);"});
29
  var commands = [ "Print", "stepOver", "stepOver", "Print", "resume" ];
30
  Protocol.Debugger.onPaused(function(messageObject)
31 32 33 34 35 36 37 38 39
  {
    var command = commands.shift();
    if (command === "Print") {
      var callFrames = messageObject.params.callFrames;
      for (var callFrame of callFrames)
        InspectorTest.log(callFrame.functionName + ":" + callFrame.location.lineNumber);
      command = commands.shift();
    }
    if (command)
40 41
      Protocol.Debugger[command]();
  });
42

43
  Protocol.Runtime.onConsoleAPICalled(function(messageObject)
44 45 46 47 48 49
  {
    if (messageObject.params.args[0].value === "completed") {
      if (commands.length)
        InspectorTest.log("[FAIL]: execution was resumed too earlier.")
      step2();
    }
50
  });
51 52 53 54
}

function step2()
{
55
  Protocol.Runtime.evaluate({ "expression": "setTimeout(testFunction, 0);"});
56
  var commands = [ "Print", "stepOver", "stepInto", "stepOver", "stepOver", "Print", "resume" ];
57
  Protocol.Debugger.onPaused(function(messageObject)
58 59 60 61 62 63 64 65 66
  {
    var command = commands.shift();
    if (command === "Print") {
      var callFrames = messageObject.params.callFrames;
      for (var callFrame of callFrames)
        InspectorTest.log(callFrame.functionName + ":" + callFrame.location.lineNumber);
      command = commands.shift();
    }
    if (command)
67 68
      Protocol.Debugger[command]();
  });
69

70
  Protocol.Runtime.onConsoleAPICalled(function(messageObject)
71 72 73 74 75 76
  {
    if (messageObject.params.args[0].value === "completed") {
      if (commands.length)
        InspectorTest.log("[FAIL]: execution was resumed too earlier.")
      InspectorTest.completeTest();
    }
77
  });
78
}