Bug 150548

Summary: Web Inspector: Cleanup sidebar panels, reduce `delete` and use Maps instead of objects
Product: WebKit Reporter: Matt Baker <mattbaker>
Component: Web InspectorAssignee: Matt Baker <mattbaker>
Status: RESOLVED FIXED    
Severity: Normal CC: bburg, commit-queue, graouts, joepeck, mattbaker, nvasilyev, timothy, webkit-bug-importer
Priority: P2 Keywords: DoNotImportToRadar
Version: WebKit Nightly Build   
Hardware: All   
OS: All   
Attachments:
Description Flags
[Patch] Proposed Fix
none
[Patch] Proposed Fix none

Description Matt Baker 2015-10-25 20:12:12 PDT
* SUMMARY
Cleanup sidebar panels, reduce `delete` and use Maps instead of objects.
Comment 1 Matt Baker 2015-10-25 20:15:17 PDT
(In reply to comment #0)
> * SUMMARY
> Cleanup sidebar panels, reduce `delete` and use Maps instead of objects.

Also using Symbol() when setting external properties, and switching to const/let (in the vicinity of the main changes).
Comment 2 Matt Baker 2015-10-25 20:21:53 PDT
Created attachment 264029 [details]
[Patch] Proposed Fix
Comment 3 Timothy Hatcher 2015-10-26 08:12:45 PDT
Comment on attachment 264029 [details]
[Patch] Proposed Fix

View in context: https://bugs.webkit.org/attachment.cgi?id=264029&action=review

> Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js:245
> -            delete this._finalAttemptToRestoreViewStateTimeout;
> +            this._finalAttemptToRestoreViewStateTimeout = undefined;

I think we should prefer 0 for timeouts, since it will be a number normally.

> Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js:720
> +WebInspector.NavigationSidebarPanel.WasExpandedDuringFilteringSymbol = Symbol("was-expanded-during-filtering");

Great!

> Source/WebInspectorUI/UserInterface/Views/ScopeChainDetailsSidebarPanel.js:164
> +        for (const type in WebInspector.ScopeChainNode.Type)

I don't think const should be used in a loop, I am surprised this works.

> Source/WebInspectorUI/UserInterface/Views/StorageSidebarPanel.js:275
> +        let manifest = frameManifest.manifest;
> +        const manifestURL = manifest.manifestURL;

Why const for the URL and let for the manifest? I think we should use const only for strictly const things.
Comment 4 Matt Baker 2015-10-26 15:03:36 PDT
(In reply to comment #3)
> Comment on attachment 264029 [details]
> [Patch] Proposed Fix
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=264029&action=review
> 
> > Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js:245
> > -            delete this._finalAttemptToRestoreViewStateTimeout;
> > +            this._finalAttemptToRestoreViewStateTimeout = undefined;
> 
> I think we should prefer 0 for timeouts, since it will be a number normally.

The IDs returned by setTimeout, setInterval, and requestAnimationFrame are similar (non-zero, unique), but in the last case we've been using `undefined` instead of zero when resetting identifiers. The consensus is that this improves clarity.

> > Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js:720
> > +WebInspector.NavigationSidebarPanel.WasExpandedDuringFilteringSymbol = Symbol("was-expanded-during-filtering");
> 
> Great!
> 
> > Source/WebInspectorUI/UserInterface/Views/ScopeChainDetailsSidebarPanel.js:164
> > +        for (const type in WebInspector.ScopeChainNode.Type)
> 
> I don't think const should be used in a loop, I am surprised this works.

AFAIK this works because for-in and for-of style loops redefine the loop variable every iteration. I'm fine switching to `let`.
> 
> > Source/WebInspectorUI/UserInterface/Views/StorageSidebarPanel.js:275
> > +        let manifest = frameManifest.manifest;
> > +        const manifestURL = manifest.manifestURL;
> 
> Why const for the URL and let for the manifest? I think we should use const
> only for strictly const things.
Comment 5 Matt Baker 2015-10-26 15:05:45 PDT
(In reply to comment #4)
> (In reply to comment #3)
> > Comment on attachment 264029 [details]
> > [Patch] Proposed Fix
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=264029&action=review
> > 
> > > Source/WebInspectorUI/UserInterface/Views/NavigationSidebarPanel.js:245
> > > -            delete this._finalAttemptToRestoreViewStateTimeout;
> > > +            this._finalAttemptToRestoreViewStateTimeout = undefined;
> > 
> > I think we should prefer 0 for timeouts, since it will be a number normally.
> 
> The IDs returned by setTimeout, setInterval, and requestAnimationFrame are
> similar (non-zero, unique), but in the last case we've been using
> `undefined` instead of zero when resetting identifiers. The consensus is
> that this improves clarity.

The name `_finalAttemptToRestoreViewStateTimeout` could be confusing here, since it holds a timeout ID, not a delay value.
Comment 6 Matt Baker 2015-10-26 15:55:09 PDT
Created attachment 264089 [details]
[Patch] Proposed Fix
Comment 7 WebKit Commit Bot 2015-10-26 16:54:40 PDT
Comment on attachment 264089 [details]
[Patch] Proposed Fix

Clearing flags on attachment: 264089

Committed r191612: <http://trac.webkit.org/changeset/191612>
Comment 8 WebKit Commit Bot 2015-10-26 16:54:45 PDT
All reviewed patches have been landed.  Closing bug.