summaryrefslogtreecommitdiff
path: root/deps/v8/test/unittests/heap/cppgc/tests.cc
blob: b144908dda9cf9cf201516f3a4f3fd7ec50db4ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2020 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 "test/unittests/heap/cppgc/tests.h"

#include <memory>

#include "src/heap/cppgc/object-allocator.h"
#include "test/unittests/heap/cppgc/test-platform.h"

#if !CPPGC_IS_STANDALONE
#include "include/v8-initialization.h"
#endif  // !CPPGC_IS_STANDALONE

namespace cppgc {
namespace internal {
namespace testing {

// static
std::shared_ptr<TestPlatform> TestWithPlatform::platform_;

// static
void TestWithPlatform::SetUpTestSuite() {
  platform_ = std::make_shared<TestPlatform>(
      std::make_unique<DelegatingTracingController>());

#if !CPPGC_IS_STANDALONE
  // For non-standalone builds, we need to initialize V8's platform so that it
  // can be looked-up by trace-event.h.
  v8::V8::InitializePlatform(platform_->GetV8Platform());
  v8::V8::Initialize();
#endif  // !CPPGC_IS_STANDALONE
}

// static
void TestWithPlatform::TearDownTestSuite() {
#if !CPPGC_IS_STANDALONE
  v8::V8::Dispose();
  v8::V8::DisposePlatform();
#endif  // !CPPGC_IS_STANDALONE
  platform_.reset();
}

TestWithHeap::TestWithHeap()
    : heap_(Heap::Create(platform_)),
      allocation_handle_(heap_->GetAllocationHandle()) {}

TestWithHeap::~TestWithHeap() = default;

void TestWithHeap::ResetLinearAllocationBuffers() {
  Heap::From(GetHeap())->object_allocator().ResetLinearAllocationBuffers();
}

TestSupportingAllocationOnly::TestSupportingAllocationOnly()
    : no_gc_scope_(GetHeap()->GetHeapHandle()) {}

}  // namespace testing
}  // namespace internal
}  // namespace cppgc