2020-10-05 15:01:50 +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.
|
|
|
|
|
|
|
|
#ifndef V8_TEST_COMMON_FLAG_UTILS_H
|
|
|
|
#define V8_TEST_COMMON_FLAG_UTILS_H
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
template <typename T>
|
2020-11-26 10:08:27 +00:00
|
|
|
class V8_NODISCARD FlagScope {
|
2020-10-05 15:01:50 +00:00
|
|
|
public:
|
|
|
|
FlagScope(T* flag, T new_value) : flag_(flag), previous_value_(*flag) {
|
|
|
|
*flag = new_value;
|
|
|
|
}
|
|
|
|
~FlagScope() { *flag_ = previous_value_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
T* flag_;
|
|
|
|
T previous_value_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
2021-06-30 14:17:08 +00:00
|
|
|
#define FLAG_VALUE_SCOPE(flag, value) \
|
2020-10-05 15:01:50 +00:00
|
|
|
v8::internal::FlagScope<bool> __scope_##flag##__LINE__( \
|
2021-06-30 14:17:08 +00:00
|
|
|
&v8::internal::FLAG_##flag, value)
|
|
|
|
#define FLAG_SCOPE(flag) FLAG_VALUE_SCOPE(flag, true)
|
2020-10-05 15:01:50 +00:00
|
|
|
|
|
|
|
#endif // V8_TEST_COMMON_FLAG_UTILS_H
|