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

Unified Diff: src/objects-printer.cc

Issue 2294913004: [printing] Fix DCHECK failure when printing FAST_HOLEY_DOUBLE_ELEMENTS (Closed)
Patch Set: adding test Created 4 years, 4 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
Index: src/objects-printer.cc
diff --git a/src/objects-printer.cc b/src/objects-printer.cc
index 2fdd274d1cf0872b20e428b1cce742c5424974bf..c52edda08470ffd333f7b8237a961656b5cf8556 100644
--- a/src/objects-printer.cc
+++ b/src/objects-printer.cc
@@ -318,19 +318,40 @@ void JSObject::PrintProperties(std::ostream& os) { // NOLINT
}
}
+namespace {
+
+template <class T>
+double GetScalarElement(T* array, int index) {
+ return array->get_scalar(index);
+}
+
+double GetScalarElement(FixedDoubleArray* array, int index) {
+ if (array->is_the_hole(index)) return kHoleNanDouble;
+ return array->get_scalar(index);
+}
+
+bool is_the_hole(double maybe_hole) {
+ return bit_cast<uint64_t>(maybe_hole) == kHoleNanInt64;
+}
+
+} // namespace
+
template <class T, bool print_the_hole>
static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
T* array = T::cast(object);
if (array->length() == 0) return;
int previous_index = 0;
- double previous_value = array->get_scalar(0);
+ double previous_value = GetScalarElement(array, 0);
double value = 0.0;
int i;
for (i = 1; i <= array->length(); i++) {
- if (i < array->length()) value = array->get_scalar(i);
+ if (i < array->length()) value = GetScalarElement(array, i);
bool values_are_nan = std::isnan(previous_value) && std::isnan(value);
if ((previous_value == value || values_are_nan) && i != array->length()) {
- continue;
+ // Values are not equal if only one of the is the hole.
Jakob Kummerow 2016/08/31 14:56:09 nit: s/the/them/
+ if (!(is_the_hole(previous_value) ^ is_the_hole(value))) {
Jakob Kummerow 2016/08/31 14:56:09 nit: !(a ^ b) === (a == b) ...and after that repl
+ continue;
+ }
}
os << "\n";
std::stringstream ss;
@@ -339,8 +360,7 @@ static void DoPrintElements(std::ostream& os, Object* object) { // NOLINT
ss << '-' << (i - 1);
}
os << std::setw(12) << ss.str() << ": ";
- if (print_the_hole &&
- FixedDoubleArray::cast(object)->is_the_hole(previous_index)) {
+ if (print_the_hole && is_the_hole(previous_value)) {
os << "<the_hole>";
} else {
os << previous_value;
« no previous file with comments | « src/heap/heap.cc ('k') | test/cctest/test-assembler-arm.cc » ('j') | test/mjsunit/debug-print.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698