Bug 138726 - Web Inspector: Provide $exception in the console for the thrown exception value
Summary: Web Inspector: Provide $exception in the console for the thrown exception value
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Joseph Pecoraro
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2014-11-13 20:16 PST by Joseph Pecoraro
Modified: 2014-12-02 14:25 PST (History)
6 users (show)

See Also:


Attachments
[PATCH] WIP - Needs Tests (9.84 KB, patch)
2014-11-13 20:18 PST, Joseph Pecoraro
no flags Details | Formatted Diff | Diff
[PATCH] Proposed Fix (32.00 KB, patch)
2014-11-17 20:21 PST, Joseph Pecoraro
timothy: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Pecoraro 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.
Comment 1 Radar WebKit Bug Importer 2014-11-13 20:16:45 PST
<rdar://problem/18980012>
Comment 2 Joseph Pecoraro 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.
Comment 3 Timothy Hatcher 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.
Comment 4 Joseph Pecoraro 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.
Comment 5 Joseph Pecoraro 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.
Comment 6 Timothy Hatcher 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()) ?
Comment 7 Joseph Pecoraro 2014-11-19 15:50:15 PST
http://trac.webkit.org/changeset/176357