test-utils.cc 1.84 KB
Newer Older
1 2 3 4
// Copyright 2014 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.

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 11
#include "src/base/platform/time.h"
#include "src/flags.h"
12
#include "src/isolate.h"
13
#include "src/objects-inl.h"
14
#include "src/v8.h"
15 16 17

namespace v8 {

18
IsolateWrapper::IsolateWrapper(bool enforce_pointer_compression)
19 20
    : array_buffer_allocator_(
          v8::ArrayBuffer::Allocator::NewDefaultAllocator()) {
21 22
  v8::Isolate::CreateParams create_params;
  create_params.array_buffer_allocator = array_buffer_allocator_;
23 24
  if (enforce_pointer_compression) {
    isolate_ = reinterpret_cast<v8::Isolate*>(
25
        i::Isolate::New(i::IsolateAllocationMode::kInV8Heap));
26 27 28 29
    v8::Isolate::Initialize(isolate_, create_params);
  } else {
    isolate_ = v8::Isolate::New(create_params);
  }
30
  CHECK_NOT_NULL(isolate_);
31 32
}

33
IsolateWrapper::~IsolateWrapper() {
34
  v8::Platform* platform = internal::V8::GetCurrentPlatform();
35
  CHECK_NOT_NULL(platform);
36
  while (platform::PumpMessageLoop(platform, isolate_)) continue;
37
  isolate_->Dispose();
38
  delete array_buffer_allocator_;
39 40
}

41 42
// static
v8::IsolateWrapper* SharedIsolateHolder::isolate_wrapper_ = nullptr;
43

44 45
namespace internal {

46 47 48 49
SaveFlags::SaveFlags() { non_default_flags_ = FlagList::argv(); }

SaveFlags::~SaveFlags() {
  FlagList::ResetAllFlags();
50
  int argc = static_cast<int>(non_default_flags_->size());
51
  FlagList::SetFlagsFromCommandLine(
52
      &argc, const_cast<char**>(non_default_flags_->data()),
53 54 55 56 57 58 59 60
      false /* remove_flags */);
  for (auto flag = non_default_flags_->begin();
       flag != non_default_flags_->end(); ++flag) {
    delete[] * flag;
  }
  delete non_default_flags_;
}

61 62
}  // namespace internal
}  // namespace v8