Commit c785f2a0 authored by dmurph's avatar dmurph Committed by Commit bot

[IndexedDB] Fix cursor pooling IsValid().

We accidentally didn't handle the case where the iterator was evicted
and invalid. This is now much more explicit and tested.

R=pwnall,cmumford
BUG=705837

Review-Url: https://codereview.chromium.org/2786463002
Cr-Commit-Position: refs/heads/master@{#460526}
parent 2d3c8ab9
...@@ -38,8 +38,16 @@ leveldb::Status LevelDBIteratorImpl::CheckStatus() { ...@@ -38,8 +38,16 @@ leveldb::Status LevelDBIteratorImpl::CheckStatus() {
} }
bool LevelDBIteratorImpl::IsValid() const { bool LevelDBIteratorImpl::IsValid() const {
return iterator_state_ == IteratorState::EVICTED_AND_VALID || switch (iterator_state_) {
iterator_->Valid(); case IteratorState::EVICTED_AND_VALID:
return true;
case IteratorState::EVICTED_AND_INVALID:
return false;
case IteratorState::ACTIVE:
return iterator_->Valid();
}
NOTREACHED();
return false;
} }
leveldb::Status LevelDBIteratorImpl::SeekToLast() { leveldb::Status LevelDBIteratorImpl::SeekToLast() {
......
...@@ -250,8 +250,6 @@ TEST_F(LevelDBTransactionTest, IterationWithEvictedCursors) { ...@@ -250,8 +250,6 @@ TEST_F(LevelDBTransactionTest, IterationWithEvictedCursors) {
EXPECT_FALSE(evicted_normal_location->IsDetached()); EXPECT_FALSE(evicted_normal_location->IsDetached());
EXPECT_FALSE(evicted_before_start->IsDetached()); EXPECT_FALSE(evicted_before_start->IsDetached());
EXPECT_FALSE(evicted_after_end->IsDetached()); EXPECT_FALSE(evicted_after_end->IsDetached());
EXPECT_FALSE(evicted_before_start->IsValid());
EXPECT_FALSE(evicted_after_end->IsValid());
// Should purge all of our earlier iterators. // Should purge all of our earlier iterators.
it1->Seek("key1"); it1->Seek("key1");
...@@ -262,6 +260,10 @@ TEST_F(LevelDBTransactionTest, IterationWithEvictedCursors) { ...@@ -262,6 +260,10 @@ TEST_F(LevelDBTransactionTest, IterationWithEvictedCursors) {
EXPECT_TRUE(evicted_before_start->IsDetached()); EXPECT_TRUE(evicted_before_start->IsDetached());
EXPECT_TRUE(evicted_after_end->IsDetached()); EXPECT_TRUE(evicted_after_end->IsDetached());
EXPECT_FALSE(evicted_before_start->IsValid());
EXPECT_TRUE(evicted_normal_location->IsValid());
EXPECT_FALSE(evicted_after_end->IsValid());
// Check we don't need to reload for just the key. // Check we don't need to reload for just the key.
EXPECT_EQ("key1", evicted_normal_location->Key()); EXPECT_EQ("key1", evicted_normal_location->Key());
EXPECT_TRUE(evicted_normal_location->IsDetached()); EXPECT_TRUE(evicted_normal_location->IsDetached());
......
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