Web Inspector: Provide $exception in the console for the thrown exception value
https://bugs.webkit.org/show_bug.cgi?id=138726
Reviewed by Timothy Hatcher.
Source/JavaScriptCore:
- debugger/DebuggerScope.cpp:
(JSC::DebuggerScope::caughtValue):
- debugger/DebuggerScope.h:
Access the caught value if this scope is a catch scope.
(JSC::JSNameScope::isFunctionNameScope):
(JSC::JSNameScope::isCatchScope):
(JSC::JSNameScope::value):
Provide an accessor for the single value in the JSNameScope (with / catch block).
- inspector/InjectedScriptSource.js:
Save the exception value and expose it via $exception. Since the command line api
is recreated on each evaluation, $exception is essentially readonly.
- inspector/ScriptDebugServer.h:
- inspector/ScriptDebugServer.cpp:
(Inspector::ScriptDebugServer::dispatchDidPause):
(Inspector::ScriptDebugServer::exceptionOrCaughtValue):
When pausing, get the exception or caught value. The exception will be provided
if we are breaking on an explicit exception. When inside of a catch block, we
can get the caught value by walking up the scope chain.
- inspector/agents/InspectorDebuggerAgent.h:
- inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::InspectorDebuggerAgent::InspectorDebuggerAgent):
(Inspector::InspectorDebuggerAgent::resume):
(Inspector::InspectorDebuggerAgent::stepOver):
(Inspector::InspectorDebuggerAgent::stepInto):
(Inspector::InspectorDebuggerAgent::stepOut):
Clearing state can be done in didContinue.
(Inspector::InspectorDebuggerAgent::didPause):
Set the exception value explicitly in the injected script when we have it.
(Inspector::InspectorDebuggerAgent::didContinue):
Clear state saved when we had paused, including clearly an exception value if needed.
(Inspector::InspectorDebuggerAgent::clearDebuggerBreakpointState):
(Inspector::InspectorDebuggerAgent::clearExceptionValue):
Call into the injected script only when needed.
- inspector/InjectedScript.cpp:
(Inspector::InjectedScript::setExceptionValue):
(Inspector::InjectedScript::clearExceptionValue):
- inspector/InjectedScript.h:
- inspector/InjectedScriptManager.cpp:
(Inspector::InjectedScriptManager::clearExceptionValue):
- inspector/InjectedScriptManager.h:
Clear on all injected scripts.
Source/WebCore:
Tests: inspector/debugger/command-line-api-exception-nested-catch.html
inspector/debugger/command-line-api-exception.html
- inspector/CommandLineAPIModuleSource.js:
Expose $exception in the more complete command line API.
Source/WebInspectorUI:
- UserInterface/Base/Test.js:
(WebInspector.loaded):
In order to use RuntimeManager to execute in the global context or on the
active debugger call frame, we need to expose the quickConsole controller.
- UserInterface/Controllers/JavaScriptRuntimeCompletionProvider.js:
Expose $exception to completion when we paused because of an exception.
LayoutTests:
Provide some tests to ensure $exception is the value we expect at different times,
such as on the exception line, when there is no exception, or when stepping through
catch blocks (it should always be the most recent caught exception).
- inspector/debugger/command-line-api-exception-expected.txt: Added.
- inspector/debugger/command-line-api-exception-nested-catch-expected.txt: Added.
- inspector/debugger/command-line-api-exception-nested-catch.html: Added.
- inspector/debugger/command-line-api-exception.html: Added.
- inspector/debugger/resources/exceptions.js: Added.
(triggerUncaughtTypeException):
(triggerUncaughtReferenceException):
(triggerUncaughtSyntaxException):
(triggerUncaughtDOMException):
(throwString):
(throwNumber):
(throwNull):
(throwObject):
(throwNode):
(catcher):
(nestedCatchBlocks):