Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: src/objects.cc

Issue 677633003: Improve printing for Symbols. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/objects.h ('k') | src/objects-printer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 47a61f627b817ca7d533aea305cfde7b90e4d110..5e975bcab42a2979e9e0c519fddf7020fa16349c 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -1534,15 +1534,7 @@ void HeapObject::HeapObjectShortPrint(std::ostream& os) { // NOLINT
}
case SYMBOL_TYPE: {
Symbol* symbol = Symbol::cast(this);
- os << "<Symbol: " << symbol->Hash();
- if (!symbol->name()->IsUndefined()) {
- os << " ";
- HeapStringAllocator allocator;
- StringStream accumulator(&allocator);
- String::cast(symbol->name())->StringShortPrint(&accumulator);
- os << accumulator.ToCString().get();
- }
- os << ">";
+ symbol->SymbolShortPrint(os);
break;
}
case HEAP_NUMBER_TYPE: {
@@ -13630,6 +13622,31 @@ int JSObject::GetEnumElementKeys(FixedArray* storage) {
}
+const char* Symbol::PrivateSymbolToName() const {
+ Heap* heap = GetIsolate()->heap();
+#define SYMBOL_CHECK_AND_PRINT(name) \
+ if (this == heap->name()) return #name;
+ PRIVATE_SYMBOL_LIST(SYMBOL_CHECK_AND_PRINT)
+#undef SYMBOL_CHECK_AND_PRINT
+ return "UNKNOWN";
+}
+
+
+void Symbol::SymbolShortPrint(std::ostream& os) {
+ os << "<Symbol: " << Hash();
+ if (!name()->IsUndefined()) {
+ os << " ";
+ HeapStringAllocator allocator;
+ StringStream accumulator(&allocator);
+ String::cast(name())->StringShortPrint(&accumulator);
+ os << accumulator.ToCString().get();
+ } else {
+ os << " (" << PrivateSymbolToName() << ")";
+ }
+ os << ">";
+}
+
+
// StringSharedKeys are used as keys in the eval cache.
class StringSharedKey : public HashTableKey {
public:
« no previous file with comments | « src/objects.h ('k') | src/objects-printer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698