<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[194685] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/194685">194685</a></dd>
<dt>Author</dt> <dd>joepeck@webkit.org</dd>
<dt>Date</dt> <dd>2016-01-06 17:44:08 -0800 (Wed, 06 Jan 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: Scope chain shows too many scopes for functions (`let` and `var` in the same function are two scopes)
https://bugs.webkit.org/show_bug.cgi?id=152349

Reviewed by Timothy Hatcher.

Source/WebInspectorUI:

* Localizations/en.lproj/localizedStrings.js:
New &quot;Closure Variables (%s)&quot; string for including the function name alongside
the closure scope section.

* UserInterface/Models/ScopeChainNode.js:
(WebInspector.ScopeChainNode):
(WebInspector.ScopeChainNode.prototype.get objects):
(WebInspector.ScopeChainNode.prototype.get object): Deleted.
Allow a ScopeChainNode to hold onto multiple RemoteObjects (for multiple JSScopes).

* UserInterface/Controllers/DebuggerManager.js:
(WebInspector.DebuggerManager.prototype._scopeChainNodeFromPayload):
Simplify the legacy case and convert &quot;Local&quot; to &quot;Closure&quot;. The UI will now
determine and display &quot;Local&quot; where appropriate in a backwards compatible way.

* UserInterface/Views/ScopeChainDetailsSidebarPanel.js:
(WebInspector.ScopeChainDetailsSidebarPanel.prototype._generateCallFramesSection):
Associate ScopeChain nodes with CallFrame frames so that we can better combine
variable sections and better label closure sections.

* UserInterface/Views/ScopeChainDetailsSidebarPanel.css:
(.scope-chain .details-section &gt; .content &gt; .group &gt; .row.properties:not(.empty)):
(.scope-chain .details-section &gt; .content &gt; .group &gt; .row.properties:not(.empty):last-child):
Styles for two object trees property sections next to eachother.

LayoutTests:

* inspector/debugger/breakpoint-scope.html:
* inspector/model/scope-chain-node.html:
The ScopeChainNode model object changed, so update tests.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsinspectordebuggerbreakpointscopehtml">trunk/LayoutTests/inspector/debugger/breakpoint-scope.html</a></li>
<li><a href="#trunkLayoutTestsinspectormodelscopechainnodehtml">trunk/LayoutTests/inspector/model/scope-chain-node.html</a></li>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUILocalizationsenlprojlocalizedStringsjs">trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceControllersDebuggerManagerjs">trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceModelsScopeChainNodejs">trunk/Source/WebInspectorUI/UserInterface/Models/ScopeChainNode.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsScopeChainDetailsSidebarPanelcss">trunk/Source/WebInspectorUI/UserInterface/Views/ScopeChainDetailsSidebarPanel.css</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsScopeChainDetailsSidebarPaneljs">trunk/Source/WebInspectorUI/UserInterface/Views/ScopeChainDetailsSidebarPanel.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (194684 => 194685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-01-07 01:43:28 UTC (rev 194684)
+++ trunk/LayoutTests/ChangeLog        2016-01-07 01:44:08 UTC (rev 194685)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2016-01-06  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+        Web Inspector: Scope chain shows too many scopes for functions (`let` and `var` in the same function are two scopes)
+        https://bugs.webkit.org/show_bug.cgi?id=152349
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/debugger/breakpoint-scope.html:
+        * inspector/model/scope-chain-node.html:
+        The ScopeChainNode model object changed, so update tests.
+
</ins><span class="cx"> 2016-01-06  Michael Catanzaro  &lt;mcatanzaro@igalia.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [GTK] css-multicol-1 tests are failing
</span></span></pre></div>
<a id="trunkLayoutTestsinspectordebuggerbreakpointscopehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/debugger/breakpoint-scope.html (194684 => 194685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/debugger/breakpoint-scope.html        2016-01-07 01:43:28 UTC (rev 194684)
+++ trunk/LayoutTests/inspector/debugger/breakpoint-scope.html        2016-01-07 01:44:08 UTC (rev 194685)
</span><span class="lines">@@ -57,7 +57,7 @@
</span><span class="cx">         for (var scope of scopeChain) {
</span><span class="cx">             scopeTypes.push(scope.type);
</span><span class="cx">             if (scope.type !== WebInspector.ScopeChainNode.Type.Global) {
</span><del>-                scope.object.getAllPropertyDescriptors(function(properties) {
</del><ins>+                scope.objects[0].getAllPropertyDescriptors(function(properties) {
</ins><span class="cx">                     InspectorTest.log(scopeTypes[scopeTypeIndex++] + &quot; properties:&quot;);
</span><span class="cx">                     for (var propertyDescriptor of properties)
</span><span class="cx">                         InspectorTest.log(&quot;    &quot; + propertyDescriptor.name);
</span></span></pre></div>
<a id="trunkLayoutTestsinspectormodelscopechainnodehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/model/scope-chain-node.html (194684 => 194685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/model/scope-chain-node.html        2016-01-07 01:43:28 UTC (rev 194684)
+++ trunk/LayoutTests/inspector/model/scope-chain-node.html        2016-01-07 01:44:08 UTC (rev 194685)
</span><span class="lines">@@ -30,7 +30,7 @@
</span><span class="cx">                 if (scope.type === WebInspector.ScopeChainNode.Type.Global)
</span><span class="cx">                     resolve({scope, propertyDescriptors: []});
</span><span class="cx">                 else {
</span><del>-                    scope.object.getDisplayablePropertyDescriptors((propertyDescriptors) =&gt; {
</del><ins>+                    scope.objects[0].getDisplayablePropertyDescriptors((propertyDescriptors) =&gt; {
</ins><span class="cx">                         resolve({scope, propertyDescriptors});
</span><span class="cx">                     });
</span><span class="cx">                 }
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (194684 => 194685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2016-01-07 01:43:28 UTC (rev 194684)
+++ trunk/Source/WebInspectorUI/ChangeLog        2016-01-07 01:44:08 UTC (rev 194685)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2016-01-06  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+        Web Inspector: Scope chain shows too many scopes for functions (`let` and `var` in the same function are two scopes)
+        https://bugs.webkit.org/show_bug.cgi?id=152349
+
+        Reviewed by Timothy Hatcher.
+
+        * Localizations/en.lproj/localizedStrings.js:
+        New &quot;Closure Variables (%s)&quot; string for including the function name alongside
+        the closure scope section.
+
+        * UserInterface/Models/ScopeChainNode.js:
+        (WebInspector.ScopeChainNode):
+        (WebInspector.ScopeChainNode.prototype.get objects):
+        (WebInspector.ScopeChainNode.prototype.get object): Deleted.
+        Allow a ScopeChainNode to hold onto multiple RemoteObjects (for multiple JSScopes).
+
+        * UserInterface/Controllers/DebuggerManager.js:
+        (WebInspector.DebuggerManager.prototype._scopeChainNodeFromPayload):
+        Simplify the legacy case and convert &quot;Local&quot; to &quot;Closure&quot;. The UI will now
+        determine and display &quot;Local&quot; where appropriate in a backwards compatible way.
+
+        * UserInterface/Views/ScopeChainDetailsSidebarPanel.js:
+        (WebInspector.ScopeChainDetailsSidebarPanel.prototype._generateCallFramesSection):
+        Associate ScopeChain nodes with CallFrame frames so that we can better combine
+        variable sections and better label closure sections.
+
+        * UserInterface/Views/ScopeChainDetailsSidebarPanel.css:
+        (.scope-chain .details-section &gt; .content &gt; .group &gt; .row.properties:not(.empty)):
+        (.scope-chain .details-section &gt; .content &gt; .group &gt; .row.properties:not(.empty):last-child):
+        Styles for two object trees property sections next to eachother.
+
</ins><span class="cx"> 2016-01-06  Devin Rousso  &lt;dcrousso+webkit@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: Add basic Animation section to Visual Sidebar
</span></span></pre></div>
<a id="trunkSourceWebInspectorUILocalizationsenlprojlocalizedStringsjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js (194684 => 194685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js        2016-01-07 01:43:28 UTC (rev 194684)
+++ trunk/Source/WebInspectorUI/Localizations/en.lproj/localizedStrings.js        2016-01-07 01:44:08 UTC (rev 194685)
</span><span class="lines">@@ -146,6 +146,7 @@
</span><span class="cx"> localizedStrings[&quot;Close Tab&quot;] = &quot;Close Tab&quot;;
</span><span class="cx"> localizedStrings[&quot;Close resource view&quot;] = &quot;Close resource view&quot;;
</span><span class="cx"> localizedStrings[&quot;Closure Variables&quot;] = &quot;Closure Variables&quot;;
</span><ins>+localizedStrings[&quot;Closure Variables (%s)&quot;] = &quot;Closure Variables (%s)&quot;;
</ins><span class="cx"> localizedStrings[&quot;Code&quot;] = &quot;Code&quot;;
</span><span class="cx"> localizedStrings[&quot;Collapse columns&quot;] = &quot;Collapse columns&quot;;
</span><span class="cx"> localizedStrings[&quot;Color&quot;] = &quot;Color&quot;;
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceControllersDebuggerManagerjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js (194684 => 194685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js        2016-01-07 01:43:28 UTC (rev 194684)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/DebuggerManager.js        2016-01-07 01:44:08 UTC (rev 194685)
</span><span class="lines">@@ -623,8 +623,9 @@
</span><span class="cx"> 
</span><span class="cx">         // COMPATIBILITY (iOS 9): Debugger.ScopeType.Local used to be provided by the backend.
</span><span class="cx">         // Newer backends no longer send this enum value, it should be computed by the frontend.
</span><ins>+        // Map this to &quot;Closure&quot; type. The frontend can recalculate this when needed.
</ins><span class="cx">         case DebuggerAgent.ScopeType.Local:
</span><del>-            type = WebInspector.ScopeChainNode.Type.Local;
</del><ins>+            type = WebInspector.ScopeChainNode.Type.Closure;
</ins><span class="cx">             break;
</span><span class="cx"> 
</span><span class="cx">         default:
</span><span class="lines">@@ -632,7 +633,7 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         var object = WebInspector.RemoteObject.fromPayload(payload.object);
</span><del>-        return new WebInspector.ScopeChainNode(type, object);
</del><ins>+        return new WebInspector.ScopeChainNode(type, [object]);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     _pauseReasonFromPayload(payload)
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceModelsScopeChainNodejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Models/ScopeChainNode.js (194684 => 194685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Models/ScopeChainNode.js        2016-01-07 01:43:28 UTC (rev 194684)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/ScopeChainNode.js        2016-01-07 01:44:08 UTC (rev 194685)
</span><span class="lines">@@ -25,18 +25,18 @@
</span><span class="cx"> 
</span><span class="cx"> WebInspector.ScopeChainNode = class ScopeChainNode extends WebInspector.Object
</span><span class="cx"> {
</span><del>-    constructor(type, object)
</del><ins>+    constructor(type, objects)
</ins><span class="cx">     {
</span><span class="cx">         super();
</span><span class="cx"> 
</span><span class="cx">         console.assert(typeof type === &quot;string&quot;);
</span><del>-        console.assert(object instanceof WebInspector.RemoteObject);
</del><ins>+        console.assert(objects.every(function(x) { return x instanceof WebInspector.RemoteObject; }));
</ins><span class="cx"> 
</span><span class="cx">         if (type in WebInspector.ScopeChainNode.Type)
</span><span class="cx">             type = WebInspector.ScopeChainNode.Type[type];
</span><span class="cx"> 
</span><span class="cx">         this._type = type || null;
</span><del>-        this._object = object || null;
</del><ins>+        this._objects = objects || [];
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Public
</span><span class="lines">@@ -46,9 +46,9 @@
</span><span class="cx">         return this._type;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    get object()
</del><ins>+    get objects()
</ins><span class="cx">     {
</span><del>-        return this._object;
</del><ins>+        return this._objects;
</ins><span class="cx">     }
</span><span class="cx"> };
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsScopeChainDetailsSidebarPanelcss"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ScopeChainDetailsSidebarPanel.css (194684 => 194685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/ScopeChainDetailsSidebarPanel.css        2016-01-07 01:43:28 UTC (rev 194684)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ScopeChainDetailsSidebarPanel.css        2016-01-07 01:44:08 UTC (rev 194685)
</span><span class="lines">@@ -46,3 +46,15 @@
</span><span class="cx">     width: calc(100% - 2px);
</span><span class="cx">     overflow: hidden;
</span><span class="cx"> }
</span><ins>+
+.scope-chain .details-section &gt; .content &gt; .group &gt; .row.properties:not(.empty) {
+    padding-top: 0px;
+    padding-bottom: 0px;
+}
+
+.scope-chain .details-section &gt; .content &gt; .group &gt; .row.properties:not(.empty):last-child {
+    position: relative;
+    top: -2px;
+
+    padding-bottom: 2px;
+}
</ins></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsScopeChainDetailsSidebarPaneljs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/ScopeChainDetailsSidebarPanel.js (194684 => 194685)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/ScopeChainDetailsSidebarPanel.js        2016-01-07 01:43:28 UTC (rev 194684)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/ScopeChainDetailsSidebarPanel.js        2016-01-07 01:44:08 UTC (rev 194685)
</span><span class="lines">@@ -164,79 +164,159 @@
</span><span class="cx">         for (let type in WebInspector.ScopeChainNode.Type)
</span><span class="cx">             sectionCountByType.set(WebInspector.ScopeChainNode.Type[type], 0);
</span><span class="cx"> 
</span><ins>+        // Scopes list goes from top/local (1) to bottom/global (5)
+        // Call frames list goes from top/local (1) to bottom/global (2)
+        //   [scope1, scope2, scope3, scope4, scope5]
+        //   [CallFrame1, CallFrame2]
</ins><span class="cx">         let scopeChain = callFrame.scopeChain;
</span><del>-        for (let scope of scopeChain) {
-            let title = null;
-            let extraPropertyDescriptor = null;
-            let collapsedByDefault = false;
</del><ins>+        let callFrames = WebInspector.debuggerManager.callFrames;
</ins><span class="cx"> 
</span><del>-            let count = sectionCountByType.get(scope.type);
-            sectionCountByType.set(scope.type, ++count);
</del><ins>+        // Group scopes with the call frame containing them.
+        // Creating a map that looks like:
+        //   CallFrame2 =&gt; [scope5, scope4]
+        //   CallFrame1 =&gt; [scope3, scope2, scope1]
+        let reversedScopeChain = scopeChain.slice().reverse();
+        let callFrameScopes = new Map;
+        let lastLength = 0;
+        for (let i = callFrames.length - 1; i &gt;= 0; --i) {
+            let nextCallFrame = callFrames[i];
+            console.assert(nextCallFrame.scopeChain.length &gt; lastLength);
+            callFrameScopes.set(nextCallFrame, reversedScopeChain.slice(lastLength, nextCallFrame.scopeChain.length));
+            lastLength = nextCallFrame.scopeChain.length;
+            if (nextCallFrame === callFrame) {
+                console.assert(lastLength === scopeChain.length);
+                break;
+            }
+        }
</ins><span class="cx"> 
</span><del>-            switch (scope.type) {
-                case WebInspector.ScopeChainNode.Type.Local:
-                    foundLocalScope = true;
-                    collapsedByDefault = false;
</del><ins>+        // Now that we have this map we can merge some of the scopes within an individual
+        // call frame. In particular, function call frames may have multiple top level
+        // closure scopes (one for `var`s one for `let`s) that can be combined to a
+        // single scope of variables.
+        // This modifies the Map, resulting in:
+        //   CallFrame2 =&gt; [scope4, scope5]
+        //   CallFrame1 =&gt; [scope1, scope2&amp;3]
+        for (let [currentCallFrame, scopes] of callFrameScopes) {
+            let firstClosureScope = null;
+            for (let scope of scopes) {
+                // Reached a non-closure scope. Bail.
+                let isClosureScope = scope.type === WebInspector.ScopeChainNode.Type.Closure;
+                if (!isClosureScope &amp;&amp; firstClosureScope)
+                    break;
</ins><span class="cx"> 
</span><del>-                    title = WebInspector.UIString(&quot;Local Variables&quot;);
</del><ins>+                // Found first closure scope. Mark it so we can provide the function name later in the UI.
+                if (isClosureScope &amp;&amp; !firstClosureScope) {
+                    firstClosureScope = scope;
+                    firstClosureScope[WebInspector.ScopeChainDetailsSidebarPanel.CallFrameBaseClosureScopeSymbol] = true;
+                    continue;
+                }
</ins><span class="cx"> 
</span><del>-                    if (callFrame.thisObject)
-                        extraPropertyDescriptor = new WebInspector.PropertyDescriptor({name: &quot;this&quot;, value: callFrame.thisObject});
-                    break;
</del><ins>+                // Found 2 sequential top level closure scopes. Merge and mark it so we can provide the function name later in the UI.
+                if (isClosureScope &amp;&amp; firstClosureScope) {
+                    let type = currentCallFrame === callFrame ? WebInspector.ScopeChainNode.Type.Local : WebInspector.ScopeChainNode.Type.Closure;
+                    let objects = firstClosureScope.objects.concat(scope.objects);
+                    let merged = new WebInspector.ScopeChainNode(type, objects);
+                    merged[WebInspector.ScopeChainDetailsSidebarPanel.CallFrameBaseClosureScopeSymbol] = true;
+                    console.assert(objects.length === 2);
</ins><span class="cx"> 
</span><del>-                case WebInspector.ScopeChainNode.Type.Block:
-                    title = WebInspector.UIString(&quot;Block Variables&quot;);
-                    collapsedByDefault = false;
</del><ins>+                    let index = scopes.indexOf(firstClosureScope);
+                    scopes.splice(index, 1); // Remove one of them.
+                    scopes[index] = merged; // Replace the remaining with the merged.
</ins><span class="cx">                     break;
</span><ins>+                }
+            }
+            scopes.reverse();
+        }
</ins><span class="cx"> 
</span><del>-                case WebInspector.ScopeChainNode.Type.Closure:
-                    title = WebInspector.UIString(&quot;Closure Variables&quot;);
-                    collapsedByDefault = false;
-                    break;
</del><ins>+        // Now we can walk the list of call frames and their scopes.
+        // We walk in top -&gt; down order:
+        //   CallFrame1 =&gt; [scope1, scope2&amp;3]
+        //   CallFrame2 =&gt; [scope5, scope4]
+        for (let [call, scopes] of [...callFrameScopes.entries()].reverse()) {
+            for (let scope of scopes) {
+                let title = null;
+                let extraPropertyDescriptor = null;
+                let collapsedByDefault = false;
</ins><span class="cx"> 
</span><del>-                case WebInspector.ScopeChainNode.Type.Catch:
-                    title = WebInspector.UIString(&quot;Catch Variables&quot;);
-                    collapsedByDefault = false;
-                    break;
</del><ins>+                let count = sectionCountByType.get(scope.type);
+                sectionCountByType.set(scope.type, ++count);
</ins><span class="cx"> 
</span><del>-                case WebInspector.ScopeChainNode.Type.FunctionName:
-                    title = WebInspector.UIString(&quot;Function Name Variable&quot;);
-                    collapsedByDefault = true;
-                    break;
</del><ins>+                switch (scope.type) {
+                    case WebInspector.ScopeChainNode.Type.Local:
+                        foundLocalScope = true;
+                        collapsedByDefault = false;
+                        title = WebInspector.UIString(&quot;Local Variables&quot;);
+                        if (call.thisObject)
+                            extraPropertyDescriptor = new WebInspector.PropertyDescriptor({name: &quot;this&quot;, value: call.thisObject});
+                        break;
</ins><span class="cx"> 
</span><del>-                case WebInspector.ScopeChainNode.Type.With:
-                    title = WebInspector.UIString(&quot;With Object Properties&quot;);
-                    collapsedByDefault = foundLocalScope;
-                    break;
</del><ins>+                    case WebInspector.ScopeChainNode.Type.Closure:
+                        if (scope[WebInspector.ScopeChainDetailsSidebarPanel.CallFrameBaseClosureScopeSymbol] &amp;&amp; call.functionName)
+                            title = WebInspector.UIString(&quot;Closure Variables (%s)&quot;).format(call.functionName);
+                        else
+                            title = WebInspector.UIString(&quot;Closure Variables&quot;);
+                        collapsedByDefault = false;
+                        break;
</ins><span class="cx"> 
</span><del>-                case WebInspector.ScopeChainNode.Type.Global:
-                    title = WebInspector.UIString(&quot;Global Variables&quot;);
-                    collapsedByDefault = true;
-                    break;
</del><ins>+                    case WebInspector.ScopeChainNode.Type.Block:
+                        title = WebInspector.UIString(&quot;Block Variables&quot;);
+                        collapsedByDefault = false;
+                        break;
</ins><span class="cx"> 
</span><del>-                case WebInspector.ScopeChainNode.Type.GlobalLexicalEnvironment:
-                    title = WebInspector.UIString(&quot;Global Lexical Environment&quot;);
-                    collapsedByDefault = true;
-                    break;
-            }
</del><ins>+                    case WebInspector.ScopeChainNode.Type.Catch:
+                        title = WebInspector.UIString(&quot;Catch Variables&quot;);
+                        collapsedByDefault = false;
+                        break;
</ins><span class="cx"> 
</span><del>-            let detailsSectionIdentifier = scope.type + &quot;-&quot; + sectionCountByType.get(scope.type);
</del><ins>+                    case WebInspector.ScopeChainNode.Type.FunctionName:
+                        title = WebInspector.UIString(&quot;Function Name Variable&quot;);
+                        collapsedByDefault = true;
+                        break;
</ins><span class="cx"> 
</span><del>-            let scopePropertyPath = WebInspector.PropertyPath.emptyPropertyPathForScope(scope.object);
-            let objectTree = new WebInspector.ObjectTreeView(scope.object, WebInspector.ObjectTreeView.Mode.Properties, scopePropertyPath);
</del><ins>+                    case WebInspector.ScopeChainNode.Type.With:
+                        title = WebInspector.UIString(&quot;With Object Properties&quot;);
+                        collapsedByDefault = foundLocalScope;
+                        break;
</ins><span class="cx"> 
</span><del>-            objectTree.showOnlyProperties();
</del><ins>+                    case WebInspector.ScopeChainNode.Type.Global:
+                        title = WebInspector.UIString(&quot;Global Variables&quot;);
+                        collapsedByDefault = true;
+                        break;
</ins><span class="cx"> 
</span><del>-            if (extraPropertyDescriptor)
-                objectTree.appendExtraPropertyDescriptor(extraPropertyDescriptor);
</del><ins>+                    case WebInspector.ScopeChainNode.Type.GlobalLexicalEnvironment:
+                        title = WebInspector.UIString(&quot;Global Lexical Environment&quot;);
+                        collapsedByDefault = true;
+                        break;
+                }
</ins><span class="cx"> 
</span><del>-            let treeOutline = objectTree.treeOutline;
-            treeOutline.addEventListener(WebInspector.TreeOutline.Event.ElementAdded, this._treeElementAdded.bind(this, detailsSectionIdentifier), this);
-            treeOutline.addEventListener(WebInspector.TreeOutline.Event.ElementDisclosureDidChanged, this._treeElementDisclosureDidChange.bind(this, detailsSectionIdentifier), this);
</del><ins>+                let detailsSectionIdentifier = scope.type + &quot;-&quot; + sectionCountByType.get(scope.type);
</ins><span class="cx"> 
</span><del>-            let detailsSection = new WebInspector.DetailsSection(detailsSectionIdentifier, title, null, null, collapsedByDefault);
-            detailsSection.groups[0].rows = [new WebInspector.DetailsSectionPropertiesRow(objectTree)];
-            detailsSections.push(detailsSection);
</del><ins>+                // FIXME: This just puts two ObjectTreeViews next to eachother, but that means
+                // that properties are not nicely sorted between the two separate lists.
+
+                let rows = [];
+                for (let object of scope.objects) {
+                    let scopePropertyPath = WebInspector.PropertyPath.emptyPropertyPathForScope(object);
+                    let objectTree = new WebInspector.ObjectTreeView(object, WebInspector.ObjectTreeView.Mode.Properties, scopePropertyPath);
+
+                    objectTree.showOnlyProperties();
+
+                    if (extraPropertyDescriptor) {
+                        objectTree.appendExtraPropertyDescriptor(extraPropertyDescriptor);
+                        extraPropertyDescriptor = null;
+                    }
+
+                    let treeOutline = objectTree.treeOutline;
+                    treeOutline.addEventListener(WebInspector.TreeOutline.Event.ElementAdded, this._treeElementAdded.bind(this, detailsSectionIdentifier), this);
+                    treeOutline.addEventListener(WebInspector.TreeOutline.Event.ElementDisclosureDidChanged, this._treeElementDisclosureDidChange.bind(this, detailsSectionIdentifier), this);
+
+                    rows.push(new WebInspector.DetailsSectionPropertiesRow(objectTree));
+                }
+
+                let detailsSection = new WebInspector.DetailsSection(detailsSectionIdentifier, title, null, null, collapsedByDefault);
+                detailsSection.groups[0].rows = rows;
+                detailsSections.push(detailsSection);
+            }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         return Promise.resolve(detailsSections);
</span><span class="lines">@@ -464,3 +544,4 @@
</span><span class="cx"> 
</span><span class="cx"> WebInspector.ScopeChainDetailsSidebarPanel._autoExpandProperties = new Set;
</span><span class="cx"> WebInspector.ScopeChainDetailsSidebarPanel.WatchExpressionsObjectGroupName = &quot;watch-expressions&quot;;
</span><ins>+WebInspector.ScopeChainDetailsSidebarPanel.CallFrameBaseClosureScopeSymbol = Symbol(&quot;scope-chain-call-frame-base-closure-scope&quot;);
</ins></span></pre>
</div>
</div>

</body>
</html>