flag-utils.h 1.32 KB
Newer Older
1 2 3 4
// Copyright 2017 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.

5 6
#ifndef V8_TEST_COMMON_WASM_FLAG_UTILS_H
#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 12 13
namespace v8 {
namespace internal {

14
#define EXPERIMENTAL_FLAG_SCOPE(flag) FLAG_SCOPE(experimental_wasm_##flag)
15

16 17
namespace wasm {

18
class V8_NODISCARD WasmFeatureScope {
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
 public:
  explicit WasmFeatureScope(WasmFeatures* features, WasmFeature feature,
                            bool val = true)
      : prev_(features->contains(feature)),
        feature_(feature),
        features_(features) {
    set(val);
  }
  ~WasmFeatureScope() { set(prev_); }

 private:
  void set(bool val) {
    if (val) {
      features_->Add(feature_);
    } else {
      features_->Remove(feature_);
    }
  }

  bool const prev_;
  WasmFeature const feature_;
  WasmFeatures* const features_;
};

#define WASM_FEATURE_SCOPE(feat) \
  WasmFeatureScope feat##_scope(&this->enabled_features_, kFeature_##feat)

#define WASM_FEATURE_SCOPE_VAL(feat, val) \
  WasmFeatureScope feat##_scope(&this->enabled_features_, kFeature_##feat, val)

}  // namespace wasm
50 51
}  // namespace internal
}  // namespace v8
52

53
#endif  // V8_TEST_COMMON_WASM_FLAG_UTILS_H