Bug 843019 - Add VariablesViewController#setSingleVariable. r=vp, r=msucan
☠☠ backed out by d5b167f3d0d2 ☠ ☠
authorBrandon Benvie <bbenvie@mozilla.com>
Thu, 26 Sep 2013 10:51:51 -0700
changeset 148914 3732f69b6d81758f30169920cac46e12efcd3eb8
parent 148913 1ea17ee6d1cdb4f08a8a9e2dbd818c30f536098b
child 148915 d5b167f3d0d287b016161dd1929dc54e69ae905d
push id34380
push userryanvm@gmail.com
push dateFri, 27 Sep 2013 01:41:00 +0000
treeherdermozilla-inbound@fdc6054e33e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvp, msucan
bugs843019
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 843019 - Add VariablesViewController#setSingleVariable. r=vp, r=msucan
browser/devtools/netmonitor/netmonitor-controller.js
browser/devtools/netmonitor/netmonitor-view.js
browser/devtools/shared/widgets/VariablesViewController.jsm
browser/devtools/webconsole/webconsole.js
--- a/browser/devtools/netmonitor/netmonitor-controller.js
+++ b/browser/devtools/netmonitor/netmonitor-controller.js
@@ -60,16 +60,17 @@ const EVENTS = {
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 let promise = Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js").Promise;
 Cu.import("resource:///modules/devtools/sourceeditor/source-editor.jsm");
 Cu.import("resource:///modules/devtools/shared/event-emitter.js");
 Cu.import("resource:///modules/devtools/SideMenuWidget.jsm");
 Cu.import("resource:///modules/devtools/VariablesView.jsm");
+Cu.import("resource:///modules/devtools/VariablesViewController.jsm");
 Cu.import("resource:///modules/devtools/ViewHelpers.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",
   "resource://gre/modules/PluralForm.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "devtools",
   "resource://gre/modules/devtools/Loader.jsm");
 
--- a/browser/devtools/netmonitor/netmonitor-view.js
+++ b/browser/devtools/netmonitor/netmonitor-view.js
@@ -1884,19 +1884,20 @@ NetworkDetailsView.prototype = {
 
         // Valid JSON.
         if (jsonObject) {
           $("#response-content-json-box").hidden = false;
           let jsonScopeName = callbackPadding
             ? L10N.getFormatStr("jsonpScopeName", callbackPadding[0].slice(0, -1))
             : L10N.getStr("jsonScopeName");
 
-          let jsonScope = this._json.addScope(jsonScopeName);
-          jsonScope.addItem().populate(jsonObject, { expanded: true });
-          jsonScope.expanded = true;
+          this._json.controller.setSingleVariable({
+            label: jsonScopeName,
+            rawObject: jsonObject,
+          });
         }
         // Malformed JSON.
         else {
           $("#response-content-textarea-box").hidden = false;
           NetMonitorView.editor("#response-content-textarea").then(aEditor => {
             aEditor.setMode(SourceEditor.MODES.JAVASCRIPT);
             aEditor.setText(aString);
           });
--- a/browser/devtools/shared/widgets/VariablesViewController.jsm
+++ b/browser/devtools/shared/widgets/VariablesViewController.jsm
@@ -35,26 +35,26 @@ this.EXPORTED_SYMBOLS = ["VariablesViewC
 
 /**
  * Controller for a VariablesView that handles interfacing with the debugger
  * protocol. Is able to populate scopes and variables via the protocol as well
  * as manage actor lifespans.
  *
  * @param VariablesView aView
  *        The view to attach to.
- * @param object aOptions
+ * @param object aOptions [optional]
  *        Options for configuring the controller. Supported options:
  *        - getObjectClient: callback for creating an object grip client
  *        - getLongStringClient: callback for creating a long string grip client
  *        - releaseActor: callback for releasing an actor when it's no longer needed
  *        - overrideValueEvalMacro: callback for creating an overriding eval macro
  *        - getterOrSetterEvalMacro: callback for creating a getter/setter eval macro
  *        - simpleValueEvalMacro: callback for creating a simple value eval macro
  */
-function VariablesViewController(aView, aOptions) {
+function VariablesViewController(aView, aOptions = {}) {
   this.addExpander = this.addExpander.bind(this);
 
   this._getObjectClient = aOptions.getObjectClient;
   this._getLongStringClient = aOptions.getLongStringClient;
   this._releaseActor = aOptions.releaseActor;
 
   if (aOptions.overrideValueEvalMacro) {
     this._overrideValueEvalMacro = aOptions.overrideValueEvalMacro;
@@ -336,16 +336,48 @@ VariablesViewController.prototype = {
    */
   releaseActors: function(aFilter) {
     for (let actor of this._actors) {
       if (!aFilter || aFilter(actor)) {
         this.releaseActor(actor);
       }
     }
   },
+
+  /**
+   * Helper function for setting up a single Scope with a single Variable
+   * contained within it.
+   *
+   * @param object aOptions
+   *        Options for the contents of the view:
+   *        - objectActor: the grip of the new ObjectActor to show.
+   *        - rawObject: the new raw object to show.
+   *        - label: the new label for the inspected object.
+   * @return Object
+   *         - variable: the created Variable.
+   *         - expanded: the Promise that resolves when the variable expands.
+   */
+  setSingleVariable: function(aOptions) {
+    this.view.empty();
+    let scope = this.view.addScope(aOptions.label);
+    scope.expanded = true;
+    scope.locked = true;
+
+    let variable = scope.addItem();
+    let expanded;
+
+    if (aOptions.objectActor) {
+      expanded = this.expand(variable, aOptions.objectActor);
+    } else if (aOptions.rawObject) {
+      variable.populate(aOptions.rawObject, { expanded: true });
+      expanded = promise.resolve();
+    }
+
+    return { variable: variable, expanded: expanded };
+  },
 };
 
 
 /**
  * Attaches a VariablesViewController to a VariablesView if it doesn't already
  * have one.
  *
  * @param VariablesView aView
--- a/browser/devtools/webconsole/webconsole.js
+++ b/browser/devtools/webconsole/webconsole.js
@@ -3476,38 +3476,33 @@ JSTerm.prototype = {
       view.delete = this._variablesViewDelete.bind(this, aOptions);
     }
     else {
       view.eval = null;
       view.switch = null;
       view.delete = null;
     }
 
-    let scope = view.addScope(aOptions.label);
-    scope.expanded = true;
-    scope.locked = true;
-
-    let container = scope.addItem();
-    container.evaluationMacro = simpleValueEvalMacro;
+    let { variable, expanded } = view.controller.setSingleVariable(aOptions);
+    variable.evaluationMacro = simpleValueEvalMacro;
 
     if (aOptions.objectActor) {
-      view.controller.expand(container, aOptions.objectActor);
       view._consoleLastObjectActor = aOptions.objectActor.actor;
     }
     else if (aOptions.rawObject) {
-      container.populate(aOptions.rawObject);
-      view.commitHierarchy();
       view._consoleLastObjectActor = null;
     }
     else {
       throw new Error("Variables View cannot open without giving it an object " +
                       "display.");
     }
 
-    this.emit("variablesview-updated", view, aOptions);
+    expanded.then(() => {
+      this.emit("variablesview-updated", view, aOptions);
+    });
   },
 
   /**
    * The evaluation function used by the variables view when editing a property
    * value.
    *
    * @private
    * @param object aOptions