Commit bb4425c0 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

More size_t index support

Addressing TODOs in the code to support size_t indices everywhere.

Bug: v8:4153
Change-Id: I06432293799feed3b6a0c634cbbdcac250430d19
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1962269Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65680}
parent 4feecc66
......@@ -941,15 +941,15 @@ void CollectElementIndices(Isolate* isolate, Handle<JSObject> object,
TYPED_ARRAYS(TYPED_ARRAY_CASE)
#undef TYPED_ARRAY_CASE
{
// TODO(bmeurer, v8:4153): Change this to size_t later.
uint32_t length =
static_cast<uint32_t>(Handle<JSTypedArray>::cast(object)->length());
size_t length = Handle<JSTypedArray>::cast(object)->length();
if (range <= length) {
length = range;
// We will add all indices, so we might as well clear it first
// and avoid duplicates.
indices->clear();
}
// {range} puts a cap on {length}.
DCHECK_LE(length, std::numeric_limits<uint32_t>::max());
for (uint32_t i = 0; i < length; i++) {
indices->push_back(i);
}
......
......@@ -86,10 +86,10 @@ bool DebugPropertyIterator::has_native_setter() {
Handle<Name> DebugPropertyIterator::raw_name() const {
DCHECK(!Done());
if (stage_ == kExoticIndices) {
return isolate_->factory()->Uint32ToString(current_key_index_);
return isolate_->factory()->SizeToString(current_key_index_);
} else {
return Handle<Name>::cast(
FixedArray::get(*keys_, current_key_index_, isolate_));
return Handle<Name>::cast(FixedArray::get(
*keys_, static_cast<int>(current_key_index_), isolate_));
}
}
......@@ -149,12 +149,7 @@ void DebugPropertyIterator::FillKeysForCurrentPrototypeAndStage() {
if (stage_ == kExoticIndices) {
if (!has_exotic_indices) return;
Handle<JSTypedArray> typed_array = Handle<JSTypedArray>::cast(receiver);
if (typed_array->WasDetached()) {
exotic_length_ = 0;
} else {
// TODO(bmeurer, v8:4153): Change this to size_t later.
exotic_length_ = static_cast<uint32_t>(typed_array->length());
}
exotic_length_ = typed_array->WasDetached() ? 0 : typed_array->length();
return;
}
bool skip_indices = has_exotic_indices;
......@@ -172,7 +167,7 @@ bool DebugPropertyIterator::should_move_to_next_stage() const {
if (prototype_iterator_.IsAtEnd()) return false;
if (stage_ == kExoticIndices) return current_key_index_ >= exotic_length_;
return keys_.is_null() ||
current_key_index_ >= static_cast<uint32_t>(keys_->length());
current_key_index_ >= static_cast<size_t>(keys_->length());
}
namespace {
......
......@@ -46,9 +46,9 @@ class DebugPropertyIterator final : public debug::PropertyIterator {
enum Stage { kExoticIndices = 0, kEnumerableStrings = 1, kAllProperties = 2 };
Stage stage_ = kExoticIndices;
uint32_t current_key_index_ = 0;
size_t current_key_index_ = 0;
Handle<FixedArray> keys_;
uint32_t exotic_length_ = 0;
size_t exotic_length_ = 0;
bool calculated_native_accessor_flags_ = false;
int native_accessor_flags_ = 0;
......
......@@ -544,22 +544,21 @@ class ElementsAccessorBase : public InternalElementsAccessor {
static ElementsKind kind() { return ElementsTraits::Kind; }
static void ValidateContents(JSObject holder, int length) {}
static void ValidateContents(JSObject holder, size_t length) {}
static void ValidateImpl(JSObject holder) {
FixedArrayBase fixed_array_base = holder.elements();
if (!fixed_array_base.IsHeapObject()) return;
// Arrays that have been shifted in place can't be verified.
if (fixed_array_base.IsFreeSpaceOrFiller()) return;
int length = 0;
size_t length = 0;
if (holder.IsJSArray()) {
Object length_obj = JSArray::cast(holder).length();
if (length_obj.IsSmi()) {
length = Smi::ToInt(length_obj);
}
} else if (holder.IsJSTypedArray()) {
// TODO(bmeurer, v8:4153): Change this to size_t later.
length = static_cast<int>(JSTypedArray::cast(holder).length());
length = JSTypedArray::cast(holder).length();
} else {
length = fixed_array_base.length();
}
......@@ -1789,7 +1788,7 @@ class DictionaryElementsAccessor
return Just<int64_t>(-1);
}
static void ValidateContents(JSObject holder, int length) {
static void ValidateContents(JSObject holder, size_t length) {
DisallowHeapAllocation no_gc;
#if DEBUG
DCHECK_EQ(holder.map().elements_kind(), DICTIONARY_ELEMENTS);
......@@ -2043,7 +2042,7 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> {
return ExceptionStatus::kSuccess;
}
static void ValidateContents(JSObject holder, int length) {
static void ValidateContents(JSObject holder, size_t length) {
#if DEBUG
Isolate* isolate = holder.GetIsolate();
Heap* heap = isolate->heap();
......@@ -2053,24 +2052,26 @@ class FastElementsAccessor : public ElementsAccessorBase<Subclass, KindTraits> {
DCHECK_NE(map, ReadOnlyRoots(heap).fixed_double_array_map());
} else if (IsDoubleElementsKind(KindTraits::Kind)) {
DCHECK_NE(map, ReadOnlyRoots(heap).fixed_cow_array_map());
if (map == ReadOnlyRoots(heap).fixed_array_map()) DCHECK_EQ(0, length);
if (map == ReadOnlyRoots(heap).fixed_array_map()) DCHECK_EQ(0u, length);
} else {
UNREACHABLE();
}
if (length == 0) return; // nothing to do!
if (length == 0u) return; // nothing to do!
#if ENABLE_SLOW_DCHECKS
DisallowHeapAllocation no_gc;
BackingStore backing_store = BackingStore::cast(elements);
DCHECK(length <= std::numeric_limits<int>::max());
int length_int = static_cast<int>(length);
if (IsSmiElementsKind(KindTraits::Kind)) {
HandleScope scope(isolate);
for (int i = 0; i < length; i++) {
for (int i = 0; i < length_int; i++) {
DCHECK(BackingStore::get(backing_store, i, isolate)->IsSmi() ||
(IsHoleyElementsKind(KindTraits::Kind) &&
backing_store.is_the_hole(isolate, i)));
}
} else if (KindTraits::Kind == PACKED_ELEMENTS ||
KindTraits::Kind == PACKED_DOUBLE_ELEMENTS) {
for (int i = 0; i < length; i++) {
for (int i = 0; i < length_int; i++) {
DCHECK(!backing_store.is_the_hole(isolate, i));
}
} else {
......
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