Reviewers: rossberg, yurys,

Description:
Implement Mirror object for Symbols.

[email protected]
BUG=v8:3290
LOG=Y

Please review this at https://codereview.chromium.org/297513006/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+84, -4 lines):
  M src/mirror-debugger.js
  A test/mjsunit/es6/mirror-symbols.js
  M tools/generate-runtime-tests.py


Index: src/mirror-debugger.js
diff --git a/src/mirror-debugger.js b/src/mirror-debugger.js
index 124347b7bd5b72cd7a977750b91a2d608aa951e2..dac636b3c6c306027ed977ea82b7c96a2b23107c 100644
--- a/src/mirror-debugger.js
+++ b/src/mirror-debugger.js
@@ -68,6 +68,8 @@ function MakeMirror(value, opt_transient) {
     mirror = new NumberMirror(value);
   } else if (IS_STRING(value)) {
     mirror = new StringMirror(value);
+  } else if (IS_SYMBOL(value)) {
+    mirror = new SymbolMirror(value);
   } else if (IS_ARRAY(value)) {
     mirror = new ArrayMirror(value);
   } else if (IS_DATE(value)) {
@@ -141,6 +143,7 @@ var NULL_TYPE = 'null';
 var BOOLEAN_TYPE = 'boolean';
 var NUMBER_TYPE = 'number';
 var STRING_TYPE = 'string';
+var SYMBOL_TYPE = 'symbol';
 var OBJECT_TYPE = 'object';
 var FUNCTION_TYPE = 'function';
 var REGEXP_TYPE = 'regexp';
@@ -198,6 +201,7 @@ var ScopeType = { Global: 0,
 //       - NullMirror
 //       - NumberMirror
 //       - StringMirror
+//       - SymbolMirror
 //       - ObjectMirror
 //         - FunctionMirror
 //           - UnresolvedFunctionMirror
@@ -282,6 +286,15 @@ Mirror.prototype.isString = function() {


 /**
+ * Check whether the mirror reflects a symbol.
+ * @returns {boolean} True if the mirror reflects a symbol
+ */
+Mirror.prototype.isSymbol = function() {
+  return this instanceof SymbolMirror;
+};
+
+
+/**
  * Check whether the mirror reflects an object.
  * @returns {boolean} True if the mirror reflects an object
  */
@@ -466,7 +479,8 @@ ValueMirror.prototype.isPrimitive = function() {
          type === 'null' ||
          type === 'boolean' ||
          type === 'number' ||
-         type === 'string';
+         type === 'string' ||
+         type === 'symbol';
 };


@@ -575,6 +589,28 @@ StringMirror.prototype.toText = function() {


 /**
+ * Mirror object for a Symbol
+ * @param {Object} value The Symbol
+ * @constructor
+ * @extends Mirror
+ */
+function SymbolMirror(value) {
+  %_CallFunction(this, SYMBOL_TYPE, value, ValueMirror);
+}
+inherits(SymbolMirror, ValueMirror);
+
+
+SymbolMirror.prototype.name = function() {
+  return %SymbolDescription(%_ValueOf(this.value_));
+}
+
+
+SymbolMirror.prototype.toText = function() {
+  return 'Symbol "' + this.name() + '"';
+}
+
+
+/**
  * Mirror object for objects.
  * @param {object} value The object reflected by this mirror
* @param {boolean} transient indicate whether this object is transient with a
@@ -1184,9 +1220,9 @@ ErrorMirror.prototype.toText = function() {

 /**
  * Mirror object for a Promise object.
- * @param {Object} data The Promise object
+ * @param {Object} value The Promise object
  * @constructor
- * @extends Mirror
+ * @extends ObjectMirror
  */
 function PromiseMirror(value) {
   %_CallFunction(this, value, PROMISE_TYPE, ObjectMirror);
@@ -2318,6 +2354,9 @@ JSONProtocolSerializer.prototype.serializeReferenceWithDisplayData_ =
     case STRING_TYPE:
       o.value = mirror.getTruncatedValue(this.maxStringLength_());
       break;
+    case SYMBOL_TYPE:
+      o.value = mirror.name();
+      break;
     case FUNCTION_TYPE:
       o.name = mirror.name();
       o.inferredName = mirror.inferredName();
@@ -2392,6 +2431,10 @@ JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference,
       content.length = mirror.length();
       break;

+    case SYMBOL_TYPE:
+      content.name = mirror.name();
+      break;
+
     case OBJECT_TYPE:
     case FUNCTION_TYPE:
     case ERROR_TYPE:
Index: test/mjsunit/es6/mirror-symbols.js
diff --git a/test/mjsunit/es6/mirror-symbols.js b/test/mjsunit/es6/mirror-symbols.js
new file mode 100644
index 0000000000000000000000000000000000000000..c2d33c393c53060ee09268f86aff66f86869d787
--- /dev/null
+++ b/test/mjsunit/es6/mirror-symbols.js
@@ -0,0 +1,37 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --expose-debug-as debug --harmony-symbols
+// Test the mirror object for symbols.
+
+function testSymbolMirror(symbol, name) {
+  // Create mirror and JSON representation.
+  var mirror = debug.MakeMirror(symbol);
+  var serializer = debug.MakeMirrorSerializer();
+  var json = JSON.stringify(serializer.serializeValue(mirror));
+
+  // Check the mirror hierachy.
+  assertTrue(mirror instanceof debug.Mirror);
+  assertTrue(mirror instanceof debug.ValueMirror);
+  assertTrue(mirror instanceof debug.SymbolMirror);
+
+  // Check the mirror properties.
+  assertTrue(mirror.isSymbol());
+  assertEquals(name, mirror.name());
+  assertEquals('symbol', mirror.type());
+  assertTrue(mirror.isPrimitive());
+  assertEquals('Symbol "' + name + '"', mirror.toText());
+  assertSame(symbol, mirror.value());
+
+  // Parse JSON representation and check.
+  var fromJSON = eval('(' + json + ')');
+  assertEquals('symbol', fromJSON.type);
+  assertEquals(name, fromJSON.name);
+}
+
+// Test a number of different symbols.
+testSymbolMirror(Symbol("a"), "a");
+testSymbolMirror(Symbol(12), "12");
+testSymbolMirror(Symbol.for("b"), "b");
+testSymbolMirror(Symbol(), undefined);
Index: tools/generate-runtime-tests.py
diff --git a/tools/generate-runtime-tests.py b/tools/generate-runtime-tests.py index 66020cbe126a89c8238afbccc6330508fa2d2c4f..96d4b3502e9f7abfa4f3bb941a30e51590017422 100755
--- a/tools/generate-runtime-tests.py
+++ b/tools/generate-runtime-tests.py
@@ -51,7 +51,7 @@ EXPECTED_FUNCTION_COUNT = 359
 EXPECTED_FUZZABLE_COUNT = 326
 EXPECTED_CCTEST_COUNT = 6
 EXPECTED_UNKNOWN_COUNT = 5
-EXPECTED_BUILTINS_COUNT = 823
+EXPECTED_BUILTINS_COUNT = 824


 # Don't call these at all.


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to