RESOLVED FIXED 138726
Web Inspector: Provide $exception in the console for the thrown exception value
https://bugs.webkit.org/show_bug.cgi?id=138726
Summary Web Inspector: Provide $exception in the console for the thrown exception value
Joseph Pecoraro
Reported 2014-11-13 20:16:32 PST
* 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.
Attachments
[PATCH] WIP - Needs Tests (9.84 KB, patch)
2014-11-13 20:18 PST, Joseph Pecoraro
no flags
[PATCH] Proposed Fix (32.00 KB, patch)
2014-11-17 20:21 PST, Joseph Pecoraro
timothy: review+
Radar WebKit Bug Importer
Comment 1 2014-11-13 20:16:45 PST
Joseph Pecoraro
Comment 2 2014-11-13 20:18:01 PST
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.
Timothy Hatcher
Comment 3 2014-11-14 09:15:41 PST
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.
Joseph Pecoraro
Comment 4 2014-11-17 20:21:22 PST
Created attachment 241758 [details] [PATCH] Proposed Fix Now with tests and proper handling of $exception inside catch blocks.
Joseph Pecoraro
Comment 5 2014-11-17 20:23:38 PST
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.
Timothy Hatcher
Comment 6 2014-11-19 10:29:23 PST
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()) ?
Joseph Pecoraro
Comment 7 2014-11-19 15:50:15 PST
Note You need to log in before you can comment on or make changes to this bug.