Bug 1255734 - DevTools: Inspecting a primitive value in console throws a TypeError. r=vporof
authorJarda Snajdr <jsnajdr@gmail.com>
Fri, 11 Mar 2016 01:33:00 -0500
changeset 288526 282de7d09bce1fd2216f93b91812cb4389c15721
parent 288525 4dfa6cdb7faa89904a3bda31f5a8890cac4481c9
child 288527 398160abc223561f29deb190949910154c4f5b03
push id18159
push userryanvm@gmail.com
push dateMon, 14 Mar 2016 15:59:30 +0000
treeherderfx-team@d50f024f55d8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvporof
bugs1255734
milestone48.0a1
Bug 1255734 - DevTools: Inspecting a primitive value in console throws a TypeError. r=vporof
devtools/client/shared/widgets/VariablesViewController.jsm
devtools/client/webconsole/test/browser_jsterm_inspect.js
--- a/devtools/client/shared/widgets/VariablesViewController.jsm
+++ b/devtools/client/shared/widgets/VariablesViewController.jsm
@@ -670,48 +670,52 @@ VariablesViewController.prototype = {
   },
 
   /**
    * Helper function for setting up a single Scope with a single Variable
    * contained within it.
    *
    * This function will empty the variables view.
    *
-   * @param object aOptions
+   * @param object options
    *        Options for the contents of the view:
    *        - objectActor: the grip of the new ObjectActor to show.
    *        - rawObject: the raw object to show.
    *        - label: the label for the inspected object.
-   * @param object aConfiguration
+   * @param object configuration
    *        Additional options for the controller:
    *        - overrideValueEvalMacro: @see _setEvaluationMacros
    *        - getterOrSetterEvalMacro: @see _setEvaluationMacros
    *        - simpleValueEvalMacro: @see _setEvaluationMacros
    * @return Object
    *         - variable: the created Variable.
    *         - expanded: the Promise that resolves when the variable expands.
    */
-  setSingleVariable: function(aOptions, aConfiguration = {}) {
-    this._setEvaluationMacros(aConfiguration);
+  setSingleVariable: function(options, configuration = {}) {
+    this._setEvaluationMacros(configuration);
     this.view.empty();
 
-    let scope = this.view.addScope(aOptions.label);
+    let scope = this.view.addScope(options.label);
     scope.expanded = true; // Expand the scope by default.
     scope.locked = true; // Prevent collapsing the scope.
 
     let variable = scope.addItem("", { enumerable: true });
     let populated;
 
-    if (aOptions.objectActor) {
+    if (options.objectActor) {
       // Save objectActor for properties filtering
-      this.objectActor = aOptions.objectActor;
-      populated = this.populate(variable, aOptions.objectActor);
-      variable.expand();
-    } else if (aOptions.rawObject) {
-      variable.populate(aOptions.rawObject, { expanded: true });
+      this.objectActor = options.objectActor;
+      if (VariablesView.isPrimitive({ value: this.objectActor })) {
+        populated = promise.resolve();
+      } else {
+        populated = this.populate(variable, options.objectActor);
+        variable.expand();
+      }
+    } else if (options.rawObject) {
+      variable.populate(options.rawObject, { expanded: true });
       populated = promise.resolve();
     }
 
     return { variable: variable, expanded: populated };
   },
 };
 
 
--- a/devtools/client/webconsole/test/browser_jsterm_inspect.js
+++ b/devtools/client/webconsole/test/browser_jsterm_inspect.js
@@ -10,21 +10,38 @@
 const TEST_URI = "data:text/html;charset=utf8,<p>hello bug 869981";
 
 add_task(function* () {
   yield loadTab(TEST_URI);
 
   let hud = yield openConsole();
   let jsterm = hud.jsterm;
 
+  /* Check that the window object is inspected */
   jsterm.execute("testProp = 'testValue'");
 
-  let fetched = jsterm.once("variablesview-fetched");
+  let updated = jsterm.once("variablesview-updated");
   jsterm.execute("inspect(window)");
-  let variable = yield fetched;
+  let view = yield updated;
+  ok(view, "variables view object");
 
-  ok(variable._variablesView, "variables view object");
+  // The single variable view contains a scope with the variable name
+  // and unnamed subitem that contains the properties
+  let variable = view.getScopeAtIndex(0).get("");
+  ok(variable, "variable object");
 
   yield findVariableViewProperties(variable, [
     { name: "testProp", value: "testValue" },
     { name: "document", value: /HTMLDocument \u2192 data:/ },
   ], { webconsole: hud });
+
+  /* Check that a primitive value can be inspected, too */
+  let updated2 = jsterm.once("variablesview-updated");
+  jsterm.execute("inspect(1)");
+  let view2 = yield updated2;
+  ok(view2, "variables view object");
+
+  // Check the label of the scope - it should contain the value
+  let scope = view.getScopeAtIndex(0);
+  ok(scope, "variable object");
+
+  is(scope.name, "1", "The value of the primitive var is correct");
 });