<!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>[197926] 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/197926">197926</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-03-09 22:15:25 -0800 (Wed, 09 Mar 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Web Inspector: Get a RemoteObject or ObjectPreview from HeapSnapshot Object Identifier
https://bugs.webkit.org/show_bug.cgi?id=155264
&lt;rdar://problem/25070716&gt;

Patch by Joseph Pecoraro &lt;pecoraro@apple.com&gt; on 2016-03-09
Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

* inspector/InjectedScript.h:
* inspector/InjectedScript.cpp:
(Inspector::InjectedScript::functionDetails):
(Inspector::InjectedScript::previewValue):
New InjectedScript methods for building Debugger.FunctionDetails
or Runtime.ObjectPreview protocol objects from a JSValue.

* inspector/InjectedScriptSource.js:
(InjectedScript.prototype.previewValue):
(InjectedScript.prototype.functionDetails):
(InjectedScript.prototype.getFunctionDetails):
(InjectedScript.RemoteObject.prototype._isPreviewableObjectInternal):
(InjectedScript.RemoteObject.prototype._createObjectPreviewForValue): Deleted.
(InjectedScript.RemoteObject.prototype._appendEntryPreviews): Deleted.
Share code around creating function details or object preview objects.

* inspector/agents/InspectorHeapAgent.cpp:
(Inspector::InspectorHeapAgent::InspectorHeapAgent):
(Inspector::InspectorHeapAgent::nodeForHeapObjectIdentifier):
(Inspector::InspectorHeapAgent::getPreview):
(Inspector::InspectorHeapAgent::getRemoteObject):
* inspector/agents/InspectorHeapAgent.h:
* inspector/protocol/Heap.json:
New protocol methods that go from heap object identifier to a
remote object or some kind of preview.

* inspector/scripts/codegen/generator.py:
Allow runtime casts for ObjectPreview.

LayoutTests:

* inspector/heap/getPreview-expected.txt: Added.
* inspector/heap/getPreview.html: Added.
* inspector/heap/getRemoteObject-expected.txt: Added.
* inspector/heap/getRemoteObject.html: Added.
Test the new protocol methods in different scenarios.

* inspector/heap/snapshot-expected.txt:
* inspector/heap/snapshot.html:
Fix typo.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsinspectorheapsnapshotexpectedtxt">trunk/LayoutTests/inspector/heap/snapshot-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorheapsnapshothtml">trunk/LayoutTests/inspector/heap/snapshot.html</a></li>
<li><a href="#trunkLayoutTestsplatformmacwk1TestExpectations">trunk/LayoutTests/platform/mac-wk1/TestExpectations</a></li>
<li><a href="#trunkSourceJavaScriptCoreChangeLog">trunk/Source/JavaScriptCore/ChangeLog</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorInjectedScriptcpp">trunk/Source/JavaScriptCore/inspector/InjectedScript.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorInjectedScripth">trunk/Source/JavaScriptCore/inspector/InjectedScript.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorInjectedScriptSourcejs">trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectoragentsInspectorHeapAgentcpp">trunk/Source/JavaScriptCore/inspector/agents/InspectorHeapAgent.cpp</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectoragentsInspectorHeapAgenth">trunk/Source/JavaScriptCore/inspector/agents/InspectorHeapAgent.h</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorprotocolHeapjson">trunk/Source/JavaScriptCore/inspector/protocol/Heap.json</a></li>
<li><a href="#trunkSourceJavaScriptCoreinspectorscriptscodegengeneratorpy">trunk/Source/JavaScriptCore/inspector/scripts/codegen/generator.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsinspectorheapgetPreviewexpectedtxt">trunk/LayoutTests/inspector/heap/getPreview-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorheapgetPreviewhtml">trunk/LayoutTests/inspector/heap/getPreview.html</a></li>
<li><a href="#trunkLayoutTestsinspectorheapgetRemoteObjectexpectedtxt">trunk/LayoutTests/inspector/heap/getRemoteObject-expected.txt</a></li>
<li><a href="#trunkLayoutTestsinspectorheapgetRemoteObjecthtml">trunk/LayoutTests/inspector/heap/getRemoteObject.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (197925 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-03-10 05:28:34 UTC (rev 197925)
+++ trunk/LayoutTests/ChangeLog        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2016-03-09  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+        Web Inspector: Get a RemoteObject or ObjectPreview from HeapSnapshot Object Identifier
+        https://bugs.webkit.org/show_bug.cgi?id=155264
+        &lt;rdar://problem/25070716&gt;
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/heap/getPreview-expected.txt: Added.
+        * inspector/heap/getPreview.html: Added.
+        * inspector/heap/getRemoteObject-expected.txt: Added.
+        * inspector/heap/getRemoteObject.html: Added.
+        Test the new protocol methods in different scenarios.
+
+        * inspector/heap/snapshot-expected.txt:
+        * inspector/heap/snapshot.html:
+        Fix typo.
+
</ins><span class="cx"> 2016-03-09  Andy VanWagoner  &lt;thetalecrafter@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [INTL] Intl Constructors not web compatible with Object.create usage
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorheapgetPreviewexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/heap/getPreview-expected.txt (0 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/heap/getPreview-expected.txt                                (rev 0)
+++ trunk/LayoutTests/inspector/heap/getPreview-expected.txt        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -0,0 +1,62 @@
</span><ins>+Test for the Heap.getRemoteObject command.
+
+
+== Running test suite: Heap.getPreview
+-- Running test case: GetPreviewNoSnapshot
+PASS: Should get an error when no snapshot exists.
+PASS: No heap snapshot
+
+-- Running test case: GetPreviewForString
+PASS: Should not have an error creating a snapshot.
+PASS: Should not have an error getting preview.
+STRING: This is the test string.
+
+-- Running test case: GetPreviewForFunction
+PASS: Should not have an error creating a snapshot.
+PASS: Should not have an error getting preview.
+FUNCTION DETAILS: {
+    &quot;location&quot;: {
+        &quot;scriptId&quot;: &quot;&lt;filtered&gt;&quot;,
+        &quot;lineNumber&quot;: 10,
+        &quot;columnNumber&quot;: 47
+    },
+    &quot;name&quot;: &quot;myFunctionName&quot;
+}
+
+-- Running test case: GetPreviewForObject
+PASS: Should not have an error creating a snapshot.
+PASS: Should not have an error getting preview.
+OBJECT PREVIEW: {
+    &quot;type&quot;: &quot;object&quot;,
+    &quot;description&quot;: &quot;Map&quot;,
+    &quot;lossless&quot;: true,
+    &quot;subtype&quot;: &quot;map&quot;,
+    &quot;overflow&quot;: false,
+    &quot;properties&quot;: [],
+    &quot;size&quot;: 1,
+    &quot;entries&quot;: [
+        {
+            &quot;key&quot;: {
+                &quot;type&quot;: &quot;string&quot;,
+                &quot;description&quot;: &quot;key&quot;,
+                &quot;lossless&quot;: true
+            },
+            &quot;value&quot;: {
+                &quot;type&quot;: &quot;string&quot;,
+                &quot;description&quot;: &quot;value&quot;,
+                &quot;lossless&quot;: true
+            }
+        }
+    ]
+}
+
+-- Running test case: GetPreviewBadIdentifier
+PASS: Should not have an error creating a snapshot.
+PASS: Should get an error when no object for identifier exists.
+PASS: No object for identifier, it may have been collected
+
+-- Running test case: GetRemoteObjectCollectedObject
+PASS: Should not have an error creating a snapshot.
+PASS: Should get an error when object has been collected.
+PASS: No object for identifier, it may have been collected
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorheapgetPreviewhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/heap/getPreview.html (0 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/heap/getPreview.html                                (rev 0)
+++ trunk/LayoutTests/inspector/heap/getPreview.html        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -0,0 +1,164 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../http/tests/inspector/resources/inspector-test.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+function triggerCreateStringObject() {
+    window.myString = &quot;This is the test string.&quot;;
+}
+
+function triggerCreateFunctionObject() {
+    window.myFunction = function myFunctionName(alpha, beta) {
+        return alpha * beta;
+    };
+}
+
+function triggerCreateMapObject() {
+    window.myMap = new Map;
+    myMap.set(&quot;key&quot;, &quot;value&quot;);
+}
+
+function triggerDeleteMapObject() {
+    window.myMap = null;
+}
+
+function test()
+{
+    let suite = InspectorTest.createAsyncSuite(&quot;Heap.getPreview&quot;);
+
+    function jsonFilter(key, value) {
+        if (key === &quot;scriptId&quot;)
+            return &quot;&lt;filtered&gt;&quot;;
+        return value;
+    }
+
+    suite.addTestCase({
+        name: &quot;GetPreviewNoSnapshot&quot;,
+        description: &quot;Calling Heap.getPreview when no snapshot exists should result in an error.&quot;,
+        test: (resolve, reject) =&gt; {
+            HeapAgent.getPreview(1, (error, string, functionDetails, objectPreviewPayload) =&gt; {
+                InspectorTest.expectThat(error, &quot;Should get an error when no snapshot exists.&quot;);
+                InspectorTest.pass(error);
+                resolve();
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: &quot;GetPreviewForString&quot;,
+        description: &quot;Calling Heap.getPreview for a live string should return the value of that string.&quot;,
+        test: (resolve, reject) =&gt; {
+            HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; { // All pre-existing objects.
+                InspectorTest.evaluateInPage(&quot;triggerCreateStringObject()&quot;);
+                HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; { // Newly created objects.
+                    InspectorTest.expectThat(!error, &quot;Should not have an error creating a snapshot.&quot;);
+                    let payload = JSON.parse(snapshotStringData);
+                    let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+
+                    let strings = snapshot.instancesWithClassName(&quot;string&quot;);
+                    let heapSnapshotNode = strings.reduce((result, x) =&gt; result.id &lt; x.id ? x : result, strings[0]);
+                    HeapAgent.getPreview(heapSnapshotNode.id, (error, string, functionDetails, objectPreviewPayload) =&gt; {
+                        InspectorTest.expectThat(!error, &quot;Should not have an error getting preview.&quot;);
+                        InspectorTest.log(&quot;STRING: &quot; + string);
+                        resolve();
+                    });
+                });
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: &quot;GetPreviewForFunction&quot;,
+        description: &quot;Calling Heap.getPreview for a live Function should return function details for that value.&quot;,
+        test: (resolve, reject) =&gt; {
+            HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; { // All pre-existing objects.
+                InspectorTest.evaluateInPage(&quot;triggerCreateFunctionObject()&quot;);
+                HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; { // Newly created objects.
+                    InspectorTest.expectThat(!error, &quot;Should not have an error creating a snapshot.&quot;);
+                    let payload = JSON.parse(snapshotStringData);
+                    let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+
+                    let functions = snapshot.instancesWithClassName(&quot;Function&quot;);
+                    let heapSnapshotNode = functions.reduce((result, x) =&gt; result.id &lt; x.id ? x : result, functions[0]);
+                    HeapAgent.getPreview(heapSnapshotNode.id, (error, string, functionDetails, objectPreviewPayload) =&gt; {
+                        InspectorTest.expectThat(!error, &quot;Should not have an error getting preview.&quot;);
+                        InspectorTest.log(&quot;FUNCTION DETAILS: &quot; + JSON.stringify(functionDetails, jsonFilter, 4));
+                        resolve();
+                    });
+                });
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: &quot;GetPreviewForObject&quot;,
+        description: &quot;Calling Heap.getPreview for a live Object should return an object preview for that value.&quot;,
+        test: (resolve, reject) =&gt; {
+            HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; { // All pre-existing objects.
+                InspectorTest.evaluateInPage(&quot;triggerCreateMapObject()&quot;);
+                HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; { // Newly created objects.
+                    InspectorTest.expectThat(!error, &quot;Should not have an error creating a snapshot.&quot;);
+                    let payload = JSON.parse(snapshotStringData);
+                    let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+
+                    let maps = snapshot.instancesWithClassName(&quot;Map&quot;);
+                    let heapSnapshotNode = maps.reduce((result, x) =&gt; result.id &lt; x.id ? x : result, maps[0]);
+                    HeapAgent.getPreview(heapSnapshotNode.id, (error, string, functionDetails, objectPreviewPayload) =&gt; {
+                        InspectorTest.expectThat(!error, &quot;Should not have an error getting preview.&quot;);
+                        InspectorTest.log(&quot;OBJECT PREVIEW: &quot; + JSON.stringify(objectPreviewPayload, jsonFilter, 4));
+                        resolve();
+                    });
+                });
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: &quot;GetPreviewBadIdentifier&quot;,
+        description: &quot;Calling Heap.getPreview with a bad identifier should result in an error.&quot;,
+        test: (resolve, reject) =&gt; {
+            HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; {
+                InspectorTest.expectThat(!error, &quot;Should not have an error creating a snapshot.&quot;);
+                HeapAgent.getPreview(9999999, (error, string, functionDetails, objectPreviewPayload) =&gt; {
+                    InspectorTest.expectThat(error, &quot;Should get an error when no object for identifier exists.&quot;);
+                    InspectorTest.pass(error);
+                    resolve();
+                });
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: &quot;GetRemoteObjectCollectedObject&quot;,
+        description: &quot;Calling Heap.getRemoteObject for an object that has been collected should result in an error.&quot;,
+        test: (resolve, reject) =&gt; {
+            HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; { // All pre-existing objects.
+                InspectorTest.evaluateInPage(&quot;triggerCreateMapObject()&quot;);
+                HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; { // Newly created objects.
+                    InspectorTest.expectThat(!error, &quot;Should not have an error creating a snapshot.&quot;);
+                    let payload = JSON.parse(snapshotStringData);
+                    let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+
+                    InspectorTest.evaluateInPage(&quot;triggerDeleteMapObject()&quot;);
+                    HeapAgent.gc();
+
+                    let maps = snapshot.instancesWithClassName(&quot;Map&quot;);
+                    let heapSnapshotNode = maps.reduce((result, x) =&gt; result.id &lt; x.id ? x : result, maps[0]);
+                    HeapAgent.getPreview(heapSnapshotNode.id, (error, string, functionDetails, objectPreviewPayload) =&gt; {
+                        InspectorTest.expectThat(error, &quot;Should get an error when object has been collected.&quot;);
+                        InspectorTest.pass(error);
+                        resolve();
+                    });
+                });
+            });
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+&lt;p&gt;Test for the Heap.getRemoteObject command.&lt;/p&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorheapgetRemoteObjectexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/heap/getRemoteObject-expected.txt (0 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/heap/getRemoteObject-expected.txt                                (rev 0)
+++ trunk/LayoutTests/inspector/heap/getRemoteObject-expected.txt        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -0,0 +1,25 @@
</span><ins>+Test for the Heap.getRemoteObject command.
+
+
+== Running test suite: Heap.getRemoteObject
+-- Running test case: GetRemoteObjectNoSnapshot
+PASS: Should get an error when no snapshot exists.
+PASS: No heap snapshot
+
+-- Running test case: GetRemoteObjectForWindow
+PASS: Should not have an error creating a snapshot.
+PASS: Should should include at least one 'Window' instance.
+PASS: Should not have an error getting remote object.
+Window
+
+-- Running test case: GetRemoteObjectBadIdentifier
+PASS: Should not have an error creating a snapshot.
+PASS: Should get an error when no object for identifier exists.
+PASS: No object for identifier, it may have been collected
+
+-- Running test case: GetRemoteObjectCollectedObject
+PASS: Should not have an error creating a snapshot.
+PASS: Should should include at least one 'Map' instance.
+PASS: Should get an error when object has been collected.
+PASS: No object for identifier, it may have been collected
+
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorheapgetRemoteObjecthtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/inspector/heap/getRemoteObject.html (0 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/heap/getRemoteObject.html                                (rev 0)
+++ trunk/LayoutTests/inspector/heap/getRemoteObject.html        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -0,0 +1,100 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;html&gt;
+&lt;head&gt;
+&lt;script src=&quot;../../http/tests/inspector/resources/inspector-test.js&quot;&gt;&lt;/script&gt;
+&lt;script&gt;
+function triggerCreateMapObject() {
+    window.myMap = new Map;
+}
+
+function triggerDeleteMapObject() {
+    window.myMap = null;
+}
+
+function test()
+{
+    let suite = InspectorTest.createAsyncSuite(&quot;Heap.getRemoteObject&quot;);
+
+    suite.addTestCase({
+        name: &quot;GetRemoteObjectNoSnapshot&quot;,
+        description: &quot;Calling Heap.getRemoteObject when no snapshot exists should result in an error.&quot;,
+        test: (resolve, reject) =&gt; {
+            HeapAgent.getRemoteObject(1, &quot;test&quot;, (error, remoteObjectPayload) =&gt; {
+                InspectorTest.expectThat(error, &quot;Should get an error when no snapshot exists.&quot;);
+                InspectorTest.pass(error);
+                resolve();
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: &quot;GetRemoteObjectForWindow&quot;,
+        description: &quot;Calling Heap.getRemoteObject for a live value should return a remote object for that value.&quot;,
+        test: (resolve, reject) =&gt; {
+            HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; {
+                InspectorTest.expectThat(!error, &quot;Should not have an error creating a snapshot.&quot;);
+                let payload = JSON.parse(snapshotStringData);
+                let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+                let heapSnapshotNode = snapshot.instancesWithClassName(&quot;Window&quot;)[0];
+                InspectorTest.expectThat(heapSnapshotNode, &quot;Should should include at least one 'Window' instance.&quot;);
+
+                HeapAgent.getRemoteObject(heapSnapshotNode.id, &quot;test&quot;, (error, remoteObjectPayload) =&gt; {
+                    InspectorTest.expectThat(!error, &quot;Should not have an error getting remote object.&quot;);
+                    let remoteObject = WebInspector.RemoteObject.fromPayload(remoteObjectPayload);
+                    InspectorTest.log(remoteObject.description);
+                    resolve();
+                });
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: &quot;GetRemoteObjectBadIdentifier&quot;,
+        description: &quot;Calling Heap.getRemoteObject with a bad identifier should result in an error.&quot;,
+        test: (resolve, reject) =&gt; {
+            HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; {
+                InspectorTest.expectThat(!error, &quot;Should not have an error creating a snapshot.&quot;);
+                HeapAgent.getRemoteObject(9999999, &quot;test&quot;, (error, remoteObjectPayload) =&gt; {
+                    InspectorTest.expectThat(error, &quot;Should get an error when no object for identifier exists.&quot;);
+                    InspectorTest.pass(error);
+                    resolve();
+                });
+            });
+        }
+    });
+
+    suite.addTestCase({
+        name: &quot;GetRemoteObjectCollectedObject&quot;,
+        description: &quot;Calling Heap.getRemoteObject for an object that has been collected should result in an error.&quot;,
+        test: (resolve, reject) =&gt; {
+            HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; { // All pre-existing objects.
+                InspectorTest.evaluateInPage(&quot;triggerCreateMapObject()&quot;);
+                HeapAgent.snapshot((error, timestamp, snapshotStringData) =&gt; { // Newly created objects.
+                    InspectorTest.expectThat(!error, &quot;Should not have an error creating a snapshot.&quot;);
+                    let payload = JSON.parse(snapshotStringData);
+                    let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+                    let maps = snapshot.instancesWithClassName(&quot;Map&quot;);
+                    InspectorTest.expectThat(maps.length, &quot;Should should include at least one 'Map' instance.&quot;);
+
+                    InspectorTest.evaluateInPage(&quot;triggerDeleteMapObject()&quot;);
+                    HeapAgent.gc();
+
+                    let heapSnapshotNode = maps.reduce((result, x) =&gt; result.id &lt; x.id ? x : result, maps[0]);
+                    HeapAgent.getRemoteObject(heapSnapshotNode.id, &quot;test&quot;, (error, remoteObjectPayload) =&gt; {
+                        InspectorTest.expectThat(error, &quot;Should get an error when object has been collected.&quot;);
+                        InspectorTest.pass(error);
+                        resolve();
+                    });
+                });
+            });
+        }
+    });
+
+    suite.runTestCasesAndFinish();
+}
+&lt;/script&gt;
+&lt;/head&gt;
+&lt;body onload=&quot;runTest()&quot;&gt;
+&lt;p&gt;Test for the Heap.getRemoteObject command.&lt;/p&gt;
+&lt;/body&gt;
+&lt;/html&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsinspectorheapsnapshotexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/heap/snapshot-expected.txt (197925 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/heap/snapshot-expected.txt        2016-03-10 05:28:34 UTC (rev 197925)
+++ trunk/LayoutTests/inspector/heap/snapshot-expected.txt        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -7,5 +7,5 @@
</span><span class="cx"> PASS: Snapshot size should be greater than 1kb.
</span><span class="cx"> PASS: Snapshot object count should be greater than 100.
</span><span class="cx"> PASS: Snapshot should include a class category for 'Window'.
</span><del>-PASS: Snapshow should include at least one 'Window' instance.
</del><ins>+PASS: Snapshot should include at least one 'Window' instance.
</ins><span class="cx"> 
</span></span></pre></div>
<a id="trunkLayoutTestsinspectorheapsnapshothtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/inspector/heap/snapshot.html (197925 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/inspector/heap/snapshot.html        2016-03-10 05:28:34 UTC (rev 197925)
+++ trunk/LayoutTests/inspector/heap/snapshot.html        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -18,7 +18,7 @@
</span><span class="cx">                 InspectorTest.expectThat(snapshot.totalSize &gt; 1024, &quot;Snapshot size should be greater than 1kb.&quot;);
</span><span class="cx">                 InspectorTest.expectThat(snapshot.totalObjectCount &gt; 100, &quot;Snapshot object count should be greater than 100.&quot;);
</span><span class="cx">                 InspectorTest.expectThat(snapshot.categories.get(&quot;Window&quot;), &quot;Snapshot should include a class category for 'Window'.&quot;);
</span><del>-                InspectorTest.expectThat(snapshot.instancesWithClassName(&quot;Window&quot;).length &gt; 0, &quot;Snapshow should include at least one 'Window' instance.&quot;);
</del><ins>+                InspectorTest.expectThat(snapshot.instancesWithClassName(&quot;Window&quot;).length &gt; 0, &quot;Snapshot should include at least one 'Window' instance.&quot;);
</ins><span class="cx">                 resolve();
</span><span class="cx">             });
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkLayoutTestsplatformmacwk1TestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/platform/mac-wk1/TestExpectations (197925 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/platform/mac-wk1/TestExpectations        2016-03-10 05:28:34 UTC (rev 197925)
+++ trunk/LayoutTests/platform/mac-wk1/TestExpectations        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -186,8 +186,12 @@
</span><span class="cx"> # ASAN test only fails on WK1:
</span><span class="cx"> webgl/1.0.3/151055_asan.html [ Failure ]
</span><span class="cx"> 
</span><del>-# Lacking WK1 TestRunner API that evaluates JavaScript through JSC APIs and not WebCore APIs
-inspector/script-profiler/event-type-API.html
</del><ins>+# Lacking WK1 TestRunner API that evaluates JavaScript through JSC APIs and not WebCore APIs.
+inspector/script-profiler/event-type-API.html [ Skip ]
</ins><span class="cx"> 
</span><ins>+# WK1 Inspector running in the same VM as the inspected page skews heap snapshot results.
+inspector/heap/getPreview.html [ Skip ]
+inspector/heap/getRemoteObject.html [ Skip ]
+
</ins><span class="cx"> # This test checks ScrollAnimator events only for main frame scrollbars that use native widgets in WK1.
</span><span class="cx"> fast/scrolling/scroll-animator-overlay-scrollbars-hovered.html [ Skip ]
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/ChangeLog (197925 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/ChangeLog        2016-03-10 05:28:34 UTC (rev 197925)
+++ trunk/Source/JavaScriptCore/ChangeLog        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2016-03-09  Joseph Pecoraro  &lt;pecoraro@apple.com&gt;
+
+        Web Inspector: Get a RemoteObject or ObjectPreview from HeapSnapshot Object Identifier
+        https://bugs.webkit.org/show_bug.cgi?id=155264
+        &lt;rdar://problem/25070716&gt;
+
+        Reviewed by Timothy Hatcher.
+
+        * inspector/InjectedScript.h:
+        * inspector/InjectedScript.cpp:
+        (Inspector::InjectedScript::functionDetails):
+        (Inspector::InjectedScript::previewValue):
+        New InjectedScript methods for building Debugger.FunctionDetails
+        or Runtime.ObjectPreview protocol objects from a JSValue.
+
+        * inspector/InjectedScriptSource.js:
+        (InjectedScript.prototype.previewValue):
+        (InjectedScript.prototype.functionDetails):
+        (InjectedScript.prototype.getFunctionDetails):
+        (InjectedScript.RemoteObject.prototype._isPreviewableObjectInternal):
+        (InjectedScript.RemoteObject.prototype._createObjectPreviewForValue): Deleted.
+        (InjectedScript.RemoteObject.prototype._appendEntryPreviews): Deleted.
+        Share code around creating function details or object preview objects.
+
+        * inspector/agents/InspectorHeapAgent.cpp:
+        (Inspector::InspectorHeapAgent::InspectorHeapAgent):
+        (Inspector::InspectorHeapAgent::nodeForHeapObjectIdentifier):
+        (Inspector::InspectorHeapAgent::getPreview):
+        (Inspector::InspectorHeapAgent::getRemoteObject):
+        * inspector/agents/InspectorHeapAgent.h:
+        * inspector/protocol/Heap.json:
+        New protocol methods that go from heap object identifier to a
+        remote object or some kind of preview.
+
+        * inspector/scripts/codegen/generator.py:
+        Allow runtime casts for ObjectPreview.
+
</ins><span class="cx"> 2016-03-09  Andy VanWagoner  &lt;thetalecrafter@gmail.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [INTL] Intl Constructors not web compatible with Object.create usage
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorInjectedScriptcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/InjectedScript.cpp (197925 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/InjectedScript.cpp        2016-03-10 05:28:34 UTC (rev 197925)
+++ trunk/Source/JavaScriptCore/inspector/InjectedScript.cpp        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -109,6 +109,23 @@
</span><span class="cx">     *result = BindingTraits&lt;Inspector::Protocol::Debugger::FunctionDetails&gt;::runtimeCast(WTFMove(resultValue));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void InjectedScript::functionDetails(ErrorString&amp; errorString, const Deprecated::ScriptValue&amp; value, RefPtr&lt;Protocol::Debugger::FunctionDetails&gt;* result)
+{
+    Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral(&quot;functionDetails&quot;), inspectorEnvironment()-&gt;functionCallHandler());
+    function.appendArgument(value);
+    function.appendArgument(true); // Preview only.
+
+    RefPtr&lt;InspectorValue&gt; resultValue;
+    makeCall(function, &amp;resultValue);
+    if (!resultValue || resultValue-&gt;type() != InspectorValue::Type::Object) {
+        if (!resultValue-&gt;asString(errorString))
+            errorString = ASCIILiteral(&quot;Internal error&quot;);
+        return;
+    }
+
+    *result = BindingTraits&lt;Inspector::Protocol::Debugger::FunctionDetails&gt;::runtimeCast(WTFMove(resultValue));
+}
+
</ins><span class="cx"> void InjectedScript::getProperties(ErrorString&amp; errorString, const String&amp; objectId, bool ownProperties, bool generatePreview, RefPtr&lt;Array&lt;Inspector::Protocol::Runtime::PropertyDescriptor&gt;&gt;* properties)
</span><span class="cx"> {
</span><span class="cx">     Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral(&quot;getProperties&quot;), inspectorEnvironment()-&gt;functionCallHandler());
</span><span class="lines">@@ -254,6 +271,24 @@
</span><span class="cx">     return BindingTraits&lt;Inspector::Protocol::Runtime::RemoteObject&gt;::runtimeCast(resultObject);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+RefPtr&lt;Inspector::Protocol::Runtime::ObjectPreview&gt; InjectedScript::previewValue(const Deprecated::ScriptValue&amp; value) const
+{
+    ASSERT(!hasNoValue());
+    Deprecated::ScriptFunctionCall wrapFunction(injectedScriptObject(), ASCIILiteral(&quot;previewValue&quot;), inspectorEnvironment()-&gt;functionCallHandler());
+    wrapFunction.appendArgument(value);
+
+    bool hadException = false;
+    Deprecated::ScriptValue r = callFunctionWithEvalEnabled(wrapFunction, hadException);
+    if (hadException)
+        return nullptr;
+
+    RefPtr&lt;InspectorObject&gt; resultObject;
+    bool castSucceeded = r.toInspectorValue(scriptState())-&gt;asObject(resultObject);
+    ASSERT_UNUSED(castSucceeded, castSucceeded);
+
+    return BindingTraits&lt;Inspector::Protocol::Runtime::ObjectPreview&gt;::runtimeCast(resultObject);
+}
+
</ins><span class="cx"> void InjectedScript::setExceptionValue(const Deprecated::ScriptValue&amp; value)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(!hasNoValue());
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorInjectedScripth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/InjectedScript.h (197925 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/InjectedScript.h        2016-03-10 05:28:34 UTC (rev 197925)
+++ trunk/Source/JavaScriptCore/inspector/InjectedScript.h        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -56,6 +56,7 @@
</span><span class="cx">     void callFunctionOn(ErrorString&amp;, const String&amp; objectId, const String&amp; expression, const String&amp; arguments, bool returnByValue, bool generatePreview, RefPtr&lt;Protocol::Runtime::RemoteObject&gt;* result, Protocol::OptOutput&lt;bool&gt;* wasThrown);
</span><span class="cx">     void evaluateOnCallFrame(ErrorString&amp;, const Deprecated::ScriptValue&amp; callFrames, const String&amp; callFrameId, const String&amp; expression, const String&amp; objectGroup, bool includeCommandLineAPI, bool returnByValue, bool generatePreview, bool saveResult, RefPtr&lt;Protocol::Runtime::RemoteObject&gt;* result, Protocol::OptOutput&lt;bool&gt;* wasThrown, Inspector::Protocol::OptOutput&lt;int&gt;* savedResultIndex);
</span><span class="cx">     void getFunctionDetails(ErrorString&amp;, const String&amp; functionId, RefPtr&lt;Protocol::Debugger::FunctionDetails&gt;* result);
</span><ins>+    void functionDetails(ErrorString&amp;, const Deprecated::ScriptValue&amp;, RefPtr&lt;Protocol::Debugger::FunctionDetails&gt;* result);
</ins><span class="cx">     void getProperties(ErrorString&amp;, const String&amp; objectId, bool ownProperties, bool generatePreview, RefPtr&lt;Protocol::Array&lt;Protocol::Runtime::PropertyDescriptor&gt;&gt;* result);
</span><span class="cx">     void getDisplayableProperties(ErrorString&amp;, const String&amp; objectId, bool generatePreview, RefPtr&lt;Protocol::Array&lt;Protocol::Runtime::PropertyDescriptor&gt;&gt;* result);
</span><span class="cx">     void getInternalProperties(ErrorString&amp;, const String&amp; objectId, bool generatePreview, RefPtr&lt;Protocol::Array&lt;Protocol::Runtime::InternalPropertyDescriptor&gt;&gt;* result);
</span><span class="lines">@@ -65,6 +66,7 @@
</span><span class="cx">     Ref&lt;Protocol::Array&lt;Protocol::Debugger::CallFrame&gt;&gt; wrapCallFrames(const Deprecated::ScriptValue&amp;) const;
</span><span class="cx">     RefPtr&lt;Protocol::Runtime::RemoteObject&gt; wrapObject(const Deprecated::ScriptValue&amp;, const String&amp; groupName, bool generatePreview = false) const;
</span><span class="cx">     RefPtr&lt;Protocol::Runtime::RemoteObject&gt; wrapTable(const Deprecated::ScriptValue&amp; table, const Deprecated::ScriptValue&amp; columns) const;
</span><ins>+    RefPtr&lt;Protocol::Runtime::ObjectPreview&gt; previewValue(const Deprecated::ScriptValue&amp;) const;
</ins><span class="cx"> 
</span><span class="cx">     void setExceptionValue(const Deprecated::ScriptValue&amp;);
</span><span class="cx">     void clearExceptionValue();
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorInjectedScriptSourcejs"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js (197925 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js        2016-03-10 05:28:34 UTC (rev 197925)
+++ trunk/Source/JavaScriptCore/inspector/InjectedScriptSource.js        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -98,6 +98,36 @@
</span><span class="cx">         return InjectedScript.primitiveTypes[typeof object] &amp;&amp; !this._isHTMLAllCollection(object);
</span><span class="cx">     },
</span><span class="cx"> 
</span><ins>+    previewValue: function(value)
+    {
+        return InjectedScript.RemoteObject.createObjectPreviewForValue(value, true);
+    },
+
+    functionDetails: function(func, previewOnly)
+    {
+        var details = InjectedScriptHost.functionDetails(func);
+        if (!details)
+            return &quot;Cannot resolve function details.&quot;;
+
+        // FIXME: provide function scope data in &quot;scopesRaw&quot; property when JSC supports it.
+        // &lt;https://webkit.org/b/87192&gt; [JSC] expose function (closure) inner context to debugger
+        if (&quot;rawScopes&quot; in details) {
+            if (previewOnly)
+                delete details.rawScopes;
+            else {
+                var objectGroupName = this._idToObjectGroupName[parsedFunctionId.id];
+                var rawScopes = details.rawScopes;
+                var scopes = [];
+                delete details.rawScopes;
+                for (var i = 0; i &lt; rawScopes.length; i++)
+                    scopes.push(InjectedScript.CallFrameProxy._createScopeJson(rawScopes[i].type, rawScopes[i].object, objectGroupName));
+                details.scopeChain = scopes;
+            }
+        }
+
+        return details;
+    },
+
</ins><span class="cx">     wrapObject: function(object, groupName, canAccessInspectedGlobalObject, generatePreview)
</span><span class="cx">     {
</span><span class="cx">         if (canAccessInspectedGlobalObject)
</span><span class="lines">@@ -332,19 +362,7 @@
</span><span class="cx">         var func = this._objectForId(parsedFunctionId);
</span><span class="cx">         if (typeof func !== &quot;function&quot;)
</span><span class="cx">             return &quot;Cannot resolve function by id.&quot;;
</span><del>-        var details = InjectedScriptHost.functionDetails(func);
-        if (!details)
-            return &quot;Cannot resolve function details.&quot;;
-        if (&quot;rawScopes&quot; in details) {
-            var objectGroupName = this._idToObjectGroupName[parsedFunctionId.id];
-            var rawScopes = details.rawScopes;
-            var scopes = [];
-            delete details.rawScopes;
-            for (var i = 0; i &lt; rawScopes.length; i++)
-                scopes.push(InjectedScript.CallFrameProxy._createScopeJson(rawScopes[i].type, rawScopes[i].object, objectGroupName));
-            details.scopeChain = scopes;
-        }
-        return details;
</del><ins>+        return injectedScript.functionDetails(func);
</ins><span class="cx">     },
</span><span class="cx"> 
</span><span class="cx">     releaseObject: function(objectId)
</span><span class="lines">@@ -1025,8 +1043,18 @@
</span><span class="cx"> 
</span><span class="cx">     if (generatePreview &amp;&amp; this.type === &quot;object&quot;)
</span><span class="cx">         this.preview = this._generatePreview(object, undefined, columnNames);
</span><del>-}
</del><ins>+};
</ins><span class="cx"> 
</span><ins>+InjectedScript.RemoteObject.createObjectPreviewForValue = function(value, generatePreview)
+{
+    var remoteObject = new InjectedScript.RemoteObject(value, undefined, false, generatePreview, undefined);
+    if (remoteObject.objectId)
+        injectedScript.releaseObject(remoteObject.objectId);
+    if (remoteObject.classPrototype &amp;&amp; remoteObject.classPrototype.objectId)
+        injectedScript.releaseObject(remoteObject.classPrototype.objectId);
+    return remoteObject.preview || remoteObject._emptyPreview();
+};
+
</ins><span class="cx"> InjectedScript.RemoteObject.prototype = {
</span><span class="cx">     _initialPreview: function()
</span><span class="cx">     {
</span><span class="lines">@@ -1065,17 +1093,6 @@
</span><span class="cx">         return preview;
</span><span class="cx">     },
</span><span class="cx"> 
</span><del>-    _createObjectPreviewForValue: function(value, generatePreview)
-    {
-        var remoteObject = new InjectedScript.RemoteObject(value, undefined, false, generatePreview, undefined);
-        if (remoteObject.objectId)
-            injectedScript.releaseObject(remoteObject.objectId);
-        if (remoteObject.classPrototype &amp;&amp; remoteObject.classPrototype.objectId)
-            injectedScript.releaseObject(remoteObject.classPrototype.objectId);
-
-        return remoteObject.preview || remoteObject._emptyPreview();
-    },
-
</del><span class="cx">     _generatePreview: function(object, firstLevelKeys, secondLevelKeys)
</span><span class="cx">     {
</span><span class="cx">         var preview = this._initialPreview();
</span><span class="lines">@@ -1202,7 +1219,7 @@
</span><span class="cx">             // Second level.
</span><span class="cx">             if ((secondLevelKeys === null || secondLevelKeys) || this._isPreviewableObject(value, object)) {
</span><span class="cx">                 // FIXME: If we want secondLevelKeys filter to continue we would need some refactoring.
</span><del>-                var subPreview = this._createObjectPreviewForValue(value, value !== object);
</del><ins>+                var subPreview = InjectedScript.RemoteObject.createObjectPreviewForValue(value, value !== object);
</ins><span class="cx">                 property.valuePreview = subPreview;
</span><span class="cx">                 if (!subPreview.lossless)
</span><span class="cx">                     preview.lossless = false;
</span><span class="lines">@@ -1266,10 +1283,10 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         preview.entries = entries.map(function(entry) {
</span><del>-            entry.value = this._createObjectPreviewForValue(entry.value, entry.value !== object);
</del><ins>+            entry.value = InjectedScript.RemoteObject.createObjectPreviewForValue(entry.value, entry.value !== object);
</ins><span class="cx">             updateMainPreview(entry.value);
</span><span class="cx">             if (&quot;key&quot; in entry) {
</span><del>-                entry.key = this._createObjectPreviewForValue(entry.key, entry.key !== object);
</del><ins>+                entry.key = InjectedScript.RemoteObject.createObjectPreviewForValue(entry.key, entry.key !== object);
</ins><span class="cx">                 updateMainPreview(entry.key);
</span><span class="cx">             }
</span><span class="cx">             return entry;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectoragentsInspectorHeapAgentcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/agents/InspectorHeapAgent.cpp (197925 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/agents/InspectorHeapAgent.cpp        2016-03-10 05:28:34 UTC (rev 197925)
+++ trunk/Source/JavaScriptCore/inspector/agents/InspectorHeapAgent.cpp        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -27,6 +27,8 @@
</span><span class="cx"> #include &quot;InspectorHeapAgent.h&quot;
</span><span class="cx"> 
</span><span class="cx"> #include &quot;HeapProfiler.h&quot;
</span><ins>+#include &quot;InjectedScript.h&quot;
+#include &quot;InjectedScriptManager.h&quot;
</ins><span class="cx"> #include &quot;InspectorEnvironment.h&quot;
</span><span class="cx"> #include &quot;JSCInlines.h&quot;
</span><span class="cx"> #include &quot;VM.h&quot;
</span><span class="lines">@@ -39,6 +41,7 @@
</span><span class="cx"> 
</span><span class="cx"> InspectorHeapAgent::InspectorHeapAgent(AgentContext&amp; context)
</span><span class="cx">     : InspectorAgentBase(ASCIILiteral(&quot;Heap&quot;))
</span><ins>+    , m_injectedScriptManager(context.injectedScriptManager)
</ins><span class="cx">     , m_frontendDispatcher(std::make_unique&lt;HeapFrontendDispatcher&gt;(context.frontendRouter))
</span><span class="cx">     , m_backendDispatcher(HeapBackendDispatcher::create(context.backendDispatcher, this))
</span><span class="cx">     , m_environment(context.environment)
</span><span class="lines">@@ -138,6 +141,116 @@
</span><span class="cx">     m_frontendDispatcher-&gt;trackingComplete(timestamp, snapshotData);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+Optional&lt;HeapSnapshotNode&gt; InspectorHeapAgent::nodeForHeapObjectIdentifier(ErrorString&amp; errorString, unsigned heapObjectIdentifier)
+{
+    HeapProfiler* heapProfiler = m_environment.vm().heapProfiler();
+    if (!heapProfiler) {
+        errorString = ASCIILiteral(&quot;No heap snapshot&quot;);
+        return Nullopt;
+    }
+
+    HeapSnapshot* snapshot = heapProfiler-&gt;mostRecentSnapshot();
+    if (!snapshot) {
+        errorString = ASCIILiteral(&quot;No heap snapshot&quot;);
+        return Nullopt;
+    }
+
+    const Optional&lt;HeapSnapshotNode&gt; optionalNode = snapshot-&gt;nodeForObjectIdentifier(heapObjectIdentifier);
+    if (!optionalNode) {
+        errorString = ASCIILiteral(&quot;No object for identifier, it may have been collected&quot;);
+        return Nullopt;
+    }
+
+    return optionalNode;
+}
+
+void InspectorHeapAgent::getPreview(ErrorString&amp; errorString, int heapObjectId, Inspector::Protocol::OptOutput&lt;String&gt;* resultString, RefPtr&lt;Inspector::Protocol::Debugger::FunctionDetails&gt;&amp; functionDetails, RefPtr&lt;Inspector::Protocol::Runtime::ObjectPreview&gt;&amp; objectPreview)
+{
+    // Prevent the cell from getting collected as we look it up.
+    VM&amp; vm = m_environment.vm();
+    JSLockHolder lock(vm);
+    DeferGC deferGC(vm.heap);
+
+    unsigned heapObjectIdentifier = static_cast&lt;unsigned&gt;(heapObjectId);
+    const Optional&lt;HeapSnapshotNode&gt; optionalNode = nodeForHeapObjectIdentifier(errorString, heapObjectIdentifier);
+    if (!optionalNode)
+        return;
+
+    // String preview.
+    JSCell* cell = optionalNode-&gt;cell;
+    if (cell-&gt;isString()) {
+        *resultString = cell-&gt;getString(nullptr);
+        return;
+    }
+
+    // FIXME: Provide preview information for Internal Objects? CodeBlock, Executable, etc.
+
+    Structure* structure = cell-&gt;structure(m_environment.vm());
+    if (!structure) {
+        errorString = ASCIILiteral(&quot;Unable to get object details - Structure&quot;);
+        return;
+    }
+
+    JSGlobalObject* globalObject = structure-&gt;globalObject();
+    if (!globalObject) {
+        errorString = ASCIILiteral(&quot;Unable to get object details - GlobalObject&quot;);
+        return;
+    }
+
+    InjectedScript injectedScript = m_injectedScriptManager.injectedScriptFor(globalObject-&gt;globalExec());
+    if (injectedScript.hasNoValue()) {
+        errorString = ASCIILiteral(&quot;Unable to get object details - InjectedScript&quot;);
+        return;
+    }
+
+    // Function preview.
+    if (cell-&gt;inherits(JSFunction::info())) {
+        Deprecated::ScriptValue functionScriptValue(m_environment.vm(), JSValue(cell));
+        injectedScript.functionDetails(errorString, functionScriptValue, &amp;functionDetails);
+        return;
+    }
+
+    // Object preview.
+    Deprecated::ScriptValue cellScriptValue(m_environment.vm(), JSValue(cell));
+    objectPreview = injectedScript.previewValue(cellScriptValue);
+}
+
+void InspectorHeapAgent::getRemoteObject(ErrorString&amp; errorString, int heapObjectId, const String* optionalObjectGroup, RefPtr&lt;Inspector::Protocol::Runtime::RemoteObject&gt;&amp; result)
+{
+    // Prevent the cell from getting collected as we look it up.
+    VM&amp; vm = m_environment.vm();
+    JSLockHolder lock(vm);
+    DeferGC deferGC(vm.heap);
+
+    unsigned heapObjectIdentifier = static_cast&lt;unsigned&gt;(heapObjectId);
+    const Optional&lt;HeapSnapshotNode&gt; optionalNode = nodeForHeapObjectIdentifier(errorString, heapObjectIdentifier);
+    if (!optionalNode)
+        return;
+
+    JSCell* cell = optionalNode-&gt;cell;
+    Structure* structure = cell-&gt;structure(m_environment.vm());
+    if (!structure) {
+        errorString = ASCIILiteral(&quot;Unable to get object details&quot;);
+        return;
+    }
+
+    JSGlobalObject* globalObject = structure-&gt;globalObject();
+    if (!globalObject) {
+        errorString = ASCIILiteral(&quot;Unable to get object details&quot;);
+        return;
+    }
+
+    InjectedScript injectedScript = m_injectedScriptManager.injectedScriptFor(globalObject-&gt;globalExec());
+    if (injectedScript.hasNoValue()) {
+        errorString = ASCIILiteral(&quot;Unable to get object details - InjectedScript&quot;);
+        return;
+    }
+
+    Deprecated::ScriptValue cellScriptValue(m_environment.vm(), JSValue(cell));
+    String objectGroup = optionalObjectGroup ? *optionalObjectGroup : String();
+    result = injectedScript.wrapObject(cellScriptValue, objectGroup, true);
+}
+
</ins><span class="cx"> static Inspector::Protocol::Heap::GarbageCollection::Type protocolTypeForHeapOperation(HeapOperation operation)
</span><span class="cx"> {
</span><span class="cx">     switch (operation) {
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectoragentsInspectorHeapAgenth"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/agents/InspectorHeapAgent.h (197925 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/agents/InspectorHeapAgent.h        2016-03-10 05:28:34 UTC (rev 197925)
+++ trunk/Source/JavaScriptCore/inspector/agents/InspectorHeapAgent.h        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -36,6 +36,7 @@
</span><span class="cx"> 
</span><span class="cx"> namespace Inspector {
</span><span class="cx"> 
</span><ins>+class InjectedScriptManager;
</ins><span class="cx"> typedef String ErrorString;
</span><span class="cx"> 
</span><span class="cx"> class JS_EXPORT_PRIVATE InspectorHeapAgent final : public InspectorAgentBase, public HeapBackendDispatcherHandler, public JSC::HeapObserver {
</span><span class="lines">@@ -54,6 +55,8 @@
</span><span class="cx">     void snapshot(ErrorString&amp;, double* timestamp, String* snapshotData) override;
</span><span class="cx">     void startTracking(ErrorString&amp;) override;
</span><span class="cx">     void stopTracking(ErrorString&amp;) override;
</span><ins>+    void getPreview(ErrorString&amp;, int heapObjectId, Inspector::Protocol::OptOutput&lt;String&gt;* resultString, RefPtr&lt;Inspector::Protocol::Debugger::FunctionDetails&gt;&amp; functionDetails, RefPtr&lt;Inspector::Protocol::Runtime::ObjectPreview&gt;&amp; objectPreview) override;
+    void getRemoteObject(ErrorString&amp;, int heapObjectId, const String* optionalObjectGroup, RefPtr&lt;Inspector::Protocol::Runtime::RemoteObject&gt;&amp; result) override;
</ins><span class="cx"> 
</span><span class="cx">     // HeapObserver
</span><span class="cx">     void willGarbageCollect() override;
</span><span class="lines">@@ -62,6 +65,9 @@
</span><span class="cx"> private:
</span><span class="cx">     void clearHeapSnapshots();
</span><span class="cx"> 
</span><ins>+    Optional&lt;JSC::HeapSnapshotNode&gt; nodeForHeapObjectIdentifier(ErrorString&amp;, unsigned heapObjectIdentifier);
+
+    InjectedScriptManager&amp; m_injectedScriptManager;
</ins><span class="cx">     std::unique_ptr&lt;HeapFrontendDispatcher&gt; m_frontendDispatcher;
</span><span class="cx">     RefPtr&lt;HeapBackendDispatcher&gt; m_backendDispatcher;
</span><span class="cx">     InspectorEnvironment&amp; m_environment;
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorprotocolHeapjson"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/protocol/Heap.json (197925 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/protocol/Heap.json        2016-03-10 05:28:34 UTC (rev 197925)
+++ trunk/Source/JavaScriptCore/inspector/protocol/Heap.json        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -46,6 +46,29 @@
</span><span class="cx">         {
</span><span class="cx">             &quot;name&quot;: &quot;stopTracking&quot;,
</span><span class="cx">             &quot;description&quot;: &quot;Stop tracking heap changes. This will produce a `trackingComplete` event.&quot;
</span><ins>+        },
+        {
+            &quot;name&quot;: &quot;getPreview&quot;,
+            &quot;description&quot;: &quot;Returns a preview (string, Debugger.FunctionDetails, or Runtime.ObjectPreview) for a Heap.HeapObjectId.&quot;,
+            &quot;parameters&quot;: [
+                { &quot;name&quot;: &quot;heapObjectId&quot;, &quot;type&quot;: &quot;integer&quot;, &quot;description&quot;: &quot;Identifier of the heap object within the snapshot.&quot; }
+            ],
+            &quot;returns&quot;: [
+                { &quot;name&quot;: &quot;string&quot;, &quot;type&quot;: &quot;string&quot;, &quot;optional&quot;: true, &quot;description&quot;: &quot;String value.&quot; },
+                { &quot;name&quot;: &quot;functionDetails&quot;, &quot;$ref&quot;: &quot;Debugger.FunctionDetails&quot;, &quot;optional&quot;: true, &quot;description&quot;: &quot;Function details.&quot; },
+                { &quot;name&quot;: &quot;preview&quot;, &quot;$ref&quot;: &quot;Runtime.ObjectPreview&quot;, &quot;optional&quot;: true, &quot;description&quot;: &quot;Object preview.&quot; }
+            ]
+        },
+        {
+            &quot;name&quot;: &quot;getRemoteObject&quot;,
+            &quot;description&quot;: &quot;Returns the strongly referenced Runtime.RemoteObject for a Heap.HeapObjectId.&quot;,
+            &quot;parameters&quot;: [
+                { &quot;name&quot;: &quot;heapObjectId&quot;, &quot;type&quot;: &quot;integer&quot;, &quot;description&quot;: &quot;Identifier of the heap object within the snapshot.&quot; },
+                { &quot;name&quot;: &quot;objectGroup&quot;, &quot;type&quot;: &quot;string&quot;, &quot;optional&quot;: true, &quot;description&quot;: &quot;Symbolic group name that can be used to release multiple objects.&quot; }
+            ],
+            &quot;returns&quot;: [
+                { &quot;name&quot;: &quot;result&quot;, &quot;$ref&quot;: &quot;Runtime.RemoteObject&quot;, &quot;description&quot;: &quot;Resulting object.&quot; }
+            ]
</ins><span class="cx">         }
</span><span class="cx">     ],
</span><span class="cx">     &quot;events&quot;: [
</span></span></pre></div>
<a id="trunkSourceJavaScriptCoreinspectorscriptscodegengeneratorpy"></a>
<div class="modfile"><h4>Modified: trunk/Source/JavaScriptCore/inspector/scripts/codegen/generator.py (197925 => 197926)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/JavaScriptCore/inspector/scripts/codegen/generator.py        2016-03-10 05:28:34 UTC (rev 197925)
+++ trunk/Source/JavaScriptCore/inspector/scripts/codegen/generator.py        2016-03-10 06:15:25 UTC (rev 197926)
</span><span class="lines">@@ -47,6 +47,7 @@
</span><span class="cx"> 
</span><span class="cx"> # FIXME: This should be converted into a property in JSON.
</span><span class="cx"> _TYPES_NEEDING_RUNTIME_CASTS = set([
</span><ins>+    &quot;Runtime.ObjectPreview&quot;,
</ins><span class="cx">     &quot;Runtime.RemoteObject&quot;,
</span><span class="cx">     &quot;Runtime.PropertyDescriptor&quot;,
</span><span class="cx">     &quot;Runtime.InternalPropertyDescriptor&quot;,
</span></span></pre>
</div>
</div>

</body>
</html>