Commit 282edda0 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[printing] Improve object printing

Change-Id: Ib2a0a0ae56f68c865ab1602b3f6c36bc2e66b304
Reviewed-on: https://chromium-review.googlesource.com/448224Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43578}
parent f7bc5ef0
...@@ -506,6 +506,7 @@ void JSPromise::JSPromisePrint(std::ostream& os) { // NOLINT ...@@ -506,6 +506,7 @@ void JSPromise::JSPromisePrint(std::ostream& os) { // NOLINT
void JSRegExp::JSRegExpPrint(std::ostream& os) { // NOLINT void JSRegExp::JSRegExpPrint(std::ostream& os) { // NOLINT
JSObjectPrintHeader(os, this, "JSRegExp"); JSObjectPrintHeader(os, this, "JSRegExp");
os << "\n - data = " << Brief(data()); os << "\n - data = " << Brief(data());
os << "\n - source = " << Brief(source());
JSObjectPrintBody(os, this); JSObjectPrintBody(os, this);
} }
......
...@@ -2433,31 +2433,6 @@ void Smi::SmiPrint(std::ostream& os) const { // NOLINT ...@@ -2433,31 +2433,6 @@ void Smi::SmiPrint(std::ostream& os) const { // NOLINT
os << value(); os << value();
} }
// Should a word be prefixed by 'a' or 'an' in order to read naturally in
// English? Returns false for non-ASCII or words that don't start with
// a capital letter. The a/an rule follows pronunciation in English.
// We don't use the BBC's overcorrect "an historic occasion" though if
// you speak a dialect you may well say "an 'istoric occasion".
static bool AnWord(String* str) {
if (str->length() == 0) return false; // A nothing.
int c0 = str->Get(0);
int c1 = str->length() > 1 ? str->Get(1) : 0;
if (c0 == 'U') {
if (c1 > 'Z') {
return true; // An Umpire, but a UTF8String, a U.
}
} else if (c0 == 'A' || c0 == 'E' || c0 == 'I' || c0 == 'O') {
return true; // An Ape, an ABCBook.
} else if ((c1 == 0 || (c1 >= 'A' && c1 <= 'Z')) &&
(c0 == 'F' || c0 == 'H' || c0 == 'M' || c0 == 'N' || c0 == 'R' ||
c0 == 'S' || c0 == 'X')) {
return true; // An MP3File, an M.
}
return false;
}
Handle<String> String::SlowFlatten(Handle<ConsString> cons, Handle<String> String::SlowFlatten(Handle<ConsString> cons,
PretenureFlag pretenure) { PretenureFlag pretenure) {
DCHECK(cons->second()->length() != 0); DCHECK(cons->second()->length() != 0);
...@@ -2712,27 +2687,34 @@ void JSObject::JSObjectShortPrint(StringStream* accumulator) { ...@@ -2712,27 +2687,34 @@ void JSObject::JSObjectShortPrint(StringStream* accumulator) {
double length = JSArray::cast(this)->length()->IsUndefined(GetIsolate()) double length = JSArray::cast(this)->length()->IsUndefined(GetIsolate())
? 0 ? 0
: JSArray::cast(this)->length()->Number(); : JSArray::cast(this)->length()->Number();
accumulator->Add("<JS Array[%u]>", static_cast<uint32_t>(length)); accumulator->Add("<JSArray[%u]>", static_cast<uint32_t>(length));
break; break;
} }
case JS_BOUND_FUNCTION_TYPE: { case JS_BOUND_FUNCTION_TYPE: {
JSBoundFunction* bound_function = JSBoundFunction::cast(this); JSBoundFunction* bound_function = JSBoundFunction::cast(this);
accumulator->Add("<JS BoundFunction"); accumulator->Add("<JSBoundFunction");
accumulator->Add( accumulator->Add(
" (BoundTargetFunction %p)>", " (BoundTargetFunction %p)>",
reinterpret_cast<void*>(bound_function->bound_target_function())); reinterpret_cast<void*>(bound_function->bound_target_function()));
break; break;
} }
case JS_WEAK_MAP_TYPE: { case JS_WEAK_MAP_TYPE: {
accumulator->Add("<JS WeakMap>"); accumulator->Add("<JSWeakMap>");
break; break;
} }
case JS_WEAK_SET_TYPE: { case JS_WEAK_SET_TYPE: {
accumulator->Add("<JS WeakSet>"); accumulator->Add("<JSWeakSet>");
break; break;
} }
case JS_REGEXP_TYPE: { case JS_REGEXP_TYPE: {
accumulator->Add("<JS RegExp>"); accumulator->Add("<JSRegExp");
JSRegExp* regexp = JSRegExp::cast(this);
if (regexp->source()->IsString()) {
accumulator->Add(" ");
String::cast(regexp->source())->StringShortPrint(accumulator);
}
accumulator->Add(">");
break; break;
} }
case JS_FUNCTION_TYPE: { case JS_FUNCTION_TYPE: {
...@@ -2742,13 +2724,13 @@ void JSObject::JSObjectShortPrint(StringStream* accumulator) { ...@@ -2742,13 +2724,13 @@ void JSObject::JSObjectShortPrint(StringStream* accumulator) {
if (fun_name->IsString()) { if (fun_name->IsString()) {
String* str = String::cast(fun_name); String* str = String::cast(fun_name);
if (str->length() > 0) { if (str->length() > 0) {
accumulator->Add("<JS Function "); accumulator->Add("<JSFunction ");
accumulator->Put(str); accumulator->Put(str);
printed = true; printed = true;
} }
} }
if (!printed) { if (!printed) {
accumulator->Add("<JS Function"); accumulator->Add("<JSFunction");
} }
if (FLAG_trace_file_names) { if (FLAG_trace_file_names) {
Object* source_name = Object* source_name =
...@@ -2762,13 +2744,13 @@ void JSObject::JSObjectShortPrint(StringStream* accumulator) { ...@@ -2762,13 +2744,13 @@ void JSObject::JSObjectShortPrint(StringStream* accumulator) {
} }
} }
} }
accumulator->Add(" (SharedFunctionInfo %p)", accumulator->Add(" (sfi = %p)",
reinterpret_cast<void*>(function->shared())); reinterpret_cast<void*>(function->shared()));
accumulator->Put('>'); accumulator->Put('>');
break; break;
} }
case JS_GENERATOR_OBJECT_TYPE: { case JS_GENERATOR_OBJECT_TYPE: {
accumulator->Add("<JS Generator>"); accumulator->Add("<JSGenerator>");
break; break;
} }
// All other JSObjects are rather similar to each other (JSObject, // All other JSObjects are rather similar to each other (JSObject,
...@@ -2792,13 +2774,11 @@ void JSObject::JSObjectShortPrint(StringStream* accumulator) { ...@@ -2792,13 +2774,11 @@ void JSObject::JSObjectShortPrint(StringStream* accumulator) {
if (constructor_name->IsString()) { if (constructor_name->IsString()) {
String* str = String::cast(constructor_name); String* str = String::cast(constructor_name);
if (str->length() > 0) { if (str->length() > 0) {
bool vowel = AnWord(str); accumulator->Add(global_object ? "<GlobalObject " : "<");
accumulator->Add("<%sa%s ",
global_object ? "Global Object: " : "",
vowel ? "n" : "");
accumulator->Put(str); accumulator->Put(str);
accumulator->Add(" with %smap %p", accumulator->Add(
map_of_this->is_deprecated() ? "deprecated " : "", " %smap = %p",
map_of_this->is_deprecated() ? "deprecated-" : "",
map_of_this); map_of_this);
printed = true; printed = true;
} }
...@@ -2806,7 +2786,7 @@ void JSObject::JSObjectShortPrint(StringStream* accumulator) { ...@@ -2806,7 +2786,7 @@ void JSObject::JSObjectShortPrint(StringStream* accumulator) {
} }
} }
if (!printed) { if (!printed) {
accumulator->Add("<JS %sObject", global_object ? "Global " : ""); accumulator->Add("<JS%sObject", global_object ? "Global " : "");
} }
} }
if (IsJSValue()) { if (IsJSValue()) {
...@@ -3032,14 +3012,14 @@ void HeapObject::HeapObjectShortPrint(std::ostream& os) { // NOLINT ...@@ -3032,14 +3012,14 @@ void HeapObject::HeapObjectShortPrint(std::ostream& os) { // NOLINT
#undef MAKE_STRUCT_CASE #undef MAKE_STRUCT_CASE
case CODE_TYPE: { case CODE_TYPE: {
Code* code = Code::cast(this); Code* code = Code::cast(this);
os << "<Code: " << Code::Kind2String(code->kind()) << ">"; os << "<Code " << Code::Kind2String(code->kind()) << ">";
break; break;
} }
case ODDBALL_TYPE: { case ODDBALL_TYPE: {
if (IsUndefined(isolate)) { if (IsUndefined(isolate)) {
os << "<undefined>"; os << "<undefined>";
} else if (IsTheHole(isolate)) { } else if (IsTheHole(isolate)) {
os << "<the hole>"; os << "<the_hole>";
} else if (IsNull(isolate)) { } else if (IsNull(isolate)) {
os << "<null>"; os << "<null>";
} else if (IsTrue(isolate)) { } else if (IsTrue(isolate)) {
...@@ -3059,13 +3039,13 @@ void HeapObject::HeapObjectShortPrint(std::ostream& os) { // NOLINT ...@@ -3059,13 +3039,13 @@ void HeapObject::HeapObjectShortPrint(std::ostream& os) { // NOLINT
break; break;
} }
case HEAP_NUMBER_TYPE: { case HEAP_NUMBER_TYPE: {
os << "<Number: "; os << "<Number ";
HeapNumber::cast(this)->HeapNumberPrint(os); HeapNumber::cast(this)->HeapNumberPrint(os);
os << ">"; os << ">";
break; break;
} }
case MUTABLE_HEAP_NUMBER_TYPE: { case MUTABLE_HEAP_NUMBER_TYPE: {
os << "<MutableNumber: "; os << "<MutableNumber ";
HeapNumber::cast(this)->HeapNumberPrint(os); HeapNumber::cast(this)->HeapNumberPrint(os);
os << '>'; os << '>';
break; break;
...@@ -3077,28 +3057,31 @@ void HeapObject::HeapObjectShortPrint(std::ostream& os) { // NOLINT ...@@ -3077,28 +3057,31 @@ void HeapObject::HeapObjectShortPrint(std::ostream& os) { // NOLINT
os << "<Foreign>"; os << "<Foreign>";
break; break;
case CELL_TYPE: { case CELL_TYPE: {
os << "Cell for "; os << "<Cell value= ";
HeapStringAllocator allocator; HeapStringAllocator allocator;
StringStream accumulator(&allocator); StringStream accumulator(&allocator);
Cell::cast(this)->value()->ShortPrint(&accumulator); Cell::cast(this)->value()->ShortPrint(&accumulator);
os << accumulator.ToCString().get(); os << accumulator.ToCString().get();
os << '>';
break; break;
} }
case PROPERTY_CELL_TYPE: { case PROPERTY_CELL_TYPE: {
os << "PropertyCell for "; os << "<PropertyCell value=";
HeapStringAllocator allocator; HeapStringAllocator allocator;
StringStream accumulator(&allocator); StringStream accumulator(&allocator);
PropertyCell* cell = PropertyCell::cast(this); PropertyCell* cell = PropertyCell::cast(this);
cell->value()->ShortPrint(&accumulator); cell->value()->ShortPrint(&accumulator);
os << accumulator.ToCString().get(); os << accumulator.ToCString().get();
os << '>';
break; break;
} }
case WEAK_CELL_TYPE: { case WEAK_CELL_TYPE: {
os << "WeakCell for "; os << "<WeakCell value= ";
HeapStringAllocator allocator; HeapStringAllocator allocator;
StringStream accumulator(&allocator); StringStream accumulator(&allocator);
WeakCell::cast(this)->value()->ShortPrint(&accumulator); WeakCell::cast(this)->value()->ShortPrint(&accumulator);
os << accumulator.ToCString().get(); os << accumulator.ToCString().get();
os << '>';
break; break;
} }
default: default:
......
...@@ -59,7 +59,7 @@ void PropertyDetails::PrintAsSlowTo(std::ostream& os) { ...@@ -59,7 +59,7 @@ void PropertyDetails::PrintAsSlowTo(std::ostream& os) {
os << "("; os << "(";
if (constness() == kConst) os << "const "; if (constness() == kConst) os << "const ";
os << (kind() == kData ? "data" : "accessor"); os << (kind() == kData ? "data" : "accessor");
os << ", dictionary_index: " << dictionary_index(); os << ", dict_index: " << dictionary_index();
os << ", attrs: " << attributes() << ")"; os << ", attrs: " << attributes() << ")";
} }
......
...@@ -528,6 +528,7 @@ RUNTIME_FUNCTION(Runtime_DebugPrint) { ...@@ -528,6 +528,7 @@ RUNTIME_FUNCTION(Runtime_DebugPrint) {
if (args[0]->IsString() && isolate->context() != nullptr) { if (args[0]->IsString() && isolate->context() != nullptr) {
// If we have a string, assume it's a code "marker" // If we have a string, assume it's a code "marker"
// and print some interesting cpu debugging info. // and print some interesting cpu debugging info.
args[0]->Print(os);
JavaScriptFrameIterator it(isolate); JavaScriptFrameIterator it(isolate);
JavaScriptFrame* frame = it.frame(); JavaScriptFrame* frame = it.frame();
os << "fp = " << static_cast<void*>(frame->fp()) os << "fp = " << static_cast<void*>(frame->fp())
...@@ -535,8 +536,8 @@ RUNTIME_FUNCTION(Runtime_DebugPrint) { ...@@ -535,8 +536,8 @@ RUNTIME_FUNCTION(Runtime_DebugPrint) {
<< ", caller_sp = " << static_cast<void*>(frame->caller_sp()) << ": "; << ", caller_sp = " << static_cast<void*>(frame->caller_sp()) << ": ";
} else { } else {
os << "DebugPrint: "; os << "DebugPrint: ";
args[0]->Print(os);
} }
args[0]->Print(os);
if (args[0]->IsHeapObject()) { if (args[0]->IsHeapObject()) {
HeapObject::cast(args[0])->map()->Print(os); HeapObject::cast(args[0])->map()->Print(os);
} }
......
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