terminate-execution-on-pause.js 2.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// Copyright 2018 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.

let {session, contextGroup, Protocol} =
    InspectorTest.start('Tests Runtime.terminateExecution on pause');

Protocol.Runtime.enable();
Protocol.Runtime.onConsoleAPICalled(
    message => InspectorTest.logMessage(message.params.args[0]));
Protocol.Debugger.enable();

InspectorTest.runAsyncTestSuite([
  async function testTerminateOnDebugger() {
    Protocol.Runtime.evaluate({expression: `
function callback() {
  debugger;
  console.log(42);
  setTimeout(callback, 0);
}
callback();
//# sourceURL=test.js`});
    await Protocol.Debugger.oncePaused();
    const terminated = Protocol.Runtime.terminateExecution();
25
    await Protocol.Debugger.resume();
26 27 28 29 30
    await terminated;
  },

  async function testTerminateAtBreakpoint() {
    Protocol.Debugger.setBreakpointByUrl({url: 'test.js', lineNumber: 2});
31
    const result = Protocol.Runtime.evaluate({expression: `
32 33 34 35 36
function callback() {
  console.log(42);
  setTimeout(callback, 0);
}
callback();
37
//# sourceURL=test.js`}).then(InspectorTest.logMessage);
38 39
    await Protocol.Debugger.oncePaused();
    const terminated = Protocol.Runtime.terminateExecution();
40
    await Protocol.Debugger.resume();
41
    await terminated;
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
    await result;
  },

  async function testTerminateRuntimeEvaluate() {
    Protocol.Runtime.evaluate({expression: `
function callback() {
  debugger;
  console.log(42);
  debugger;
}
callback();
//# sourceURL=test.js`});
    await Protocol.Debugger.oncePaused();
    await Promise.all([
      Protocol.Runtime.terminateExecution().then(InspectorTest.logMessage),
      Protocol.Runtime.evaluate({expression: 'console.log(42)'}).then(InspectorTest.logMessage)
    ]);
    await Protocol.Debugger.resume();
    await Protocol.Debugger.oncePaused();
    await Protocol.Debugger.resume();
  },

  async function testTerminateRuntimeEvaluateOnCallFrame() {
    Protocol.Runtime.evaluate({expression: `
function callback() {
  let a = 1;
  debugger;
  console.log(43);
}
callback();
//# sourceURL=test.js`});
    let message = await Protocol.Debugger.oncePaused();
    let topFrameId = message.params.callFrames[0].callFrameId;
    await Protocol.Debugger.evaluateOnCallFrame({callFrameId: topFrameId, expression: "a"})
    .then(InspectorTest.logMessage)
    await Promise.all([
      Protocol.Runtime.terminateExecution().then(InspectorTest.logMessage),
      Protocol.Debugger.evaluateOnCallFrame({callFrameId: topFrameId, expression: "a"})
          .then(InspectorTest.logMessage)
    ]);
    await Protocol.Debugger.resume();
  },
84
]);