caught-uncaught-exceptions.js 1.76 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
let {session, contextGroup, Protocol} = InspectorTest.start("Check that inspector correctly passes caught/uncaught information.");
6

7
contextGroup.addScript(
8 9
`function throwCaught() { try { throw new Error(); } catch (_) {} }
 function throwUncaught() { throw new Error(); }
10 11 12 13 14 15 16 17 18 19 20 21 22
 function throwInPromiseCaught() {
   var reject;
   new Promise(function(res, rej) { reject = rej; }).catch(() => {});
   reject();
 }
 function throwInPromiseUncaught() {
   new Promise(function promiseUncaught() { throw new Error(); });
 }
 function throwInMapConstructor() { new Map('a'); }
 function throwInAsyncIterator() {
   let it = (async function*() {})();
   it.next.call({});
 }
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
 function schedule(f) { setTimeout(f, 0); }
`);

Protocol.Debugger.enable();

Protocol.Debugger.setPauseOnExceptions({ "state": "all" });
Protocol.Debugger.onPaused(message => {
  InspectorTest.log("paused in " + message.params.callFrames[0].functionName);
  InspectorTest.log("uncaught: " + message.params.data.uncaught);
  Protocol.Debugger.resume();
});

Protocol.Runtime.evaluate({ "expression": "schedule(throwCaught);" })
  .then(() => Protocol.Runtime.evaluate(
      { "expression": "schedule(throwUncaught);" }))
38 39 40 41 42 43 44 45 46
  .then(() => Protocol.Runtime.evaluate(
      { "expression": "schedule(throwInPromiseCaught);"}))
  .then(() => Protocol.Runtime.evaluate(
      { "expression": "schedule(throwInPromiseUncaught);"}))
  .then(() => Protocol.Runtime.evaluate(
      { "expression": "schedule(throwInMapConstructor);"}))
  .then(() => Protocol.Runtime.evaluate(
      { "expression": "schedule(throwInAsyncIterator);"}))
 .then(() => InspectorTest.completeTest());