Bug 1024054 - Create a previewer for ES6 Symbol. r=past
authorNick Fitzgerald <fitzgen@gmail.com>
Mon, 25 Aug 2014 11:07:00 +0200
changeset 201580 6ab8a358adb97cc31fefbc0907d07c6943949dc3
parent 201579 68d1093896b12f3ef4f25bb0bea924236c41c727
child 201581 ce6cce273a0aa21dcff49c1f234b5ad1d7502b42
push id27374
push userryanvm@gmail.com
push dateTue, 26 Aug 2014 18:16:27 +0000
treeherdermozilla-central@c850f3af9f2c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspast
bugs1024054
milestone34.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 1024054 - Create a previewer for ES6 Symbol. r=past
browser/devtools/shared/widgets/VariablesView.jsm
browser/devtools/webconsole/console-output.js
browser/devtools/webconsole/test/browser_webconsole_output_01.js
toolkit/devtools/webconsole/utils.js
--- a/browser/devtools/shared/widgets/VariablesView.jsm
+++ b/browser/devtools/shared/widgets/VariablesView.jsm
@@ -3204,16 +3204,17 @@ VariablesView.isPrimitive = function(aDe
   // strings are considered types.
   let type = grip.type;
   if (type == "undefined" ||
       type == "null" ||
       type == "Infinity" ||
       type == "-Infinity" ||
       type == "NaN" ||
       type == "-0" ||
+      type == "symbol" ||
       type == "longString") {
     return true;
   }
 
   return false;
 };
 
 /**
@@ -3421,16 +3422,21 @@ VariablesView.stringifiers.byType = {
     if (!stringifier && aGrip.class) {
       stringifier = VariablesView.stringifiers.byObjectClass[aGrip.class];
     }
     if (stringifier) {
       return stringifier(aGrip, aOptions);
     }
     return null;
   },
+
+  symbol: function(aGrip, aOptions) {
+    const name = aGrip.name || "";
+    return "Symbol(" + name + ")";
+  },
 }; // VariablesView.stringifiers.byType
 
 VariablesView.stringifiers.byObjectClass = {
   Function: function(aGrip, {concise}) {
     // TODO: Bug 948484 - support arrow functions and ES6 generators
 
     let name = aGrip.userDisplayName || aGrip.displayName || aGrip.name || "";
     name = VariablesView.getString(name, { noStringQuotes: true });
--- a/browser/devtools/webconsole/console-output.js
+++ b/browser/devtools/webconsole/console-output.js
@@ -1124,16 +1124,17 @@ Messages.Extended.prototype = Heritage.e
       "longstring": "console-string",
       "string": "console-string",
       "regexp": "cm-string-2",
       "boolean": "cm-atom",
       "-infinity": "cm-atom",
       "infinity": "cm-atom",
       "null": "cm-atom",
       "undefined": "cm-comment",
+      "symbol": "cm-atom"
     };
 
     let className = map[typeof grip];
     if (!className && grip && grip.type) {
       className = map[grip.type.toLowerCase()];
     }
     if (!className && grip && grip.class) {
       className = map[grip.class.toLowerCase()];
--- a/browser/devtools/webconsole/test/browser_webconsole_output_01.js
+++ b/browser/devtools/webconsole/test/browser_webconsole_output_01.js
@@ -70,16 +70,34 @@ let inputTests = [
   },
 
   // 8
   {
     input: "/foobar/",
     output: "/foobar/",
     inspectable: true,
   },
+
+  // 9
+  {
+    input: "Symbol()",
+    output: "Symbol()"
+  },
+
+  // 10
+  {
+    input: "Symbol('foo')",
+    output: "Symbol(foo)"
+  },
+
+  // 11
+  {
+    input: "Symbol.iterator",
+    output: "Symbol(Symbol.iterator)"
+  },
 ];
 
 longString = initialString = null;
 
 function test() {
   registerCleanupFunction(() => {
     DebuggerServer.LONG_STRING_LENGTH = LONG_STRING_LENGTH;
     DebuggerServer.LONG_STRING_INITIAL_LENGTH = LONG_STRING_INITIAL_LENGTH;
--- a/toolkit/devtools/webconsole/utils.js
+++ b/toolkit/devtools/webconsole/utils.js
@@ -1738,16 +1738,19 @@ function JSTermHelpers(aOwner)
    *
    * @param any aValue
    *        A value you want to output as a string.
    * @return void
    */
   aOwner.sandbox.print = function JSTH_print(aValue)
   {
     aOwner.helperResult = { rawOutput: true };
+    if (typeof aValue === "symbol") {
+      return Symbol.prototype.toString.call(aValue);
+    }
     // Waiving Xrays here allows us to see a closer representation of the
     // underlying object. This may execute arbitrary content code, but that
     // code will run with content privileges, and the result will be rendered
     // inert by coercing it to a String.
     return String(Cu.waiveXrays(aValue));
   };
 }
 exports.JSTermHelpers = JSTermHelpers;