Inspect primitive values in the object inspector instead of as inline comments (bug 1027424). r=rcampbell
authorPanos Astithas <past@mozilla.com>
Mon, 23 Jun 2014 22:25:40 +0300
changeset 212387 0701ea0bfaf6309bab3645bf8b0c0aefa2b49468
parent 212386 0f335eff972fb6c814f58824fe2dbffc6ac051d8
child 212388 d825d00cceeef0485feb9720fc8cd193ce3786fb
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrcampbell
bugs1027424
milestone33.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
Inspect primitive values in the object inspector instead of as inline comments (bug 1027424). r=rcampbell
browser/devtools/scratchpad/scratchpad.js
browser/devtools/scratchpad/test/browser.ini
browser/devtools/scratchpad/test/browser_scratchpad_inspect_primitives.js
--- a/browser/devtools/scratchpad/scratchpad.js
+++ b/browser/devtools/scratchpad/scratchpad.js
@@ -522,36 +522,32 @@ var Scratchpad = {
       }
     }, reject);
 
     return deferred.promise;
   },
 
   /**
    * Execute the selected text (if any) or the entire editor content in the
-   * current context. If the result is primitive then it is written as a
-   * comment. Otherwise, the resulting object is inspected up in the sidebar.
+   * current context. The resulting object is inspected up in the sidebar.
    *
    * @return Promise
    *         The promise for the script evaluation result.
    */
   inspect: function SP_inspect()
   {
     let deferred = promise.defer();
     let reject = aReason => deferred.reject(aReason);
 
     this.execute().then(([aString, aError, aResult]) => {
       let resolve = () => deferred.resolve([aString, aError, aResult]);
 
       if (aError) {
         this.writeAsErrorComment(aError.exception).then(resolve, reject);
       }
-      else if (VariablesView.isPrimitive({ value: aResult })) {
-        this._writePrimitiveAsComment(aResult).then(resolve, reject);
-      }
       else {
         this.editor.dropSelection();
         this.sidebar.open(aString, aResult).then(resolve, reject);
       }
     }, reject);
 
     return deferred.promise;
   },
@@ -2218,25 +2214,33 @@ ScratchpadSidebar.prototype = {
       this.variablesView = null;
     }
     return this._sidebar.destroy();
   },
 
   /**
    * Update the object currently inspected by the sidebar.
    *
-   * @param object aObject
-   *        The object to inspect in the sidebar.
+   * @param any aValue
+   *        The JS value to inspect in the sidebar.
    * @return Promise
    *         A promise that resolves when the update completes.
    */
-  _update: function SS__update(aObject)
+  _update: function SS__update(aValue)
   {
-    let options = { objectActor: aObject };
+    let options, onlyEnumVisible;
+    if (VariablesView.isPrimitive({ value: aValue })) {
+      options = { rawObject: { value: aValue } };
+      onlyEnumVisible = true;
+    } else {
+      options = { objectActor: aValue };
+      onlyEnumVisible = false;
+    }
     let view = this.variablesView;
+    view.onlyEnumVisible = onlyEnumVisible;
     view.empty();
     return view.controller.setSingleVariable(options).expanded;
   }
 };
 
 
 /**
  * Report an error coming over the remote debugger protocol.
--- a/browser/devtools/scratchpad/test/browser.ini
+++ b/browser/devtools/scratchpad/test/browser.ini
@@ -24,16 +24,17 @@ support-files = head.js
 [browser_scratchpad_edit_ui_updates.js]
 [browser_scratchpad_revert_to_saved.js]
 [browser_scratchpad_run_error_goto_line.js]
 [browser_scratchpad_contexts.js]
 [browser_scratchpad_execute_print.js]
 [browser_scratchpad_files.js]
 [browser_scratchpad_initialization.js]
 [browser_scratchpad_inspect.js]
+[browser_scratchpad_inspect_primitives.js]
 [browser_scratchpad_long_string.js]
 [browser_scratchpad_open.js]
 [browser_scratchpad_open_error_console.js]
 [browser_scratchpad_throw_output.js]
 [browser_scratchpad_pprint-02.js]
 [browser_scratchpad_pprint.js]
 [browser_scratchpad_pprint_error_goto_line.js]
 [browser_scratchpad_restore.js]
new file mode 100644
--- /dev/null
+++ b/browser/devtools/scratchpad/test/browser_scratchpad_inspect_primitives.js
@@ -0,0 +1,62 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Test that inspecting primitive values uses the object inspector, not an
+// inline comment.
+
+let {Task} = Cu.import("resource://gre/modules/Task.jsm", {});
+let {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
+
+function test() {
+  const options = {
+    tabContent: "test inspecting primitive values"
+  };
+  openTabAndScratchpad(options)
+    .then(Task.async(runTests))
+    .then(finish, console.error);
+}
+
+function* runTests([win, sp]) {
+  // Inspect a number.
+  yield checkResults(sp, 7);
+
+  // Inspect a string.
+  yield checkResults(sp, "foobar", true);
+
+  // Inspect a boolean.
+  yield checkResults(sp, true);
+}
+
+// Helper function that does the actual testing.
+let checkResults = Task.async(function* (sp, value, isString = false) {
+  let sourceValue = value;
+  if (isString) {
+    sourceValue = '"' + value + '"';
+  }
+  let source = "var foobar = " + sourceValue + "; foobar";
+  sp.setText(source);
+  yield sp.inspect();
+
+  let sidebar = sp.sidebar;
+  ok(sidebar.visible, "sidebar is open");
+
+  let found = false;
+
+  outer: for (let scope of sidebar.variablesView) {
+    for (let [, obj] of scope) {
+      for (let [, prop] of obj) {
+        if (prop.name == "value" && prop.value == value) {
+          found = true;
+          break outer;
+        }
+      }
+    }
+  }
+
+  ok(found, "found the value of " + value);
+
+  let tabbox = sidebar._sidebar._tabbox;
+  ok(!tabbox.hasAttribute("hidden"), "Scratchpad sidebar visible");
+  sidebar.hide();
+  ok(tabbox.hasAttribute("hidden"), "Scratchpad sidebar hidden");
+});