1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_TEST_COMMON_WASM_FLAG_UTILS_H
6 #define V8_TEST_COMMON_WASM_FLAG_UTILS_H
7 
8 #include "src/wasm/wasm-features.h"
9 #include "test/common/flag-utils.h"
10 
11 namespace v8 {
12 namespace internal {
13 
14 #define EXPERIMENTAL_FLAG_SCOPE(flag) FLAG_SCOPE(experimental_wasm_##flag)
15 
16 namespace wasm {
17 
18 class V8_NODISCARD WasmFeatureScope {
19  public:
20   explicit WasmFeatureScope(WasmFeatures* features, WasmFeature feature,
21                             bool val = true)
22       : prev_(features->contains(feature)),
23         feature_(feature),
24         features_(features) {
25     set(val);
26   }
~WasmFeatureScope()27   ~WasmFeatureScope() { set(prev_); }
28 
29  private:
set(bool val)30   void set(bool val) {
31     if (val) {
32       features_->Add(feature_);
33     } else {
34       features_->Remove(feature_);
35     }
36   }
37 
38   bool const prev_;
39   WasmFeature const feature_;
40   WasmFeatures* const features_;
41 };
42 
43 #define WASM_FEATURE_SCOPE(feat) \
44   WasmFeatureScope feat##_scope(&this->enabled_features_, kFeature_##feat)
45 
46 #define WASM_FEATURE_SCOPE_VAL(feat, val) \
47   WasmFeatureScope feat##_scope(&this->enabled_features_, kFeature_##feat, val)
48 
49 }  // namespace wasm
50 }  // namespace internal
51 }  // namespace v8
52 
53 #endif  // V8_TEST_COMMON_WASM_FLAG_UTILS_H
54