v8/test/cctest/heap/test-iterators.cc
Maya Lekova 3253767622 Revert "Move API-related files"
This reverts commit 9ac8b20086.

Reason for revert: Breaks CFI bot 
https://ci.chromium.org/p/v8/builders/ci/V8%20Linux64%20-%20cfi/20442

Original change's description:
> Move API-related files
> 
> NOPRESUBMIT=true
> TBR=verwaest@chromium.org
> 
> Bug: v8:9247
> Change-Id: I45bfe0782ba92aa7ed27a9e308d0aab9ba1bac7f
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1613988
> Reviewed-by: Yang Guo <yangguo@chromium.org>
> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
> Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
> Commit-Queue: Yang Guo <yangguo@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#61579}

TBR=rmcilroy@chromium.org,yangguo@chromium.org,mstarzinger@chromium.org,verwaest@chromium.org

Change-Id: I28ee9174a1cbc1dae9711977bf9369253ef43058
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:9247
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1615463
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#61583}
2019-05-16 15:00:18 +00:00

102 lines
2.8 KiB
C++

// Copyright 2019 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.
#include "include/v8.h"
#include "src/api-inl.h"
#include "src/heap/combined-heap.h"
#include "src/heap/heap.h"
#include "src/heap/read-only-heap.h"
#include "src/isolate.h"
#include "src/objects.h"
#include "src/objects/heap-object.h"
#include "src/roots-inl.h"
#include "test/cctest/cctest.h"
namespace v8 {
namespace internal {
namespace heap {
TEST(HeapIteratorNullPastEnd) {
HeapIterator iterator(CcTest::heap());
while (!iterator.next().is_null()) {
}
for (int i = 0; i < 20; i++) {
CHECK(iterator.next().is_null());
}
}
TEST(ReadOnlyHeapIteratorNullPastEnd) {
ReadOnlyHeapIterator iterator(CcTest::heap()->read_only_heap());
while (!iterator.next().is_null()) {
}
for (int i = 0; i < 20; i++) {
CHECK(iterator.next().is_null());
}
}
TEST(CombinedHeapIteratorNullPastEnd) {
CombinedHeapIterator iterator(CcTest::heap());
while (!iterator.next().is_null()) {
}
for (int i = 0; i < 20; i++) {
CHECK(iterator.next().is_null());
}
}
namespace {
// An arbitrary object guaranteed to live on the non-read-only heap.
Object CreateWritableObject() {
return *v8::Utils::OpenHandle(*v8::Object::New(CcTest::isolate()));
}
} // namespace
TEST(ReadOnlyHeapIterator) {
CcTest::InitializeVM();
HandleScope handle_scope(CcTest::i_isolate());
const Object sample_object = CreateWritableObject();
ReadOnlyHeapIterator iterator(CcTest::read_only_heap());
for (HeapObject obj = iterator.next(); !obj.is_null();
obj = iterator.next()) {
CHECK(ReadOnlyHeap::Contains(obj));
CHECK(!CcTest::heap()->Contains(obj));
CHECK_NE(sample_object, obj);
}
}
TEST(HeapIterator) {
CcTest::InitializeVM();
HandleScope handle_scope(CcTest::i_isolate());
const Object sample_object = CreateWritableObject();
HeapIterator iterator(CcTest::heap());
bool seen_sample_object = false;
for (HeapObject obj = iterator.next(); !obj.is_null();
obj = iterator.next()) {
CHECK(!ReadOnlyHeap::Contains(obj));
CHECK(CcTest::heap()->Contains(obj));
if (sample_object == obj) seen_sample_object = true;
}
CHECK(seen_sample_object);
}
TEST(CombinedHeapIterator) {
CcTest::InitializeVM();
HandleScope handle_scope(CcTest::i_isolate());
const Object sample_object = CreateWritableObject();
CombinedHeapIterator iterator(CcTest::heap());
bool seen_sample_object = false;
for (HeapObject obj = iterator.next(); !obj.is_null();
obj = iterator.next()) {
CHECK(IsValidHeapObject(CcTest::heap(), obj));
if (sample_object == obj) seen_sample_object = true;
}
CHECK(seen_sample_object);
}
} // namespace heap
} // namespace internal
} // namespace v8