<!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>[164151] trunk/Source/JavaScriptCore</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/164151">164151</a></dd>
<dt>Author</dt> <dd>joepeck@webkit.org</dd>
<dt>Date</dt> <dd>2014-02-14 19:06:46 -0800 (Fri, 14 Feb 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: CRASH when debugger closes while paused and remote inspecting a JSContext
https://bugs.webkit.org/show_bug.cgi?id=127757

Reviewed by Timothy Hatcher.

The problem was that the lifetime of the InspectorController and all agents
was tied to the remote inspector session. So, if a remote inspector was
disconnected while in the nested run loop, everything would get torn
down and when execution continued out of the nested runloop we would be
back in the original call stack of destroyed objects.

This patch changes the lifetime of the InspectorController and agents to
the JSGlobalObject. This way the agents are always alive, just the
frontend and backend channels are destroyed and recreated each remote
inspector session. This matches the agent lifetime for WebCore agents.
We can also later take advantage of the agents being alive before
and between inspector debug sessions to stash exception messages to
pass on to a debugger if a debugger is connected later.

* inspector/JSGlobalObjectInspectorController.h:
* inspector/JSGlobalObjectInspectorController.cpp:
(Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController):
Cleaner initialization of agents. Easier to follow.

(Inspector::JSGlobalObjectInspectorController::disconnectFrontend):
Move InjectedScript disconnection only once the global object is destroyed.
This way if a developer has attached once and included an injected script,
we will keep it around with any state it might want to remember until
the global object is destroyed.

(Inspector::JSGlobalObjectInspectorController::globalObjectDestroyed):
Disconnect agents and injected scripts when the global object is destroyed.

* inspector/InjectedScriptManager.cpp:
(Inspector::InjectedScriptManager::disconnect):
Now that the injected script manager is reused between remote
inspector sessions, don't clear the pointer on disconnect calls.
We now only call this once when the global object is getting
destroyed anyways so it doesn't matter. But if we wanted to call
disconnect multiple times, e.g. once per session, we could.

* inspector/ScriptDebugServer.cpp:
(Inspector::ScriptDebugServer::dispatchFunctionToListeners):
If the only listener was removed during the nested runloop, then when
we dispatch an event after the nested runloop the listener list will
be empty. Instead of asserting, just pass by an empty list.

* runtime/JSGlobalObject.h:
(JSC::JSGlobalObject::inspectorController):
Tie the inspector controller lifetime to the JSGlobalObject.

* runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::~JSGlobalObject):
(JSC::JSGlobalObject::init):
Create the inspector controller, and eagerly signal teardown
in destruction.

* runtime/JSGlobalObjectDebuggable.h:
* runtime/JSGlobalObjectDebuggable.cpp:
(JSC::JSGlobalObjectDebuggable::connect):
(JSC::JSGlobalObjectDebuggable::disconnect):
(JSC::JSGlobalObjectDebuggable::dispatchMessageFromRemoteFrontend):
Simplify by using the inspector controller on JSGlobalObject.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorInjectedScriptManagercpp">trunk/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorJSGlobalObjectInspectorControllercpp">trunk/Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorJSGlobalObjectInspectorControllerh">trunk/Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorScriptDebugServercpp">trunk/Source/JavaScriptCore/inspector/ScriptDebugServer.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjectcpp">trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjecth">trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjectDebuggablecpp">trunk/Source/JavaScriptCore/runtime/JSGlobalObjectDebuggable.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreruntimeJSGlobalObjectDebuggableh">trunk/Source/JavaScriptCore/runtime/JSGlobalObjectDebuggable.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (164150 => 164151)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2014-02-15 02:52:32 UTC (rev 164150)
+++ trunk/Source/JavaScriptCore/ChangeLog        2014-02-15 03:06:46 UTC (rev 164151)
</span><span class="lines">@@ -1,3 +1,69 @@
</span><ins>+2014-02-14  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+        Web Inspector: CRASH when debugger closes while paused and remote inspecting a JSContext
+        https://bugs.webkit.org/show_bug.cgi?id=127757
+
+        Reviewed by Timothy Hatcher.
+
+        The problem was that the lifetime of the InspectorController and all agents
+        was tied to the remote inspector session. So, if a remote inspector was
+        disconnected while in the nested run loop, everything would get torn
+        down and when execution continued out of the nested runloop we would be
+        back in the original call stack of destroyed objects.
+
+        This patch changes the lifetime of the InspectorController and agents to
+        the JSGlobalObject. This way the agents are always alive, just the
+        frontend and backend channels are destroyed and recreated each remote
+        inspector session. This matches the agent lifetime for WebCore agents.
+        We can also later take advantage of the agents being alive before
+        and between inspector debug sessions to stash exception messages to
+        pass on to a debugger if a debugger is connected later.
+
+        * inspector/JSGlobalObjectInspectorController.h:
+        * inspector/JSGlobalObjectInspectorController.cpp:
+        (Inspector::JSGlobalObjectInspectorController::JSGlobalObjectInspectorController):
+        Cleaner initialization of agents. Easier to follow.
+
+        (Inspector::JSGlobalObjectInspectorController::disconnectFrontend):
+        Move InjectedScript disconnection only once the global object is destroyed.
+        This way if a developer has attached once and included an injected script,
+        we will keep it around with any state it might want to remember until
+        the global object is destroyed.
+
+        (Inspector::JSGlobalObjectInspectorController::globalObjectDestroyed):
+        Disconnect agents and injected scripts when the global object is destroyed.
+
+        * inspector/InjectedScriptManager.cpp:
+        (Inspector::InjectedScriptManager::disconnect):
+        Now that the injected script manager is reused between remote
+        inspector sessions, don't clear the pointer on disconnect calls.
+        We now only call this once when the global object is getting
+        destroyed anyways so it doesn't matter. But if we wanted to call
+        disconnect multiple times, e.g. once per session, we could.
+
+        * inspector/ScriptDebugServer.cpp:
+        (Inspector::ScriptDebugServer::dispatchFunctionToListeners):
+        If the only listener was removed during the nested runloop, then when
+        we dispatch an event after the nested runloop the listener list will
+        be empty. Instead of asserting, just pass by an empty list.
+
+        * runtime/JSGlobalObject.h:
+        (JSC::JSGlobalObject::inspectorController):
+        Tie the inspector controller lifetime to the JSGlobalObject.
+
+        * runtime/JSGlobalObject.cpp:
+        (JSC::JSGlobalObject::~JSGlobalObject):
+        (JSC::JSGlobalObject::init):
+        Create the inspector controller, and eagerly signal teardown
+        in destruction.
+
+        * runtime/JSGlobalObjectDebuggable.h:
+        * runtime/JSGlobalObjectDebuggable.cpp:
+        (JSC::JSGlobalObjectDebuggable::connect):
+        (JSC::JSGlobalObjectDebuggable::disconnect):
+        (JSC::JSGlobalObjectDebuggable::dispatchMessageFromRemoteFrontend):
+        Simplify by using the inspector controller on JSGlobalObject.
+
</ins><span class="cx"> 2014-02-14  Mark Hahnenberg  &lt;mhahnenberg@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         -[JSManagedValue value] needs to be protected by the API lock
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorInjectedScriptManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp (164150 => 164151)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp        2014-02-15 02:52:32 UTC (rev 164150)
+++ trunk/Source/JavaScriptCore/inspector/InjectedScriptManager.cpp        2014-02-15 03:06:46 UTC (rev 164151)
</span><span class="lines">@@ -60,7 +60,6 @@
</span><span class="cx"> void InjectedScriptManager::disconnect()
</span><span class="cx"> {
</span><span class="cx">     discardInjectedScripts();
</span><del>-    m_injectedScriptHost = nullptr;
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> InjectedScriptHost* InjectedScriptManager::injectedScriptHost()
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorJSGlobalObjectInspectorControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.cpp (164150 => 164151)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.cpp        2014-02-15 02:52:32 UTC (rev 164150)
+++ trunk/Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.cpp        2014-02-15 03:06:46 UTC (rev 164151)
</span><span class="lines">@@ -48,21 +48,16 @@
</span><span class="cx">     , m_injectedScriptManager(std::make_unique&lt;InjectedScriptManager&gt;(*this, InjectedScriptHost::create()))
</span><span class="cx">     , m_inspectorFrontendChannel(nullptr)
</span><span class="cx"> {
</span><del>-    m_agents.append(std::make_unique&lt;InspectorAgent&gt;());
</del><ins>+    auto runtimeAgent = std::make_unique&lt;JSGlobalObjectRuntimeAgent&gt;(m_injectedScriptManager.get(), m_globalObject);
+    auto consoleAgent = std::make_unique&lt;JSGlobalObjectConsoleAgent&gt;(m_injectedScriptManager.get());
+    auto debuggerAgent = std::make_unique&lt;JSGlobalObjectDebuggerAgent&gt;(m_injectedScriptManager.get(), m_globalObject, consoleAgent.get());
</ins><span class="cx"> 
</span><del>-    auto runtimeAgentPtr = std::make_unique&lt;JSGlobalObjectRuntimeAgent&gt;(m_injectedScriptManager.get(), m_globalObject);
-    InspectorRuntimeAgent* runtimeAgent = runtimeAgentPtr.get();
-    m_agents.append(std::move(runtimeAgentPtr));
</del><ins>+    runtimeAgent-&gt;setScriptDebugServer(&amp;debuggerAgent-&gt;scriptDebugServer());
</ins><span class="cx"> 
</span><del>-    auto consoleAgentPtr = std::make_unique&lt;JSGlobalObjectConsoleAgent&gt;(m_injectedScriptManager.get());
-    InspectorConsoleAgent* consoleAgent = consoleAgentPtr.get();
-    m_agents.append(std::move(consoleAgentPtr));
-
-    auto debuggerAgentPtr = std::make_unique&lt;JSGlobalObjectDebuggerAgent&gt;(m_injectedScriptManager.get(), m_globalObject, consoleAgent);
-    InspectorDebuggerAgent* debuggerAgent = debuggerAgentPtr.get();
-    m_agents.append(std::move(debuggerAgentPtr));
-
-    runtimeAgent-&gt;setScriptDebugServer(&amp;debuggerAgent-&gt;scriptDebugServer());
</del><ins>+    m_agents.append(std::make_unique&lt;InspectorAgent&gt;());
+    m_agents.append(std::move(runtimeAgent));
+    m_agents.append(std::move(consoleAgent));
+    m_agents.append(std::move(debuggerAgent));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> JSGlobalObjectInspectorController::~JSGlobalObjectInspectorController()
</span><span class="lines">@@ -70,6 +65,13 @@
</span><span class="cx">     m_agents.discardAgents();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void JSGlobalObjectInspectorController::globalObjectDestroyed()
+{
+    disconnectFrontend(InspectorDisconnectReason::InspectedTargetDestroyed);
+
+    m_injectedScriptManager-&gt;disconnect();
+}
+
</ins><span class="cx"> void JSGlobalObjectInspectorController::connectFrontend(InspectorFrontendChannel* frontendChannel)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!m_inspectorFrontendChannel);
</span><span class="lines">@@ -91,8 +93,6 @@
</span><span class="cx">     m_inspectorBackendDispatcher-&gt;clearFrontend();
</span><span class="cx">     m_inspectorBackendDispatcher.clear();
</span><span class="cx">     m_inspectorFrontendChannel = nullptr;
</span><del>-
-    m_injectedScriptManager-&gt;disconnect();
</del><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void JSGlobalObjectInspectorController::dispatchMessageFromFrontend(const String&amp; message)
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorJSGlobalObjectInspectorControllerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.h (164150 => 164151)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.h        2014-02-15 02:52:32 UTC (rev 164150)
+++ trunk/Source/JavaScriptCore/inspector/JSGlobalObjectInspectorController.h        2014-02-15 03:06:46 UTC (rev 164151)
</span><span class="lines">@@ -56,6 +56,8 @@
</span><span class="cx">     void disconnectFrontend(InspectorDisconnectReason reason);
</span><span class="cx">     void dispatchMessageFromFrontend(const String&amp;);
</span><span class="cx"> 
</span><ins>+    void globalObjectDestroyed();
+
</ins><span class="cx">     virtual bool developerExtrasEnabled() const override { return true; }
</span><span class="cx">     virtual bool canAccessInspectedScriptState(JSC::ExecState*) const override { return true; }
</span><span class="cx">     virtual InspectorFunctionCallHandler functionCallHandler() const override;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorScriptDebugServercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/ScriptDebugServer.cpp (164150 => 164151)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/ScriptDebugServer.cpp        2014-02-15 02:52:32 UTC (rev 164150)
+++ trunk/Source/JavaScriptCore/inspector/ScriptDebugServer.cpp        2014-02-15 03:06:46 UTC (rev 164151)
</span><span class="lines">@@ -279,8 +279,8 @@
</span><span class="cx">     TemporaryChange&lt;bool&gt; change(m_callingListeners, true);
</span><span class="cx"> 
</span><span class="cx">     if (ListenerSet* listeners = getListenersForGlobalObject(globalObject)) {
</span><del>-        ASSERT(!listeners-&gt;isEmpty());
-        dispatchFunctionToListeners(*listeners, callback);
</del><ins>+        if (!listeners-&gt;isEmpty())
+            dispatchFunctionToListeners(*listeners, callback);
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp (164150 => 164151)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp        2014-02-15 02:52:32 UTC (rev 164150)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp        2014-02-15 03:06:46 UTC (rev 164151)
</span><span class="lines">@@ -7,13 +7,13 @@
</span><span class="cx">  * are met:
</span><span class="cx">  *
</span><span class="cx">  * 1.  Redistributions of source code must retain the above copyright
</span><del>- *     notice, this list of conditions and the following disclaimer. 
</del><ins>+ *     notice, this list of conditions and the following disclaimer.
</ins><span class="cx">  * 2.  Redistributions in binary form must reproduce the above copyright
</span><span class="cx">  *     notice, this list of conditions and the following disclaimer in the
</span><del>- *     documentation and/or other materials provided with the distribution. 
</del><ins>+ *     documentation and/or other materials provided with the distribution.
</ins><span class="cx">  * 3.  Neither the name of Apple Computer, Inc. (&quot;Apple&quot;) nor the names of
</span><span class="cx">  *     its contributors may be used to endorse or promote products derived
</span><del>- *     from this software without specific prior written permission. 
</del><ins>+ *     from this software without specific prior written permission.
</ins><span class="cx">  *
</span><span class="cx">  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS &quot;AS IS&quot; AND ANY
</span><span class="cx">  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
</span><span class="lines">@@ -60,6 +60,7 @@
</span><span class="cx"> #include &quot;JSArrayBufferPrototype.h&quot;
</span><span class="cx"> #include &quot;JSArrayIterator.h&quot;
</span><span class="cx"> #include &quot;JSBoundFunction.h&quot;
</span><ins>+#include &quot;JSCInlines.h&quot;
</ins><span class="cx"> #include &quot;JSCallbackConstructor.h&quot;
</span><span class="cx"> #include &quot;JSCallbackFunction.h&quot;
</span><span class="cx"> #include &quot;JSCallbackObject.h&quot;
</span><span class="lines">@@ -100,7 +101,6 @@
</span><span class="cx"> #include &quot;ObjCCallbackFunction.h&quot;
</span><span class="cx"> #include &quot;ObjectConstructor.h&quot;
</span><span class="cx"> #include &quot;ObjectPrototype.h&quot;
</span><del>-#include &quot;JSCInlines.h&quot;
</del><span class="cx"> #include &quot;ParserError.h&quot;
</span><span class="cx"> #include &quot;RegExpConstructor.h&quot;
</span><span class="cx"> #include &quot;RegExpMatchesArray.h&quot;
</span><span class="lines">@@ -124,7 +124,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(REMOTE_INSPECTOR)
</span><span class="cx"> #include &quot;JSGlobalObjectDebuggable.h&quot;
</span><del>-#include &quot;RemoteInspector.h&quot;
</del><ins>+#include &quot;JSGlobalObjectInspectorController.h&quot;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(WEB_REPLAY)
</span><span class="lines">@@ -171,6 +171,10 @@
</span><span class="cx"> 
</span><span class="cx"> JSGlobalObject::~JSGlobalObject()
</span><span class="cx"> {
</span><ins>+#if ENABLE(REMOTE_INSPECTOR)
+    m_inspectorController-&gt;globalObjectDestroyed();
+#endif
+
</ins><span class="cx">     if (m_debugger)
</span><span class="cx">         m_debugger-&gt;detach(this, Debugger::GlobalObjectIsDestructing);
</span><span class="cx"> 
</span><span class="lines">@@ -184,7 +188,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void JSGlobalObject::setGlobalThis(VM&amp; vm, JSObject* globalThis)
</span><del>-{ 
</del><ins>+{
</ins><span class="cx">     m_globalThis.set(vm, this, globalThis);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -198,6 +202,7 @@
</span><span class="cx">     m_debugger = 0;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(REMOTE_INSPECTOR)
</span><ins>+    m_inspectorController = std::make_unique&lt;Inspector::JSGlobalObjectInspectorController&gt;(*this);
</ins><span class="cx">     m_inspectorDebuggable = std::make_unique&lt;JSGlobalObjectDebuggable&gt;(*this);
</span><span class="cx">     m_inspectorDebuggable-&gt;init();
</span><span class="cx">     m_inspectorDebuggable-&gt;setRemoteDebuggingAllowed(true);
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjecth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h (164150 => 164151)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h        2014-02-15 02:52:32 UTC (rev 164150)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h        2014-02-15 03:06:46 UTC (rev 164151)
</span><span class="lines">@@ -46,6 +46,10 @@
</span><span class="cx"> struct OpaqueJSClass;
</span><span class="cx"> struct OpaqueJSClassContextData;
</span><span class="cx"> 
</span><ins>+namespace Inspector {
+class JSGlobalObjectInspectorController;
+}
+
</ins><span class="cx"> namespace JSC {
</span><span class="cx"> 
</span><span class="cx"> class ArrayPrototype;
</span><span class="lines">@@ -233,6 +237,7 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(REMOTE_INSPECTOR)
</span><ins>+    std::unique_ptr&lt;Inspector::JSGlobalObjectInspectorController&gt; m_inspectorController;
</ins><span class="cx">     std::unique_ptr&lt;JSGlobalObjectDebuggable&gt; m_inspectorDebuggable;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="lines">@@ -430,6 +435,10 @@
</span><span class="cx">     InputCursor&amp; inputCursor() const { return *m_inputCursor; }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>+#if ENABLE(REMOTE_INSPECTOR)
+    Inspector::JSGlobalObjectInspectorController&amp; inspectorController() const { return *m_inspectorController.get(); }
+#endif
+
</ins><span class="cx">     void setName(const String&amp;);
</span><span class="cx">     const String&amp; name() const { return m_name; }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjectDebuggablecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObjectDebuggable.cpp (164150 => 164151)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObjectDebuggable.cpp        2014-02-15 02:52:32 UTC (rev 164150)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObjectDebuggable.cpp        2014-02-15 03:06:46 UTC (rev 164151)
</span><span class="lines">@@ -43,12 +43,6 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-JSGlobalObjectDebuggable::~JSGlobalObjectDebuggable()
-{
-    if (m_inspectorController)
-        disconnectInternal(InspectorDisconnectReason::InspectedTargetDestroyed);
-}
-
</del><span class="cx"> String JSGlobalObjectDebuggable::name() const
</span><span class="cx"> {
</span><span class="cx">     String name = m_globalObject.name();
</span><span class="lines">@@ -59,29 +53,21 @@
</span><span class="cx"> {
</span><span class="cx">     APIEntryShim entryShim(&amp;m_globalObject.vm());
</span><span class="cx"> 
</span><del>-    ASSERT(!m_inspectorController);
-    m_inspectorController = std::make_unique&lt;Inspector::JSGlobalObjectInspectorController&gt;(m_globalObject);
-    m_inspectorController-&gt;connectFrontend(frontendChannel);
</del><ins>+    m_globalObject.inspectorController().connectFrontend(frontendChannel);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void JSGlobalObjectDebuggable::disconnect()
</span><span class="cx"> {
</span><del>-    disconnectInternal(InspectorDisconnectReason::InspectorDestroyed);
-}
-
-void JSGlobalObjectDebuggable::disconnectInternal(InspectorDisconnectReason reason)
-{
</del><span class="cx">     APIEntryShim entryShim(&amp;m_globalObject.vm());
</span><span class="cx"> 
</span><del>-    m_inspectorController-&gt;disconnectFrontend(reason);
-    m_inspectorController = nullptr;
</del><ins>+    m_globalObject.inspectorController().disconnectFrontend(InspectorDisconnectReason::InspectorDestroyed);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void JSGlobalObjectDebuggable::dispatchMessageFromRemoteFrontend(const String&amp; message)
</span><span class="cx"> {
</span><span class="cx">     APIEntryShim entryShim(&amp;m_globalObject.vm());
</span><span class="cx"> 
</span><del>-    m_inspectorController-&gt;dispatchMessageFromFrontend(message);
</del><ins>+    m_globalObject.inspectorController().dispatchMessageFromFrontend(message);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> } // namespace JSC
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreruntimeJSGlobalObjectDebuggableh"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/runtime/JSGlobalObjectDebuggable.h (164150 => 164151)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/runtime/JSGlobalObjectDebuggable.h        2014-02-15 02:52:32 UTC (rev 164150)
+++ trunk/Source/JavaScriptCore/runtime/JSGlobalObjectDebuggable.h        2014-02-15 03:06:46 UTC (rev 164151)
</span><span class="lines">@@ -44,7 +44,7 @@
</span><span class="cx">     WTF_MAKE_NONCOPYABLE(JSGlobalObjectDebuggable);
</span><span class="cx"> public:
</span><span class="cx">     JSGlobalObjectDebuggable(JSGlobalObject&amp;);
</span><del>-    ~JSGlobalObjectDebuggable();
</del><ins>+    ~JSGlobalObjectDebuggable() { }
</ins><span class="cx"> 
</span><span class="cx">     virtual Inspector::RemoteInspectorDebuggable::DebuggableType type() const override { return Inspector::RemoteInspectorDebuggable::JavaScript; }
</span><span class="cx"> 
</span><span class="lines">@@ -56,10 +56,7 @@
</span><span class="cx">     virtual void dispatchMessageFromRemoteFrontend(const String&amp; message) override;
</span><span class="cx"> 
</span><span class="cx"> private:
</span><del>-    void disconnectInternal(Inspector::InspectorDisconnectReason reason);
-
</del><span class="cx">     JSGlobalObject&amp; m_globalObject;
</span><del>-    std::unique_ptr&lt;Inspector::JSGlobalObjectInspectorController&gt; m_inspectorController;
</del><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace JSC
</span></span></pre>
</div>
</div>

</body>
</html>