Chromium Code Reviews| Index: src/objects-printer.cc |
| diff --git a/src/objects-printer.cc b/src/objects-printer.cc |
| index 3aeefa00ef7159d5d728f2bb3f6600d014ed82b3..2c8ea687e96c227d210d39043c2fffda7790dd5a 100644 |
| --- a/src/objects-printer.cc |
| +++ b/src/objects-printer.cc |
| @@ -4,6 +4,8 @@ |
| #include "src/objects.h" |
| +#include <iomanip> |
| + |
| #include "src/disasm.h" |
| #include "src/disassembler.h" |
| #include "src/interpreter/bytecodes.h" |
| @@ -318,9 +320,32 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT |
| template <class T> |
| static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT |
| - T* p = T::cast(object); |
| - for (int i = 0; i < p->length(); i++) { |
| - os << "\n " << i << ": " << p->get_scalar(i); |
| + T* array = T::cast(object); |
| + if (array->length() == 0) return; |
| + int previous_index = 0; |
| + double previous_value = array->get_scalar(0); |
| + double value; |
| + int i; |
| + for (i = 1; i <= array->length(); i++) { |
| + if (i < array->length()) value = array->get_scalar(i); |
| + bool values_are_nan = previous_value != previous_value && value != value; |
|
Yang
2016/07/26 13:33:42
isnan()?
|
| + if ((previous_value == value || values_are_nan) && i != array->length()) { |
| + continue; |
| + } |
| + os << "\n"; |
| + std::stringstream ss; |
| + ss << previous_index; |
| + if (previous_index != i - 1) { |
| + ss << '-' << (i - 1); |
| + } |
| + os << std::setw(12) << ss.str() << ": "; |
| + if (previous_value == previous_value) { |
| + os << previous_value; |
| + } else { |
| + os << "<the_hole>"; |
|
Yang
2016/07/26 13:36:34
as discussed, this could also just be a non-hole n
|
| + } |
| + previous_index = i; |
| + previous_value = value; |
| } |
| } |
| @@ -328,6 +353,7 @@ static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT |
| void JSObject::PrintElements(std::ostream& os) { // NOLINT |
| // Don't call GetElementsKind, its validation code can cause the printer to |
| // fail when debugging. |
| + if (elements()->length() == 0) return; |
| switch (map()->elements_kind()) { |
| case FAST_HOLEY_SMI_ELEMENTS: |
| case FAST_SMI_ELEMENTS: |
| @@ -335,26 +361,31 @@ void JSObject::PrintElements(std::ostream& os) { // NOLINT |
| case FAST_ELEMENTS: |
| case FAST_STRING_WRAPPER_ELEMENTS: { |
| // Print in array notation for non-sparse arrays. |
| - FixedArray* p = FixedArray::cast(elements()); |
| - for (int i = 0; i < p->length(); i++) { |
| - os << "\n " << i << ": " << Brief(p->get(i)); |
| + FixedArray* array = FixedArray::cast(elements()); |
| + Object* previous_value = array->get(0); |
| + Object* value; |
| + int previous_index = 0; |
| + int i; |
| + for (i = 1; i <= array->length(); i++) { |
| + if (i < array->length()) value = array->get(i); |
| + if (previous_value == value && i != array->length()) { |
| + continue; |
| + } |
| + os << "\n"; |
| + std::stringstream ss; |
| + ss << previous_index; |
| + if (previous_index != i - 1) { |
| + ss << '-' << (i - 1); |
| + } |
| + os << std::setw(12) << ss.str() << ": " << Brief(previous_value); |
| + previous_index = i; |
| + previous_value = value; |
| } |
| break; |
| } |
| case FAST_HOLEY_DOUBLE_ELEMENTS: |
| case FAST_DOUBLE_ELEMENTS: { |
| - // Print in array notation for non-sparse arrays. |
| - if (elements()->length() > 0) { |
| - FixedDoubleArray* p = FixedDoubleArray::cast(elements()); |
| - for (int i = 0; i < p->length(); i++) { |
| - os << "\n " << i << ": "; |
| - if (p->is_the_hole(i)) { |
| - os << "<the hole>"; |
| - } else { |
| - os << p->get_scalar(i); |
| - } |
| - } |
| - } |
| + DoPrintElements<FixedDoubleArray>(os, elements()); |
| break; |
| } |