2014-09-04 08:44:03 +00:00
|
|
|
// 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.
|
|
|
|
|
2014-10-01 08:34:25 +00:00
|
|
|
#include "test/unittests/test-utils.h"
|
2014-09-04 08:44:03 +00:00
|
|
|
|
2015-07-15 12:26:06 +00:00
|
|
|
#include "include/libplatform/libplatform.h"
|
2017-11-13 12:04:57 +00:00
|
|
|
#include "include/v8.h"
|
2018-07-23 11:42:37 +00:00
|
|
|
#include "src/api-inl.h"
|
2014-10-06 12:27:24 +00:00
|
|
|
#include "src/base/platform/time.h"
|
|
|
|
#include "src/flags.h"
|
2015-04-21 10:21:50 +00:00
|
|
|
#include "src/isolate.h"
|
2017-02-09 08:35:03 +00:00
|
|
|
#include "src/objects-inl.h"
|
2015-07-15 12:26:06 +00:00
|
|
|
#include "src/v8.h"
|
2014-09-04 08:44:03 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
|
2018-10-30 12:48:12 +00:00
|
|
|
IsolateWrapper::IsolateWrapper(bool enforce_pointer_compression)
|
2018-10-29 20:49:54 +00:00
|
|
|
: array_buffer_allocator_(
|
|
|
|
v8::ArrayBuffer::Allocator::NewDefaultAllocator()) {
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = array_buffer_allocator_;
|
2018-10-30 12:48:12 +00:00
|
|
|
if (enforce_pointer_compression) {
|
|
|
|
isolate_ = reinterpret_cast<v8::Isolate*>(
|
2018-11-07 09:05:38 +00:00
|
|
|
i::Isolate::New(i::IsolateAllocationMode::kInV8Heap));
|
2018-10-30 12:48:12 +00:00
|
|
|
v8::Isolate::Initialize(isolate_, create_params);
|
|
|
|
} else {
|
|
|
|
isolate_ = v8::Isolate::New(create_params);
|
|
|
|
}
|
2018-10-29 20:49:54 +00:00
|
|
|
CHECK_NOT_NULL(isolate_);
|
2014-09-04 08:44:03 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
IsolateWrapper::~IsolateWrapper() {
|
2015-07-15 12:26:06 +00:00
|
|
|
v8::Platform* platform = internal::V8::GetCurrentPlatform();
|
2018-10-29 20:49:54 +00:00
|
|
|
CHECK_NOT_NULL(platform);
|
2015-07-15 12:26:06 +00:00
|
|
|
while (platform::PumpMessageLoop(platform, isolate_)) continue;
|
2014-09-04 08:44:03 +00:00
|
|
|
isolate_->Dispose();
|
2015-04-29 09:54:34 +00:00
|
|
|
delete array_buffer_allocator_;
|
2018-08-13 15:35:29 +00:00
|
|
|
}
|
|
|
|
|
2018-10-29 20:49:54 +00:00
|
|
|
// static
|
|
|
|
v8::IsolateWrapper* SharedIsolateHolder::isolate_wrapper_ = nullptr;
|
2017-11-14 09:15:41 +00:00
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
namespace internal {
|
|
|
|
|
2017-03-14 13:33:13 +00:00
|
|
|
SaveFlags::SaveFlags() { non_default_flags_ = FlagList::argv(); }
|
|
|
|
|
|
|
|
SaveFlags::~SaveFlags() {
|
|
|
|
FlagList::ResetAllFlags();
|
2017-08-30 07:24:59 +00:00
|
|
|
int argc = static_cast<int>(non_default_flags_->size());
|
2017-03-14 13:33:13 +00:00
|
|
|
FlagList::SetFlagsFromCommandLine(
|
2017-08-30 07:24:59 +00:00
|
|
|
&argc, const_cast<char**>(non_default_flags_->data()),
|
2017-03-14 13:33:13 +00:00
|
|
|
false /* remove_flags */);
|
|
|
|
for (auto flag = non_default_flags_->begin();
|
|
|
|
flag != non_default_flags_->end(); ++flag) {
|
|
|
|
delete[] * flag;
|
|
|
|
}
|
|
|
|
delete non_default_flags_;
|
|
|
|
}
|
|
|
|
|
2014-09-04 08:44:03 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|