Bug 1403130 - Allow DOMNodes and cyclic objects to be rendered with the sidebar.setExpression API method. draft
authorLuca Greco <lgreco@mozilla.com>
Thu, 12 Oct 2017 15:55:47 +0200
changeset 679405 9a44c5d722a0e99363c19e4c2a65ab9ada9e2e72
parent 679404 a2bfe214f458e5a95006fa8e6f5dc6442b92822a
child 735595 a75249870006e1afd1648db47b336e4fd5ede613
push id84216
push userluca.greco@alcacoop.it
push dateThu, 12 Oct 2017 16:43:41 +0000
bugs1403130
milestone58.0a1
Bug 1403130 - Allow DOMNodes and cyclic objects to be rendered with the sidebar.setExpression API method. MozReview-Commit-ID: AjHn7KfVhas
browser/components/extensions/ext-devtools-panels.js
--- a/browser/components/extensions/ext-devtools-panels.js
+++ b/browser/components/extensions/ext-devtools-panels.js
@@ -436,16 +436,27 @@ class ParentDevToolsInspectorSidebar {
 
     if (this.extensionSidebar) {
       this.extensionSidebar.setObject(object);
     } else {
       // Defer the sidebar.setObject call.
       this._initializeSidebar = () => this.extensionSidebar.setObject(object);
     }
   }
+
+  setObjectValueGrip(objectValueGrip, rootTitle) {
+    if (this.extensionSidebar) {
+      this.extensionSidebar.setObjectValueGrip(objectValueGrip, rootTitle);
+    } else {
+      // Defer the sidebar.setObject call.
+      this._initializeSidebar = () => {
+        this.extensionSidebar.setObjectValueGrip(objectValueGrip, rootTitle);
+      };
+    }
+  }
 }
 
 const sidebarsById = new Map();
 
 this.devtools_panels = class extends ExtensionAPI {
   getAPI(context) {
     // Lazily retrieved inspectedWindow actor front per child context
     // (used by Sidebar.setExpression).
@@ -509,28 +520,30 @@ this.devtools_panels = class extends Ext
               async setExpression(sidebarId, evalExpression, rootTitle) {
                 const sidebar = sidebarsById.get(sidebarId);
 
                 if (!waitForInspectedWindowFront) {
                   waitForInspectedWindowFront = getInspectedWindowFront(context);
                 }
 
                 const front = await waitForInspectedWindowFront;
-                const evalOptions = Object.assign({}, getToolboxEvalOptions(context));
+                const evalOptions = Object.assign({
+                  evalResultAsGrip: true,
+                }, getToolboxEvalOptions(context));
                 const evalResult = await front.eval(callerInfo, evalExpression, evalOptions);
 
                 let jsonObject;
 
                 if (evalResult.exceptionInfo) {
                   jsonObject = evalResult.exceptionInfo;
-                } else {
-                  jsonObject = evalResult.value;
+
+                  return sidebar.setObject(jsonObject, rootTitle);
                 }
 
-                return sidebar.setObject(jsonObject, rootTitle);
+                return sidebar.setObjectValueGrip(evalResult.valueGrip);
               },
             },
           },
           create(title, icon, url) {
             // Get a fallback icon from the manifest data.
             if (icon === "" && context.extension.manifest.icons) {
               const iconInfo = IconDetails.getPreferredIcon(context.extension.manifest.icons,
                                                             context.extension, 128);