Line data Source code
1 : // Copyright 2014 the V8 project authors. All rights reserved.
2 : // Use of this source code is governed by a BSD-style license that can be
3 : // found in the LICENSE file.
4 :
5 : #include "test/unittests/test-utils.h"
6 :
7 : #include "include/libplatform/libplatform.h"
8 : #include "src/base/platform/time.h"
9 : #include "src/flags.h"
10 : #include "src/isolate.h"
11 : #include "src/objects-inl.h"
12 : #include "src/v8.h"
13 :
14 : namespace v8 {
15 :
16 : // static
17 : v8::ArrayBuffer::Allocator* TestWithIsolate::array_buffer_allocator_ = nullptr;
18 :
19 : // static
20 : Isolate* TestWithIsolate::isolate_ = nullptr;
21 :
22 1134 : TestWithIsolate::TestWithIsolate()
23 2268 : : isolate_scope_(isolate()), handle_scope_(isolate()) {}
24 :
25 :
26 2268 : TestWithIsolate::~TestWithIsolate() {}
27 :
28 :
29 : // static
30 1134 : void TestWithIsolate::SetUpTestCase() {
31 : Test::SetUpTestCase();
32 2268 : EXPECT_EQ(NULL, isolate_);
33 : v8::Isolate::CreateParams create_params;
34 1134 : array_buffer_allocator_ = v8::ArrayBuffer::Allocator::NewDefaultAllocator();
35 1134 : create_params.array_buffer_allocator = array_buffer_allocator_;
36 1134 : isolate_ = v8::Isolate::New(create_params);
37 2268 : EXPECT_TRUE(isolate_ != NULL);
38 1134 : }
39 :
40 :
41 : // static
42 1134 : void TestWithIsolate::TearDownTestCase() {
43 2268 : ASSERT_TRUE(isolate_ != NULL);
44 1134 : v8::Platform* platform = internal::V8::GetCurrentPlatform();
45 2268 : ASSERT_TRUE(platform != NULL);
46 1136 : while (platform::PumpMessageLoop(platform, isolate_)) continue;
47 1134 : isolate_->Dispose();
48 1134 : isolate_ = NULL;
49 1134 : delete array_buffer_allocator_;
50 : Test::TearDownTestCase();
51 : }
52 :
53 :
54 784 : TestWithContext::TestWithContext()
55 2352 : : context_(Context::New(isolate())), context_scope_(context_) {}
56 :
57 :
58 1568 : TestWithContext::~TestWithContext() {}
59 :
60 :
61 : namespace base {
62 : namespace {
63 :
64 : inline int64_t GetRandomSeedFromFlag(int random_seed) {
65 280 : return random_seed ? random_seed : TimeTicks::Now().ToInternalValue();
66 : }
67 :
68 : } // namespace
69 :
70 140 : TestWithRandomNumberGenerator::TestWithRandomNumberGenerator()
71 420 : : rng_(GetRandomSeedFromFlag(::v8::internal::FLAG_random_seed)) {}
72 :
73 :
74 140 : TestWithRandomNumberGenerator::~TestWithRandomNumberGenerator() {}
75 :
76 : } // namespace base
77 :
78 :
79 : namespace internal {
80 :
81 1005 : TestWithIsolate::~TestWithIsolate() {}
82 :
83 992 : TestWithIsolateAndZone::~TestWithIsolateAndZone() {}
84 :
85 23724 : Factory* TestWithIsolate::factory() const { return isolate()->factory(); }
86 :
87 321 : base::RandomNumberGenerator* TestWithIsolate::random_number_generator() const {
88 321 : return isolate()->random_number_generator();
89 : }
90 :
91 929 : TestWithZone::~TestWithZone() {}
92 :
93 571 : TestWithNativeContext::~TestWithNativeContext() {}
94 :
95 726 : Handle<Context> TestWithNativeContext::native_context() const {
96 726 : return isolate()->native_context();
97 : }
98 :
99 40 : SaveFlags::SaveFlags() { non_default_flags_ = FlagList::argv(); }
100 :
101 40 : SaveFlags::~SaveFlags() {
102 40 : FlagList::ResetAllFlags();
103 80 : int argc = static_cast<int>(non_default_flags_->size());
104 : FlagList::SetFlagsFromCommandLine(
105 : &argc, const_cast<char**>(non_default_flags_->data()),
106 40 : false /* remove_flags */);
107 640 : for (auto flag = non_default_flags_->begin();
108 560 : flag != non_default_flags_->end(); ++flag) {
109 520 : delete[] * flag;
110 : }
111 80 : delete non_default_flags_;
112 40 : }
113 :
114 : } // namespace internal
115 7893 : } // namespace v8
|