break-on-exception-and-step.js 2.46 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 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
// 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 for break on exception and stepping.');

session.setupScriptMap();
Protocol.Debugger.enable();
Protocol.Debugger.setBlackboxPatterns({patterns: ['expr\.js']});
Protocol.Debugger.onPaused(async ({params:{callFrames:[topFrame], data}}) => {
  if (data) {
    InspectorTest.log('paused on exception:');
    InspectorTest.logMessage(data);
  }
  await session.logSourceLocation(topFrame.location);
  Protocol.Debugger.stepInto();
});

contextGroup.addScript(`
function a() { n(); };
function b() { c(); };
function c() { n(); };
function d() { x = 1; try { e(); } catch(x) { x = 2; } };
function e() { n(); };
function f() { x = 1; try { g(); } catch(x) { x = 2; } };
function g() { h(); };
function h() { x = 1; throw 1; };
`);

InspectorTest.runAsyncTestSuite([
  async function testStepThrougA() {
    Protocol.Debugger.pause();
    await Protocol.Runtime.evaluate({expression: 'a()\n//# sourceURL=expr.js'});
  },

  async function testStepThrougB() {
    Protocol.Debugger.pause();
    await Protocol.Runtime.evaluate({expression: 'b()\n//# sourceURL=expr.js'});
  },

  async function testStepThrougD() {
    await Protocol.Debugger.setPauseOnExceptions({state: 'uncaught'});
    Protocol.Debugger.pause();
    await Protocol.Runtime.evaluate({expression: 'd()\n//# sourceURL=expr.js'});
    await Protocol.Debugger.setPauseOnExceptions({state: 'none'});
  },

  async function testStepThrougDWithBreakOnAllExceptions() {
    await Protocol.Debugger.setPauseOnExceptions({state: 'all'});
    Protocol.Debugger.pause();
    await Protocol.Runtime.evaluate({expression: 'd()\n//# sourceURL=expr.js'});
    await Protocol.Debugger.setPauseOnExceptions({state: 'none'});
  },

  async function testStepThrougF() {
    await Protocol.Debugger.setPauseOnExceptions({state: 'uncaught'});
    Protocol.Debugger.pause();
    await Protocol.Runtime.evaluate({expression: 'f()\n//# sourceURL=expr.js'});
    await Protocol.Debugger.setPauseOnExceptions({state: 'none'});
  },

  async function testStepThrougFWithBreakOnAllExceptions() {
    await Protocol.Debugger.setPauseOnExceptions({state: 'all'});
    Protocol.Debugger.pause();
    await Protocol.Runtime.evaluate({expression: 'f()\n//# sourceURL=expr.js'});
    await Protocol.Debugger.setPauseOnExceptions({state: 'none'});
  }
]);