v8/test/common/flag-utils.h
Clemens Backes d701dde2be [cleanup] Remove redundant FLAG_SCOPE macros
FLAG_SCOPE_EXTERNAL can be used outside of the v8::internal namespace,
while FLAG_SCOPE can not.
This CL refactors FLAG_SCOPE such that it can be used anywhere, and
removes the redudant FLAG_SCOPE_EXTERNAL macro.
Also, UNFLAG_SCOPE_EXTERNAL is removed in favor of FLAG_SCOPE_VAL, as
the word "flag" in the macro name is meant to refer to a flag, and not
to the verb or action of "flagging" something, hence "unflag" does not
match the terminology.

R=ahaas@chromium.org

Bug: v8:11879
Change-Id: I2d761012c3e4330abb611bf67130eb57ec5bb964
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2988920
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75482}
2021-06-30 15:05:25 +00:00

33 lines
834 B
C++

// 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>
class V8_NODISCARD FlagScope {
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
#define FLAG_VALUE_SCOPE(flag, value) \
v8::internal::FlagScope<bool> __scope_##flag##__LINE__( \
&v8::internal::FLAG_##flag, value)
#define FLAG_SCOPE(flag) FLAG_VALUE_SCOPE(flag, true)
#endif // V8_TEST_COMMON_FLAG_UTILS_H