2020-05-26 14:40:57 +00:00
|
|
|
// 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/test-platform.h"
|
|
|
|
|
2020-10-08 11:16:20 +00:00
|
|
|
#include "include/libplatform/libplatform.h"
|
2020-05-26 14:40:57 +00:00
|
|
|
#include "src/base/platform/platform.h"
|
|
|
|
#include "src/base/platform/time.h"
|
|
|
|
|
|
|
|
namespace cppgc {
|
|
|
|
namespace internal {
|
|
|
|
namespace testing {
|
|
|
|
|
2020-11-19 12:27:35 +00:00
|
|
|
TestPlatform::TestPlatform(
|
|
|
|
std::unique_ptr<v8::TracingController> tracing_controller)
|
|
|
|
: DefaultPlatform(0 /* thread_pool_size */, IdleTaskSupport::kEnabled,
|
|
|
|
std::move(tracing_controller)) {}
|
2020-05-26 14:40:57 +00:00
|
|
|
|
2020-09-25 18:04:34 +00:00
|
|
|
std::unique_ptr<cppgc::JobHandle> TestPlatform::PostJob(
|
2020-10-08 11:16:20 +00:00
|
|
|
cppgc::TaskPriority priority, std::unique_ptr<cppgc::JobTask> job_task) {
|
|
|
|
if (AreBackgroundTasksDisabled()) return nullptr;
|
|
|
|
return v8_platform_->PostJob(priority, std::move(job_task));
|
2020-05-26 14:40:57 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 11:16:20 +00:00
|
|
|
void TestPlatform::RunAllForegroundTasks() {
|
|
|
|
v8::platform::PumpMessageLoop(v8_platform_.get(), kNoIsolate);
|
|
|
|
if (GetForegroundTaskRunner()->IdleTasksEnabled()) {
|
|
|
|
v8::platform::RunIdleTasks(v8_platform_.get(), kNoIsolate,
|
|
|
|
std::numeric_limits<double>::max());
|
2020-05-26 14:40:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TestPlatform::DisableBackgroundTasksScope::DisableBackgroundTasksScope(
|
|
|
|
TestPlatform* platform)
|
|
|
|
: platform_(platform) {
|
|
|
|
++platform_->disabled_background_tasks_;
|
|
|
|
}
|
|
|
|
|
|
|
|
TestPlatform::DisableBackgroundTasksScope::~DisableBackgroundTasksScope()
|
|
|
|
V8_NOEXCEPT {
|
|
|
|
--platform_->disabled_background_tasks_;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace testing
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace cppgc
|