diff --git a/js/src/irregexp/RegExpShim.h b/js/src/irregexp/RegExpShim.h index 27f2fa9e0ba4..0c347756f0b2 100644 --- a/js/src/irregexp/RegExpShim.h +++ b/js/src/irregexp/RegExpShim.h @@ -244,6 +244,21 @@ template return mozilla::AddToHash(aHash, aArgs...); } +template +class Optional { + mozilla::Maybe inner_; + + public: + Optional() = default; + Optional(T t) { inner_.emplace(t); } + + bool has_value() const { return inner_.isSome(); } + const T& value() const { return inner_.ref(); } + + T* operator->() { return &inner_.ref(); } + T& operator*() { return inner_.ref(); } +}; + namespace bits { inline uint64_t CountTrailingZeros(uint64_t value) { @@ -1105,15 +1120,13 @@ inline bool IsEitherUnicode(RegExpFlags flags) { return flags.unicode() || flags.unicodeSets(); } -inline std::optional TryRegExpFlagFromChar(char c) { +inline base::Optional TryRegExpFlagFromChar(char c) { RegExpFlag flag; // The parser only calls this after verifying that it's a supported flag. - if (JS::MaybeParseRegExpFlag(c, &flag)) { - return flag; - } + MOZ_ALWAYS_TRUE(JS::MaybeParseRegExpFlag(c, &flag)); - return std::optional{}; + return base::Optional(flag); } inline bool operator==(const RegExpFlags& lhs, const int& rhs) {