* SUMMARY When pausing on exceptions it can be difficult or impossible to interact with the actual thrown exception object. For example breaking on an uncaught exception, there is no named reference to the thrown value that would otherwise have been available in "catch (e)". We can provide a named reference in the console, such as "$e". * TEST <button id="x">Click Me</button> <script> var times = 0; document.getElementById('x').addEventListener('click', function() { times++; if (times === 1) [].x.x; if (times === 2) throw "string error"; if (times === 3) throw null; if (times === 4) throw document; }); </script> * STEPS TO REPRODUCE 1. Inspect test page 2. Enable break on all exceptions 3. Click the button on the page to trigger exceptions => should be able to get the different thrown values (Errors / objects) via "$e" in the console.
<rdar://problem/18980012>
Created attachment 241541 [details] [PATCH] WIP - Needs Tests I only expose "$e" in console autocompletion when we are paused because of an exception. I still think "$exception" might be clearer.
Comment on attachment 241541 [details] [PATCH] WIP - Needs Tests View in context: https://bugs.webkit.org/attachment.cgi?id=241541&action=review > Source/JavaScriptCore/inspector/InjectedScriptSource.js:1054 > + this.$e = injectedScript._exceptionValue; I am fine with $e or $exception. Autocomplete will kick in.
Created attachment 241758 [details] [PATCH] Proposed Fix Now with tests and proper handling of $exception inside catch blocks.
Comment on attachment 241758 [details] [PATCH] Proposed Fix View in context: https://bugs.webkit.org/attachment.cgi?id=241758&action=review > LayoutTests/inspector/debugger/command-line-api-exception.html:60 > + WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.CallFramesDidChange, function(event) { Note that these tests use Event.CallFramesDidChange and not Event.Paused because DebuggerManager's Event.Paused/Event.Resumed do not get called if we immediately pause after stepping (50ms). This event will get called on every pause.
Comment on attachment 241758 [details] [PATCH] Proposed Fix View in context: https://bugs.webkit.org/attachment.cgi?id=241758&action=review > LayoutTests/inspector/debugger/command-line-api-exception-nested-catch-expected.txt:12 > +CONSOLE MESSAGE: line 67: inner exception > +CONSOLE MESSAGE: line 69: outer exception > +Checks that $exception is the value of the current exception, even in nested catch blocks. > + > +BEFORE : $exception => undefined > +OUTER 1: $exception => outer exception > +INNER 1: $exception => inner exception > +INNER 2: $exception => inner exception > + CATCH: $exception === e2 ? true > +OUTER 2: $exception => outer exception > + CATCH: $exception === e1 ? true > +AFTER : $exception => undefined Nice test. > Source/JavaScriptCore/inspector/InjectedScriptManager.cpp:128 > + for (auto it = m_idToInjectedScript.begin(); it != m_idToInjectedScript.end(); ++it) > + it->value.clearExceptionValue(); for (auto injectedScript : m_idToInjectedScript.values()) ?
http://trac.webkit.org/changeset/176357