Commit d9736047 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Implement Mirror object for Symbols.

R=rossberg@chromium.org, yurys@chromium.org
BUG=v8:3290
LOG=Y

Review URL: https://codereview.chromium.org/297513006

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21414 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c1eff30f
......@@ -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
......@@ -281,6 +285,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';
};
......@@ -574,6 +588,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.description = function() {
return %SymbolDescription(%_ValueOf(this.value_));
}
SymbolMirror.prototype.toText = function() {
return %_CallFunction(this.value_, builtins.SymbolToString);
}
/**
* Mirror object for objects.
* @param {object} value The object reflected by this mirror
......@@ -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.description = mirror.description();
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.description = mirror.description();
break;
case OBJECT_TYPE:
case FUNCTION_TYPE:
case ERROR_TYPE:
......
// 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);
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment