blob: 53e6372a3cb04f5678452afe7c8cdd63f447fc74 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script src="resources/exceptions.js"></script>
<script>
window.onerror = function(){};
function test()
{
WI.debuggerManager.allExceptionsBreakpoint.disabled = false;
function dumpCommandLineAPIValue(prefix) {
WI.runtimeManager.evaluateInInspectedWindow("$exception", {objectGroup: "test", includeCommandLineAPI: true, doNotPauseOnExceptionsAndMuteConsole: true}, function(result, wasThrown) {
InspectorTest.log(prefix + ": $exception => " + result.description);
});
}
function checkIfExceptionValueMatchesVariable(varName) {
WI.runtimeManager.evaluateInInspectedWindow("$exception === " + varName, {objectGroup: "test", includeCommandLineAPI: true, doNotPauseOnExceptionsAndMuteConsole: true}, function(result, wasThrown) {
InspectorTest.log(" CATCH: $exception === " + varName + " ? " + result.description);
});
}
let suite = InspectorTest.createAsyncSuite("CommandLineAPI.$exception");
suite.addTestCase({
name: "EmptyBefore",
description: "Without exceptions, $exception should be undefined",
test(resolve, reject) {
WI.runtimeManager.evaluateInInspectedWindow("$exception", {objectGroup: "test", includeCommandLineAPI: true, doNotPauseOnExceptionsAndMuteConsole: true}, (result, wasThrown) => {
InspectorTest.expectThat(result.description === "undefined", "$exception should be undefined if there is no exception.");
resolve();
});
}
});
suite.addTestCase({
name: "CheckExceptionInsideNestedCatchBlocks",
description: "Check $exception is always the current exception object when stepping through catch blocks.",
test(resolve, reject) {
InspectorTest.evaluateInPage("setTimeout(nestedCatchBlocks, 0)");
let phase = 0;
let listener = WI.debuggerManager.addEventListener(WI.DebuggerManager.Event.CallFramesDidChange, (event) => {
if (!WI.debuggerManager.activeCallFrame)
return;
phase++;
// Skip past the first pause to the second pause.
if (phase === 1) {
dumpCommandLineAPIValue("OUTER 1");
WI.debuggerManager.resume();
return;
}
// Paused on the exception in the inner try, step over to get into the inner catch.
if (phase === 2) {
dumpCommandLineAPIValue("INNER 1");
WI.debuggerManager.stepOver();
return;
}
// Paused in the inner catch, verify $exception is "inner exception".
if (phase === 3) {
dumpCommandLineAPIValue("INNER 2");
checkIfExceptionValueMatchesVariable("e2");
WI.debuggerManager.stepOver();
return;
}
// Stepped into the outer catch, verify $exception is "outer exception".
if (phase === 4) {
dumpCommandLineAPIValue("OUTER 2");
checkIfExceptionValueMatchesVariable("e1");
InspectorTest.singleFireEventListener("AfterTestFunction", resolve);
WI.debuggerManager.resume().then(() => {
WI.debuggerManager.removeEventListener(WI.DebuggerManager.Event.CallFramesDidChange, listener);
}, reject);
return;
}
});
}
});
suite.addTestCase({
name: "EmptyAfter",
description: "Without exceptions, $exception should be undefined",
test(resolve, reject) {
WI.runtimeManager.evaluateInInspectedWindow("$exception", {objectGroup: "test", includeCommandLineAPI: true, doNotPauseOnExceptionsAndMuteConsole: true}, (result, wasThrown) => {
InspectorTest.expectThat(result.description === "undefined", "$exception should be undefined if there is no exception.");
resolve();
});
}
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Checks that <code>$exception</code> is the value of the current exception, even in nested catch blocks.</p>
</body>
</html>