Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / v8 / src / objects-printer.cc
1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #include "src/disasm.h"
8 #include "src/disassembler.h"
9 #include "src/heap/objects-visiting.h"
10 #include "src/jsregexp.h"
11 #include "src/ostreams.h"
12
13 namespace v8 {
14 namespace internal {
15
16 #ifdef OBJECT_PRINT
17
18 void Object::Print() {
19   OFStream os(stdout);
20   this->Print(os);
21   os << std::flush;
22 }
23
24
25 void Object::Print(std::ostream& os) {  // NOLINT
26   if (IsSmi()) {
27     Smi::cast(this)->SmiPrint(os);
28   } else {
29     HeapObject::cast(this)->HeapObjectPrint(os);
30   }
31 }
32
33
34 void HeapObject::PrintHeader(std::ostream& os, const char* id) {  // NOLINT
35   os << "" << reinterpret_cast<void*>(this) << ": [" << id << "]\n";
36 }
37
38
39 void HeapObject::HeapObjectPrint(std::ostream& os) {  // NOLINT
40   InstanceType instance_type = map()->instance_type();
41
42   HandleScope scope(GetIsolate());
43   if (instance_type < FIRST_NONSTRING_TYPE) {
44     String::cast(this)->StringPrint(os);
45     return;
46   }
47
48   switch (instance_type) {
49     case SYMBOL_TYPE:
50       Symbol::cast(this)->SymbolPrint(os);
51       break;
52     case MAP_TYPE:
53       Map::cast(this)->MapPrint(os);
54       break;
55     case HEAP_NUMBER_TYPE:
56       HeapNumber::cast(this)->HeapNumberPrint(os);
57       break;
58     case MUTABLE_HEAP_NUMBER_TYPE:
59       os << "<mutable ";
60       HeapNumber::cast(this)->HeapNumberPrint(os);
61       os << ">";
62       break;
63     case FIXED_DOUBLE_ARRAY_TYPE:
64       FixedDoubleArray::cast(this)->FixedDoubleArrayPrint(os);
65       break;
66     case CONSTANT_POOL_ARRAY_TYPE:
67       ConstantPoolArray::cast(this)->ConstantPoolArrayPrint(os);
68       break;
69     case FIXED_ARRAY_TYPE:
70       FixedArray::cast(this)->FixedArrayPrint(os);
71       break;
72     case BYTE_ARRAY_TYPE:
73       ByteArray::cast(this)->ByteArrayPrint(os);
74       break;
75     case FREE_SPACE_TYPE:
76       FreeSpace::cast(this)->FreeSpacePrint(os);
77       break;
78
79 #define PRINT_EXTERNAL_ARRAY(Type, type, TYPE, ctype, size)            \
80   case EXTERNAL_##TYPE##_ARRAY_TYPE:                                   \
81     External##Type##Array::cast(this)->External##Type##ArrayPrint(os); \
82     break;
83
84      TYPED_ARRAYS(PRINT_EXTERNAL_ARRAY)
85 #undef PRINT_EXTERNAL_ARRAY
86
87 #define PRINT_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
88   case Fixed##Type##Array::kInstanceType:                      \
89     Fixed##Type##Array::cast(this)->FixedTypedArrayPrint(os);  \
90     break;
91
92     TYPED_ARRAYS(PRINT_FIXED_TYPED_ARRAY)
93 #undef PRINT_FIXED_TYPED_ARRAY
94
95     case FILLER_TYPE:
96       os << "filler";
97       break;
98     case JS_OBJECT_TYPE:  // fall through
99     case JS_CONTEXT_EXTENSION_OBJECT_TYPE:
100     case JS_ARRAY_TYPE:
101     case JS_GENERATOR_OBJECT_TYPE:
102     case JS_REGEXP_TYPE:
103       JSObject::cast(this)->JSObjectPrint(os);
104       break;
105     case ODDBALL_TYPE:
106       Oddball::cast(this)->to_string()->Print(os);
107       break;
108     case JS_MODULE_TYPE:
109       JSModule::cast(this)->JSModulePrint(os);
110       break;
111     case JS_FUNCTION_TYPE:
112       JSFunction::cast(this)->JSFunctionPrint(os);
113       break;
114     case JS_GLOBAL_PROXY_TYPE:
115       JSGlobalProxy::cast(this)->JSGlobalProxyPrint(os);
116       break;
117     case JS_GLOBAL_OBJECT_TYPE:
118       JSGlobalObject::cast(this)->JSGlobalObjectPrint(os);
119       break;
120     case JS_BUILTINS_OBJECT_TYPE:
121       JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(os);
122       break;
123     case JS_VALUE_TYPE:
124       os << "Value wrapper around:";
125       JSValue::cast(this)->value()->Print(os);
126       break;
127     case JS_DATE_TYPE:
128       JSDate::cast(this)->JSDatePrint(os);
129       break;
130     case CODE_TYPE:
131       Code::cast(this)->CodePrint(os);
132       break;
133     case JS_PROXY_TYPE:
134       JSProxy::cast(this)->JSProxyPrint(os);
135       break;
136     case JS_FUNCTION_PROXY_TYPE:
137       JSFunctionProxy::cast(this)->JSFunctionProxyPrint(os);
138       break;
139     case JS_SET_TYPE:
140       JSSet::cast(this)->JSSetPrint(os);
141       break;
142     case JS_MAP_TYPE:
143       JSMap::cast(this)->JSMapPrint(os);
144       break;
145     case JS_SET_ITERATOR_TYPE:
146       JSSetIterator::cast(this)->JSSetIteratorPrint(os);
147       break;
148     case JS_MAP_ITERATOR_TYPE:
149       JSMapIterator::cast(this)->JSMapIteratorPrint(os);
150       break;
151     case JS_WEAK_MAP_TYPE:
152       JSWeakMap::cast(this)->JSWeakMapPrint(os);
153       break;
154     case JS_WEAK_SET_TYPE:
155       JSWeakSet::cast(this)->JSWeakSetPrint(os);
156       break;
157     case FOREIGN_TYPE:
158       Foreign::cast(this)->ForeignPrint(os);
159       break;
160     case SHARED_FUNCTION_INFO_TYPE:
161       SharedFunctionInfo::cast(this)->SharedFunctionInfoPrint(os);
162       break;
163     case JS_MESSAGE_OBJECT_TYPE:
164       JSMessageObject::cast(this)->JSMessageObjectPrint(os);
165       break;
166     case CELL_TYPE:
167       Cell::cast(this)->CellPrint(os);
168       break;
169     case PROPERTY_CELL_TYPE:
170       PropertyCell::cast(this)->PropertyCellPrint(os);
171       break;
172     case WEAK_CELL_TYPE:
173       WeakCell::cast(this)->WeakCellPrint(os);
174       break;
175     case JS_ARRAY_BUFFER_TYPE:
176       JSArrayBuffer::cast(this)->JSArrayBufferPrint(os);
177       break;
178     case JS_TYPED_ARRAY_TYPE:
179       JSTypedArray::cast(this)->JSTypedArrayPrint(os);
180       break;
181     case JS_DATA_VIEW_TYPE:
182       JSDataView::cast(this)->JSDataViewPrint(os);
183       break;
184 #define MAKE_STRUCT_CASE(NAME, Name, name) \
185   case NAME##_TYPE:                        \
186     Name::cast(this)->Name##Print(os);     \
187     break;
188   STRUCT_LIST(MAKE_STRUCT_CASE)
189 #undef MAKE_STRUCT_CASE
190
191     default:
192       os << "UNKNOWN TYPE " << map()->instance_type();
193       UNREACHABLE();
194       break;
195   }
196 }
197
198
199 void ByteArray::ByteArrayPrint(std::ostream& os) {  // NOLINT
200   os << "byte array, data starts at " << GetDataStartAddress();
201 }
202
203
204 void FreeSpace::FreeSpacePrint(std::ostream& os) {  // NOLINT
205   os << "free space, size " << Size();
206 }
207
208
209 #define EXTERNAL_ARRAY_PRINTER(Type, type, TYPE, ctype, size)                \
210   void External##Type##Array::External##Type##ArrayPrint(std::ostream& os) { \
211     os << "external " #type " array";                                        \
212   }
213
214 TYPED_ARRAYS(EXTERNAL_ARRAY_PRINTER)
215
216 #undef EXTERNAL_ARRAY_PRINTER
217
218
219 template <class Traits>
220 void FixedTypedArray<Traits>::FixedTypedArrayPrint(
221     std::ostream& os) {  // NOLINT
222   os << "fixed " << Traits::Designator();
223 }
224
225
226 void JSObject::PrintProperties(std::ostream& os) {  // NOLINT
227   if (HasFastProperties()) {
228     DescriptorArray* descs = map()->instance_descriptors();
229     for (int i = 0; i < map()->NumberOfOwnDescriptors(); i++) {
230       os << "   ";
231       descs->GetKey(i)->NamePrint(os);
232       os << ": ";
233       switch (descs->GetType(i)) {
234         case FIELD: {
235           FieldIndex index = FieldIndex::ForDescriptor(map(), i);
236           os << Brief(RawFastPropertyAt(index)) << " (field at offset "
237              << index.property_index() << ")\n";
238           break;
239         }
240         case CONSTANT:
241           os << Brief(descs->GetConstant(i)) << " (constant)\n";
242           break;
243         case CALLBACKS:
244           os << Brief(descs->GetCallbacksObject(i)) << " (callback)\n";
245           break;
246         case NORMAL:  // only in slow mode
247           UNREACHABLE();
248           break;
249       }
250     }
251   } else {
252     property_dictionary()->Print(os);
253   }
254 }
255
256
257 template <class T>
258 static void DoPrintElements(std::ostream& os, Object* object) {  // NOLINT
259   T* p = T::cast(object);
260   for (int i = 0; i < p->length(); i++) {
261     os << "   " << i << ": " << p->get_scalar(i) << "\n";
262   }
263 }
264
265
266 void JSObject::PrintElements(std::ostream& os) {  // NOLINT
267   // Don't call GetElementsKind, its validation code can cause the printer to
268   // fail when debugging.
269   switch (map()->elements_kind()) {
270     case FAST_HOLEY_SMI_ELEMENTS:
271     case FAST_SMI_ELEMENTS:
272     case FAST_HOLEY_ELEMENTS:
273     case FAST_ELEMENTS: {
274       // Print in array notation for non-sparse arrays.
275       FixedArray* p = FixedArray::cast(elements());
276       for (int i = 0; i < p->length(); i++) {
277         os << "   " << i << ": " << Brief(p->get(i)) << "\n";
278       }
279       break;
280     }
281     case FAST_HOLEY_DOUBLE_ELEMENTS:
282     case FAST_DOUBLE_ELEMENTS: {
283       // Print in array notation for non-sparse arrays.
284       if (elements()->length() > 0) {
285         FixedDoubleArray* p = FixedDoubleArray::cast(elements());
286         for (int i = 0; i < p->length(); i++) {
287           os << "   " << i << ": ";
288           if (p->is_the_hole(i)) {
289             os << "<the hole>";
290           } else {
291             os << p->get_scalar(i);
292           }
293           os << "\n";
294         }
295       }
296       break;
297     }
298
299
300 #define PRINT_ELEMENTS(Kind, Type)         \
301   case Kind: {                             \
302     DoPrintElements<Type>(os, elements()); \
303     break;                                 \
304   }
305
306     PRINT_ELEMENTS(EXTERNAL_UINT8_CLAMPED_ELEMENTS, ExternalUint8ClampedArray)
307     PRINT_ELEMENTS(EXTERNAL_INT8_ELEMENTS, ExternalInt8Array)
308     PRINT_ELEMENTS(EXTERNAL_UINT8_ELEMENTS,
309         ExternalUint8Array)
310     PRINT_ELEMENTS(EXTERNAL_INT16_ELEMENTS, ExternalInt16Array)
311     PRINT_ELEMENTS(EXTERNAL_UINT16_ELEMENTS,
312         ExternalUint16Array)
313     PRINT_ELEMENTS(EXTERNAL_INT32_ELEMENTS, ExternalInt32Array)
314     PRINT_ELEMENTS(EXTERNAL_UINT32_ELEMENTS,
315         ExternalUint32Array)
316     PRINT_ELEMENTS(EXTERNAL_FLOAT32_ELEMENTS, ExternalFloat32Array)
317     PRINT_ELEMENTS(EXTERNAL_FLOAT64_ELEMENTS, ExternalFloat64Array)
318
319     PRINT_ELEMENTS(UINT8_ELEMENTS, FixedUint8Array)
320     PRINT_ELEMENTS(UINT8_CLAMPED_ELEMENTS, FixedUint8ClampedArray)
321     PRINT_ELEMENTS(INT8_ELEMENTS, FixedInt8Array)
322     PRINT_ELEMENTS(UINT16_ELEMENTS, FixedUint16Array)
323     PRINT_ELEMENTS(INT16_ELEMENTS, FixedInt16Array)
324     PRINT_ELEMENTS(UINT32_ELEMENTS, FixedUint32Array)
325     PRINT_ELEMENTS(INT32_ELEMENTS, FixedInt32Array)
326     PRINT_ELEMENTS(FLOAT32_ELEMENTS, FixedFloat32Array)
327     PRINT_ELEMENTS(FLOAT64_ELEMENTS, FixedFloat64Array)
328
329 #undef PRINT_ELEMENTS
330
331     case DICTIONARY_ELEMENTS:
332       elements()->Print(os);
333       break;
334     case SLOPPY_ARGUMENTS_ELEMENTS: {
335       FixedArray* p = FixedArray::cast(elements());
336       os << "   parameter map:";
337       for (int i = 2; i < p->length(); i++) {
338         os << " " << (i - 2) << ":" << Brief(p->get(i));
339       }
340       os << "\n   context: " << Brief(p->get(0))
341          << "\n   arguments: " << Brief(p->get(1)) << "\n";
342       break;
343     }
344   }
345 }
346
347
348 void JSObject::PrintTransitions(std::ostream& os) {  // NOLINT
349   if (!map()->HasTransitionArray()) return;
350   map()->transitions()->PrintTransitions(os, false);
351 }
352
353
354 void JSObject::JSObjectPrint(std::ostream& os) {  // NOLINT
355   HeapObject::PrintHeader(os, "JSObject");
356   // Don't call GetElementsKind, its validation code can cause the printer to
357   // fail when debugging.
358   PrototypeIterator iter(GetIsolate(), this);
359   os << " - map = " << reinterpret_cast<void*>(map()) << " ["
360      << ElementsKindToString(this->map()->elements_kind())
361      << "]\n - prototype = " << reinterpret_cast<void*>(iter.GetCurrent())
362      << "\n {\n";
363   PrintProperties(os);
364   PrintTransitions(os);
365   PrintElements(os);
366   os << " }\n";
367 }
368
369
370 void JSModule::JSModulePrint(std::ostream& os) {  // NOLINT
371   HeapObject::PrintHeader(os, "JSModule");
372   os << " - map = " << reinterpret_cast<void*>(map()) << "\n"
373      << " - context = ";
374   context()->Print(os);
375   os << " - scope_info = " << Brief(scope_info())
376      << ElementsKindToString(this->map()->elements_kind()) << " {\n";
377   PrintProperties(os);
378   PrintElements(os);
379   os << " }\n";
380 }
381
382
383 static const char* TypeToString(InstanceType type) {
384   switch (type) {
385 #define TYPE_TO_STRING(TYPE) case TYPE: return #TYPE;
386   INSTANCE_TYPE_LIST(TYPE_TO_STRING)
387 #undef TYPE_TO_STRING
388   }
389   UNREACHABLE();
390   return "UNKNOWN";  // Keep the compiler happy.
391 }
392
393
394 void Symbol::SymbolPrint(std::ostream& os) {  // NOLINT
395   HeapObject::PrintHeader(os, "Symbol");
396   os << " - hash: " << Hash();
397   os << "\n - name: " << Brief(name());
398   if (name()->IsUndefined()) {
399     os << " (" << PrivateSymbolToName() << ")";
400   }
401   os << "\n - private: " << is_private();
402   os << "\n - own: " << is_own();
403   os << "\n";
404 }
405
406
407 void Map::MapPrint(std::ostream& os) {  // NOLINT
408   HeapObject::PrintHeader(os, "Map");
409   os << " - type: " << TypeToString(instance_type()) << "\n";
410   os << " - instance size: " << instance_size() << "\n";
411   os << " - inobject properties: " << inobject_properties() << "\n";
412   os << " - elements kind: " << ElementsKindToString(elements_kind());
413   os << "\n - pre-allocated property fields: "
414      << pre_allocated_property_fields() << "\n";
415   os << " - unused property fields: " << unused_property_fields() << "\n";
416   if (is_dictionary_map()) os << " - dictionary_map\n";
417   if (is_prototype_map()) os << " - prototype_map\n";
418   if (is_hidden_prototype()) os << " - hidden_prototype\n";
419   if (has_named_interceptor()) os << " - named_interceptor\n";
420   if (has_indexed_interceptor()) os << " - indexed_interceptor\n";
421   if (is_undetectable()) os << " - undetectable\n";
422   if (has_instance_call_handler()) os << " - instance_call_handler\n";
423   if (is_access_check_needed()) os << " - access_check_needed\n";
424   if (is_frozen()) {
425     os << " - frozen\n";
426   } else if (!is_extensible()) {
427     os << " - sealed\n";
428   }
429   os << " - back pointer: " << Brief(GetBackPointer());
430   os << "\n - instance descriptors " << (owns_descriptors() ? "(own) " : "")
431      << "#" << NumberOfOwnDescriptors() << ": "
432      << Brief(instance_descriptors());
433   if (HasTransitionArray()) {
434     os << "\n - transitions: " << Brief(transitions());
435   }
436   os << "\n - prototype: " << Brief(prototype());
437   os << "\n - constructor: " << Brief(constructor());
438   os << "\n - code cache: " << Brief(code_cache());
439   os << "\n - dependent code: " << Brief(dependent_code());
440   os << "\n";
441 }
442
443
444 void CodeCache::CodeCachePrint(std::ostream& os) {  // NOLINT
445   HeapObject::PrintHeader(os, "CodeCache");
446   os << "\n - default_cache: " << Brief(default_cache());
447   os << "\n - normal_type_cache: " << Brief(normal_type_cache());
448 }
449
450
451 void PolymorphicCodeCache::PolymorphicCodeCachePrint(
452     std::ostream& os) {  // NOLINT
453   HeapObject::PrintHeader(os, "PolymorphicCodeCache");
454   os << "\n - cache: " << Brief(cache());
455 }
456
457
458 void TypeFeedbackInfo::TypeFeedbackInfoPrint(std::ostream& os) {  // NOLINT
459   HeapObject::PrintHeader(os, "TypeFeedbackInfo");
460   os << " - ic_total_count: " << ic_total_count()
461      << ", ic_with_type_info_count: " << ic_with_type_info_count()
462      << ", ic_generic_count: " << ic_generic_count() << "\n";
463 }
464
465
466 void AliasedArgumentsEntry::AliasedArgumentsEntryPrint(
467     std::ostream& os) {  // NOLINT
468   HeapObject::PrintHeader(os, "AliasedArgumentsEntry");
469   os << "\n - aliased_context_slot: " << aliased_context_slot();
470 }
471
472
473 void FixedArray::FixedArrayPrint(std::ostream& os) {  // NOLINT
474   HeapObject::PrintHeader(os, "FixedArray");
475   os << " - length: " << length();
476   for (int i = 0; i < length(); i++) {
477     os << "\n  [" << i << "]: " << Brief(get(i));
478   }
479   os << "\n";
480 }
481
482
483 void FixedDoubleArray::FixedDoubleArrayPrint(std::ostream& os) {  // NOLINT
484   HeapObject::PrintHeader(os, "FixedDoubleArray");
485   os << " - length: " << length();
486   for (int i = 0; i < length(); i++) {
487     os << "\n  [" << i << "]: ";
488     if (is_the_hole(i)) {
489       os << "<the hole>";
490     } else {
491       os << get_scalar(i);
492     }
493   }
494   os << "\n";
495 }
496
497
498 void ConstantPoolArray::ConstantPoolArrayPrint(std::ostream& os) {  // NOLINT
499   HeapObject::PrintHeader(os, "ConstantPoolArray");
500   os << " - length: " << length();
501   for (int i = 0; i <= last_index(INT32, SMALL_SECTION); i++) {
502     if (i < last_index(INT64, SMALL_SECTION)) {
503       os << "\n  [" << i << "]: double: " << get_int64_entry_as_double(i);
504     } else if (i <= last_index(CODE_PTR, SMALL_SECTION)) {
505       os << "\n  [" << i << "]: code target pointer: "
506          << reinterpret_cast<void*>(get_code_ptr_entry(i));
507     } else if (i <= last_index(HEAP_PTR, SMALL_SECTION)) {
508       os << "\n  [" << i << "]: heap pointer: "
509          << reinterpret_cast<void*>(get_heap_ptr_entry(i));
510     } else if (i <= last_index(INT32, SMALL_SECTION)) {
511       os << "\n  [" << i << "]: int32: " << get_int32_entry(i);
512     }
513   }
514   if (is_extended_layout()) {
515     os << "\n  Extended section:";
516     for (int i = first_extended_section_index();
517          i <= last_index(INT32, EXTENDED_SECTION); i++) {
518       if (i < last_index(INT64, EXTENDED_SECTION)) {
519         os << "\n  [" << i << "]: double: " << get_int64_entry_as_double(i);
520       } else if (i <= last_index(CODE_PTR, EXTENDED_SECTION)) {
521         os << "\n  [" << i << "]: code target pointer: "
522            << reinterpret_cast<void*>(get_code_ptr_entry(i));
523       } else if (i <= last_index(HEAP_PTR, EXTENDED_SECTION)) {
524         os << "\n  [" << i << "]: heap pointer: "
525            << reinterpret_cast<void*>(get_heap_ptr_entry(i));
526       } else if (i <= last_index(INT32, EXTENDED_SECTION)) {
527         os << "\n  [" << i << "]: int32: " << get_int32_entry(i);
528       }
529     }
530   }
531   os << "\n";
532 }
533
534
535 void JSValue::JSValuePrint(std::ostream& os) {  // NOLINT
536   HeapObject::PrintHeader(os, "ValueObject");
537   value()->Print(os);
538 }
539
540
541 void JSMessageObject::JSMessageObjectPrint(std::ostream& os) {  // NOLINT
542   HeapObject::PrintHeader(os, "JSMessageObject");
543   os << " - type: " << Brief(type());
544   os << "\n - arguments: " << Brief(arguments());
545   os << "\n - start_position: " << start_position();
546   os << "\n - end_position: " << end_position();
547   os << "\n - script: " << Brief(script());
548   os << "\n - stack_frames: " << Brief(stack_frames());
549   os << "\n";
550 }
551
552
553 void String::StringPrint(std::ostream& os) {  // NOLINT
554   if (StringShape(this).IsInternalized()) {
555     os << "#";
556   } else if (StringShape(this).IsCons()) {
557     os << "c\"";
558   } else {
559     os << "\"";
560   }
561
562   const char truncated_epilogue[] = "...<truncated>";
563   int len = length();
564   if (!FLAG_use_verbose_printer) {
565     if (len > 100) {
566       len = 100 - sizeof(truncated_epilogue);
567     }
568   }
569   for (int i = 0; i < len; i++) {
570     os << AsUC16(Get(i));
571   }
572   if (len != length()) {
573     os << truncated_epilogue;
574   }
575
576   if (!StringShape(this).IsInternalized()) os << "\"";
577 }
578
579
580 void Name::NamePrint(std::ostream& os) {  // NOLINT
581   if (IsString()) {
582     String::cast(this)->StringPrint(os);
583   } else if (IsSymbol()) {
584     Symbol::cast(this)->name()->Print(os);
585   } else {
586     os << Brief(this);
587   }
588 }
589
590
591 // This method is only meant to be called from gdb for debugging purposes.
592 // Since the string can also be in two-byte encoding, non-Latin1 characters
593 // will be ignored in the output.
594 char* String::ToAsciiArray() {
595   // Static so that subsequent calls frees previously allocated space.
596   // This also means that previous results will be overwritten.
597   static char* buffer = NULL;
598   if (buffer != NULL) delete[] buffer;
599   buffer = new char[length()+1];
600   WriteToFlat(this, reinterpret_cast<uint8_t*>(buffer), 0, length());
601   buffer[length()] = 0;
602   return buffer;
603 }
604
605
606 static const char* const weekdays[] = {
607   "???", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
608 };
609
610
611 void JSDate::JSDatePrint(std::ostream& os) {  // NOLINT
612   HeapObject::PrintHeader(os, "JSDate");
613   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
614   os << " - value = ";
615   value()->Print(os);
616   if (!year()->IsSmi()) {
617     os << " - time = NaN\n";
618   } else {
619     // TODO(svenpanne) Add some basic formatting to our streams.
620     Vector<char> buf = Vector<char>::New(100);
621     SNPrintF(
622         buf, " - time = %s %04d/%02d/%02d %02d:%02d:%02d\n",
623         weekdays[weekday()->IsSmi() ? Smi::cast(weekday())->value() + 1 : 0],
624         year()->IsSmi() ? Smi::cast(year())->value() : -1,
625         month()->IsSmi() ? Smi::cast(month())->value() : -1,
626         day()->IsSmi() ? Smi::cast(day())->value() : -1,
627         hour()->IsSmi() ? Smi::cast(hour())->value() : -1,
628         min()->IsSmi() ? Smi::cast(min())->value() : -1,
629         sec()->IsSmi() ? Smi::cast(sec())->value() : -1);
630     os << buf.start();
631   }
632 }
633
634
635 void JSProxy::JSProxyPrint(std::ostream& os) {  // NOLINT
636   HeapObject::PrintHeader(os, "JSProxy");
637   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
638   os << " - handler = ";
639   handler()->Print(os);
640   os << "\n - hash = ";
641   hash()->Print(os);
642   os << "\n";
643 }
644
645
646 void JSFunctionProxy::JSFunctionProxyPrint(std::ostream& os) {  // NOLINT
647   HeapObject::PrintHeader(os, "JSFunctionProxy");
648   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
649   os << " - handler = ";
650   handler()->Print(os);
651   os << "\n - call_trap = ";
652   call_trap()->Print(os);
653   os << "\n - construct_trap = ";
654   construct_trap()->Print(os);
655   os << "\n";
656 }
657
658
659 void JSSet::JSSetPrint(std::ostream& os) {  // NOLINT
660   HeapObject::PrintHeader(os, "JSSet");
661   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
662   os << " - table = " << Brief(table());
663   os << "\n";
664 }
665
666
667 void JSMap::JSMapPrint(std::ostream& os) {  // NOLINT
668   HeapObject::PrintHeader(os, "JSMap");
669   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
670   os << " - table = " << Brief(table());
671   os << "\n";
672 }
673
674
675 template <class Derived, class TableType>
676 void
677 OrderedHashTableIterator<Derived, TableType>::OrderedHashTableIteratorPrint(
678     std::ostream& os) {  // NOLINT
679   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
680   os << " - table = " << Brief(table());
681   os << "\n - index = " << Brief(index());
682   os << "\n - kind = " << Brief(kind());
683   os << "\n";
684 }
685
686
687 template void OrderedHashTableIterator<
688     JSSetIterator,
689     OrderedHashSet>::OrderedHashTableIteratorPrint(std::ostream& os);  // NOLINT
690
691
692 template void OrderedHashTableIterator<
693     JSMapIterator,
694     OrderedHashMap>::OrderedHashTableIteratorPrint(std::ostream& os);  // NOLINT
695
696
697 void JSSetIterator::JSSetIteratorPrint(std::ostream& os) {  // NOLINT
698   HeapObject::PrintHeader(os, "JSSetIterator");
699   OrderedHashTableIteratorPrint(os);
700 }
701
702
703 void JSMapIterator::JSMapIteratorPrint(std::ostream& os) {  // NOLINT
704   HeapObject::PrintHeader(os, "JSMapIterator");
705   OrderedHashTableIteratorPrint(os);
706 }
707
708
709 void JSWeakMap::JSWeakMapPrint(std::ostream& os) {  // NOLINT
710   HeapObject::PrintHeader(os, "JSWeakMap");
711   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
712   os << " - table = " << Brief(table());
713   os << "\n";
714 }
715
716
717 void JSWeakSet::JSWeakSetPrint(std::ostream& os) {  // NOLINT
718   HeapObject::PrintHeader(os, "JSWeakSet");
719   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
720   os << " - table = " << Brief(table());
721   os << "\n";
722 }
723
724
725 void JSArrayBuffer::JSArrayBufferPrint(std::ostream& os) {  // NOLINT
726   HeapObject::PrintHeader(os, "JSArrayBuffer");
727   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
728   os << " - backing_store = " << backing_store() << "\n";
729   os << " - byte_length = " << Brief(byte_length());
730   os << "\n";
731 }
732
733
734 void JSTypedArray::JSTypedArrayPrint(std::ostream& os) {  // NOLINT
735   HeapObject::PrintHeader(os, "JSTypedArray");
736   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
737   os << " - buffer = " << Brief(buffer());
738   os << "\n - byte_offset = " << Brief(byte_offset());
739   os << "\n - byte_length = " << Brief(byte_length());
740   os << "\n - length = " << Brief(length());
741   os << "\n";
742   PrintElements(os);
743 }
744
745
746 void JSDataView::JSDataViewPrint(std::ostream& os) {  // NOLINT
747   HeapObject::PrintHeader(os, "JSDataView");
748   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
749   os << " - buffer =" << Brief(buffer());
750   os << "\n - byte_offset = " << Brief(byte_offset());
751   os << "\n - byte_length = " << Brief(byte_length());
752   os << "\n";
753 }
754
755
756 void JSFunction::JSFunctionPrint(std::ostream& os) {  // NOLINT
757   HeapObject::PrintHeader(os, "Function");
758   os << " - map = " << reinterpret_cast<void*>(map()) << "\n";
759   os << " - initial_map = ";
760   if (has_initial_map()) os << Brief(initial_map());
761   os << "\n - shared_info = " << Brief(shared());
762   os << "\n   - name = " << Brief(shared()->name());
763   os << "\n - context = " << Brief(context());
764   if (shared()->bound()) {
765     os << "\n - bindings = " << Brief(function_bindings());
766   } else {
767     os << "\n - literals = " << Brief(literals());
768   }
769   os << "\n - code = " << Brief(code());
770   os << "\n";
771   PrintProperties(os);
772   PrintElements(os);
773   os << "\n";
774 }
775
776
777 void SharedFunctionInfo::SharedFunctionInfoPrint(std::ostream& os) {  // NOLINT
778   HeapObject::PrintHeader(os, "SharedFunctionInfo");
779   os << " - name: " << Brief(name());
780   os << "\n - expected_nof_properties: " << expected_nof_properties();
781   os << "\n - ast_node_count: " << ast_node_count();
782   os << "\n - instance class name = ";
783   instance_class_name()->Print(os);
784   os << "\n - code = " << Brief(code());
785   if (HasSourceCode()) {
786     os << "\n - source code = ";
787     String* source = String::cast(Script::cast(script())->source());
788     int start = start_position();
789     int length = end_position() - start;
790     SmartArrayPointer<char> source_string =
791         source->ToCString(DISALLOW_NULLS,
792                           FAST_STRING_TRAVERSAL,
793                           start, length, NULL);
794     os << source_string.get();
795   }
796   // Script files are often large, hard to read.
797   // os << "\n - script =";
798   // script()->Print(os);
799   os << "\n - function token position = " << function_token_position();
800   os << "\n - start position = " << start_position();
801   os << "\n - end position = " << end_position();
802   os << "\n - is expression = " << is_expression();
803   os << "\n - debug info = " << Brief(debug_info());
804   os << "\n - length = " << length();
805   os << "\n - optimized_code_map = " << Brief(optimized_code_map());
806   os << "\n - feedback_vector = ";
807   feedback_vector()->FixedArrayPrint(os);
808   os << "\n";
809 }
810
811
812 void JSGlobalProxy::JSGlobalProxyPrint(std::ostream& os) {  // NOLINT
813   os << "global_proxy ";
814   JSObjectPrint(os);
815   os << "native context : " << Brief(native_context());
816   os << "\n";
817 }
818
819
820 void JSGlobalObject::JSGlobalObjectPrint(std::ostream& os) {  // NOLINT
821   os << "global ";
822   JSObjectPrint(os);
823   os << "native context : " << Brief(native_context());
824   os << "\n";
825 }
826
827
828 void JSBuiltinsObject::JSBuiltinsObjectPrint(std::ostream& os) {  // NOLINT
829   os << "builtins ";
830   JSObjectPrint(os);
831 }
832
833
834 void Cell::CellPrint(std::ostream& os) {  // NOLINT
835   HeapObject::PrintHeader(os, "Cell");
836 }
837
838
839 void PropertyCell::PropertyCellPrint(std::ostream& os) {  // NOLINT
840   HeapObject::PrintHeader(os, "PropertyCell");
841 }
842
843
844 void WeakCell::WeakCellPrint(std::ostream& os) {  // NOLINT
845   HeapObject::PrintHeader(os, "WeakCell");
846 }
847
848
849 void Code::CodePrint(std::ostream& os) {  // NOLINT
850   HeapObject::PrintHeader(os, "Code");
851 #ifdef ENABLE_DISASSEMBLER
852   if (FLAG_use_verbose_printer) {
853     Disassemble(NULL, os);
854   }
855 #endif
856 }
857
858
859 void Foreign::ForeignPrint(std::ostream& os) {  // NOLINT
860   os << "foreign address : " << foreign_address();
861 }
862
863
864 void ExecutableAccessorInfo::ExecutableAccessorInfoPrint(
865     std::ostream& os) {  // NOLINT
866   HeapObject::PrintHeader(os, "ExecutableAccessorInfo");
867   os << "\n - name: " << Brief(name());
868   os << "\n - flag: " << Brief(flag());
869   os << "\n - getter: " << Brief(getter());
870   os << "\n - setter: " << Brief(setter());
871   os << "\n - data: " << Brief(data());
872   os << "\n";
873 }
874
875
876 void DeclaredAccessorInfo::DeclaredAccessorInfoPrint(
877     std::ostream& os) {  // NOLINT
878   HeapObject::PrintHeader(os, "DeclaredAccessorInfo");
879   os << "\n - name: " << Brief(name());
880   os << "\n - flag: " << Brief(flag());
881   os << "\n - descriptor: " << Brief(descriptor());
882   os << "\n";
883 }
884
885
886 void DeclaredAccessorDescriptor::DeclaredAccessorDescriptorPrint(
887     std::ostream& os) {  // NOLINT
888   HeapObject::PrintHeader(os, "DeclaredAccessorDescriptor");
889   os << "\n - internal field: " << Brief(serialized_data());
890   os << "\n";
891 }
892
893
894 void Box::BoxPrint(std::ostream& os) {  // NOLINT
895   HeapObject::PrintHeader(os, "Box");
896   os << "\n - value: " << Brief(value());
897   os << "\n";
898 }
899
900
901 void AccessorPair::AccessorPairPrint(std::ostream& os) {  // NOLINT
902   HeapObject::PrintHeader(os, "AccessorPair");
903   os << "\n - getter: " << Brief(getter());
904   os << "\n - setter: " << Brief(setter());
905   os << "\n";
906 }
907
908
909 void AccessCheckInfo::AccessCheckInfoPrint(std::ostream& os) {  // NOLINT
910   HeapObject::PrintHeader(os, "AccessCheckInfo");
911   os << "\n - named_callback: " << Brief(named_callback());
912   os << "\n - indexed_callback: " << Brief(indexed_callback());
913   os << "\n - data: " << Brief(data());
914   os << "\n";
915 }
916
917
918 void InterceptorInfo::InterceptorInfoPrint(std::ostream& os) {  // NOLINT
919   HeapObject::PrintHeader(os, "InterceptorInfo");
920   os << "\n - getter: " << Brief(getter());
921   os << "\n - setter: " << Brief(setter());
922   os << "\n - query: " << Brief(query());
923   os << "\n - deleter: " << Brief(deleter());
924   os << "\n - enumerator: " << Brief(enumerator());
925   os << "\n - data: " << Brief(data());
926   os << "\n";
927 }
928
929
930 void CallHandlerInfo::CallHandlerInfoPrint(std::ostream& os) {  // NOLINT
931   HeapObject::PrintHeader(os, "CallHandlerInfo");
932   os << "\n - callback: " << Brief(callback());
933   os << "\n - data: " << Brief(data());
934   os << "\n";
935 }
936
937
938 void FunctionTemplateInfo::FunctionTemplateInfoPrint(
939     std::ostream& os) {  // NOLINT
940   HeapObject::PrintHeader(os, "FunctionTemplateInfo");
941   os << "\n - class name: " << Brief(class_name());
942   os << "\n - tag: " << Brief(tag());
943   os << "\n - property_list: " << Brief(property_list());
944   os << "\n - serial_number: " << Brief(serial_number());
945   os << "\n - call_code: " << Brief(call_code());
946   os << "\n - property_accessors: " << Brief(property_accessors());
947   os << "\n - prototype_template: " << Brief(prototype_template());
948   os << "\n - parent_template: " << Brief(parent_template());
949   os << "\n - named_property_handler: " << Brief(named_property_handler());
950   os << "\n - indexed_property_handler: " << Brief(indexed_property_handler());
951   os << "\n - instance_template: " << Brief(instance_template());
952   os << "\n - signature: " << Brief(signature());
953   os << "\n - access_check_info: " << Brief(access_check_info());
954   os << "\n - hidden_prototype: " << (hidden_prototype() ? "true" : "false");
955   os << "\n - undetectable: " << (undetectable() ? "true" : "false");
956   os << "\n - need_access_check: " << (needs_access_check() ? "true" : "false");
957   os << "\n";
958 }
959
960
961 void ObjectTemplateInfo::ObjectTemplateInfoPrint(std::ostream& os) {  // NOLINT
962   HeapObject::PrintHeader(os, "ObjectTemplateInfo");
963   os << " - tag: " << Brief(tag());
964   os << "\n - property_list: " << Brief(property_list());
965   os << "\n - property_accessors: " << Brief(property_accessors());
966   os << "\n - constructor: " << Brief(constructor());
967   os << "\n - internal_field_count: " << Brief(internal_field_count());
968   os << "\n";
969 }
970
971
972 void SignatureInfo::SignatureInfoPrint(std::ostream& os) {  // NOLINT
973   HeapObject::PrintHeader(os, "SignatureInfo");
974   os << "\n - receiver: " << Brief(receiver());
975   os << "\n - args: " << Brief(args());
976   os << "\n";
977 }
978
979
980 void TypeSwitchInfo::TypeSwitchInfoPrint(std::ostream& os) {  // NOLINT
981   HeapObject::PrintHeader(os, "TypeSwitchInfo");
982   os << "\n - types: " << Brief(types());
983   os << "\n";
984 }
985
986
987 void AllocationSite::AllocationSitePrint(std::ostream& os) {  // NOLINT
988   HeapObject::PrintHeader(os, "AllocationSite");
989   os << " - weak_next: " << Brief(weak_next());
990   os << "\n - dependent code: " << Brief(dependent_code());
991   os << "\n - nested site: " << Brief(nested_site());
992   os << "\n - memento found count: "
993      << Brief(Smi::FromInt(memento_found_count()));
994   os << "\n - memento create count: "
995      << Brief(Smi::FromInt(memento_create_count()));
996   os << "\n - pretenure decision: "
997      << Brief(Smi::FromInt(pretenure_decision()));
998   os << "\n - transition_info: ";
999   if (transition_info()->IsSmi()) {
1000     ElementsKind kind = GetElementsKind();
1001     os << "Array allocation with ElementsKind " << ElementsKindToString(kind);
1002   } else if (transition_info()->IsJSArray()) {
1003     os << "Array literal " << Brief(transition_info());
1004   } else {
1005     os << "unknown transition_info" << Brief(transition_info());
1006   }
1007   os << "\n";
1008 }
1009
1010
1011 void AllocationMemento::AllocationMementoPrint(std::ostream& os) {  // NOLINT
1012   HeapObject::PrintHeader(os, "AllocationMemento");
1013   os << " - allocation site: ";
1014   if (IsValid()) {
1015     GetAllocationSite()->Print(os);
1016   } else {
1017     os << "<invalid>\n";
1018   }
1019 }
1020
1021
1022 void Script::ScriptPrint(std::ostream& os) {  // NOLINT
1023   HeapObject::PrintHeader(os, "Script");
1024   os << "\n - source: " << Brief(source());
1025   os << "\n - name: " << Brief(name());
1026   os << "\n - line_offset: " << Brief(line_offset());
1027   os << "\n - column_offset: " << Brief(column_offset());
1028   os << "\n - type: " << Brief(type());
1029   os << "\n - id: " << Brief(id());
1030   os << "\n - context data: " << Brief(context_data());
1031   os << "\n - wrapper: " << Brief(wrapper());
1032   os << "\n - compilation type: " << compilation_type();
1033   os << "\n - line ends: " << Brief(line_ends());
1034   os << "\n - eval from shared: " << Brief(eval_from_shared());
1035   os << "\n - eval from instructions offset: "
1036      << Brief(eval_from_instructions_offset());
1037   os << "\n";
1038 }
1039
1040
1041 void DebugInfo::DebugInfoPrint(std::ostream& os) {  // NOLINT
1042   HeapObject::PrintHeader(os, "DebugInfo");
1043   os << "\n - shared: " << Brief(shared());
1044   os << "\n - original_code: " << Brief(original_code());
1045   os << "\n - code: " << Brief(code());
1046   os << "\n - break_points: ";
1047   break_points()->Print(os);
1048 }
1049
1050
1051 void BreakPointInfo::BreakPointInfoPrint(std::ostream& os) {  // NOLINT
1052   HeapObject::PrintHeader(os, "BreakPointInfo");
1053   os << "\n - code_position: " << code_position()->value();
1054   os << "\n - source_position: " << source_position()->value();
1055   os << "\n - statement_position: " << statement_position()->value();
1056   os << "\n - break_point_objects: " << Brief(break_point_objects());
1057   os << "\n";
1058 }
1059
1060
1061 void DescriptorArray::Print() {
1062   OFStream os(stdout);
1063   this->PrintDescriptors(os);
1064   os << std::flush;
1065 }
1066
1067
1068 void DescriptorArray::PrintDescriptors(std::ostream& os) {  // NOLINT
1069   os << "Descriptor array " << number_of_descriptors() << "\n";
1070   for (int i = 0; i < number_of_descriptors(); i++) {
1071     Descriptor desc;
1072     Get(i, &desc);
1073     os << " " << i << ": " << desc << "\n";
1074   }
1075   os << "\n";
1076 }
1077
1078
1079 void TransitionArray::Print() {
1080   OFStream os(stdout);
1081   this->PrintTransitions(os);
1082   os << std::flush;
1083 }
1084
1085
1086 void TransitionArray::PrintTransitions(std::ostream& os,
1087                                        bool print_header) {  // NOLINT
1088   if (print_header) {
1089     os << "Transition array " << number_of_transitions() << "\n";
1090   }
1091   for (int i = 0; i < number_of_transitions(); i++) {
1092     Name* key = GetKey(i);
1093     os << "   ";
1094     key->NamePrint(os);
1095     os << ": ";
1096     if (key == GetHeap()->frozen_symbol()) {
1097       os << " (transition to frozen)";
1098     } else if (key == GetHeap()->elements_transition_symbol()) {
1099       os << " (transition to "
1100          << ElementsKindToString(GetTarget(i)->elements_kind()) << ")";
1101     } else if (key == GetHeap()->observed_symbol()) {
1102       os << " (transition to Object.observe)";
1103     } else {
1104       PropertyDetails details = GetTargetDetails(i);
1105       switch (details.type()) {
1106         case FIELD: {
1107           os << " (transition to field)";
1108           break;
1109         }
1110         case CONSTANT:
1111           os << " (transition to constant " << Brief(GetTargetValue(i)) << ")";
1112           break;
1113         case CALLBACKS:
1114           os << " (transition to callback " << Brief(GetTargetValue(i)) << ")";
1115           break;
1116         // Values below are never in the target descriptor array.
1117         case NORMAL:
1118           UNREACHABLE();
1119           break;
1120       }
1121       os << ", attrs: " << details.attributes();
1122     }
1123     os << " -> " << Brief(GetTarget(i)) << "\n";
1124   }
1125 }
1126
1127
1128 #endif  // OBJECT_PRINT
1129
1130
1131 } }  // namespace v8::internal