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 "include/v8.h"
9 : #include "src/api-inl.h"
10 : #include "src/base/platform/time.h"
11 : #include "src/flags.h"
12 : #include "src/isolate.h"
13 : #include "src/objects-inl.h"
14 : #include "src/v8.h"
15 :
16 : namespace v8 {
17 :
18 1247 : IsolateWrapper::IsolateWrapper(bool enforce_pointer_compression)
19 : : array_buffer_allocator_(
20 1247 : v8::ArrayBuffer::Allocator::NewDefaultAllocator()) {
21 : v8::Isolate::CreateParams create_params;
22 1247 : create_params.array_buffer_allocator = array_buffer_allocator_;
23 1247 : if (enforce_pointer_compression) {
24 : isolate_ = reinterpret_cast<v8::Isolate*>(
25 1 : i::Isolate::New(i::IsolateAllocationMode::kInV8Heap));
26 1 : v8::Isolate::Initialize(isolate_, create_params);
27 : } else {
28 1246 : isolate_ = v8::Isolate::New(create_params);
29 : }
30 1247 : CHECK_NOT_NULL(isolate_);
31 1247 : }
32 :
33 1247 : IsolateWrapper::~IsolateWrapper() {
34 1247 : v8::Platform* platform = internal::V8::GetCurrentPlatform();
35 1247 : CHECK_NOT_NULL(platform);
36 1250 : while (platform::PumpMessageLoop(platform, isolate_)) continue;
37 1247 : isolate_->Dispose();
38 1247 : delete array_buffer_allocator_;
39 1247 : }
40 :
41 : // static
42 : v8::IsolateWrapper* SharedIsolateHolder::isolate_wrapper_ = nullptr;
43 :
44 : namespace internal {
45 :
46 32 : SaveFlags::SaveFlags() { non_default_flags_ = FlagList::argv(); }
47 :
48 32 : SaveFlags::~SaveFlags() {
49 32 : FlagList::ResetAllFlags();
50 64 : int argc = static_cast<int>(non_default_flags_->size());
51 : FlagList::SetFlagsFromCommandLine(
52 : &argc, const_cast<char**>(non_default_flags_->data()),
53 32 : false /* remove_flags */);
54 512 : for (auto flag = non_default_flags_->begin();
55 448 : flag != non_default_flags_->end(); ++flag) {
56 416 : delete[] * flag;
57 : }
58 64 : delete non_default_flags_;
59 32 : }
60 :
61 : } // namespace internal
62 9111 : } // namespace v8
|