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 679398 a77d8cf437304ebe1e9cac6f5c553de0d1aee56f
parent 679397 230bd47c24e9605e2abb7146cc050bf8945fc124
child 735593 00e6ad92c4c500d5884345e3a9b8e04d522966c9
push id84214
push userluca.greco@alcacoop.it
push dateThu, 12 Oct 2017 16:34:23 +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);