v8/test/unittests/test-utils.cc
Clemens Backes 52c7ab5654 [cleanup][test] Remove redundant NOLINT annotations
cpplint rules change over time, and we change the exact rules we enable
for v8. This CL removes NOLINT annotations which are not needed
according to the currently enabled rules.

R=ahaas@chromium.org

Bug: v8:11717
Change-Id: Ica92f4ddc9c351c1c63147cbcf050086ca26cc07
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2859854
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74297}
2021-04-30 11:46:14 +00:00

88 lines
2.7 KiB
C++

// 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.
#include "test/unittests/test-utils.h"
#include "include/libplatform/libplatform.h"
#include "include/v8.h"
#include "src/api/api-inl.h"
#include "src/base/platform/time.h"
#include "src/execution/isolate.h"
#include "src/flags/flags.h"
#include "src/init/v8.h"
#include "src/objects/objects-inl.h"
namespace v8 {
namespace {
// counter_lookup_callback doesn't pass through any state information about
// the current Isolate, so we have to store the current counter map somewhere.
// Fortunately tests run serially, so we can just store it in a static global.
CounterMap* kCurrentCounterMap = nullptr;
} // namespace
IsolateWrapper::IsolateWrapper(CountersMode counters_mode)
: array_buffer_allocator_(
v8::ArrayBuffer::Allocator::NewDefaultAllocator()) {
CHECK_NULL(kCurrentCounterMap);
v8::Isolate::CreateParams create_params;
create_params.array_buffer_allocator = array_buffer_allocator_.get();
if (counters_mode == kEnableCounters) {
counter_map_ = std::make_unique<CounterMap>();
kCurrentCounterMap = counter_map_.get();
create_params.counter_lookup_callback = [](const char* name) {
CHECK_NOT_NULL(kCurrentCounterMap);
// If the name doesn't exist in the counter map, operator[] will default
// initialize it to zero.
return &(*kCurrentCounterMap)[name];
};
} else {
create_params.counter_lookup_callback = [](const char* name) -> int* {
return nullptr;
};
}
isolate_ = v8::Isolate::New(create_params);
CHECK_NOT_NULL(isolate());
}
IsolateWrapper::~IsolateWrapper() {
v8::Platform* platform = internal::V8::GetCurrentPlatform();
CHECK_NOT_NULL(platform);
while (platform::PumpMessageLoop(platform, isolate())) continue;
isolate_->Dispose();
if (counter_map_) {
CHECK_EQ(kCurrentCounterMap, counter_map_.get());
kCurrentCounterMap = nullptr;
} else {
CHECK_NULL(kCurrentCounterMap);
}
}
namespace internal {
SaveFlags::SaveFlags() {
// For each flag, save the current flag value.
#define FLAG_MODE_APPLY(ftype, ctype, nam, def, cmt) SAVED_##nam = FLAG_##nam;
#include "src/flags/flag-definitions.h"
#undef FLAG_MODE_APPLY
}
SaveFlags::~SaveFlags() {
// For each flag, set back the old flag value if it changed (don't write the
// flag if it didn't change, to keep TSAN happy).
#define FLAG_MODE_APPLY(ftype, ctype, nam, def, cmt) \
if (SAVED_##nam != FLAG_##nam) { \
FLAG_##nam = SAVED_##nam; \
}
#include "src/flags/flag-definitions.h" // NOLINT
#undef FLAG_MODE_APPLY
}
} // namespace internal
} // namespace v8