Revision: 21414
Author: [email protected]
Date: Wed May 21 15:13:50 2014 UTC
Log: Implement Mirror object for Symbols.
[email protected], [email protected]
BUG=v8:3290
LOG=Y
Review URL: https://codereview.chromium.org/297513006
http://code.google.com/p/v8/source/detail?r=21414
Added:
/branches/bleeding_edge/test/mjsunit/es6/mirror-symbols.js
Modified:
/branches/bleeding_edge/src/mirror-debugger.js
/branches/bleeding_edge/tools/generate-runtime-tests.py
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/es6/mirror-symbols.js Wed May 21
15:13:50 2014 UTC
@@ -0,0 +1,38 @@
+// 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, description) {
+ // 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(description, mirror.description());
+ assertEquals('symbol', mirror.type());
+ assertTrue(mirror.isPrimitive());
+ var description_text = description === undefined ? "" : description;
+ assertEquals('Symbol(' + description_text + ')', mirror.toText());
+ assertSame(symbol, mirror.value());
+
+ // Parse JSON representation and check.
+ var fromJSON = eval('(' + json + ')');
+ assertEquals('symbol', fromJSON.type);
+ assertEquals(description, fromJSON.description);
+}
+
+// Test a number of different symbols.
+testSymbolMirror(Symbol("a"), "a");
+testSymbolMirror(Symbol(12), "12");
+testSymbolMirror(Symbol.for("b"), "b");
+testSymbolMirror(Symbol(), undefined);
=======================================
--- /branches/bleeding_edge/src/mirror-debugger.js Fri May 16 13:06:20 2014
UTC
+++ /branches/bleeding_edge/src/mirror-debugger.js Wed May 21 15:13:50 2014
UTC
@@ -68,6 +68,8 @@
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 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 @@
// - NullMirror
// - NumberMirror
// - StringMirror
+// - SymbolMirror
// - ObjectMirror
// - FunctionMirror
// - UnresolvedFunctionMirror
@@ -281,6 +285,15 @@
};
+/**
+ * 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 @@
type === 'null' ||
type === 'boolean' ||
type === 'number' ||
- type === 'string';
+ type === 'string' ||
+ type === 'symbol';
};
@@ -572,6 +586,28 @@
StringMirror.prototype.toText = function() {
return this.getTruncatedValue(kMaxProtocolStringLength);
};
+
+
+/**
+ * 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.description = function() {
+ return %SymbolDescription(%_ValueOf(this.value_));
+}
+
+
+SymbolMirror.prototype.toText = function() {
+ return %_CallFunction(this.value_, builtins.SymbolToString);
+}
/**
@@ -1184,9 +1220,9 @@
/**
* 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 @@
case STRING_TYPE:
o.value = mirror.getTruncatedValue(this.maxStringLength_());
break;
+ case SYMBOL_TYPE:
+ o.description = mirror.description();
+ break;
case FUNCTION_TYPE:
o.name = mirror.name();
o.inferredName = mirror.inferredName();
@@ -2392,6 +2431,10 @@
content.length = mirror.length();
break;
+ case SYMBOL_TYPE:
+ content.description = mirror.description();
+ break;
+
case OBJECT_TYPE:
case FUNCTION_TYPE:
case ERROR_TYPE:
=======================================
--- /branches/bleeding_edge/tools/generate-runtime-tests.py Wed May 21
08:47:02 2014 UTC
+++ /branches/bleeding_edge/tools/generate-runtime-tests.py Wed May 21
15:13:50 2014 UTC
@@ -51,7 +51,7 @@
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.