2018-06-03 05:09:41 +00:00
|
|
|
// Copyright 2018 the V8 project authors. All rights reserved.
|
2016-10-19 02:00:21 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
let {session, contextGroup, Protocol} = InspectorTest.start(
|
|
|
|
'Tests for break on exception.');
|
2016-10-19 02:00:21 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
Protocol.Debugger.enable();
|
|
|
|
Protocol.Debugger.onPaused(({params:{data}}) => {
|
|
|
|
InspectorTest.log('paused on exception:');
|
|
|
|
InspectorTest.logMessage(data);
|
|
|
|
Protocol.Debugger.resume();
|
|
|
|
});
|
|
|
|
|
|
|
|
contextGroup.addInlineScript(`
|
|
|
|
function throws() {
|
|
|
|
throw 1;
|
|
|
|
}
|
|
|
|
function caught() {
|
|
|
|
try {
|
|
|
|
throws();
|
|
|
|
} catch (e) {
|
|
|
|
}
|
2016-10-19 02:00:21 +00:00
|
|
|
}
|
2018-06-03 05:09:41 +00:00
|
|
|
function uncaught() {
|
|
|
|
throws();
|
2016-10-19 02:00:21 +00:00
|
|
|
}
|
2018-06-03 05:09:41 +00:00
|
|
|
function uncaughtFinally() {
|
|
|
|
try {
|
|
|
|
throws();
|
|
|
|
} finally {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function caughtFinally() {
|
|
|
|
L: try {
|
|
|
|
throws();
|
|
|
|
} finally {
|
|
|
|
break L;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, 'test.js');
|
2016-10-19 02:00:21 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
InspectorTest.runAsyncTestSuite([
|
|
|
|
async function testPauseOnInitialState() {
|
|
|
|
await evaluate('caught()');
|
|
|
|
await evaluate('uncaught()');
|
|
|
|
await evaluate('uncaughtFinally()');
|
|
|
|
await evaluate('caughtFinally()');
|
|
|
|
},
|
2016-10-19 02:00:21 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
async function testPauseOnExceptionOff() {
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'none'});
|
|
|
|
await evaluate('caught()');
|
|
|
|
await evaluate('uncaught()');
|
|
|
|
await evaluate('uncaughtFinally()');
|
|
|
|
await evaluate('caughtFinally()');
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'none'});
|
|
|
|
},
|
|
|
|
|
|
|
|
async function testBreakOnUncaughtException() {
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'uncaught'});
|
|
|
|
await evaluate('caught()');
|
|
|
|
await evaluate('uncaught()');
|
|
|
|
await evaluate('uncaughtFinally()');
|
|
|
|
await evaluate('caughtFinally()');
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'none'});
|
|
|
|
},
|
2016-10-19 02:00:21 +00:00
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
async function testBreakOnAll() {
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'all'});
|
|
|
|
await evaluate('caught()');
|
|
|
|
await evaluate('uncaught()');
|
|
|
|
await evaluate('uncaughtFinally()');
|
|
|
|
await evaluate('caughtFinally()');
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'none'});
|
2016-10-19 02:00:21 +00:00
|
|
|
},
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
async function testTryFinallyOriginalMessage() {
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'all'});
|
|
|
|
await evaluate(`
|
|
|
|
try {
|
|
|
|
throw 1;
|
|
|
|
} finally {
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'none'});
|
2016-10-19 02:00:21 +00:00
|
|
|
},
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
async function testPromiseRejectedByCallback() {
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'uncaught'});
|
|
|
|
await evaluate(`
|
|
|
|
function fun() { eval("throw 'rejection';") }
|
|
|
|
var p = new Promise(function(res, rej) { fun(); res(); });
|
|
|
|
var r;
|
|
|
|
p.then(() => { r = 'resolved'; }, (e) => { r = 'rejected' + e; });
|
|
|
|
`);
|
|
|
|
InspectorTest.log('r = ');
|
|
|
|
InspectorTest.logMessage((await Protocol.Runtime.evaluate({
|
|
|
|
expression: 'r'
|
|
|
|
})).result.result);
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'none'});
|
2016-10-19 02:00:21 +00:00
|
|
|
},
|
|
|
|
|
2018-06-03 05:09:41 +00:00
|
|
|
async function testBreakOnExceptionAfterReconnect() {
|
|
|
|
contextGroup.addInlineScript('function f() { throw new Error(); }');
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'uncaught'});
|
|
|
|
await evaluate('f()');
|
|
|
|
InspectorTest.log('\nreconnect..');
|
|
|
|
session.reconnect();
|
|
|
|
await evaluate('f()');
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'none'});
|
|
|
|
},
|
|
|
|
|
|
|
|
async function testBreakOnExceptionInSilentMode(next) {
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({ state: "all" });
|
|
|
|
InspectorTest.log(`evaluate 'caught()'`);
|
|
|
|
await Protocol.Runtime.evaluate({expression: 'caught()', silent: true});
|
|
|
|
InspectorTest.log(`evaluate 'uncaught()'`);
|
|
|
|
await Protocol.Runtime.evaluate({expression: 'uncaught()', silent: true});
|
|
|
|
InspectorTest.log(`evaluate 'uncaughtFinally()'`);
|
|
|
|
await Protocol.Runtime.evaluate({
|
|
|
|
expression: 'uncaughtFinally()',
|
|
|
|
silent: true
|
|
|
|
});
|
|
|
|
InspectorTest.log(`evaluate 'caughtFinally()'`);
|
|
|
|
await Protocol.Runtime.evaluate({
|
|
|
|
xpression: 'caughtFinally()',
|
|
|
|
silent: true
|
|
|
|
});
|
|
|
|
await Protocol.Debugger.setPauseOnExceptions({state: 'none'});
|
2016-10-19 02:00:21 +00:00
|
|
|
}
|
|
|
|
]);
|
2018-06-03 05:09:41 +00:00
|
|
|
|
|
|
|
async function evaluate(expression) {
|
|
|
|
InspectorTest.log(`\nevaluate '${expression}'..`);
|
|
|
|
contextGroup.addInlineScript(expression);
|
|
|
|
await InspectorTest.waitForPendingTasks();
|
|
|
|
}
|