<!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>[202566] 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/202566">202566</a></dd>
<dt>Author</dt> <dd>bburg@apple.com</dd>
<dt>Date</dt> <dd>2016-06-28 08:12:10 -0700 (Tue, 28 Jun 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: QuickConsole should update its selection when RuntimeManager.defaultExecutionContextIdentifier changes
https://bugs.webkit.org/show_bug.cgi?id=159183

Reviewed by Timothy Hatcher.

Source/WebInspectorUI:

Currently, the UI listens for state changes in the Frame tree to decide when to reset
the selected execution context back to its default value. This is no good, because this
should happen even if we have no UI (i.e., testing models only). The UI should simply
display changes to the model rather than driving them based on other model changes.

Move the logic to reset the execution context into RuntimeManager. When the selected
context changes, an event is fired which causes the QuickConsole to rebuild its path components.

* UserInterface/Controllers/RuntimeManager.js:
(WebInspector.RuntimeManager):
(WebInspector.RuntimeManager.prototype.set defaultExecutionContextIdentifier):
Fire an event when the execution context actually changes.

(WebInspector.RuntimeManager.prototype._frameExecutionContextsCleared):
Added. If the selected context was cleared, reset back to default.

* UserInterface/Models/Frame.js:
(WebInspector.Frame.prototype.clearExecutionContexts):
Include the contexts that were cleared so clients can match against them.

* UserInterface/Views/QuickConsole.js:
(WebInspector.QuickConsole):
Use the proper constant name. Both the old and new names evaluated to `undefined`.
No need to keep track of the selected path component, it will always match the
defaultExecutionContextIdentifier in RuntimeManager.

(WebInspector.QuickConsole.prototype.get selectedExecutionContextIdentifier):
(WebInspector.QuickConsole.prototype.set selectedExecutionContextIdentifier):
Forward to RuntimeManager. This name is less awkward for the UI code that manages selections.

(WebInspector.QuickConsole.prototype._executionContextPathComponentsToDisplay):
Special-case for the main frame execution context.

(WebInspector.QuickConsole.prototype._framePageExecutionContextsChanged):
Remove indirection.

(WebInspector.QuickConsole.prototype._frameExecutionContextsCleared):
Fix the guard to handle undefined execution contexts in the case where it represents the main frame (undefined).

(WebInspector.QuickConsole.prototype._defaultExecutionContextChanged):
Rebuild when the model changes.

(WebInspector.QuickConsole.prototype._pathComponentSelected): Simplify.
(WebInspector.QuickConsole.prototype.get executionContextIdentifier):
(WebInspector.QuickConsole.prototype._removeExecutionContextPathComponentForFrame):
Move the fallback selection behavior into RuntimeManager.

(WebInspector.QuickConsole.prototype._updateExecutionContextPathComponentForFrame): Deleted.
This has been dead code ever since we removed iOS 6 legacy support.

LayoutTests:

Add a new test case for reverting to the top-level execution context when the selected context is destroyed.

* inspector/runtime/change-execution-context-identifier-expected.txt:
* inspector/runtime/change-execution-context-identifier.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsinspectorruntimechangeexecutioncontextidentifierexpectedtxt">trunk/LayoutTests/inspector/runtime/change-execution-context-identifier-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorruntimechangeexecutioncontextidentifierhtml">trunk/LayoutTests/inspector/runtime/change-execution-context-identifier.html</a></li>
<li><a href="#trunkSourceWebInspectorUIChangeLog">trunk/Source/WebInspectorUI/ChangeLog</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceControllersRuntimeManagerjs">trunk/Source/WebInspectorUI/UserInterface/Controllers/RuntimeManager.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceModelsFramejs">trunk/Source/WebInspectorUI/UserInterface/Models/Frame.js</a></li>
<li><a href="#trunkSourceWebInspectorUIUserInterfaceViewsQuickConsolejs">trunk/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (202565 => 202566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-06-28 15:10:50 UTC (rev 202565)
+++ trunk/LayoutTests/ChangeLog        2016-06-28 15:12:10 UTC (rev 202566)
</span><span class="lines">@@ -1,3 +1,15 @@
</span><ins>+2016-06-28  Brian Burg  &lt;bburg@apple.com&gt;
+
+        Web Inspector: QuickConsole should update its selection when RuntimeManager.defaultExecutionContextIdentifier changes
+        https://bugs.webkit.org/show_bug.cgi?id=159183
+
+        Reviewed by Timothy Hatcher.
+
+        Add a new test case for reverting to the top-level execution context when the selected context is destroyed.
+
+        * inspector/runtime/change-execution-context-identifier-expected.txt:
+        * inspector/runtime/change-execution-context-identifier.html:
+
</ins><span class="cx"> 2016-06-28  Adam Bergkvist  &lt;adam.bergkvist@ericsson.com&gt;
</span><span class="cx"> 
</span><span class="cx">         WebRTC: Robustify 'this' type check in RTCPeerConnection JS built-ins
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorruntimechangeexecutioncontextidentifierexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/runtime/change-execution-context-identifier-expected.txt (202565 => 202566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/runtime/change-execution-context-identifier-expected.txt        2016-06-28 15:10:50 UTC (rev 202565)
+++ trunk/LayoutTests/inspector/runtime/change-execution-context-identifier-expected.txt        2016-06-28 15:12:10 UTC (rev 202566)
</span><span class="lines">@@ -1,4 +1,3 @@
</span><del>-
</del><span class="cx"> Test that RuntimeManager.evaluateInInspectedWindow respects the selected execution context.
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -19,3 +18,8 @@
</span><span class="cx"> Passphrase in selected frame: coldwater
</span><span class="cx"> PASS: The passphrase should match the phrase defined in the main frame.
</span><span class="cx"> 
</span><ins>+-- Running test case: ScriptExecutionContextRemoveSubframe
+PASS: The test page should only have one sub-frame.
+PASS: The test page should now have no sub-frames.
+PASS: When a selected non-top-level execution context is removed, the default execution context should revert to the top-level context.
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorruntimechangeexecutioncontextidentifierhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/runtime/change-execution-context-identifier.html (202565 => 202566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/runtime/change-execution-context-identifier.html        2016-06-28 15:10:50 UTC (rev 202565)
+++ trunk/LayoutTests/inspector/runtime/change-execution-context-identifier.html        2016-06-28 15:12:10 UTC (rev 202566)
</span><span class="lines">@@ -36,7 +36,7 @@
</span><span class="cx">         description: &quot;Test that evaluateInInspectedWindow works when defaultExecutionContextIdentifier is a subframe context.&quot;,
</span><span class="cx">         test: (resolve, reject) =&gt; {
</span><span class="cx">             let mainFrame = WebInspector.frameResourceManager.mainFrame;
</span><del>-            let subframes = WebInspector.frameResourceManager.frames.filter((frame) =&gt; frame != mainFrame);
</del><ins>+            let subframes = WebInspector.frameResourceManager.frames.filter((frame) =&gt; frame !== mainFrame);
</ins><span class="cx">             InspectorTest.expectThat(subframes.length === 1, &quot;The test page should only have one sub-frame.&quot;);
</span><span class="cx"> 
</span><span class="cx">             WebInspector.runtimeManager.defaultExecutionContextIdentifier = subframes[0].pageExecutionContext.id;
</span><span class="lines">@@ -63,12 +63,35 @@
</span><span class="cx">         }
</span><span class="cx">     });
</span><span class="cx"> 
</span><ins>+    suite.addTestCase({
+        name: &quot;ScriptExecutionContextRemoveSubframe&quot;,
+        description: &quot;Test that evaluateInInspectedWindow works when the defaultExecutionContextIdentifier is destroyed and reverts to the top-level context.&quot;,
+        test: (resolve, reject) =&gt; {
+            let mainFrame = WebInspector.frameResourceManager.mainFrame;
+            let subframes = WebInspector.frameResourceManager.frames.filter((frame) =&gt; frame !== mainFrame);
+            InspectorTest.expectThat(subframes.length === 1, &quot;The test page should only have one sub-frame.&quot;);
+
+            // Set the execution context to the subframe so we can switch away from it when the frame is detached.
+            WebInspector.runtimeManager.defaultExecutionContextIdentifier = subframes[0].pageExecutionContext.id;
+
+            // Force-override the contextId, otherwise we won't be able to access the iframe's DOM element when evaluating in the iframe execution context.
+            let expression = `document.getElementById(&quot;subframe&quot;).remove();`;
+            let objectGroup = &quot;test&quot;;
+            let contextId = WebInspector.RuntimeManager.TopLevelExecutionContextIdentifier;
+            RuntimeAgent.evaluate.invoke({expression, objectGroup, contextId}, () =&gt; {
+                InspectorTest.expectThat(WebInspector.frameResourceManager.frames.length === 1, &quot;The test page should now have no sub-frames.&quot;);
+                InspectorTest.expectThat(WebInspector.runtimeManager.defaultExecutionContextIdentifier === WebInspector.RuntimeManager.TopLevelExecutionContextIdentifier, &quot;When a selected non-top-level execution context is removed, the default execution context should revert to the top-level context.&quot;);
+                resolve();
+            });
+        }
+    });
+
</ins><span class="cx">     suite.runTestCasesAndFinish();
</span><span class="cx"> }
</span><span class="cx"> &lt;/script&gt;
</span><span class="cx"> &lt;/head&gt;
</span><span class="cx"> &lt;body&gt;
</span><del>-&lt;iframe src=&quot;resources/change-execution-context-identifier-subframe.html&quot; onload=&quot;runTest()&quot;&gt;&lt;/iframe&gt;
</del><ins>+&lt;iframe id=&quot;subframe&quot; src=&quot;resources/change-execution-context-identifier-subframe.html&quot; onload=&quot;runTest()&quot;&gt;&lt;/iframe&gt;
</ins><span class="cx"> &lt;p&gt;Test that RuntimeManager.evaluateInInspectedWindow respects the selected execution context.&lt;/p&gt;
</span><span class="cx"> &lt;/body&gt;
</span><span class="cx"> &lt;/html&gt;
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/ChangeLog (202565 => 202566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/ChangeLog        2016-06-28 15:10:50 UTC (rev 202565)
+++ trunk/Source/WebInspectorUI/ChangeLog        2016-06-28 15:12:10 UTC (rev 202566)
</span><span class="lines">@@ -1,3 +1,60 @@
</span><ins>+2016-06-28  Brian Burg  &lt;bburg@apple.com&gt;
+
+        Web Inspector: QuickConsole should update its selection when RuntimeManager.defaultExecutionContextIdentifier changes
+        https://bugs.webkit.org/show_bug.cgi?id=159183
+
+        Reviewed by Timothy Hatcher.
+
+        Currently, the UI listens for state changes in the Frame tree to decide when to reset
+        the selected execution context back to its default value. This is no good, because this
+        should happen even if we have no UI (i.e., testing models only). The UI should simply
+        display changes to the model rather than driving them based on other model changes.
+
+        Move the logic to reset the execution context into RuntimeManager. When the selected
+        context changes, an event is fired which causes the QuickConsole to rebuild its path components.
+
+        * UserInterface/Controllers/RuntimeManager.js:
+        (WebInspector.RuntimeManager):
+        (WebInspector.RuntimeManager.prototype.set defaultExecutionContextIdentifier):
+        Fire an event when the execution context actually changes.
+
+        (WebInspector.RuntimeManager.prototype._frameExecutionContextsCleared):
+        Added. If the selected context was cleared, reset back to default.
+
+        * UserInterface/Models/Frame.js:
+        (WebInspector.Frame.prototype.clearExecutionContexts):
+        Include the contexts that were cleared so clients can match against them.
+
+        * UserInterface/Views/QuickConsole.js:
+        (WebInspector.QuickConsole):
+        Use the proper constant name. Both the old and new names evaluated to `undefined`.
+        No need to keep track of the selected path component, it will always match the
+        defaultExecutionContextIdentifier in RuntimeManager.
+
+        (WebInspector.QuickConsole.prototype.get selectedExecutionContextIdentifier):
+        (WebInspector.QuickConsole.prototype.set selectedExecutionContextIdentifier):
+        Forward to RuntimeManager. This name is less awkward for the UI code that manages selections.
+
+        (WebInspector.QuickConsole.prototype._executionContextPathComponentsToDisplay):
+        Special-case for the main frame execution context.
+
+        (WebInspector.QuickConsole.prototype._framePageExecutionContextsChanged):
+        Remove indirection.
+
+        (WebInspector.QuickConsole.prototype._frameExecutionContextsCleared):
+        Fix the guard to handle undefined execution contexts in the case where it represents the main frame (undefined).
+
+        (WebInspector.QuickConsole.prototype._defaultExecutionContextChanged):
+        Rebuild when the model changes.
+
+        (WebInspector.QuickConsole.prototype._pathComponentSelected): Simplify.
+        (WebInspector.QuickConsole.prototype.get executionContextIdentifier):
+        (WebInspector.QuickConsole.prototype._removeExecutionContextPathComponentForFrame):
+        Move the fallback selection behavior into RuntimeManager.
+
+        (WebInspector.QuickConsole.prototype._updateExecutionContextPathComponentForFrame): Deleted.
+        This has been dead code ever since we removed iOS 6 legacy support.
+
</ins><span class="cx"> 2016-06-27  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Web Inspector: When modifying sessionStorage, localStorage gets updated
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceControllersRuntimeManagerjs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Controllers/RuntimeManager.js (202565 => 202566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Controllers/RuntimeManager.js        2016-06-28 15:10:50 UTC (rev 202565)
+++ trunk/Source/WebInspectorUI/UserInterface/Controllers/RuntimeManager.js        2016-06-28 15:12:10 UTC (rev 202566)
</span><span class="lines">@@ -31,6 +31,8 @@
</span><span class="cx"> 
</span><span class="cx">         // Enable the RuntimeAgent to receive notification of execution contexts.
</span><span class="cx">         RuntimeAgent.enable();
</span><ins>+
+        WebInspector.Frame.addEventListener(WebInspector.Frame.Event.ExecutionContextsCleared, this._frameExecutionContextsCleared, this);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Public
</span><span class="lines">@@ -124,13 +126,32 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     get defaultExecutionContextIdentifier() { return this._defaultExecutionContextIdentifier; }
</span><del>-    set defaultExecutionContextIdentifier(value) { this._defaultExecutionContextIdentifier = value; }
</del><ins>+    set defaultExecutionContextIdentifier(value)
+    {
+        if (this._defaultExecutionContextIdentifier === value)
+            return;
+
+        this._defaultExecutionContextIdentifier = value;
+        this.dispatchEventToListeners(WebInspector.RuntimeManager.Event.DefaultExecutionContextChanged);
+    }
+
+    // Private
+
+    _frameExecutionContextsCleared(event)
+    {
+        let contexts = event.data.contexts || [];
+
+        let currentContextWasDestroyed = contexts.some((context) =&gt; context.id === this._defaultExecutionContextIdentifier);
+        if (currentContextWasDestroyed)
+            this.defaultExecutionContextIdentifier = WebInspector.RuntimeManager.TopLevelExecutionContextIdentifier;
+    }
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> WebInspector.RuntimeManager.TopLevelExecutionContextIdentifier = undefined;
</span><span class="cx"> 
</span><span class="cx"> WebInspector.RuntimeManager.Event = {
</span><del>-    DidEvaluate: &quot;runtime-manager-did-evaluate&quot;
</del><ins>+    DidEvaluate: Symbol(&quot;runtime-manager-did-evaluate&quot;),
+    DefaultExecutionContextChanged: Symbol(&quot;runtime-manager-default-execution-context-changed&quot;),
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> WebInspector.RuntimeManager.ConsoleObjectGroup = &quot;console&quot;;
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceModelsFramejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Models/Frame.js (202565 => 202566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Models/Frame.js        2016-06-28 15:10:50 UTC (rev 202565)
+++ trunk/Source/WebInspectorUI/UserInterface/Models/Frame.js        2016-06-28 15:12:10 UTC (rev 202566)
</span><span class="lines">@@ -206,8 +206,9 @@
</span><span class="cx">     clearExecutionContexts(committingProvisionalLoad)
</span><span class="cx">     {
</span><span class="cx">         if (this._executionContextList.contexts.length) {
</span><ins>+            let contexts = this._executionContextList.contexts.slice();
</ins><span class="cx">             this._executionContextList.clear();
</span><del>-            this.dispatchEventToListeners(WebInspector.Frame.Event.ExecutionContextsCleared, {committingProvisionalLoad:!!committingProvisionalLoad});
</del><ins>+            this.dispatchEventToListeners(WebInspector.Frame.Event.ExecutionContextsCleared, {committingProvisionalLoad:!!committingProvisionalLoad, contexts});
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebInspectorUIUserInterfaceViewsQuickConsolejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js (202565 => 202566)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js        2016-06-28 15:10:50 UTC (rev 202565)
+++ trunk/Source/WebInspectorUI/UserInterface/Views/QuickConsole.js        2016-06-28 15:12:10 UTC (rev 202566)
</span><span class="lines">@@ -1,5 +1,5 @@
</span><span class="cx"> /*
</span><del>- * Copyright (C) 2013, 2015 Apple Inc. All rights reserved.
</del><ins>+ * Copyright (C) 2013, 2015, 2016 Apple Inc. All rights reserved.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -31,9 +31,8 @@
</span><span class="cx"> 
</span><span class="cx">         this._toggleOrFocusKeyboardShortcut = new WebInspector.KeyboardShortcut(null, WebInspector.KeyboardShortcut.Key.Escape, this._toggleOrFocus.bind(this));
</span><span class="cx"> 
</span><del>-        var mainFrameExecutionContext = new WebInspector.ExecutionContext(WebInspector.QuickConsole.MainFrameContextExecutionIdentifier, WebInspector.UIString(&quot;Main Frame&quot;), true, null);
</del><ins>+        let mainFrameExecutionContext = new WebInspector.ExecutionContext(WebInspector.RuntimeManager.TopLevelContextExecutionIdentifier, WebInspector.UIString(&quot;Main Frame&quot;), true, null);
</ins><span class="cx">         this._mainFrameExecutionContextPathComponent = this._createExecutionContextPathComponent(mainFrameExecutionContext.name, mainFrameExecutionContext.identifier);
</span><del>-        this._selectedExecutionContextPathComponent = this._mainFrameExecutionContextPathComponent;
</del><span class="cx"> 
</span><span class="cx">         this._otherExecutionContextPathComponents = [];
</span><span class="cx">         this._frameIdentifierToExecutionContextPathComponentMap = {};
</span><span class="lines">@@ -70,6 +69,8 @@
</span><span class="cx">         WebInspector.Frame.addEventListener(WebInspector.Frame.Event.ExecutionContextsCleared, this._frameExecutionContextsCleared, this);
</span><span class="cx"> 
</span><span class="cx">         WebInspector.debuggerManager.addEventListener(WebInspector.DebuggerManager.Event.ActiveCallFrameDidChange, this._debuggerActiveCallFrameDidChange, this);
</span><ins>+
+        WebInspector.runtimeManager.addEventListener(WebInspector.RuntimeManager.Event.DefaultExecutionContextChanged, this._defaultExecutionContextChanged, this);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // Public
</span><span class="lines">@@ -79,11 +80,19 @@
</span><span class="cx">         return this._navigationBar;
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    get executionContextIdentifier()
</del><ins>+    get selectedExecutionContextIdentifier()
</ins><span class="cx">     {
</span><del>-        return this._selectedExecutionContextPathComponent._executionContextIdentifier;
</del><ins>+        return WebInspector.runtimeManager.defaultExecutionContextIdentifier;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    set selectedExecutionContextIdentifier(value)
+    {
+        if (value === this.selectedExecutionContextIdentifier)
+            return;
+
+        WebInspector.runtimeManager.defaultExecutionContextIdentifier = value;
+    }
+
</ins><span class="cx">     consoleLogVisibilityChanged(visible)
</span><span class="cx">     {
</span><span class="cx">         if (visible === this.element.classList.contains(WebInspector.QuickConsole.ShowingLogClassName))
</span><span class="lines">@@ -124,7 +133,10 @@
</span><span class="cx">         if (!this._otherExecutionContextPathComponents.length)
</span><span class="cx">             return [];
</span><span class="cx"> 
</span><del>-        return [this._selectedExecutionContextPathComponent];
</del><ins>+        if (this.selectedExecutionContextIdentifier === this._mainFrameExecutionContextPathComponent._executionContextIdentifier)
+            return [this._mainFrameExecutionContextPathComponent];
+
+        return this._otherExecutionContextPathComponents.filter((component) =&gt; component._executionContextIdentifier === this.selectedExecutionContextIdentifier);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     _rebuildExecutionContextPathComponents()
</span><span class="lines">@@ -147,24 +159,22 @@
</span><span class="cx">         var newExecutionContextPathComponent = this._insertExecutionContextPathComponentForFrame(frame, shouldAutomaticallySelect);
</span><span class="cx"> 
</span><span class="cx">         if (shouldAutomaticallySelect) {
</span><del>-            delete this._restoreSelectedExecutionContextForFrame;
-            this._selectedExecutionContextPathComponent = newExecutionContextPathComponent;
-            WebInspector.runtimeManager.defaultExecutionContextIdentifier = this.executionContextIdentifier;
-            this._rebuildExecutionContextPathComponents();
</del><ins>+            this._restoreSelectedExecutionContextForFrame = null;
+            this.selectedExecutionContextIdentifier = newExecutionContextPathComponent._executionContextIdentifier;
</ins><span class="cx">         }
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     _frameExecutionContextsCleared(event)
</span><span class="cx">     {
</span><del>-        var frame = event.target;
</del><ins>+        let frame = event.target;
</ins><span class="cx"> 
</span><span class="cx">         // If this frame is navigating and it is selected in the UI we want to reselect its new item after navigation.
</span><span class="cx">         if (event.data.committingProvisionalLoad &amp;&amp; !this._restoreSelectedExecutionContextForFrame) {
</span><del>-            var executionContextPathComponent = this._frameIdentifierToExecutionContextPathComponentMap[frame.id];
-            if (this._selectedExecutionContextPathComponent === executionContextPathComponent) {
</del><ins>+            let executionContextPathComponent = this._frameIdentifierToExecutionContextPathComponentMap[frame.id];
+            if (executionContextPathComponent &amp;&amp; executionContextPathComponent._executionContextIdentifier === this.selectedExecutionContextIdentifier) {
</ins><span class="cx">                 this._restoreSelectedExecutionContextForFrame = frame;
</span><span class="cx">                 // As a fail safe, if the frame never gets an execution context, clear the restore value.
</span><del>-                setTimeout(function() { delete this._restoreSelectedExecutionContextForFrame; }.bind(this), 10);
</del><ins>+                setTimeout(() =&gt; { this._restoreSelectedExecutionContextForFrame = false; }, 10);
</ins><span class="cx">             }
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -171,6 +181,11 @@
</span><span class="cx">         this._removeExecutionContextPathComponentForFrame(frame);
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    _defaultExecutionContextChanged(event)
+    {
+        this._rebuildExecutionContextPathComponents();
+    }
+
</ins><span class="cx">     _createExecutionContextPathComponent(name, identifier)
</span><span class="cx">     {
</span><span class="cx">         var pathComponent = new WebInspector.HierarchicalPathComponent(name, &quot;execution-context&quot;, identifier, true, true);
</span><span class="lines">@@ -261,11 +276,6 @@
</span><span class="cx">         if (next)
</span><span class="cx">             next.previousSibling = prev;
</span><span class="cx"> 
</span><del>-        if (this._selectedExecutionContextPathComponent === executionContextPathComponent) {
-            this._selectedExecutionContextPathComponent = this._mainFrameExecutionContextPathComponent;
-            WebInspector.runtimeManager.defaultExecutionContextIdentifier = this.executionContextIdentifier;
-        }
-
</del><span class="cx">         this._otherExecutionContextPathComponents.remove(executionContextPathComponent, true);
</span><span class="cx">         delete this._frameIdentifierToExecutionContextPathComponentMap[frame.id];
</span><span class="cx"> 
</span><span class="lines">@@ -273,37 +283,9 @@
</span><span class="cx">             this._rebuildExecutionContextPathComponents();
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    _updateExecutionContextPathComponentForFrame(frame)
-    {
-        if (frame.isMainFrame())
-            return;
-
-        var executionContextPathComponent = this._frameIdentifierToExecutionContextPathComponentMap[frame.id];
-        if (!executionContextPathComponent)
-            return;
-
-        var wasSelected = this._selectedExecutionContextPathComponent === executionContextPathComponent;
-
-        this._removeExecutionContextPathComponentForFrame(frame, true);
-        var newExecutionContextPathComponent = this._insertExecutionContextPathComponentForFrame(frame, true);
-
-        if (wasSelected) {
-            this._selectedExecutionContextPathComponent = newExecutionContextPathComponent;
-            WebInspector.runtimeManager.defaultExecutionContextIdentifier = this.executionContextIdentifier;
-        }
-
-        this._rebuildExecutionContextPathComponents();
-    }
-
</del><span class="cx">     _pathComponentSelected(event)
</span><span class="cx">     {
</span><del>-        if (event.data.pathComponent === this._selectedExecutionContextPathComponent)
-            return;
-
-        this._selectedExecutionContextPathComponent = event.data.pathComponent;
-        WebInspector.runtimeManager.defaultExecutionContextIdentifier = this.executionContextIdentifier;
-
-        this._rebuildExecutionContextPathComponents();
</del><ins>+        this.selectedExecutionContextIdentifier = event.data.pathComponent._executionContextIdentifier;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     _pathComponentClicked(event)
</span></span></pre>
</div>
</div>

</body>
</html>