summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/inspector-protocol/debugger/debugger-pause-in-tight-loop.html
blob: a420eb16e2199c094e649198a93f33a5e2540c04 (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
<html>
<head>
<script type="text/javascript" src="../../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
<script>

function testFunction()
{
    setTimeout(hotFunction, 0);
}

var terminated = false;
function hotFunction() {
  evaluateInFrontend("InspectorTest.didFireTimer()");

  var message_id = 1;
  var ts = Date.now();
  while (!terminated) {
      // Without this try/catch v8 will optimize the function and break will not work.
      try {
          if (Date.now() - ts > 1000) {
              ts = Date.now();
              console.error("Message #" + message_id++);
          }
      } catch (e) {
      }
  }
}

function test()
{
    InspectorTest.sendCommand("Inspector.enable", {});
    InspectorTest.sendCommand("Debugger.enable", {}, didEnableDebugger);
    function didEnableDebugger()
    {
        // Start tight loop in page.
        InspectorTest.sendCommand("Runtime.evaluate", { "expression": "testFunction()" }, didEval);
        function didEval()
        {
            InspectorTest.log("didEval");
        }
    }

    InspectorTest.didFireTimer = function()
    {
        InspectorTest.log("didFireTimer");
        InspectorTest.sendCommand("Debugger.pause", { });
    }

    InspectorTest.eventHandler["Debugger.paused"] = function(messageObject)
    {
        var message = messageObject["params"]["message"];
        InspectorTest.log("SUCCESS: Paused");
        InspectorTest.sendCommand("Runtime.evaluate", { "expression": "terminated = true;" });
        InspectorTest.sendCommand("Debugger.resume", { });
        InspectorTest.completeTest();
    }
}
</script>
</head>
<body onLoad="runTest();">
</body>
</html>