OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/objects.h" | 5 #include "src/objects.h" |
6 | 6 |
7 #include "src/disasm.h" | 7 #include "src/disasm.h" |
8 #include "src/disassembler.h" | 8 #include "src/disassembler.h" |
9 #include "src/interpreter/bytecodes.h" | 9 #include "src/interpreter/bytecodes.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 void Object::Print(std::ostream& os) { // NOLINT | 26 void Object::Print(std::ostream& os) { // NOLINT |
27 if (IsSmi()) { | 27 if (IsSmi()) { |
28 Smi::cast(this)->SmiPrint(os); | 28 Smi::cast(this)->SmiPrint(os); |
29 } else { | 29 } else { |
30 HeapObject::cast(this)->HeapObjectPrint(os); | 30 HeapObject::cast(this)->HeapObjectPrint(os); |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 | 34 |
35 void HeapObject::PrintHeader(std::ostream& os, const char* id) { // NOLINT | 35 void HeapObject::PrintHeader(std::ostream& os, const char* id) { // NOLINT |
36 os << "" << reinterpret_cast<void*>(this) << ": [" << id << "]\n"; | 36 os << reinterpret_cast<void*>(this) << ": [" << id << "]\n"; |
37 } | 37 } |
38 | 38 |
39 | 39 |
40 void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT | 40 void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT |
41 InstanceType instance_type = map()->instance_type(); | 41 InstanceType instance_type = map()->instance_type(); |
42 | 42 |
43 HandleScope scope(GetIsolate()); | 43 HandleScope scope(GetIsolate()); |
44 if (instance_type < FIRST_NONSTRING_TYPE) { | 44 if (instance_type < FIRST_NONSTRING_TYPE) { |
45 String::cast(this)->StringPrint(os); | 45 String::cast(this)->StringPrint(os); |
46 return; | 46 return; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 case JS_GLOBAL_PROXY_TYPE: | 110 case JS_GLOBAL_PROXY_TYPE: |
111 JSGlobalProxy::cast(this)->JSGlobalProxyPrint(os); | 111 JSGlobalProxy::cast(this)->JSGlobalProxyPrint(os); |
112 break; | 112 break; |
113 case JS_GLOBAL_OBJECT_TYPE: | 113 case JS_GLOBAL_OBJECT_TYPE: |
114 JSGlobalObject::cast(this)->JSGlobalObjectPrint(os); | 114 JSGlobalObject::cast(this)->JSGlobalObjectPrint(os); |
115 break; | 115 break; |
116 case JS_BUILTINS_OBJECT_TYPE: | 116 case JS_BUILTINS_OBJECT_TYPE: |
117 JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(os); | 117 JSBuiltinsObject::cast(this)->JSBuiltinsObjectPrint(os); |
118 break; | 118 break; |
119 case JS_VALUE_TYPE: | 119 case JS_VALUE_TYPE: |
120 os << "Value wrapper around:"; | 120 JSValue::cast(this)->JSValuePrint(os); |
121 JSValue::cast(this)->value()->Print(os); | |
122 break; | 121 break; |
123 case JS_DATE_TYPE: | 122 case JS_DATE_TYPE: |
124 JSDate::cast(this)->JSDatePrint(os); | 123 JSDate::cast(this)->JSDatePrint(os); |
125 break; | 124 break; |
126 case CODE_TYPE: | 125 case CODE_TYPE: |
127 Code::cast(this)->CodePrint(os); | 126 Code::cast(this)->CodePrint(os); |
128 break; | 127 break; |
129 case JS_PROXY_TYPE: | 128 case JS_PROXY_TYPE: |
130 JSProxy::cast(this)->JSProxyPrint(os); | 129 JSProxy::cast(this)->JSProxyPrint(os); |
131 break; | 130 break; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 os << " " << (i - 2) << ":" << Brief(p->get(i)); | 380 os << " " << (i - 2) << ":" << Brief(p->get(i)); |
382 } | 381 } |
383 os << "\n context: " << Brief(p->get(0)) | 382 os << "\n context: " << Brief(p->get(0)) |
384 << "\n arguments: " << Brief(p->get(1)) << "\n"; | 383 << "\n arguments: " << Brief(p->get(1)) << "\n"; |
385 break; | 384 break; |
386 } | 385 } |
387 } | 386 } |
388 } | 387 } |
389 | 388 |
390 | 389 |
| 390 static void JSObjectPrintHeader(std::ostream& os, JSObject* obj, |
| 391 const char* id) { // NOLINT |
| 392 obj->PrintHeader(os, id); |
| 393 // Don't call GetElementsKind, its validation code can cause the printer to |
| 394 // fail when debugging. |
| 395 PrototypeIterator iter(obj->GetIsolate(), obj); |
| 396 os << " - map = " << reinterpret_cast<void*>(obj->map()) << " [" |
| 397 << ElementsKindToString(obj->map()->elements_kind()) |
| 398 << "]\n - prototype = " << reinterpret_cast<void*>(iter.GetCurrent()); |
| 399 } |
| 400 |
| 401 |
| 402 static void JSObjectPrintBody(std::ostream& os, JSObject* obj) { // NOLINT |
| 403 os << "\n {\n"; |
| 404 obj->PrintProperties(os); |
| 405 obj->PrintTransitions(os); |
| 406 obj->PrintElements(os); |
| 407 os << " }\n"; |
| 408 } |
| 409 |
| 410 |
391 void JSObject::JSObjectPrint(std::ostream& os) { // NOLINT | 411 void JSObject::JSObjectPrint(std::ostream& os) { // NOLINT |
392 HeapObject::PrintHeader(os, "JSObject"); | 412 JSObjectPrintHeader(os, this, "JSObject"); |
393 // Don't call GetElementsKind, its validation code can cause the printer to | 413 JSObjectPrintBody(os, this); |
394 // fail when debugging. | |
395 PrototypeIterator iter(GetIsolate(), this); | |
396 os << " - map = " << reinterpret_cast<void*>(map()) << " [" | |
397 << ElementsKindToString(this->map()->elements_kind()) | |
398 << "]\n - prototype = " << reinterpret_cast<void*>(iter.GetCurrent()) | |
399 << "\n {\n"; | |
400 PrintProperties(os); | |
401 PrintTransitions(os); | |
402 PrintElements(os); | |
403 os << " }\n"; | |
404 } | 414 } |
405 | 415 |
406 | 416 |
407 void JSModule::JSModulePrint(std::ostream& os) { // NOLINT | 417 void JSModule::JSModulePrint(std::ostream& os) { // NOLINT |
408 HeapObject::PrintHeader(os, "JSModule"); | 418 HeapObject::PrintHeader(os, "JSModule"); |
409 os << " - map = " << reinterpret_cast<void*>(map()) << "\n" | 419 os << " - map = " << reinterpret_cast<void*>(map()) << "\n" |
410 << " - context = "; | 420 << " - context = "; |
411 context()->Print(os); | 421 context()->Print(os); |
412 os << " - scope_info = " << Brief(scope_info()) | 422 os << " - scope_info = " << Brief(scope_info()) |
413 << ElementsKindToString(this->map()->elements_kind()) << " {\n"; | 423 << ElementsKindToString(this->map()->elements_kind()) << " {\n"; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 if (is_dictionary_map()) os << " - dictionary_map\n"; | 464 if (is_dictionary_map()) os << " - dictionary_map\n"; |
455 if (is_hidden_prototype()) os << " - hidden_prototype\n"; | 465 if (is_hidden_prototype()) os << " - hidden_prototype\n"; |
456 if (has_named_interceptor()) os << " - named_interceptor\n"; | 466 if (has_named_interceptor()) os << " - named_interceptor\n"; |
457 if (has_indexed_interceptor()) os << " - indexed_interceptor\n"; | 467 if (has_indexed_interceptor()) os << " - indexed_interceptor\n"; |
458 if (is_undetectable()) os << " - undetectable\n"; | 468 if (is_undetectable()) os << " - undetectable\n"; |
459 if (is_callable()) os << " - callable\n"; | 469 if (is_callable()) os << " - callable\n"; |
460 if (is_constructor()) os << " - constructor\n"; | 470 if (is_constructor()) os << " - constructor\n"; |
461 if (is_access_check_needed()) os << " - access_check_needed\n"; | 471 if (is_access_check_needed()) os << " - access_check_needed\n"; |
462 if (!is_extensible()) os << " - non-extensible\n"; | 472 if (!is_extensible()) os << " - non-extensible\n"; |
463 if (is_observed()) os << " - observed\n"; | 473 if (is_observed()) os << " - observed\n"; |
| 474 if (is_strong()) os << " - strong_map\n"; |
464 if (is_prototype_map()) { | 475 if (is_prototype_map()) { |
465 os << " - prototype_map\n"; | 476 os << " - prototype_map\n"; |
466 os << " - prototype info: " << Brief(prototype_info()); | 477 os << " - prototype info: " << Brief(prototype_info()); |
467 } else { | 478 } else { |
468 os << " - back pointer: " << Brief(GetBackPointer()); | 479 os << " - back pointer: " << Brief(GetBackPointer()); |
469 } | 480 } |
470 os << "\n - instance descriptors " << (owns_descriptors() ? "(own) " : "") | 481 os << "\n - instance descriptors " << (owns_descriptors() ? "(own) " : "") |
471 << "#" << NumberOfOwnDescriptors() << ": " | 482 << "#" << NumberOfOwnDescriptors() << ": " |
472 << Brief(instance_descriptors()); | 483 << Brief(instance_descriptors()); |
473 if (FLAG_unbox_double_fields) { | 484 if (FLAG_unbox_double_fields) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 for (int i = 0; i < entry_size; i++) { | 638 for (int i = 0; i < entry_size; i++) { |
628 int index = GetIndex(slot) + i; | 639 int index = GetIndex(slot) + i; |
629 os << "\n [" << index << "]: " << Brief(get(index)); | 640 os << "\n [" << index << "]: " << Brief(get(index)); |
630 } | 641 } |
631 } | 642 } |
632 os << "\n"; | 643 os << "\n"; |
633 } | 644 } |
634 | 645 |
635 | 646 |
636 void JSValue::JSValuePrint(std::ostream& os) { // NOLINT | 647 void JSValue::JSValuePrint(std::ostream& os) { // NOLINT |
637 HeapObject::PrintHeader(os, "ValueObject"); | 648 JSObjectPrintHeader(os, this, "JSValue"); |
638 value()->Print(os); | 649 os << "\n - value = " << Brief(value()); |
| 650 JSObjectPrintBody(os, this); |
639 } | 651 } |
640 | 652 |
641 | 653 |
642 void JSMessageObject::JSMessageObjectPrint(std::ostream& os) { // NOLINT | 654 void JSMessageObject::JSMessageObjectPrint(std::ostream& os) { // NOLINT |
643 HeapObject::PrintHeader(os, "JSMessageObject"); | 655 JSObjectPrintHeader(os, this, "JSMessageObject"); |
644 os << " - type: " << type(); | 656 os << "\n - type: " << type(); |
645 os << "\n - arguments: " << Brief(argument()); | 657 os << "\n - arguments: " << Brief(argument()); |
646 os << "\n - start_position: " << start_position(); | 658 os << "\n - start_position: " << start_position(); |
647 os << "\n - end_position: " << end_position(); | 659 os << "\n - end_position: " << end_position(); |
648 os << "\n - script: " << Brief(script()); | 660 os << "\n - script: " << Brief(script()); |
649 os << "\n - stack_frames: " << Brief(stack_frames()); | 661 os << "\n - stack_frames: " << Brief(stack_frames()); |
650 os << "\n"; | 662 JSObjectPrintBody(os, this); |
651 } | 663 } |
652 | 664 |
653 | 665 |
654 void String::StringPrint(std::ostream& os) { // NOLINT | 666 void String::StringPrint(std::ostream& os) { // NOLINT |
655 if (StringShape(this).IsInternalized()) { | 667 if (StringShape(this).IsInternalized()) { |
656 os << "#"; | 668 os << "#"; |
657 } else if (StringShape(this).IsCons()) { | 669 } else if (StringShape(this).IsCons()) { |
658 os << "c\""; | 670 os << "c\""; |
659 } else { | 671 } else { |
660 os << "\""; | 672 os << "\""; |
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1321 } | 1333 } |
1322 } | 1334 } |
1323 | 1335 |
1324 | 1336 |
1325 void JSObject::PrintTransitions(std::ostream& os) { // NOLINT | 1337 void JSObject::PrintTransitions(std::ostream& os) { // NOLINT |
1326 TransitionArray::PrintTransitions(os, map()->raw_transitions()); | 1338 TransitionArray::PrintTransitions(os, map()->raw_transitions()); |
1327 } | 1339 } |
1328 #endif // defined(DEBUG) || defined(OBJECT_PRINT) | 1340 #endif // defined(DEBUG) || defined(OBJECT_PRINT) |
1329 } // namespace internal | 1341 } // namespace internal |
1330 } // namespace v8 | 1342 } // namespace v8 |
OLD | NEW |