<!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
<rdar://problem/25070716>
Patch by Joseph Pecoraro <pecoraro@apple.com> 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 <pecoraro@apple.com>
+
+ Web Inspector: Get a RemoteObject or ObjectPreview from HeapSnapshot Object Identifier
+ https://bugs.webkit.org/show_bug.cgi?id=155264
+ <rdar://problem/25070716>
+
+ 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 <thetalecrafter@gmail.com>
</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: {
+ "location": {
+ "scriptId": "<filtered>",
+ "lineNumber": 10,
+ "columnNumber": 47
+ },
+ "name": "myFunctionName"
+}
+
+-- Running test case: GetPreviewForObject
+PASS: Should not have an error creating a snapshot.
+PASS: Should not have an error getting preview.
+OBJECT PREVIEW: {
+ "type": "object",
+ "description": "Map",
+ "lossless": true,
+ "subtype": "map",
+ "overflow": false,
+ "properties": [],
+ "size": 1,
+ "entries": [
+ {
+ "key": {
+ "type": "string",
+ "description": "key",
+ "lossless": true
+ },
+ "value": {
+ "type": "string",
+ "description": "value",
+ "lossless": 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>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
+<script>
+function triggerCreateStringObject() {
+ window.myString = "This is the test string.";
+}
+
+function triggerCreateFunctionObject() {
+ window.myFunction = function myFunctionName(alpha, beta) {
+ return alpha * beta;
+ };
+}
+
+function triggerCreateMapObject() {
+ window.myMap = new Map;
+ myMap.set("key", "value");
+}
+
+function triggerDeleteMapObject() {
+ window.myMap = null;
+}
+
+function test()
+{
+ let suite = InspectorTest.createAsyncSuite("Heap.getPreview");
+
+ function jsonFilter(key, value) {
+ if (key === "scriptId")
+ return "<filtered>";
+ return value;
+ }
+
+ suite.addTestCase({
+ name: "GetPreviewNoSnapshot",
+ description: "Calling Heap.getPreview when no snapshot exists should result in an error.",
+ test: (resolve, reject) => {
+ HeapAgent.getPreview(1, (error, string, functionDetails, objectPreviewPayload) => {
+ InspectorTest.expectThat(error, "Should get an error when no snapshot exists.");
+ InspectorTest.pass(error);
+ resolve();
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "GetPreviewForString",
+ description: "Calling Heap.getPreview for a live string should return the value of that string.",
+ test: (resolve, reject) => {
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => { // All pre-existing objects.
+ InspectorTest.evaluateInPage("triggerCreateStringObject()");
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => { // Newly created objects.
+ InspectorTest.expectThat(!error, "Should not have an error creating a snapshot.");
+ let payload = JSON.parse(snapshotStringData);
+ let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+
+ let strings = snapshot.instancesWithClassName("string");
+ let heapSnapshotNode = strings.reduce((result, x) => result.id < x.id ? x : result, strings[0]);
+ HeapAgent.getPreview(heapSnapshotNode.id, (error, string, functionDetails, objectPreviewPayload) => {
+ InspectorTest.expectThat(!error, "Should not have an error getting preview.");
+ InspectorTest.log("STRING: " + string);
+ resolve();
+ });
+ });
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "GetPreviewForFunction",
+ description: "Calling Heap.getPreview for a live Function should return function details for that value.",
+ test: (resolve, reject) => {
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => { // All pre-existing objects.
+ InspectorTest.evaluateInPage("triggerCreateFunctionObject()");
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => { // Newly created objects.
+ InspectorTest.expectThat(!error, "Should not have an error creating a snapshot.");
+ let payload = JSON.parse(snapshotStringData);
+ let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+
+ let functions = snapshot.instancesWithClassName("Function");
+ let heapSnapshotNode = functions.reduce((result, x) => result.id < x.id ? x : result, functions[0]);
+ HeapAgent.getPreview(heapSnapshotNode.id, (error, string, functionDetails, objectPreviewPayload) => {
+ InspectorTest.expectThat(!error, "Should not have an error getting preview.");
+ InspectorTest.log("FUNCTION DETAILS: " + JSON.stringify(functionDetails, jsonFilter, 4));
+ resolve();
+ });
+ });
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "GetPreviewForObject",
+ description: "Calling Heap.getPreview for a live Object should return an object preview for that value.",
+ test: (resolve, reject) => {
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => { // All pre-existing objects.
+ InspectorTest.evaluateInPage("triggerCreateMapObject()");
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => { // Newly created objects.
+ InspectorTest.expectThat(!error, "Should not have an error creating a snapshot.");
+ let payload = JSON.parse(snapshotStringData);
+ let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+
+ let maps = snapshot.instancesWithClassName("Map");
+ let heapSnapshotNode = maps.reduce((result, x) => result.id < x.id ? x : result, maps[0]);
+ HeapAgent.getPreview(heapSnapshotNode.id, (error, string, functionDetails, objectPreviewPayload) => {
+ InspectorTest.expectThat(!error, "Should not have an error getting preview.");
+ InspectorTest.log("OBJECT PREVIEW: " + JSON.stringify(objectPreviewPayload, jsonFilter, 4));
+ resolve();
+ });
+ });
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "GetPreviewBadIdentifier",
+ description: "Calling Heap.getPreview with a bad identifier should result in an error.",
+ test: (resolve, reject) => {
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => {
+ InspectorTest.expectThat(!error, "Should not have an error creating a snapshot.");
+ HeapAgent.getPreview(9999999, (error, string, functionDetails, objectPreviewPayload) => {
+ InspectorTest.expectThat(error, "Should get an error when no object for identifier exists.");
+ InspectorTest.pass(error);
+ resolve();
+ });
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "GetRemoteObjectCollectedObject",
+ description: "Calling Heap.getRemoteObject for an object that has been collected should result in an error.",
+ test: (resolve, reject) => {
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => { // All pre-existing objects.
+ InspectorTest.evaluateInPage("triggerCreateMapObject()");
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => { // Newly created objects.
+ InspectorTest.expectThat(!error, "Should not have an error creating a snapshot.");
+ let payload = JSON.parse(snapshotStringData);
+ let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+
+ InspectorTest.evaluateInPage("triggerDeleteMapObject()");
+ HeapAgent.gc();
+
+ let maps = snapshot.instancesWithClassName("Map");
+ let heapSnapshotNode = maps.reduce((result, x) => result.id < x.id ? x : result, maps[0]);
+ HeapAgent.getPreview(heapSnapshotNode.id, (error, string, functionDetails, objectPreviewPayload) => {
+ InspectorTest.expectThat(error, "Should get an error when object has been collected.");
+ InspectorTest.pass(error);
+ resolve();
+ });
+ });
+ });
+ }
+ });
+
+ suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>Test for the Heap.getRemoteObject command.</p>
+</body>
+</html>
</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>+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
+<script>
+function triggerCreateMapObject() {
+ window.myMap = new Map;
+}
+
+function triggerDeleteMapObject() {
+ window.myMap = null;
+}
+
+function test()
+{
+ let suite = InspectorTest.createAsyncSuite("Heap.getRemoteObject");
+
+ suite.addTestCase({
+ name: "GetRemoteObjectNoSnapshot",
+ description: "Calling Heap.getRemoteObject when no snapshot exists should result in an error.",
+ test: (resolve, reject) => {
+ HeapAgent.getRemoteObject(1, "test", (error, remoteObjectPayload) => {
+ InspectorTest.expectThat(error, "Should get an error when no snapshot exists.");
+ InspectorTest.pass(error);
+ resolve();
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "GetRemoteObjectForWindow",
+ description: "Calling Heap.getRemoteObject for a live value should return a remote object for that value.",
+ test: (resolve, reject) => {
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => {
+ InspectorTest.expectThat(!error, "Should not have an error creating a snapshot.");
+ let payload = JSON.parse(snapshotStringData);
+ let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+ let heapSnapshotNode = snapshot.instancesWithClassName("Window")[0];
+ InspectorTest.expectThat(heapSnapshotNode, "Should should include at least one 'Window' instance.");
+
+ HeapAgent.getRemoteObject(heapSnapshotNode.id, "test", (error, remoteObjectPayload) => {
+ InspectorTest.expectThat(!error, "Should not have an error getting remote object.");
+ let remoteObject = WebInspector.RemoteObject.fromPayload(remoteObjectPayload);
+ InspectorTest.log(remoteObject.description);
+ resolve();
+ });
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "GetRemoteObjectBadIdentifier",
+ description: "Calling Heap.getRemoteObject with a bad identifier should result in an error.",
+ test: (resolve, reject) => {
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => {
+ InspectorTest.expectThat(!error, "Should not have an error creating a snapshot.");
+ HeapAgent.getRemoteObject(9999999, "test", (error, remoteObjectPayload) => {
+ InspectorTest.expectThat(error, "Should get an error when no object for identifier exists.");
+ InspectorTest.pass(error);
+ resolve();
+ });
+ });
+ }
+ });
+
+ suite.addTestCase({
+ name: "GetRemoteObjectCollectedObject",
+ description: "Calling Heap.getRemoteObject for an object that has been collected should result in an error.",
+ test: (resolve, reject) => {
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => { // All pre-existing objects.
+ InspectorTest.evaluateInPage("triggerCreateMapObject()");
+ HeapAgent.snapshot((error, timestamp, snapshotStringData) => { // Newly created objects.
+ InspectorTest.expectThat(!error, "Should not have an error creating a snapshot.");
+ let payload = JSON.parse(snapshotStringData);
+ let snapshot = WebInspector.HeapSnapshot.fromPayload(payload);
+ let maps = snapshot.instancesWithClassName("Map");
+ InspectorTest.expectThat(maps.length, "Should should include at least one 'Map' instance.");
+
+ InspectorTest.evaluateInPage("triggerDeleteMapObject()");
+ HeapAgent.gc();
+
+ let heapSnapshotNode = maps.reduce((result, x) => result.id < x.id ? x : result, maps[0]);
+ HeapAgent.getRemoteObject(heapSnapshotNode.id, "test", (error, remoteObjectPayload) => {
+ InspectorTest.expectThat(error, "Should get an error when object has been collected.");
+ InspectorTest.pass(error);
+ resolve();
+ });
+ });
+ });
+ }
+ });
+
+ suite.runTestCasesAndFinish();
+}
+</script>
+</head>
+<body onload="runTest()">
+<p>Test for the Heap.getRemoteObject command.</p>
+</body>
+</html>
</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 > 1024, "Snapshot size should be greater than 1kb.");
</span><span class="cx"> InspectorTest.expectThat(snapshot.totalObjectCount > 100, "Snapshot object count should be greater than 100.");
</span><span class="cx"> InspectorTest.expectThat(snapshot.categories.get("Window"), "Snapshot should include a class category for 'Window'.");
</span><del>- InspectorTest.expectThat(snapshot.instancesWithClassName("Window").length > 0, "Snapshow should include at least one 'Window' instance.");
</del><ins>+ InspectorTest.expectThat(snapshot.instancesWithClassName("Window").length > 0, "Snapshot should include at least one 'Window' instance.");
</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 <pecoraro@apple.com>
+
+ Web Inspector: Get a RemoteObject or ObjectPreview from HeapSnapshot Object Identifier
+ https://bugs.webkit.org/show_bug.cgi?id=155264
+ <rdar://problem/25070716>
+
+ 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 <thetalecrafter@gmail.com>
</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<Inspector::Protocol::Debugger::FunctionDetails>::runtimeCast(WTFMove(resultValue));
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void InjectedScript::functionDetails(ErrorString& errorString, const Deprecated::ScriptValue& value, RefPtr<Protocol::Debugger::FunctionDetails>* result)
+{
+ Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("functionDetails"), inspectorEnvironment()->functionCallHandler());
+ function.appendArgument(value);
+ function.appendArgument(true); // Preview only.
+
+ RefPtr<InspectorValue> resultValue;
+ makeCall(function, &resultValue);
+ if (!resultValue || resultValue->type() != InspectorValue::Type::Object) {
+ if (!resultValue->asString(errorString))
+ errorString = ASCIILiteral("Internal error");
+ return;
+ }
+
+ *result = BindingTraits<Inspector::Protocol::Debugger::FunctionDetails>::runtimeCast(WTFMove(resultValue));
+}
+
</ins><span class="cx"> void InjectedScript::getProperties(ErrorString& errorString, const String& objectId, bool ownProperties, bool generatePreview, RefPtr<Array<Inspector::Protocol::Runtime::PropertyDescriptor>>* properties)
</span><span class="cx"> {
</span><span class="cx"> Deprecated::ScriptFunctionCall function(injectedScriptObject(), ASCIILiteral("getProperties"), inspectorEnvironment()->functionCallHandler());
</span><span class="lines">@@ -254,6 +271,24 @@
</span><span class="cx"> return BindingTraits<Inspector::Protocol::Runtime::RemoteObject>::runtimeCast(resultObject);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+RefPtr<Inspector::Protocol::Runtime::ObjectPreview> InjectedScript::previewValue(const Deprecated::ScriptValue& value) const
+{
+ ASSERT(!hasNoValue());
+ Deprecated::ScriptFunctionCall wrapFunction(injectedScriptObject(), ASCIILiteral("previewValue"), inspectorEnvironment()->functionCallHandler());
+ wrapFunction.appendArgument(value);
+
+ bool hadException = false;
+ Deprecated::ScriptValue r = callFunctionWithEvalEnabled(wrapFunction, hadException);
+ if (hadException)
+ return nullptr;
+
+ RefPtr<InspectorObject> resultObject;
+ bool castSucceeded = r.toInspectorValue(scriptState())->asObject(resultObject);
+ ASSERT_UNUSED(castSucceeded, castSucceeded);
+
+ return BindingTraits<Inspector::Protocol::Runtime::ObjectPreview>::runtimeCast(resultObject);
+}
+
</ins><span class="cx"> void InjectedScript::setExceptionValue(const Deprecated::ScriptValue& 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&, const String& objectId, const String& expression, const String& arguments, bool returnByValue, bool generatePreview, RefPtr<Protocol::Runtime::RemoteObject>* result, Protocol::OptOutput<bool>* wasThrown);
</span><span class="cx"> void evaluateOnCallFrame(ErrorString&, const Deprecated::ScriptValue& callFrames, const String& callFrameId, const String& expression, const String& objectGroup, bool includeCommandLineAPI, bool returnByValue, bool generatePreview, bool saveResult, RefPtr<Protocol::Runtime::RemoteObject>* result, Protocol::OptOutput<bool>* wasThrown, Inspector::Protocol::OptOutput<int>* savedResultIndex);
</span><span class="cx"> void getFunctionDetails(ErrorString&, const String& functionId, RefPtr<Protocol::Debugger::FunctionDetails>* result);
</span><ins>+ void functionDetails(ErrorString&, const Deprecated::ScriptValue&, RefPtr<Protocol::Debugger::FunctionDetails>* result);
</ins><span class="cx"> void getProperties(ErrorString&, const String& objectId, bool ownProperties, bool generatePreview, RefPtr<Protocol::Array<Protocol::Runtime::PropertyDescriptor>>* result);
</span><span class="cx"> void getDisplayableProperties(ErrorString&, const String& objectId, bool generatePreview, RefPtr<Protocol::Array<Protocol::Runtime::PropertyDescriptor>>* result);
</span><span class="cx"> void getInternalProperties(ErrorString&, const String& objectId, bool generatePreview, RefPtr<Protocol::Array<Protocol::Runtime::InternalPropertyDescriptor>>* result);
</span><span class="lines">@@ -65,6 +66,7 @@
</span><span class="cx"> Ref<Protocol::Array<Protocol::Debugger::CallFrame>> wrapCallFrames(const Deprecated::ScriptValue&) const;
</span><span class="cx"> RefPtr<Protocol::Runtime::RemoteObject> wrapObject(const Deprecated::ScriptValue&, const String& groupName, bool generatePreview = false) const;
</span><span class="cx"> RefPtr<Protocol::Runtime::RemoteObject> wrapTable(const Deprecated::ScriptValue& table, const Deprecated::ScriptValue& columns) const;
</span><ins>+ RefPtr<Protocol::Runtime::ObjectPreview> previewValue(const Deprecated::ScriptValue&) const;
</ins><span class="cx">
</span><span class="cx"> void setExceptionValue(const Deprecated::ScriptValue&);
</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] && !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 "Cannot resolve function details.";
+
+ // FIXME: provide function scope data in "scopesRaw" property when JSC supports it.
+ // <https://webkit.org/b/87192> [JSC] expose function (closure) inner context to debugger
+ if ("rawScopes" 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 < 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 !== "function")
</span><span class="cx"> return "Cannot resolve function by id.";
</span><del>- var details = InjectedScriptHost.functionDetails(func);
- if (!details)
- return "Cannot resolve function details.";
- if ("rawScopes" in details) {
- var objectGroupName = this._idToObjectGroupName[parsedFunctionId.id];
- var rawScopes = details.rawScopes;
- var scopes = [];
- delete details.rawScopes;
- for (var i = 0; i < 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 && this.type === "object")
</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 && 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 && 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 ("key" 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 "InspectorHeapAgent.h"
</span><span class="cx">
</span><span class="cx"> #include "HeapProfiler.h"
</span><ins>+#include "InjectedScript.h"
+#include "InjectedScriptManager.h"
</ins><span class="cx"> #include "InspectorEnvironment.h"
</span><span class="cx"> #include "JSCInlines.h"
</span><span class="cx"> #include "VM.h"
</span><span class="lines">@@ -39,6 +41,7 @@
</span><span class="cx">
</span><span class="cx"> InspectorHeapAgent::InspectorHeapAgent(AgentContext& context)
</span><span class="cx"> : InspectorAgentBase(ASCIILiteral("Heap"))
</span><ins>+ , m_injectedScriptManager(context.injectedScriptManager)
</ins><span class="cx"> , m_frontendDispatcher(std::make_unique<HeapFrontendDispatcher>(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->trackingComplete(timestamp, snapshotData);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+Optional<HeapSnapshotNode> InspectorHeapAgent::nodeForHeapObjectIdentifier(ErrorString& errorString, unsigned heapObjectIdentifier)
+{
+ HeapProfiler* heapProfiler = m_environment.vm().heapProfiler();
+ if (!heapProfiler) {
+ errorString = ASCIILiteral("No heap snapshot");
+ return Nullopt;
+ }
+
+ HeapSnapshot* snapshot = heapProfiler->mostRecentSnapshot();
+ if (!snapshot) {
+ errorString = ASCIILiteral("No heap snapshot");
+ return Nullopt;
+ }
+
+ const Optional<HeapSnapshotNode> optionalNode = snapshot->nodeForObjectIdentifier(heapObjectIdentifier);
+ if (!optionalNode) {
+ errorString = ASCIILiteral("No object for identifier, it may have been collected");
+ return Nullopt;
+ }
+
+ return optionalNode;
+}
+
+void InspectorHeapAgent::getPreview(ErrorString& errorString, int heapObjectId, Inspector::Protocol::OptOutput<String>* resultString, RefPtr<Inspector::Protocol::Debugger::FunctionDetails>& functionDetails, RefPtr<Inspector::Protocol::Runtime::ObjectPreview>& objectPreview)
+{
+ // Prevent the cell from getting collected as we look it up.
+ VM& vm = m_environment.vm();
+ JSLockHolder lock(vm);
+ DeferGC deferGC(vm.heap);
+
+ unsigned heapObjectIdentifier = static_cast<unsigned>(heapObjectId);
+ const Optional<HeapSnapshotNode> optionalNode = nodeForHeapObjectIdentifier(errorString, heapObjectIdentifier);
+ if (!optionalNode)
+ return;
+
+ // String preview.
+ JSCell* cell = optionalNode->cell;
+ if (cell->isString()) {
+ *resultString = cell->getString(nullptr);
+ return;
+ }
+
+ // FIXME: Provide preview information for Internal Objects? CodeBlock, Executable, etc.
+
+ Structure* structure = cell->structure(m_environment.vm());
+ if (!structure) {
+ errorString = ASCIILiteral("Unable to get object details - Structure");
+ return;
+ }
+
+ JSGlobalObject* globalObject = structure->globalObject();
+ if (!globalObject) {
+ errorString = ASCIILiteral("Unable to get object details - GlobalObject");
+ return;
+ }
+
+ InjectedScript injectedScript = m_injectedScriptManager.injectedScriptFor(globalObject->globalExec());
+ if (injectedScript.hasNoValue()) {
+ errorString = ASCIILiteral("Unable to get object details - InjectedScript");
+ return;
+ }
+
+ // Function preview.
+ if (cell->inherits(JSFunction::info())) {
+ Deprecated::ScriptValue functionScriptValue(m_environment.vm(), JSValue(cell));
+ injectedScript.functionDetails(errorString, functionScriptValue, &functionDetails);
+ return;
+ }
+
+ // Object preview.
+ Deprecated::ScriptValue cellScriptValue(m_environment.vm(), JSValue(cell));
+ objectPreview = injectedScript.previewValue(cellScriptValue);
+}
+
+void InspectorHeapAgent::getRemoteObject(ErrorString& errorString, int heapObjectId, const String* optionalObjectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& result)
+{
+ // Prevent the cell from getting collected as we look it up.
+ VM& vm = m_environment.vm();
+ JSLockHolder lock(vm);
+ DeferGC deferGC(vm.heap);
+
+ unsigned heapObjectIdentifier = static_cast<unsigned>(heapObjectId);
+ const Optional<HeapSnapshotNode> optionalNode = nodeForHeapObjectIdentifier(errorString, heapObjectIdentifier);
+ if (!optionalNode)
+ return;
+
+ JSCell* cell = optionalNode->cell;
+ Structure* structure = cell->structure(m_environment.vm());
+ if (!structure) {
+ errorString = ASCIILiteral("Unable to get object details");
+ return;
+ }
+
+ JSGlobalObject* globalObject = structure->globalObject();
+ if (!globalObject) {
+ errorString = ASCIILiteral("Unable to get object details");
+ return;
+ }
+
+ InjectedScript injectedScript = m_injectedScriptManager.injectedScriptFor(globalObject->globalExec());
+ if (injectedScript.hasNoValue()) {
+ errorString = ASCIILiteral("Unable to get object details - InjectedScript");
+ 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&, double* timestamp, String* snapshotData) override;
</span><span class="cx"> void startTracking(ErrorString&) override;
</span><span class="cx"> void stopTracking(ErrorString&) override;
</span><ins>+ void getPreview(ErrorString&, int heapObjectId, Inspector::Protocol::OptOutput<String>* resultString, RefPtr<Inspector::Protocol::Debugger::FunctionDetails>& functionDetails, RefPtr<Inspector::Protocol::Runtime::ObjectPreview>& objectPreview) override;
+ void getRemoteObject(ErrorString&, int heapObjectId, const String* optionalObjectGroup, RefPtr<Inspector::Protocol::Runtime::RemoteObject>& 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<JSC::HeapSnapshotNode> nodeForHeapObjectIdentifier(ErrorString&, unsigned heapObjectIdentifier);
+
+ InjectedScriptManager& m_injectedScriptManager;
</ins><span class="cx"> std::unique_ptr<HeapFrontendDispatcher> m_frontendDispatcher;
</span><span class="cx"> RefPtr<HeapBackendDispatcher> m_backendDispatcher;
</span><span class="cx"> InspectorEnvironment& 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"> "name": "stopTracking",
</span><span class="cx"> "description": "Stop tracking heap changes. This will produce a `trackingComplete` event."
</span><ins>+ },
+ {
+ "name": "getPreview",
+ "description": "Returns a preview (string, Debugger.FunctionDetails, or Runtime.ObjectPreview) for a Heap.HeapObjectId.",
+ "parameters": [
+ { "name": "heapObjectId", "type": "integer", "description": "Identifier of the heap object within the snapshot." }
+ ],
+ "returns": [
+ { "name": "string", "type": "string", "optional": true, "description": "String value." },
+ { "name": "functionDetails", "$ref": "Debugger.FunctionDetails", "optional": true, "description": "Function details." },
+ { "name": "preview", "$ref": "Runtime.ObjectPreview", "optional": true, "description": "Object preview." }
+ ]
+ },
+ {
+ "name": "getRemoteObject",
+ "description": "Returns the strongly referenced Runtime.RemoteObject for a Heap.HeapObjectId.",
+ "parameters": [
+ { "name": "heapObjectId", "type": "integer", "description": "Identifier of the heap object within the snapshot." },
+ { "name": "objectGroup", "type": "string", "optional": true, "description": "Symbolic group name that can be used to release multiple objects." }
+ ],
+ "returns": [
+ { "name": "result", "$ref": "Runtime.RemoteObject", "description": "Resulting object." }
+ ]
</ins><span class="cx"> }
</span><span class="cx"> ],
</span><span class="cx"> "events": [
</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>+ "Runtime.ObjectPreview",
</ins><span class="cx"> "Runtime.RemoteObject",
</span><span class="cx"> "Runtime.PropertyDescriptor",
</span><span class="cx"> "Runtime.InternalPropertyDescriptor",
</span></span></pre>
</div>
</div>
</body>
</html>