Commit cd86053f authored by cbruni's avatar cbruni Committed by Commit bot

[printing] Fix DCHECK failure when printing FAST_HOLEY_DOUBLE_ELEMENTS

This CL fixes %DebugPrint for FAST_HOLEY_DOUBLE_ELEMENTS and now properly
distinguishes TheHole and NaN values.

BUG=

Review-Url: https://codereview.chromium.org/2294913004
Cr-Commit-Position: refs/heads/master@{#39293}
parent 6faf6c15
......@@ -318,18 +318,37 @@ 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 bit_cast<double>(kHoleNanInt64);
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()) {
if (i != array->length() && (previous_value == value || values_are_nan) &&
is_the_hole(previous_value) == is_the_hole(value)) {
continue;
}
os << "\n";
......@@ -339,8 +358,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;
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
// Make sure printing different element kinds doesn't crash.
var array;
var obj = {};
array = [];
%DebugPrint(array);
// FAST_SMI_ELEMENTS
array = [1, 2, 3];
%DebugPrint(array);
// FAST_HOLEY_SMI_ELEMENTS
array[10] = 100;
array[11] = 100;
%DebugPrint(array);
// FAST_ELEMENTS
array = [1, obj, obj];
%DebugPrint(array);
// FAST_HOLEY_ELEMENTS
array[100] = obj;
array[101] = obj;
%DebugPrint(array);
// FAST_DOUBLE_ELEMENTS
array = [1.1, 2.2, 3.3, 3.3, 3.3, NaN];
%DebugPrint(array);
array.push(NaN);
array.push(NaN);
%DebugPrint(array);
// FAST_HOLEY_DOUBLE_ELEMENTS
array[100] = 1.2;
array[101] = 1.2;
%DebugPrint(array);
// DICTIONARY_ELEMENTS
%NormalizeElements(array);
%DebugPrint(array);
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