Bug 1429613 - Variant matcher callbacks renamed from match to operator() - r=froydnj

Mechanical change from Matcher::match(...) to Matcher::operator()(...).
This will now permit the use of generic lambdas, and facilitate the
implementation of multi-lambda match.

Differential Revision: https://phabricator.services.mozilla.com/D24889

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gerald Squelart 2019-04-02 11:53:47 +00:00
parent d0f1336b84
commit e2d15a1cfb
23 changed files with 402 additions and 333 deletions

View File

@ -136,7 +136,7 @@ struct GetOrInternStringMatcher {
explicit GetOrInternStringMatcher(InternedStringSet& strings) explicit GetOrInternStringMatcher(InternedStringSet& strings)
: internedStrings(strings) {} : internedStrings(strings) {}
const CharT* match(const std::string* str) { const CharT* operator()(const std::string* str) {
MOZ_ASSERT(str); MOZ_ASSERT(str);
size_t length = str->length() / sizeof(CharT); size_t length = str->length() / sizeof(CharT);
auto tempString = reinterpret_cast<const CharT*>(str->data()); auto tempString = reinterpret_cast<const CharT*>(str->data());
@ -147,7 +147,7 @@ struct GetOrInternStringMatcher {
return internedStrings.back().get(); return internedStrings.back().get();
} }
const CharT* match(uint64_t ref) { const CharT* operator()(uint64_t ref) {
if (MOZ_LIKELY(ref < internedStrings.length())) { if (MOZ_LIKELY(ref < internedStrings.length())) {
auto& string = internedStrings[ref]; auto& string = internedStrings[ref];
MOZ_ASSERT(string); MOZ_ASSERT(string);
@ -788,31 +788,33 @@ class TwoByteString
using Base = Variant<JSAtom*, const char16_t*, JS::ubi::EdgeName>; using Base = Variant<JSAtom*, const char16_t*, JS::ubi::EdgeName>;
struct AsTwoByteStringMatcher { struct AsTwoByteStringMatcher {
TwoByteString match(JSAtom* atom) { return TwoByteString(atom); } TwoByteString operator()(JSAtom* atom) { return TwoByteString(atom); }
TwoByteString match(const char16_t* chars) { return TwoByteString(chars); } TwoByteString operator()(const char16_t* chars) {
return TwoByteString(chars);
}
}; };
struct IsNonNullMatcher { struct IsNonNullMatcher {
template <typename T> template <typename T>
bool match(const T& t) { bool operator()(const T& t) {
return t != nullptr; return t != nullptr;
} }
}; };
struct LengthMatcher { struct LengthMatcher {
size_t match(JSAtom* atom) { size_t operator()(JSAtom* atom) {
MOZ_ASSERT(atom); MOZ_ASSERT(atom);
JS::ubi::AtomOrTwoByteChars s(atom); JS::ubi::AtomOrTwoByteChars s(atom);
return s.length(); return s.length();
} }
size_t match(const char16_t* chars) { size_t operator()(const char16_t* chars) {
MOZ_ASSERT(chars); MOZ_ASSERT(chars);
return NS_strlen(chars); return NS_strlen(chars);
} }
size_t match(const JS::ubi::EdgeName& ptr) { size_t operator()(const JS::ubi::EdgeName& ptr) {
MOZ_ASSERT(ptr); MOZ_ASSERT(ptr);
return NS_strlen(ptr.get()); return NS_strlen(ptr.get());
} }
@ -825,15 +827,17 @@ class TwoByteString
CopyToBufferMatcher(RangedPtr<char16_t> destination, size_t maxLength) CopyToBufferMatcher(RangedPtr<char16_t> destination, size_t maxLength)
: destination(destination), maxLength(maxLength) {} : destination(destination), maxLength(maxLength) {}
size_t match(JS::ubi::EdgeName& ptr) { return ptr ? match(ptr.get()) : 0; } size_t operator()(JS::ubi::EdgeName& ptr) {
return ptr ? operator()(ptr.get()) : 0;
}
size_t match(JSAtom* atom) { size_t operator()(JSAtom* atom) {
MOZ_ASSERT(atom); MOZ_ASSERT(atom);
JS::ubi::AtomOrTwoByteChars s(atom); JS::ubi::AtomOrTwoByteChars s(atom);
return s.copyToBuffer(destination, maxLength); return s.copyToBuffer(destination, maxLength);
} }
size_t match(const char16_t* chars) { size_t operator()(const char16_t* chars) {
MOZ_ASSERT(chars); MOZ_ASSERT(chars);
JS::ubi::AtomOrTwoByteChars s(chars); JS::ubi::AtomOrTwoByteChars s(chars);
return s.copyToBuffer(destination, maxLength); return s.copyToBuffer(destination, maxLength);
@ -896,19 +900,19 @@ struct TwoByteString::HashPolicy {
using Lookup = TwoByteString; using Lookup = TwoByteString;
struct HashingMatcher { struct HashingMatcher {
js::HashNumber match(const JSAtom* atom) { js::HashNumber operator()(const JSAtom* atom) {
return js::DefaultHasher<const JSAtom*>::hash(atom); return js::DefaultHasher<const JSAtom*>::hash(atom);
} }
js::HashNumber match(const char16_t* chars) { js::HashNumber operator()(const char16_t* chars) {
MOZ_ASSERT(chars); MOZ_ASSERT(chars);
auto length = NS_strlen(chars); auto length = NS_strlen(chars);
return HashString(chars, length); return HashString(chars, length);
} }
js::HashNumber match(const JS::ubi::EdgeName& ptr) { js::HashNumber operator()(const JS::ubi::EdgeName& ptr) {
MOZ_ASSERT(ptr); MOZ_ASSERT(ptr);
return match(ptr.get()); return operator()(ptr.get());
} }
}; };
@ -921,11 +925,11 @@ struct TwoByteString::HashPolicy {
const TwoByteString& rhs; const TwoByteString& rhs;
explicit EqualityMatcher(const TwoByteString& rhs) : rhs(rhs) {} explicit EqualityMatcher(const TwoByteString& rhs) : rhs(rhs) {}
bool match(const JSAtom* atom) { bool operator()(const JSAtom* atom) {
return rhs.is<JSAtom*>() && rhs.as<JSAtom*>() == atom; return rhs.is<JSAtom*>() && rhs.as<JSAtom*>() == atom;
} }
bool match(const char16_t* chars) { bool operator()(const char16_t* chars) {
MOZ_ASSERT(chars); MOZ_ASSERT(chars);
const char16_t* rhsChars = nullptr; const char16_t* rhsChars = nullptr;
@ -943,9 +947,9 @@ struct TwoByteString::HashPolicy {
return memcmp(chars, rhsChars, length * sizeof(char16_t)) == 0; return memcmp(chars, rhsChars, length * sizeof(char16_t)) == 0;
} }
bool match(const JS::ubi::EdgeName& ptr) { bool operator()(const JS::ubi::EdgeName& ptr) {
MOZ_ASSERT(ptr); MOZ_ASSERT(ptr);
return match(ptr.get()); return operator()(ptr.get());
} }
}; };

View File

@ -7233,22 +7233,22 @@ void ArchivedOriginScope::GetBindingClause(nsACString& aBindingClause) const {
explicit Matcher(nsACString* aBindingClause) explicit Matcher(nsACString* aBindingClause)
: mBindingClause(aBindingClause) {} : mBindingClause(aBindingClause) {}
void match(const Origin& aOrigin) { void operator()(const Origin& aOrigin) {
*mBindingClause = NS_LITERAL_CSTRING( *mBindingClause = NS_LITERAL_CSTRING(
" WHERE originKey = :originKey " " WHERE originKey = :originKey "
"AND originAttributes = :originAttributes"); "AND originAttributes = :originAttributes");
} }
void match(const Prefix& aPrefix) { void operator()(const Prefix& aPrefix) {
*mBindingClause = NS_LITERAL_CSTRING(" WHERE originKey = :originKey"); *mBindingClause = NS_LITERAL_CSTRING(" WHERE originKey = :originKey");
} }
void match(const Pattern& aPattern) { void operator()(const Pattern& aPattern) {
*mBindingClause = NS_LITERAL_CSTRING( *mBindingClause = NS_LITERAL_CSTRING(
" WHERE originAttributes MATCH :originAttributesPattern"); " WHERE originAttributes MATCH :originAttributesPattern");
} }
void match(const Null& aNull) { *mBindingClause = EmptyCString(); } void operator()(const Null& aNull) { *mBindingClause = EmptyCString(); }
}; };
mData.match(Matcher(&aBindingClause)); mData.match(Matcher(&aBindingClause));
@ -7264,7 +7264,7 @@ nsresult ArchivedOriginScope::BindToStatement(
explicit Matcher(mozIStorageStatement* aStmt) : mStmt(aStmt) {} explicit Matcher(mozIStorageStatement* aStmt) : mStmt(aStmt) {}
nsresult match(const Origin& aOrigin) { nsresult operator()(const Origin& aOrigin) {
nsresult rv = mStmt->BindUTF8StringByName(NS_LITERAL_CSTRING("originKey"), nsresult rv = mStmt->BindUTF8StringByName(NS_LITERAL_CSTRING("originKey"),
aOrigin.OriginNoSuffix()); aOrigin.OriginNoSuffix());
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
@ -7280,7 +7280,7 @@ nsresult ArchivedOriginScope::BindToStatement(
return NS_OK; return NS_OK;
} }
nsresult match(const Prefix& aPrefix) { nsresult operator()(const Prefix& aPrefix) {
nsresult rv = mStmt->BindUTF8StringByName(NS_LITERAL_CSTRING("originKey"), nsresult rv = mStmt->BindUTF8StringByName(NS_LITERAL_CSTRING("originKey"),
aPrefix.OriginNoSuffix()); aPrefix.OriginNoSuffix());
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
@ -7290,7 +7290,7 @@ nsresult ArchivedOriginScope::BindToStatement(
return NS_OK; return NS_OK;
} }
nsresult match(const Pattern& aPattern) { nsresult operator()(const Pattern& aPattern) {
nsresult rv = mStmt->BindUTF8StringByName( nsresult rv = mStmt->BindUTF8StringByName(
NS_LITERAL_CSTRING("originAttributesPattern"), NS_LITERAL_CSTRING("originAttributesPattern"),
NS_LITERAL_CSTRING("pattern1")); NS_LITERAL_CSTRING("pattern1"));
@ -7301,7 +7301,7 @@ nsresult ArchivedOriginScope::BindToStatement(
return NS_OK; return NS_OK;
} }
nsresult match(const Null& aNull) { return NS_OK; } nsresult operator()(const Null& aNull) { return NS_OK; }
}; };
nsresult rv = mData.match(Matcher(aStmt)); nsresult rv = mData.match(Matcher(aStmt));
@ -7323,7 +7323,7 @@ bool ArchivedOriginScope::HasMatches(
explicit Matcher(ArchivedOriginHashtable* aHashtable) explicit Matcher(ArchivedOriginHashtable* aHashtable)
: mHashtable(aHashtable) {} : mHashtable(aHashtable) {}
bool match(const Origin& aOrigin) { bool operator()(const Origin& aOrigin) {
nsCString hashKey = GetArchivedOriginHashKey(aOrigin.OriginSuffix(), nsCString hashKey = GetArchivedOriginHashKey(aOrigin.OriginSuffix(),
aOrigin.OriginNoSuffix()); aOrigin.OriginNoSuffix());
@ -7331,7 +7331,7 @@ bool ArchivedOriginScope::HasMatches(
return mHashtable->Get(hashKey, &archivedOriginInfo); return mHashtable->Get(hashKey, &archivedOriginInfo);
} }
bool match(const Prefix& aPrefix) { bool operator()(const Prefix& aPrefix) {
for (auto iter = mHashtable->ConstIter(); !iter.Done(); iter.Next()) { for (auto iter = mHashtable->ConstIter(); !iter.Done(); iter.Next()) {
ArchivedOriginInfo* archivedOriginInfo = iter.Data(); ArchivedOriginInfo* archivedOriginInfo = iter.Data();
@ -7343,7 +7343,7 @@ bool ArchivedOriginScope::HasMatches(
return false; return false;
} }
bool match(const Pattern& aPattern) { bool operator()(const Pattern& aPattern) {
for (auto iter = mHashtable->ConstIter(); !iter.Done(); iter.Next()) { for (auto iter = mHashtable->ConstIter(); !iter.Done(); iter.Next()) {
ArchivedOriginInfo* archivedOriginInfo = iter.Data(); ArchivedOriginInfo* archivedOriginInfo = iter.Data();
@ -7356,7 +7356,7 @@ bool ArchivedOriginScope::HasMatches(
return false; return false;
} }
bool match(const Null& aNull) { return mHashtable->Count(); } bool operator()(const Null& aNull) { return mHashtable->Count(); }
}; };
return mData.match(Matcher(aHashtable)); return mData.match(Matcher(aHashtable));
@ -7373,14 +7373,14 @@ void ArchivedOriginScope::RemoveMatches(
explicit Matcher(ArchivedOriginHashtable* aHashtable) explicit Matcher(ArchivedOriginHashtable* aHashtable)
: mHashtable(aHashtable) {} : mHashtable(aHashtable) {}
void match(const Origin& aOrigin) { void operator()(const Origin& aOrigin) {
nsCString hashKey = GetArchivedOriginHashKey(aOrigin.OriginSuffix(), nsCString hashKey = GetArchivedOriginHashKey(aOrigin.OriginSuffix(),
aOrigin.OriginNoSuffix()); aOrigin.OriginNoSuffix());
mHashtable->Remove(hashKey); mHashtable->Remove(hashKey);
} }
void match(const Prefix& aPrefix) { void operator()(const Prefix& aPrefix) {
for (auto iter = mHashtable->Iter(); !iter.Done(); iter.Next()) { for (auto iter = mHashtable->Iter(); !iter.Done(); iter.Next()) {
ArchivedOriginInfo* archivedOriginInfo = iter.Data(); ArchivedOriginInfo* archivedOriginInfo = iter.Data();
@ -7390,7 +7390,7 @@ void ArchivedOriginScope::RemoveMatches(
} }
} }
void match(const Pattern& aPattern) { void operator()(const Pattern& aPattern) {
for (auto iter = mHashtable->Iter(); !iter.Done(); iter.Next()) { for (auto iter = mHashtable->Iter(); !iter.Done(); iter.Next()) {
ArchivedOriginInfo* archivedOriginInfo = iter.Data(); ArchivedOriginInfo* archivedOriginInfo = iter.Data();
@ -7401,7 +7401,7 @@ void ArchivedOriginScope::RemoveMatches(
} }
} }
void match(const Null& aNull) { mHashtable->Clear(); } void operator()(const Null& aNull) { mHashtable->Clear(); }
}; };
mData.match(Matcher(aHashtable)); mData.match(Matcher(aHashtable));

View File

@ -13,47 +13,49 @@ namespace mozilla {
struct LogValueMatcher { struct LogValueMatcher {
nsCString& mString; nsCString& mString;
void match(const DDNoValue&) const {} void operator()(const DDNoValue&) const {}
void match(const DDLogObject& a) const { a.AppendPrintf(mString); } void operator()(const DDLogObject& a) const { a.AppendPrintf(mString); }
void match(const char* a) const { mString.AppendPrintf(R"("%s")", a); } void operator()(const char* a) const { mString.AppendPrintf(R"("%s")", a); }
void match(const nsCString& a) const { void operator()(const nsCString& a) const {
mString.AppendPrintf(R"(nsCString("%s"))", a.Data()); mString.AppendPrintf(R"(nsCString("%s"))", a.Data());
} }
void match(bool a) const { mString.AppendPrintf(a ? "true" : "false"); } void operator()(bool a) const { mString.AppendPrintf(a ? "true" : "false"); }
void match(int8_t a) const { mString.AppendPrintf("int8_t(%" PRIi8 ")", a); } void operator()(int8_t a) const {
void match(uint8_t a) const { mString.AppendPrintf("int8_t(%" PRIi8 ")", a);
}
void operator()(uint8_t a) const {
mString.AppendPrintf("uint8_t(%" PRIu8 ")", a); mString.AppendPrintf("uint8_t(%" PRIu8 ")", a);
} }
void match(int16_t a) const { void operator()(int16_t a) const {
mString.AppendPrintf("int16_t(%" PRIi16 ")", a); mString.AppendPrintf("int16_t(%" PRIi16 ")", a);
} }
void match(uint16_t a) const { void operator()(uint16_t a) const {
mString.AppendPrintf("uint16_t(%" PRIu16 ")", a); mString.AppendPrintf("uint16_t(%" PRIu16 ")", a);
} }
void match(int32_t a) const { void operator()(int32_t a) const {
mString.AppendPrintf("int32_t(%" PRIi32 ")", a); mString.AppendPrintf("int32_t(%" PRIi32 ")", a);
} }
void match(uint32_t a) const { void operator()(uint32_t a) const {
mString.AppendPrintf("uint32_t(%" PRIu32 ")", a); mString.AppendPrintf("uint32_t(%" PRIu32 ")", a);
} }
void match(int64_t a) const { void operator()(int64_t a) const {
mString.AppendPrintf("int64_t(%" PRIi64 ")", a); mString.AppendPrintf("int64_t(%" PRIi64 ")", a);
} }
void match(uint64_t a) const { void operator()(uint64_t a) const {
mString.AppendPrintf("uint64_t(%" PRIu64 ")", a); mString.AppendPrintf("uint64_t(%" PRIu64 ")", a);
} }
void match(double a) const { mString.AppendPrintf("double(%f)", a); } void operator()(double a) const { mString.AppendPrintf("double(%f)", a); }
void match(const DDRange& a) const { void operator()(const DDRange& a) const {
mString.AppendPrintf("%" PRIi64 "<=(%" PRIi64 "B)<%" PRIi64 "", a.mOffset, mString.AppendPrintf("%" PRIi64 "<=(%" PRIi64 "B)<%" PRIi64 "", a.mOffset,
a.mBytes, a.mOffset + a.mBytes); a.mBytes, a.mOffset + a.mBytes);
} }
void match(const nsresult& a) const { void operator()(const nsresult& a) const {
nsCString name; nsCString name;
GetErrorName(a, name); GetErrorName(a, name);
mString.AppendPrintf("nsresult(%s =0x%08" PRIx32 ")", name.get(), mString.AppendPrintf("nsresult(%s =0x%08" PRIx32 ")", name.get(),
static_cast<uint32_t>(a)); static_cast<uint32_t>(a));
} }
void match(const MediaResult& a) const { void operator()(const MediaResult& a) const {
nsCString name; nsCString name;
GetErrorName(a.Code(), name); GetErrorName(a.Code(), name);
mString.AppendPrintf("MediaResult(%s =0x%08" PRIx32 ", \"%s\")", name.get(), mString.AppendPrintf("MediaResult(%s =0x%08" PRIx32 ", \"%s\")", name.get(),
@ -69,38 +71,38 @@ struct LogValueMatcherJson {
JSONWriter& mJW; JSONWriter& mJW;
const char* mPropertyName; const char* mPropertyName;
void match(const DDNoValue&) const { mJW.NullProperty(mPropertyName); } void operator()(const DDNoValue&) const { mJW.NullProperty(mPropertyName); }
void match(const DDLogObject& a) const { void operator()(const DDLogObject& a) const {
mJW.StringProperty( mJW.StringProperty(
mPropertyName, mPropertyName,
nsPrintfCString(R"("%s[%p]")", a.TypeName(), a.Pointer()).get()); nsPrintfCString(R"("%s[%p]")", a.TypeName(), a.Pointer()).get());
} }
void match(const char* a) const { mJW.StringProperty(mPropertyName, a); } void operator()(const char* a) const { mJW.StringProperty(mPropertyName, a); }
void match(const nsCString& a) const { void operator()(const nsCString& a) const {
mJW.StringProperty(mPropertyName, a.Data()); mJW.StringProperty(mPropertyName, a.Data());
} }
void match(bool a) const { mJW.BoolProperty(mPropertyName, a); } void operator()(bool a) const { mJW.BoolProperty(mPropertyName, a); }
void match(int8_t a) const { mJW.IntProperty(mPropertyName, a); } void operator()(int8_t a) const { mJW.IntProperty(mPropertyName, a); }
void match(uint8_t a) const { mJW.IntProperty(mPropertyName, a); } void operator()(uint8_t a) const { mJW.IntProperty(mPropertyName, a); }
void match(int16_t a) const { mJW.IntProperty(mPropertyName, a); } void operator()(int16_t a) const { mJW.IntProperty(mPropertyName, a); }
void match(uint16_t a) const { mJW.IntProperty(mPropertyName, a); } void operator()(uint16_t a) const { mJW.IntProperty(mPropertyName, a); }
void match(int32_t a) const { mJW.IntProperty(mPropertyName, a); } void operator()(int32_t a) const { mJW.IntProperty(mPropertyName, a); }
void match(uint32_t a) const { mJW.IntProperty(mPropertyName, a); } void operator()(uint32_t a) const { mJW.IntProperty(mPropertyName, a); }
void match(int64_t a) const { mJW.IntProperty(mPropertyName, a); } void operator()(int64_t a) const { mJW.IntProperty(mPropertyName, a); }
void match(uint64_t a) const { mJW.DoubleProperty(mPropertyName, a); } void operator()(uint64_t a) const { mJW.DoubleProperty(mPropertyName, a); }
void match(double a) const { mJW.DoubleProperty(mPropertyName, a); } void operator()(double a) const { mJW.DoubleProperty(mPropertyName, a); }
void match(const DDRange& a) const { void operator()(const DDRange& a) const {
mJW.StartArrayProperty(mPropertyName); mJW.StartArrayProperty(mPropertyName);
mJW.IntElement(a.mOffset); mJW.IntElement(a.mOffset);
mJW.IntElement(a.mOffset + a.mBytes); mJW.IntElement(a.mOffset + a.mBytes);
mJW.EndArray(); mJW.EndArray();
} }
void match(const nsresult& a) const { void operator()(const nsresult& a) const {
nsCString name; nsCString name;
GetErrorName(a, name); GetErrorName(a, name);
mJW.StringProperty(mPropertyName, name.get()); mJW.StringProperty(mPropertyName, name.get());
} }
void match(const MediaResult& a) const { void operator()(const MediaResult& a) const {
nsCString name; nsCString name;
GetErrorName(a.Code(), name); GetErrorName(a.Code(), name);
mJW.StringProperty(mPropertyName, mJW.StringProperty(mPropertyName,

View File

@ -152,7 +152,7 @@ struct ParamTraits<IpdlTuple::IpdlTupleElement> {
explicit LogMatcher(std::wstring* aLog) : mLog(aLog) {} explicit LogMatcher(std::wstring* aLog) : mLog(aLog) {}
template <typename EntryType> template <typename EntryType>
void match(const EntryType& aParam) { void operator()(const EntryType& aParam) {
LogParam(aParam, mLog); LogParam(aParam, mLog);
} }

View File

@ -212,13 +212,19 @@ class OriginScope {
explicit Matcher(const OriginScope& aThis) : mThis(aThis) {} explicit Matcher(const OriginScope& aThis) : mThis(aThis) {}
bool match(const Origin& aOther) { return mThis.MatchesOrigin(aOther); } bool operator()(const Origin& aOther) {
return mThis.MatchesOrigin(aOther);
}
bool match(const Prefix& aOther) { return mThis.MatchesPrefix(aOther); } bool operator()(const Prefix& aOther) {
return mThis.MatchesPrefix(aOther);
}
bool match(const Pattern& aOther) { return mThis.MatchesPattern(aOther); } bool operator()(const Pattern& aOther) {
return mThis.MatchesPattern(aOther);
}
bool match(const Null& aOther) { return true; } bool operator()(const Null& aOther) { return true; }
}; };
return aOther.mData.match(Matcher(*this)); return aOther.mData.match(Matcher(*this));
@ -245,19 +251,19 @@ class OriginScope {
explicit OriginMatcher(const Origin& aOther) : mOther(aOther) {} explicit OriginMatcher(const Origin& aOther) : mOther(aOther) {}
bool match(const Origin& aThis) { bool operator()(const Origin& aThis) {
return aThis.GetOrigin().Equals(mOther.GetOrigin()); return aThis.GetOrigin().Equals(mOther.GetOrigin());
} }
bool match(const Prefix& aThis) { bool operator()(const Prefix& aThis) {
return aThis.GetOriginNoSuffix().Equals(mOther.GetOriginNoSuffix()); return aThis.GetOriginNoSuffix().Equals(mOther.GetOriginNoSuffix());
} }
bool match(const Pattern& aThis) { bool operator()(const Pattern& aThis) {
return aThis.GetPattern().Matches(mOther.GetAttributes()); return aThis.GetPattern().Matches(mOther.GetAttributes());
} }
bool match(const Null& aThis) { bool operator()(const Null& aThis) {
// Null covers everything. // Null covers everything.
return true; return true;
} }
@ -272,22 +278,22 @@ class OriginScope {
explicit PrefixMatcher(const Prefix& aOther) : mOther(aOther) {} explicit PrefixMatcher(const Prefix& aOther) : mOther(aOther) {}
bool match(const Origin& aThis) { bool operator()(const Origin& aThis) {
return aThis.GetOriginNoSuffix().Equals(mOther.GetOriginNoSuffix()); return aThis.GetOriginNoSuffix().Equals(mOther.GetOriginNoSuffix());
} }
bool match(const Prefix& aThis) { bool operator()(const Prefix& aThis) {
return aThis.GetOriginNoSuffix().Equals(mOther.GetOriginNoSuffix()); return aThis.GetOriginNoSuffix().Equals(mOther.GetOriginNoSuffix());
} }
bool match(const Pattern& aThis) { bool operator()(const Pattern& aThis) {
// The match will be always true here because any origin attributes // The match will be always true here because any origin attributes
// pattern overlaps any origin prefix (an origin prefix targets all // pattern overlaps any origin prefix (an origin prefix targets all
// origin attributes). // origin attributes).
return true; return true;
} }
bool match(const Null& aThis) { bool operator()(const Null& aThis) {
// Null covers everything. // Null covers everything.
return true; return true;
} }
@ -302,22 +308,22 @@ class OriginScope {
explicit PatternMatcher(const Pattern& aOther) : mOther(aOther) {} explicit PatternMatcher(const Pattern& aOther) : mOther(aOther) {}
bool match(const Origin& aThis) { bool operator()(const Origin& aThis) {
return mOther.GetPattern().Matches(aThis.GetAttributes()); return mOther.GetPattern().Matches(aThis.GetAttributes());
} }
bool match(const Prefix& aThis) { bool operator()(const Prefix& aThis) {
// The match will be always true here because any origin attributes // The match will be always true here because any origin attributes
// pattern overlaps any origin prefix (an origin prefix targets all // pattern overlaps any origin prefix (an origin prefix targets all
// origin attributes). // origin attributes).
return true; return true;
} }
bool match(const Pattern& aThis) { bool operator()(const Pattern& aThis) {
return aThis.GetPattern().Overlaps(mOther.GetPattern()); return aThis.GetPattern().Overlaps(mOther.GetPattern());
} }
bool match(const Null& aThis) { bool operator()(const Null& aThis) {
// Null covers everything. // Null covers everything.
return true; return true;
} }

View File

@ -13,7 +13,7 @@ struct Setter {
Setter(FilterNode* aNode, DrawTarget* aDT, bool aInputsChanged) Setter(FilterNode* aNode, DrawTarget* aDT, bool aInputsChanged)
: mNode{aNode}, mIndex{0}, mDT{aDT}, mInputsChanged{aInputsChanged} {} : mNode{aNode}, mIndex{0}, mDT{aDT}, mInputsChanged{aInputsChanged} {}
template <typename T> template <typename T>
void match(T& aValue) { void operator()(T& aValue) {
mNode->SetAttribute(mIndex, aValue); mNode->SetAttribute(mIndex, aValue);
} }
@ -24,12 +24,13 @@ struct Setter {
}; };
template <> template <>
void Setter::match<std::vector<Float>>(std::vector<Float>& aValue) { void Setter::operator()<std::vector<Float>>(std::vector<Float>& aValue) {
mNode->SetAttribute(mIndex, aValue.data(), aValue.size()); mNode->SetAttribute(mIndex, aValue.data(), aValue.size());
} }
template <> template <>
void Setter::match<RefPtr<SourceSurface>>(RefPtr<SourceSurface>& aSurface) { void Setter::operator()<RefPtr<SourceSurface>>(
RefPtr<SourceSurface>& aSurface) {
if (!mInputsChanged) { if (!mInputsChanged) {
return; return;
} }
@ -37,7 +38,7 @@ void Setter::match<RefPtr<SourceSurface>>(RefPtr<SourceSurface>& aSurface) {
} }
template <> template <>
void Setter::match<RefPtr<FilterNode>>(RefPtr<FilterNode>& aNode) { void Setter::operator()<RefPtr<FilterNode>>(RefPtr<FilterNode>& aNode) {
RefPtr<FilterNode> node = aNode; RefPtr<FilterNode> node = aNode;
if (node->GetBackendType() == FilterBackend::FILTER_BACKEND_CAPTURE) { if (node->GetBackendType() == FilterBackend::FILTER_BACKEND_CAPTURE) {
FilterNodeCapture* captureNode = FilterNodeCapture* captureNode =

View File

@ -102,7 +102,7 @@ void FocusState::Update(LayersId aRootLayerTreeId,
FocusState& mFocusState; FocusState& mFocusState;
const uint64_t mSequenceNumber; const uint64_t mSequenceNumber;
bool match(const FocusTarget::NoFocusTarget& aNoFocusTarget) { bool operator()(const FocusTarget::NoFocusTarget& aNoFocusTarget) {
FS_LOG("Setting target to nil (reached a nil target) with seq=%" PRIu64 FS_LOG("Setting target to nil (reached a nil target) with seq=%" PRIu64
"\n", "\n",
mSequenceNumber); mSequenceNumber);
@ -123,7 +123,7 @@ void FocusState::Update(LayersId aRootLayerTreeId,
return true; return true;
} }
bool match(const LayersId& aRefLayerId) { bool operator()(const LayersId& aRefLayerId) {
// Guard against infinite loops // Guard against infinite loops
MOZ_ASSERT(mFocusState.mFocusLayersId != aRefLayerId); MOZ_ASSERT(mFocusState.mFocusLayersId != aRefLayerId);
if (mFocusState.mFocusLayersId == aRefLayerId) { if (mFocusState.mFocusLayersId == aRefLayerId) {
@ -141,7 +141,7 @@ void FocusState::Update(LayersId aRootLayerTreeId,
return false; return false;
} }
bool match(const FocusTarget::ScrollTargets& aScrollTargets) { bool operator()(const FocusTarget::ScrollTargets& aScrollTargets) {
FS_LOG("Setting target to h=%" PRIu64 ", v=%" PRIu64 FS_LOG("Setting target to h=%" PRIu64 ", v=%" PRIu64
", and seq=%" PRIu64 "\n", ", and seq=%" PRIu64 "\n",
aScrollTargets.mHorizontal, aScrollTargets.mVertical, aScrollTargets.mHorizontal, aScrollTargets.mVertical,

View File

@ -668,12 +668,12 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
nsTArray<IntRect>& mSourceRegions; nsTArray<IntRect>& mSourceRegions;
nsTArray<RefPtr<SourceSurface>>& mInputImages; nsTArray<RefPtr<SourceSurface>>& mInputImages;
already_AddRefed<FilterNode> match( already_AddRefed<FilterNode> operator()(
const EmptyAttributes& aEmptyAttributes) { const EmptyAttributes& aEmptyAttributes) {
return nullptr; return nullptr;
} }
already_AddRefed<FilterNode> match(const BlendAttributes& aBlend) { already_AddRefed<FilterNode> operator()(const BlendAttributes& aBlend) {
uint32_t mode = aBlend.mBlendMode; uint32_t mode = aBlend.mBlendMode;
RefPtr<FilterNode> filter; RefPtr<FilterNode> filter;
if (mode == SVG_FEBLEND_MODE_UNKNOWN) { if (mode == SVG_FEBLEND_MODE_UNKNOWN) {
@ -718,7 +718,7 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return filter.forget(); return filter.forget();
} }
already_AddRefed<FilterNode> match( already_AddRefed<FilterNode> operator()(
const ColorMatrixAttributes& aMatrixAttributes) { const ColorMatrixAttributes& aMatrixAttributes) {
float colorMatrix[20]; float colorMatrix[20];
if (!ComputeColorMatrix(aMatrixAttributes, colorMatrix)) { if (!ComputeColorMatrix(aMatrixAttributes, colorMatrix)) {
@ -744,7 +744,7 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return filter.forget(); return filter.forget();
} }
already_AddRefed<FilterNode> match( already_AddRefed<FilterNode> operator()(
const MorphologyAttributes& aMorphology) { const MorphologyAttributes& aMorphology) {
Size radii = aMorphology.mRadii; Size radii = aMorphology.mRadii;
int32_t rx = radii.width; int32_t rx = radii.width;
@ -775,7 +775,7 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return filter.forget(); return filter.forget();
} }
already_AddRefed<FilterNode> match(const FloodAttributes& aFlood) { already_AddRefed<FilterNode> operator()(const FloodAttributes& aFlood) {
Color color = aFlood.mColor; Color color = aFlood.mColor;
RefPtr<FilterNode> filter = mDT->CreateFilter(FilterType::FLOOD); RefPtr<FilterNode> filter = mDT->CreateFilter(FilterType::FLOOD);
if (!filter) { if (!filter) {
@ -785,7 +785,7 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return filter.forget(); return filter.forget();
} }
already_AddRefed<FilterNode> match(const TileAttributes& aTile) { already_AddRefed<FilterNode> operator()(const TileAttributes& aTile) {
RefPtr<FilterNode> filter = mDT->CreateFilter(FilterType::TILE); RefPtr<FilterNode> filter = mDT->CreateFilter(FilterType::TILE);
if (!filter) { if (!filter) {
return nullptr; return nullptr;
@ -795,7 +795,7 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return filter.forget(); return filter.forget();
} }
already_AddRefed<FilterNode> match( already_AddRefed<FilterNode> operator()(
const ComponentTransferAttributes& aComponentTransfer) { const ComponentTransferAttributes& aComponentTransfer) {
RefPtr<FilterNode> filters[4]; // one for each FILTER_*_TRANSFER type RefPtr<FilterNode> filters[4]; // one for each FILTER_*_TRANSFER type
bool useRgb = aComponentTransfer.mTypes[kChannelG] == bool useRgb = aComponentTransfer.mTypes[kChannelG] ==
@ -822,7 +822,7 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return lastFilter.forget(); return lastFilter.forget();
} }
already_AddRefed<FilterNode> match(const OpacityAttributes& aOpacity) { already_AddRefed<FilterNode> operator()(const OpacityAttributes& aOpacity) {
RefPtr<FilterNode> filter = mDT->CreateFilter(FilterType::OPACITY); RefPtr<FilterNode> filter = mDT->CreateFilter(FilterType::OPACITY);
if (!filter) { if (!filter) {
return nullptr; return nullptr;
@ -832,7 +832,7 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return filter.forget(); return filter.forget();
} }
already_AddRefed<FilterNode> match( already_AddRefed<FilterNode> operator()(
const ConvolveMatrixAttributes& aConvolveMatrix) { const ConvolveMatrixAttributes& aConvolveMatrix) {
RefPtr<FilterNode> filter = RefPtr<FilterNode> filter =
mDT->CreateFilter(FilterType::CONVOLVE_MATRIX); mDT->CreateFilter(FilterType::CONVOLVE_MATRIX);
@ -866,11 +866,11 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return filter.forget(); return filter.forget();
} }
already_AddRefed<FilterNode> match(const OffsetAttributes& aOffset) { already_AddRefed<FilterNode> operator()(const OffsetAttributes& aOffset) {
return FilterWrappers::Offset(mDT, mSources[0], aOffset.mValue); return FilterWrappers::Offset(mDT, mSources[0], aOffset.mValue);
} }
already_AddRefed<FilterNode> match( already_AddRefed<FilterNode> operator()(
const DisplacementMapAttributes& aDisplacementMap) { const DisplacementMapAttributes& aDisplacementMap) {
RefPtr<FilterNode> filter = RefPtr<FilterNode> filter =
mDT->CreateFilter(FilterType::DISPLACEMENT_MAP); mDT->CreateFilter(FilterType::DISPLACEMENT_MAP);
@ -894,7 +894,7 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return filter.forget(); return filter.forget();
} }
already_AddRefed<FilterNode> match( already_AddRefed<FilterNode> operator()(
const TurbulenceAttributes& aTurbulence) { const TurbulenceAttributes& aTurbulence) {
RefPtr<FilterNode> filter = mDT->CreateFilter(FilterType::TURBULENCE); RefPtr<FilterNode> filter = mDT->CreateFilter(FilterType::TURBULENCE);
if (!filter) { if (!filter) {
@ -918,7 +918,8 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return FilterWrappers::Offset(mDT, filter, aTurbulence.mOffset); return FilterWrappers::Offset(mDT, filter, aTurbulence.mOffset);
} }
already_AddRefed<FilterNode> match(const CompositeAttributes& aComposite) { already_AddRefed<FilterNode> operator()(
const CompositeAttributes& aComposite) {
RefPtr<FilterNode> filter; RefPtr<FilterNode> filter;
uint32_t op = aComposite.mOperator; uint32_t op = aComposite.mOperator;
if (op == SVG_FECOMPOSITE_OPERATOR_ARITHMETIC) { if (op == SVG_FECOMPOSITE_OPERATOR_ARITHMETIC) {
@ -955,7 +956,7 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return filter.forget(); return filter.forget();
} }
already_AddRefed<FilterNode> match(const MergeAttributes& aMerge) { already_AddRefed<FilterNode> operator()(const MergeAttributes& aMerge) {
if (mSources.Length() == 0) { if (mSources.Length() == 0) {
return nullptr; return nullptr;
} }
@ -975,13 +976,13 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return filter.forget(); return filter.forget();
} }
already_AddRefed<FilterNode> match( already_AddRefed<FilterNode> operator()(
const GaussianBlurAttributes& aGaussianBlur) { const GaussianBlurAttributes& aGaussianBlur) {
return FilterWrappers::GaussianBlur(mDT, mSources[0], return FilterWrappers::GaussianBlur(mDT, mSources[0],
aGaussianBlur.mStdDeviation); aGaussianBlur.mStdDeviation);
} }
already_AddRefed<FilterNode> match( already_AddRefed<FilterNode> operator()(
const DropShadowAttributes& aDropShadow) { const DropShadowAttributes& aDropShadow) {
RefPtr<FilterNode> alpha = FilterWrappers::ToAlpha(mDT, mSources[0]); RefPtr<FilterNode> alpha = FilterWrappers::ToAlpha(mDT, mSources[0]);
RefPtr<FilterNode> blur = RefPtr<FilterNode> blur =
@ -1020,13 +1021,13 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return filter.forget(); return filter.forget();
} }
already_AddRefed<FilterNode> match( already_AddRefed<FilterNode> operator()(
const SpecularLightingAttributes& aLighting) { const SpecularLightingAttributes& aLighting) {
return match( return operator()(
*(static_cast<const DiffuseLightingAttributes*>(&aLighting))); *(static_cast<const DiffuseLightingAttributes*>(&aLighting)));
} }
already_AddRefed<FilterNode> match( already_AddRefed<FilterNode> operator()(
const DiffuseLightingAttributes& aLighting) { const DiffuseLightingAttributes& aLighting) {
bool isSpecular = bool isSpecular =
mDescription.Attributes().is<SpecularLightingAttributes>(); mDescription.Attributes().is<SpecularLightingAttributes>();
@ -1117,7 +1118,7 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return filter.forget(); return filter.forget();
} }
already_AddRefed<FilterNode> match(const ImageAttributes& aImage) { already_AddRefed<FilterNode> operator()(const ImageAttributes& aImage) {
const Matrix& TM = aImage.mTransform; const Matrix& TM = aImage.mTransform;
if (!TM.Determinant()) { if (!TM.Determinant()) {
return nullptr; return nullptr;
@ -1137,7 +1138,7 @@ static already_AddRefed<FilterNode> FilterNodeFromPrimitiveDescription(
return transform.forget(); return transform.forget();
} }
already_AddRefed<FilterNode> match(const ToAlphaAttributes& aToAlpha) { already_AddRefed<FilterNode> operator()(const ToAlphaAttributes& aToAlpha) {
return FilterWrappers::ToAlpha(mDT, mSources[0]); return FilterWrappers::ToAlpha(mDT, mSources[0]);
} }
}; };
@ -1367,19 +1368,19 @@ static nsIntRegion ResultChangeRegionForPrimitive(
const FilterPrimitiveDescription& mDescription; const FilterPrimitiveDescription& mDescription;
const nsTArray<nsIntRegion>& mInputChangeRegions; const nsTArray<nsIntRegion>& mInputChangeRegions;
nsIntRegion match(const EmptyAttributes& aEmptyAttributes) { nsIntRegion operator()(const EmptyAttributes& aEmptyAttributes) {
return nsIntRegion(); return nsIntRegion();
} }
nsIntRegion match(const BlendAttributes& aBlend) { nsIntRegion operator()(const BlendAttributes& aBlend) {
return UnionOfRegions(mInputChangeRegions); return UnionOfRegions(mInputChangeRegions);
} }
nsIntRegion match(const ColorMatrixAttributes& aColorMatrix) { nsIntRegion operator()(const ColorMatrixAttributes& aColorMatrix) {
return mInputChangeRegions[0]; return mInputChangeRegions[0];
} }
nsIntRegion match(const MorphologyAttributes& aMorphology) { nsIntRegion operator()(const MorphologyAttributes& aMorphology) {
Size radii = aMorphology.mRadii; Size radii = aMorphology.mRadii;
int32_t rx = clamped(int32_t(ceil(radii.width)), 0, kMorphologyMaxRadius); int32_t rx = clamped(int32_t(ceil(radii.width)), 0, kMorphologyMaxRadius);
int32_t ry = int32_t ry =
@ -1387,21 +1388,24 @@ static nsIntRegion ResultChangeRegionForPrimitive(
return mInputChangeRegions[0].Inflated(nsIntMargin(ry, rx, ry, rx)); return mInputChangeRegions[0].Inflated(nsIntMargin(ry, rx, ry, rx));
} }
nsIntRegion match(const FloodAttributes& aFlood) { return nsIntRegion(); } nsIntRegion operator()(const FloodAttributes& aFlood) {
return nsIntRegion();
}
nsIntRegion match(const TileAttributes& aTile) { nsIntRegion operator()(const TileAttributes& aTile) {
return mDescription.PrimitiveSubregion(); return mDescription.PrimitiveSubregion();
} }
nsIntRegion match(const ComponentTransferAttributes& aComponentTransfer) { nsIntRegion operator()(
const ComponentTransferAttributes& aComponentTransfer) {
return mInputChangeRegions[0]; return mInputChangeRegions[0];
} }
nsIntRegion match(const OpacityAttributes& aOpacity) { nsIntRegion operator()(const OpacityAttributes& aOpacity) {
return UnionOfRegions(mInputChangeRegions); return UnionOfRegions(mInputChangeRegions);
} }
nsIntRegion match(const ConvolveMatrixAttributes& aConvolveMatrix) { nsIntRegion operator()(const ConvolveMatrixAttributes& aConvolveMatrix) {
if (aConvolveMatrix.mEdgeMode != EDGE_MODE_NONE) { if (aConvolveMatrix.mEdgeMode != EDGE_MODE_NONE) {
return mDescription.PrimitiveSubregion(); return mDescription.PrimitiveSubregion();
} }
@ -1416,37 +1420,37 @@ static nsIntRegion ResultChangeRegionForPrimitive(
return mInputChangeRegions[0].Inflated(m); return mInputChangeRegions[0].Inflated(m);
} }
nsIntRegion match(const OffsetAttributes& aOffset) { nsIntRegion operator()(const OffsetAttributes& aOffset) {
IntPoint offset = aOffset.mValue; IntPoint offset = aOffset.mValue;
return mInputChangeRegions[0].MovedBy(offset.x, offset.y); return mInputChangeRegions[0].MovedBy(offset.x, offset.y);
} }
nsIntRegion match(const DisplacementMapAttributes& aDisplacementMap) { nsIntRegion operator()(const DisplacementMapAttributes& aDisplacementMap) {
int32_t scale = ceil(std::abs(aDisplacementMap.mScale)); int32_t scale = ceil(std::abs(aDisplacementMap.mScale));
return mInputChangeRegions[0].Inflated( return mInputChangeRegions[0].Inflated(
nsIntMargin(scale, scale, scale, scale)); nsIntMargin(scale, scale, scale, scale));
} }
nsIntRegion match(const TurbulenceAttributes& aTurbulence) { nsIntRegion operator()(const TurbulenceAttributes& aTurbulence) {
return nsIntRegion(); return nsIntRegion();
} }
nsIntRegion match(const CompositeAttributes& aComposite) { nsIntRegion operator()(const CompositeAttributes& aComposite) {
return UnionOfRegions(mInputChangeRegions); return UnionOfRegions(mInputChangeRegions);
} }
nsIntRegion match(const MergeAttributes& aMerge) { nsIntRegion operator()(const MergeAttributes& aMerge) {
return UnionOfRegions(mInputChangeRegions); return UnionOfRegions(mInputChangeRegions);
} }
nsIntRegion match(const GaussianBlurAttributes& aGaussianBlur) { nsIntRegion operator()(const GaussianBlurAttributes& aGaussianBlur) {
const Size& stdDeviation = aGaussianBlur.mStdDeviation; const Size& stdDeviation = aGaussianBlur.mStdDeviation;
int32_t dx = InflateSizeForBlurStdDev(stdDeviation.width); int32_t dx = InflateSizeForBlurStdDev(stdDeviation.width);
int32_t dy = InflateSizeForBlurStdDev(stdDeviation.height); int32_t dy = InflateSizeForBlurStdDev(stdDeviation.height);
return mInputChangeRegions[0].Inflated(nsIntMargin(dy, dx, dy, dx)); return mInputChangeRegions[0].Inflated(nsIntMargin(dy, dx, dy, dx));
} }
nsIntRegion match(const DropShadowAttributes& aDropShadow) { nsIntRegion operator()(const DropShadowAttributes& aDropShadow) {
IntPoint offset = aDropShadow.mOffset; IntPoint offset = aDropShadow.mOffset;
nsIntRegion offsetRegion = nsIntRegion offsetRegion =
mInputChangeRegions[0].MovedBy(offset.x, offset.y); mInputChangeRegions[0].MovedBy(offset.x, offset.y);
@ -1459,21 +1463,23 @@ static nsIntRegion ResultChangeRegionForPrimitive(
return blurRegion; return blurRegion;
} }
nsIntRegion match(const SpecularLightingAttributes& aLighting) { nsIntRegion operator()(const SpecularLightingAttributes& aLighting) {
return match( return operator()(
*(static_cast<const DiffuseLightingAttributes*>(&aLighting))); *(static_cast<const DiffuseLightingAttributes*>(&aLighting)));
} }
nsIntRegion match(const DiffuseLightingAttributes& aLighting) { nsIntRegion operator()(const DiffuseLightingAttributes& aLighting) {
Size kernelUnitLength = aLighting.mKernelUnitLength; Size kernelUnitLength = aLighting.mKernelUnitLength;
int32_t dx = ceil(kernelUnitLength.width); int32_t dx = ceil(kernelUnitLength.width);
int32_t dy = ceil(kernelUnitLength.height); int32_t dy = ceil(kernelUnitLength.height);
return mInputChangeRegions[0].Inflated(nsIntMargin(dy, dx, dy, dx)); return mInputChangeRegions[0].Inflated(nsIntMargin(dy, dx, dy, dx));
} }
nsIntRegion match(const ImageAttributes& aImage) { return nsIntRegion(); } nsIntRegion operator()(const ImageAttributes& aImage) {
return nsIntRegion();
}
nsIntRegion match(const ToAlphaAttributes& aToAlpha) { nsIntRegion operator()(const ToAlphaAttributes& aToAlpha) {
return mInputChangeRegions[0]; return mInputChangeRegions[0];
} }
}; };
@ -1560,15 +1566,15 @@ nsIntRegion FilterSupport::PostFilterExtentsForPrimitive(
const FilterPrimitiveDescription& mDescription; const FilterPrimitiveDescription& mDescription;
const nsTArray<nsIntRegion>& mInputExtents; const nsTArray<nsIntRegion>& mInputExtents;
nsIntRegion match(const EmptyAttributes& aEmptyAttributes) { nsIntRegion operator()(const EmptyAttributes& aEmptyAttributes) {
return IntRect(); return IntRect();
} }
nsIntRegion match(const BlendAttributes& aBlend) { nsIntRegion operator()(const BlendAttributes& aBlend) {
return ResultChangeRegionForPrimitive(mDescription, mInputExtents); return ResultChangeRegionForPrimitive(mDescription, mInputExtents);
} }
nsIntRegion match(const ColorMatrixAttributes& aColorMatrix) { nsIntRegion operator()(const ColorMatrixAttributes& aColorMatrix) {
if (aColorMatrix.mType == (uint32_t)SVG_FECOLORMATRIX_TYPE_MATRIX) { if (aColorMatrix.mType == (uint32_t)SVG_FECOLORMATRIX_TYPE_MATRIX) {
const nsTArray<float>& values = aColorMatrix.mValues; const nsTArray<float>& values = aColorMatrix.mValues;
if (values.Length() == 20 && values[19] > 0.0f) { if (values.Length() == 20 && values[19] > 0.0f) {
@ -1578,7 +1584,7 @@ nsIntRegion FilterSupport::PostFilterExtentsForPrimitive(
return mInputExtents[0]; return mInputExtents[0];
} }
nsIntRegion match(const MorphologyAttributes& aMorphology) { nsIntRegion operator()(const MorphologyAttributes& aMorphology) {
uint32_t op = aMorphology.mOperator; uint32_t op = aMorphology.mOperator;
if (op == SVG_OPERATOR_ERODE) { if (op == SVG_OPERATOR_ERODE) {
return mInputExtents[0]; return mInputExtents[0];
@ -1590,18 +1596,19 @@ nsIntRegion FilterSupport::PostFilterExtentsForPrimitive(
return mInputExtents[0].Inflated(nsIntMargin(ry, rx, ry, rx)); return mInputExtents[0].Inflated(nsIntMargin(ry, rx, ry, rx));
} }
nsIntRegion match(const FloodAttributes& aFlood) { nsIntRegion operator()(const FloodAttributes& aFlood) {
if (aFlood.mColor.a == 0.0f) { if (aFlood.mColor.a == 0.0f) {
return IntRect(); return IntRect();
} }
return mDescription.PrimitiveSubregion(); return mDescription.PrimitiveSubregion();
} }
nsIntRegion match(const TileAttributes& aTile) { nsIntRegion operator()(const TileAttributes& aTile) {
return ResultChangeRegionForPrimitive(mDescription, mInputExtents); return ResultChangeRegionForPrimitive(mDescription, mInputExtents);
} }
nsIntRegion match(const ComponentTransferAttributes& aComponentTransfer) { nsIntRegion operator()(
const ComponentTransferAttributes& aComponentTransfer) {
if (ResultOfZeroUnderTransferFunction(aComponentTransfer, kChannelA) > if (ResultOfZeroUnderTransferFunction(aComponentTransfer, kChannelA) >
0.0f) { 0.0f) {
return mDescription.PrimitiveSubregion(); return mDescription.PrimitiveSubregion();
@ -1609,27 +1616,27 @@ nsIntRegion FilterSupport::PostFilterExtentsForPrimitive(
return mInputExtents[0]; return mInputExtents[0];
} }
nsIntRegion match(const OpacityAttributes& aOpacity) { nsIntRegion operator()(const OpacityAttributes& aOpacity) {
return ResultChangeRegionForPrimitive(mDescription, mInputExtents); return ResultChangeRegionForPrimitive(mDescription, mInputExtents);
} }
nsIntRegion match(const ConvolveMatrixAttributes& aConvolveMatrix) { nsIntRegion operator()(const ConvolveMatrixAttributes& aConvolveMatrix) {
return ResultChangeRegionForPrimitive(mDescription, mInputExtents); return ResultChangeRegionForPrimitive(mDescription, mInputExtents);
} }
nsIntRegion match(const OffsetAttributes& aOffset) { nsIntRegion operator()(const OffsetAttributes& aOffset) {
return ResultChangeRegionForPrimitive(mDescription, mInputExtents); return ResultChangeRegionForPrimitive(mDescription, mInputExtents);
} }
nsIntRegion match(const DisplacementMapAttributes& aDisplacementMap) { nsIntRegion operator()(const DisplacementMapAttributes& aDisplacementMap) {
return ResultChangeRegionForPrimitive(mDescription, mInputExtents); return ResultChangeRegionForPrimitive(mDescription, mInputExtents);
} }
nsIntRegion match(const TurbulenceAttributes& aTurbulence) { nsIntRegion operator()(const TurbulenceAttributes& aTurbulence) {
return mDescription.PrimitiveSubregion(); return mDescription.PrimitiveSubregion();
} }
nsIntRegion match(const CompositeAttributes& aComposite) { nsIntRegion operator()(const CompositeAttributes& aComposite) {
uint32_t op = aComposite.mOperator; uint32_t op = aComposite.mOperator;
if (op == SVG_FECOMPOSITE_OPERATOR_ARITHMETIC) { if (op == SVG_FECOMPOSITE_OPERATOR_ARITHMETIC) {
// The arithmetic composite primitive can draw outside the bounding // The arithmetic composite primitive can draw outside the bounding
@ -1660,31 +1667,32 @@ nsIntRegion FilterSupport::PostFilterExtentsForPrimitive(
return ResultChangeRegionForPrimitive(mDescription, mInputExtents); return ResultChangeRegionForPrimitive(mDescription, mInputExtents);
} }
nsIntRegion match(const MergeAttributes& aMerge) { nsIntRegion operator()(const MergeAttributes& aMerge) {
return ResultChangeRegionForPrimitive(mDescription, mInputExtents); return ResultChangeRegionForPrimitive(mDescription, mInputExtents);
} }
nsIntRegion match(const GaussianBlurAttributes& aGaussianBlur) { nsIntRegion operator()(const GaussianBlurAttributes& aGaussianBlur) {
return ResultChangeRegionForPrimitive(mDescription, mInputExtents); return ResultChangeRegionForPrimitive(mDescription, mInputExtents);
} }
nsIntRegion match(const DropShadowAttributes& aDropShadow) { nsIntRegion operator()(const DropShadowAttributes& aDropShadow) {
return ResultChangeRegionForPrimitive(mDescription, mInputExtents); return ResultChangeRegionForPrimitive(mDescription, mInputExtents);
} }
nsIntRegion match(const DiffuseLightingAttributes& aDiffuseLighting) { nsIntRegion operator()(const DiffuseLightingAttributes& aDiffuseLighting) {
return mDescription.PrimitiveSubregion(); return mDescription.PrimitiveSubregion();
} }
nsIntRegion match(const SpecularLightingAttributes& aSpecularLighting) { nsIntRegion operator()(
const SpecularLightingAttributes& aSpecularLighting) {
return mDescription.PrimitiveSubregion(); return mDescription.PrimitiveSubregion();
} }
nsIntRegion match(const ImageAttributes& aImage) { nsIntRegion operator()(const ImageAttributes& aImage) {
return mDescription.PrimitiveSubregion(); return mDescription.PrimitiveSubregion();
} }
nsIntRegion match(const ToAlphaAttributes& aToAlpha) { nsIntRegion operator()(const ToAlphaAttributes& aToAlpha) {
return ResultChangeRegionForPrimitive(mDescription, mInputExtents); return ResultChangeRegionForPrimitive(mDescription, mInputExtents);
} }
}; };
@ -1738,19 +1746,19 @@ static nsIntRegion SourceNeededRegionForPrimitive(
const nsIntRegion& mResultNeededRegion; const nsIntRegion& mResultNeededRegion;
const int32_t mInputIndex; const int32_t mInputIndex;
nsIntRegion match(const EmptyAttributes& aEmptyAttributes) { nsIntRegion operator()(const EmptyAttributes& aEmptyAttributes) {
return nsIntRegion(); return nsIntRegion();
} }
nsIntRegion match(const BlendAttributes& aBlend) { nsIntRegion operator()(const BlendAttributes& aBlend) {
return mResultNeededRegion; return mResultNeededRegion;
} }
nsIntRegion match(const ColorMatrixAttributes& aColorMatrix) { nsIntRegion operator()(const ColorMatrixAttributes& aColorMatrix) {
return mResultNeededRegion; return mResultNeededRegion;
} }
nsIntRegion match(const MorphologyAttributes& aMorphology) { nsIntRegion operator()(const MorphologyAttributes& aMorphology) {
Size radii = aMorphology.mRadii; Size radii = aMorphology.mRadii;
int32_t rx = clamped(int32_t(ceil(radii.width)), 0, kMorphologyMaxRadius); int32_t rx = clamped(int32_t(ceil(radii.width)), 0, kMorphologyMaxRadius);
int32_t ry = int32_t ry =
@ -1758,24 +1766,25 @@ static nsIntRegion SourceNeededRegionForPrimitive(
return mResultNeededRegion.Inflated(nsIntMargin(ry, rx, ry, rx)); return mResultNeededRegion.Inflated(nsIntMargin(ry, rx, ry, rx));
} }
nsIntRegion match(const FloodAttributes& aFlood) { nsIntRegion operator()(const FloodAttributes& aFlood) {
MOZ_CRASH("GFX: this shouldn't be called for filters without inputs"); MOZ_CRASH("GFX: this shouldn't be called for filters without inputs");
return nsIntRegion(); return nsIntRegion();
} }
nsIntRegion match(const TileAttributes& aTile) { nsIntRegion operator()(const TileAttributes& aTile) {
return IntRect(INT32_MIN / 2, INT32_MIN / 2, INT32_MAX, INT32_MAX); return IntRect(INT32_MIN / 2, INT32_MIN / 2, INT32_MAX, INT32_MAX);
} }
nsIntRegion match(const ComponentTransferAttributes& aComponentTransfer) { nsIntRegion operator()(
const ComponentTransferAttributes& aComponentTransfer) {
return mResultNeededRegion; return mResultNeededRegion;
} }
nsIntRegion match(const OpacityAttributes& aOpacity) { nsIntRegion operator()(const OpacityAttributes& aOpacity) {
return mResultNeededRegion; return mResultNeededRegion;
} }
nsIntRegion match(const ConvolveMatrixAttributes& aConvolveMatrix) { nsIntRegion operator()(const ConvolveMatrixAttributes& aConvolveMatrix) {
Size kernelUnitLength = aConvolveMatrix.mKernelUnitLength; Size kernelUnitLength = aConvolveMatrix.mKernelUnitLength;
IntSize kernelSize = aConvolveMatrix.mKernelSize; IntSize kernelSize = aConvolveMatrix.mKernelSize;
IntPoint target = aConvolveMatrix.mTarget; IntPoint target = aConvolveMatrix.mTarget;
@ -1787,12 +1796,12 @@ static nsIntRegion SourceNeededRegionForPrimitive(
return mResultNeededRegion.Inflated(m); return mResultNeededRegion.Inflated(m);
} }
nsIntRegion match(const OffsetAttributes& aOffset) { nsIntRegion operator()(const OffsetAttributes& aOffset) {
IntPoint offset = aOffset.mValue; IntPoint offset = aOffset.mValue;
return mResultNeededRegion.MovedBy(-nsIntPoint(offset.x, offset.y)); return mResultNeededRegion.MovedBy(-nsIntPoint(offset.x, offset.y));
} }
nsIntRegion match(const DisplacementMapAttributes& aDisplacementMap) { nsIntRegion operator()(const DisplacementMapAttributes& aDisplacementMap) {
if (mInputIndex == 1) { if (mInputIndex == 1) {
return mResultNeededRegion; return mResultNeededRegion;
} }
@ -1801,27 +1810,27 @@ static nsIntRegion SourceNeededRegionForPrimitive(
nsIntMargin(scale, scale, scale, scale)); nsIntMargin(scale, scale, scale, scale));
} }
nsIntRegion match(const TurbulenceAttributes& aTurbulence) { nsIntRegion operator()(const TurbulenceAttributes& aTurbulence) {
MOZ_CRASH("GFX: this shouldn't be called for filters without inputs"); MOZ_CRASH("GFX: this shouldn't be called for filters without inputs");
return nsIntRegion(); return nsIntRegion();
} }
nsIntRegion match(const CompositeAttributes& aComposite) { nsIntRegion operator()(const CompositeAttributes& aComposite) {
return mResultNeededRegion; return mResultNeededRegion;
} }
nsIntRegion match(const MergeAttributes& aMerge) { nsIntRegion operator()(const MergeAttributes& aMerge) {
return mResultNeededRegion; return mResultNeededRegion;
} }
nsIntRegion match(const GaussianBlurAttributes& aGaussianBlur) { nsIntRegion operator()(const GaussianBlurAttributes& aGaussianBlur) {
const Size& stdDeviation = aGaussianBlur.mStdDeviation; const Size& stdDeviation = aGaussianBlur.mStdDeviation;
int32_t dx = InflateSizeForBlurStdDev(stdDeviation.width); int32_t dx = InflateSizeForBlurStdDev(stdDeviation.width);
int32_t dy = InflateSizeForBlurStdDev(stdDeviation.height); int32_t dy = InflateSizeForBlurStdDev(stdDeviation.height);
return mResultNeededRegion.Inflated(nsIntMargin(dy, dx, dy, dx)); return mResultNeededRegion.Inflated(nsIntMargin(dy, dx, dy, dx));
} }
nsIntRegion match(const DropShadowAttributes& aDropShadow) { nsIntRegion operator()(const DropShadowAttributes& aDropShadow) {
IntPoint offset = aDropShadow.mOffset; IntPoint offset = aDropShadow.mOffset;
nsIntRegion offsetRegion = nsIntRegion offsetRegion =
mResultNeededRegion.MovedBy(-nsIntPoint(offset.x, offset.y)); mResultNeededRegion.MovedBy(-nsIntPoint(offset.x, offset.y));
@ -1834,24 +1843,24 @@ static nsIntRegion SourceNeededRegionForPrimitive(
return blurRegion; return blurRegion;
} }
nsIntRegion match(const SpecularLightingAttributes& aLighting) { nsIntRegion operator()(const SpecularLightingAttributes& aLighting) {
return match( return operator()(
*(static_cast<const DiffuseLightingAttributes*>(&aLighting))); *(static_cast<const DiffuseLightingAttributes*>(&aLighting)));
} }
nsIntRegion match(const DiffuseLightingAttributes& aLighting) { nsIntRegion operator()(const DiffuseLightingAttributes& aLighting) {
Size kernelUnitLength = aLighting.mKernelUnitLength; Size kernelUnitLength = aLighting.mKernelUnitLength;
int32_t dx = ceil(kernelUnitLength.width); int32_t dx = ceil(kernelUnitLength.width);
int32_t dy = ceil(kernelUnitLength.height); int32_t dy = ceil(kernelUnitLength.height);
return mResultNeededRegion.Inflated(nsIntMargin(dy, dx, dy, dx)); return mResultNeededRegion.Inflated(nsIntMargin(dy, dx, dy, dx));
} }
nsIntRegion match(const ImageAttributes& aImage) { nsIntRegion operator()(const ImageAttributes& aImage) {
MOZ_CRASH("GFX: this shouldn't be called for filters without inputs"); MOZ_CRASH("GFX: this shouldn't be called for filters without inputs");
return nsIntRegion(); return nsIntRegion();
} }
nsIntRegion match(const ToAlphaAttributes& aToAlpha) { nsIntRegion operator()(const ToAlphaAttributes& aToAlpha) {
return mResultNeededRegion; return mResultNeededRegion;
} }
}; };

View File

@ -980,7 +980,7 @@ struct ParamTraits<mozilla::Variant<Ts...>> {
Message* msg; Message* msg;
template <class T> template <class T>
void match(const T& t) { void operator()(const T& t) {
WriteParam(msg, t); WriteParam(msg, t);
} }
}; };

View File

@ -119,7 +119,7 @@ struct GCPolicy<mozilla::Variant<Ts...>> {
private: private:
struct IsValidMatcher { struct IsValidMatcher {
template <typename T> template <typename T>
bool match(T& v) { bool operator()(T& v) {
return GCPolicy<T>::isValid(v); return GCPolicy<T>::isValid(v);
}; };
}; };

View File

@ -47,7 +47,7 @@ struct InvokeMemberFunction {
: args{std::forward<ActualArgs>(actualArgs)...} {} : args{std::forward<ActualArgs>(actualArgs)...} {}
template <class Parser> template <class Parser>
auto match(Parser* parser) auto operator()(Parser* parser)
-> decltype(this->matchInternal(GetThis<Parser>::get(parser), -> decltype(this->matchInternal(GetThis<Parser>::get(parser),
std::index_sequence_for<Args...>{})) { std::index_sequence_for<Args...>{})) {
return this->matchInternal(GetThis<Parser>::get(parser), return this->matchInternal(GetThis<Parser>::get(parser),
@ -88,21 +88,21 @@ struct TokenStreamComputeLineAndColumn {
struct ParseHandlerMatcher { struct ParseHandlerMatcher {
template <class Parser> template <class Parser>
frontend::FullParseHandler& match(Parser* parser) { frontend::FullParseHandler& operator()(Parser* parser) {
return parser->handler_; return parser->handler_;
} }
}; };
struct ParserSharedBaseMatcher { struct ParserSharedBaseMatcher {
template <class Parser> template <class Parser>
frontend::ParserSharedBase& match(Parser* parser) { frontend::ParserSharedBase& operator()(Parser* parser) {
return *static_cast<frontend::ParserSharedBase*>(parser); return *static_cast<frontend::ParserSharedBase*>(parser);
} }
}; };
struct ErrorReporterMatcher { struct ErrorReporterMatcher {
template <class Parser> template <class Parser>
frontend::ErrorReporter& match(Parser* parser) { frontend::ErrorReporter& operator()(Parser* parser) {
return parser->tokenStream; return parser->tokenStream;
} }
}; };

View File

@ -87,13 +87,17 @@ class CrossCompartmentKey {
struct WrappedMatcher { struct WrappedMatcher {
F f_; F f_;
explicit WrappedMatcher(F f) : f_(f) {} explicit WrappedMatcher(F f) : f_(f) {}
auto match(JSObject*& obj) { return f_(&obj); } auto operator()(JSObject*& obj) { return f_(&obj); }
auto match(JSString*& str) { return f_(&str); } auto operator()(JSString*& str) { return f_(&str); }
auto match(DebuggerAndScript& tpl) { return f_(&mozilla::Get<1>(tpl)); } auto operator()(DebuggerAndScript& tpl) {
auto match(DebuggerAndLazyScript& tpl) { return f_(&mozilla::Get<1>(tpl));
}
auto operator()(DebuggerAndLazyScript& tpl) {
return f_(&mozilla::Get<1>(tpl));
}
auto operator()(DebuggerAndObject& tpl) {
return f_(&mozilla::Get<1>(tpl)); return f_(&mozilla::Get<1>(tpl));
} }
auto match(DebuggerAndObject& tpl) { return f_(&mozilla::Get<1>(tpl)); }
} matcher(f); } matcher(f);
return wrapped.match(matcher); return wrapped.match(matcher);
} }
@ -104,15 +108,15 @@ class CrossCompartmentKey {
struct DebuggerMatcher { struct DebuggerMatcher {
F f_; F f_;
explicit DebuggerMatcher(F f) : f_(f) {} explicit DebuggerMatcher(F f) : f_(f) {}
ReturnType match(JSObject*& obj) { return ReturnType(); } ReturnType operator()(JSObject*& obj) { return ReturnType(); }
ReturnType match(JSString*& str) { return ReturnType(); } ReturnType operator()(JSString*& str) { return ReturnType(); }
ReturnType match(DebuggerAndScript& tpl) { ReturnType operator()(DebuggerAndScript& tpl) {
return f_(&mozilla::Get<0>(tpl)); return f_(&mozilla::Get<0>(tpl));
} }
ReturnType match(DebuggerAndLazyScript& tpl) { ReturnType operator()(DebuggerAndLazyScript& tpl) {
return f_(&mozilla::Get<0>(tpl)); return f_(&mozilla::Get<0>(tpl));
} }
ReturnType match(DebuggerAndObject& tpl) { ReturnType operator()(DebuggerAndObject& tpl) {
return f_(&mozilla::Get<0>(tpl)); return f_(&mozilla::Get<0>(tpl));
} }
} matcher(f); } matcher(f);
@ -125,21 +129,21 @@ class CrossCompartmentKey {
struct Hasher : public DefaultHasher<CrossCompartmentKey> { struct Hasher : public DefaultHasher<CrossCompartmentKey> {
struct HashFunctor { struct HashFunctor {
HashNumber match(JSObject* obj) { HashNumber operator()(JSObject* obj) {
return DefaultHasher<JSObject*>::hash(obj); return DefaultHasher<JSObject*>::hash(obj);
} }
HashNumber match(JSString* str) { HashNumber operator()(JSString* str) {
return DefaultHasher<JSString*>::hash(str); return DefaultHasher<JSString*>::hash(str);
} }
HashNumber match(const DebuggerAndScript& tpl) { HashNumber operator()(const DebuggerAndScript& tpl) {
return DefaultHasher<NativeObject*>::hash(mozilla::Get<0>(tpl)) ^ return DefaultHasher<NativeObject*>::hash(mozilla::Get<0>(tpl)) ^
DefaultHasher<JSScript*>::hash(mozilla::Get<1>(tpl)); DefaultHasher<JSScript*>::hash(mozilla::Get<1>(tpl));
} }
HashNumber match(const DebuggerAndLazyScript& tpl) { HashNumber operator()(const DebuggerAndLazyScript& tpl) {
return DefaultHasher<NativeObject*>::hash(mozilla::Get<0>(tpl)) ^ return DefaultHasher<NativeObject*>::hash(mozilla::Get<0>(tpl)) ^
DefaultHasher<LazyScript*>::hash(mozilla::Get<1>(tpl)); DefaultHasher<LazyScript*>::hash(mozilla::Get<1>(tpl));
} }
HashNumber match(const DebuggerAndObject& tpl) { HashNumber operator()(const DebuggerAndObject& tpl) {
return DefaultHasher<NativeObject*>::hash(mozilla::Get<0>(tpl)) ^ return DefaultHasher<NativeObject*>::hash(mozilla::Get<0>(tpl)) ^
DefaultHasher<JSObject*>::hash(mozilla::Get<1>(tpl)) ^ DefaultHasher<JSObject*>::hash(mozilla::Get<1>(tpl)) ^
(mozilla::Get<2>(tpl) << 5); (mozilla::Get<2>(tpl) << 5);

View File

@ -234,15 +234,17 @@ static void FinishOffThreadIonCompile(jit::IonBuilder* builder,
static JSRuntime* GetSelectorRuntime(const CompilationSelector& selector) { static JSRuntime* GetSelectorRuntime(const CompilationSelector& selector) {
struct Matcher { struct Matcher {
JSRuntime* match(JSScript* script) { JSRuntime* operator()(JSScript* script) {
return script->runtimeFromMainThread(); return script->runtimeFromMainThread();
} }
JSRuntime* match(Realm* realm) { return realm->runtimeFromMainThread(); } JSRuntime* operator()(Realm* realm) {
JSRuntime* match(Zone* zone) { return zone->runtimeFromMainThread(); } return realm->runtimeFromMainThread();
JSRuntime* match(ZonesInState zbs) { return zbs.runtime; } }
JSRuntime* match(JSRuntime* runtime) { return runtime; } JSRuntime* operator()(Zone* zone) { return zone->runtimeFromMainThread(); }
JSRuntime* match(AllCompilations all) { return nullptr; } JSRuntime* operator()(ZonesInState zbs) { return zbs.runtime; }
JSRuntime* match(CompilationsUsingNursery cun) { return cun.runtime; } JSRuntime* operator()(JSRuntime* runtime) { return runtime; }
JSRuntime* operator()(AllCompilations all) { return nullptr; }
JSRuntime* operator()(CompilationsUsingNursery cun) { return cun.runtime; }
}; };
return selector.match(Matcher()); return selector.match(Matcher());
@ -250,13 +252,13 @@ static JSRuntime* GetSelectorRuntime(const CompilationSelector& selector) {
static bool JitDataStructuresExist(const CompilationSelector& selector) { static bool JitDataStructuresExist(const CompilationSelector& selector) {
struct Matcher { struct Matcher {
bool match(JSScript* script) { return !!script->realm()->jitRealm(); } bool operator()(JSScript* script) { return !!script->realm()->jitRealm(); }
bool match(Realm* realm) { return !!realm->jitRealm(); } bool operator()(Realm* realm) { return !!realm->jitRealm(); }
bool match(Zone* zone) { return !!zone->jitZone(); } bool operator()(Zone* zone) { return !!zone->jitZone(); }
bool match(ZonesInState zbs) { return zbs.runtime->hasJitRuntime(); } bool operator()(ZonesInState zbs) { return zbs.runtime->hasJitRuntime(); }
bool match(JSRuntime* runtime) { return runtime->hasJitRuntime(); } bool operator()(JSRuntime* runtime) { return runtime->hasJitRuntime(); }
bool match(AllCompilations all) { return true; } bool operator()(AllCompilations all) { return true; }
bool match(CompilationsUsingNursery cun) { bool operator()(CompilationsUsingNursery cun) {
return cun.runtime->hasJitRuntime(); return cun.runtime->hasJitRuntime();
} }
}; };
@ -269,20 +271,22 @@ static bool IonBuilderMatches(const CompilationSelector& selector,
struct BuilderMatches { struct BuilderMatches {
jit::IonBuilder* builder_; jit::IonBuilder* builder_;
bool match(JSScript* script) { return script == builder_->script(); } bool operator()(JSScript* script) { return script == builder_->script(); }
bool match(Realm* realm) { return realm == builder_->script()->realm(); } bool operator()(Realm* realm) {
bool match(Zone* zone) { return realm == builder_->script()->realm();
}
bool operator()(Zone* zone) {
return zone == builder_->script()->zoneFromAnyThread(); return zone == builder_->script()->zoneFromAnyThread();
} }
bool match(JSRuntime* runtime) { bool operator()(JSRuntime* runtime) {
return runtime == builder_->script()->runtimeFromAnyThread(); return runtime == builder_->script()->runtimeFromAnyThread();
} }
bool match(AllCompilations all) { return true; } bool operator()(AllCompilations all) { return true; }
bool match(ZonesInState zbs) { bool operator()(ZonesInState zbs) {
return zbs.runtime == builder_->script()->runtimeFromAnyThread() && return zbs.runtime == builder_->script()->runtimeFromAnyThread() &&
zbs.state == builder_->script()->zoneFromAnyThread()->gcState(); zbs.state == builder_->script()->zoneFromAnyThread()->gcState();
} }
bool match(CompilationsUsingNursery cun) { bool operator()(CompilationsUsingNursery cun) {
return cun.runtime == builder_->script()->runtimeFromAnyThread() && return cun.runtime == builder_->script()->runtimeFromAnyThread() &&
!builder_->safeForMinorGC(); !builder_->safeForMinorGC();
} }

View File

@ -2320,12 +2320,12 @@ struct SourceCompressionTask::PerformTaskWork {
explicit PerformTaskWork(SourceCompressionTask* task) : task_(task) {} explicit PerformTaskWork(SourceCompressionTask* task) : task_(task) {}
template <typename Unit> template <typename Unit>
void match(const ScriptSource::Uncompressed<Unit>&) { void operator()(const ScriptSource::Uncompressed<Unit>&) {
task_->workEncodingSpecific<Unit>(); task_->workEncodingSpecific<Unit>();
} }
template <typename T> template <typename T>
void match(const T&) { void operator()(const T&) {
MOZ_CRASH( MOZ_CRASH(
"why are we compressing missing, already-compressed, or " "why are we compressing missing, already-compressed, or "
"BinAST source?"); "BinAST source?");

View File

@ -714,12 +714,12 @@ class ScriptSource {
private: private:
struct UncompressedDataMatcher { struct UncompressedDataMatcher {
template <typename Unit> template <typename Unit>
const void* match(const Uncompressed<Unit>& u) { const void* operator()(const Uncompressed<Unit>& u) {
return u.units(); return u.units();
} }
template <typename T> template <typename T>
const void* match(const T&) { const void* operator()(const T&) {
MOZ_CRASH( MOZ_CRASH(
"attempting to access uncompressed data in a " "attempting to access uncompressed data in a "
"ScriptSource not containing it"); "ScriptSource not containing it");
@ -736,12 +736,12 @@ class ScriptSource {
private: private:
struct CompressedDataMatcher { struct CompressedDataMatcher {
template <typename Unit> template <typename Unit>
char* match(const Compressed<Unit>& c) { char* operator()(const Compressed<Unit>& c) {
return const_cast<char*>(c.raw.chars()); return const_cast<char*>(c.raw.chars());
} }
template <typename T> template <typename T>
char* match(const T&) { char* operator()(const T&) {
MOZ_CRASH( MOZ_CRASH(
"attempting to access compressed data in a ScriptSource " "attempting to access compressed data in a ScriptSource "
"not containing it"); "not containing it");
@ -757,12 +757,14 @@ class ScriptSource {
private: private:
struct BinASTDataMatcher { struct BinASTDataMatcher {
void* match(const BinAST& b) { return const_cast<char*>(b.string.chars()); } void* operator()(const BinAST& b) {
return const_cast<char*>(b.string.chars());
}
void notBinAST() { MOZ_CRASH("ScriptSource isn't backed by BinAST data"); } void notBinAST() { MOZ_CRASH("ScriptSource isn't backed by BinAST data"); }
template <typename T> template <typename T>
void* match(const T&) { void* operator()(const T&) {
notBinAST(); notBinAST();
return nullptr; return nullptr;
} }
@ -774,18 +776,18 @@ class ScriptSource {
private: private:
struct HasUncompressedSource { struct HasUncompressedSource {
template <typename Unit> template <typename Unit>
bool match(const Uncompressed<Unit>&) { bool operator()(const Uncompressed<Unit>&) {
return true; return true;
} }
template <typename Unit> template <typename Unit>
bool match(const Compressed<Unit>&) { bool operator()(const Compressed<Unit>&) {
return false; return false;
} }
bool match(const BinAST&) { return false; } bool operator()(const BinAST&) { return false; }
bool match(const Missing&) { return false; } bool operator()(const Missing&) { return false; }
}; };
public: public:
@ -802,18 +804,18 @@ class ScriptSource {
private: private:
struct HasCompressedSource { struct HasCompressedSource {
template <typename Unit> template <typename Unit>
bool match(const Compressed<Unit>&) { bool operator()(const Compressed<Unit>&) {
return true; return true;
} }
template <typename Unit> template <typename Unit>
bool match(const Uncompressed<Unit>&) { bool operator()(const Uncompressed<Unit>&) {
return false; return false;
} }
bool match(const BinAST&) { return false; } bool operator()(const BinAST&) { return false; }
bool match(const Missing&) { return false; } bool operator()(const Missing&) { return false; }
}; };
public: public:
@ -829,21 +831,21 @@ class ScriptSource {
template <typename Unit> template <typename Unit>
struct SourceTypeMatcher { struct SourceTypeMatcher {
template <template <typename C> class Data> template <template <typename C> class Data>
bool match(const Data<Unit>&) { bool operator()(const Data<Unit>&) {
return true; return true;
} }
template <template <typename C> class Data, typename NotUnit> template <template <typename C> class Data, typename NotUnit>
bool match(const Data<NotUnit>&) { bool operator()(const Data<NotUnit>&) {
return false; return false;
} }
bool match(const BinAST&) { bool operator()(const BinAST&) {
MOZ_CRASH("doesn't make sense to ask source type of BinAST data"); MOZ_CRASH("doesn't make sense to ask source type of BinAST data");
return false; return false;
} }
bool match(const Missing&) { bool operator()(const Missing&) {
MOZ_CRASH("doesn't make sense to ask source type when missing"); MOZ_CRASH("doesn't make sense to ask source type when missing");
return false; return false;
} }
@ -858,19 +860,19 @@ class ScriptSource {
private: private:
struct SourceCharSizeMatcher { struct SourceCharSizeMatcher {
template <template <typename C> class Data, typename Unit> template <template <typename C> class Data, typename Unit>
uint8_t match(const Data<Unit>& data) { uint8_t operator()(const Data<Unit>& data) {
static_assert(std::is_same<Unit, mozilla::Utf8Unit>::value || static_assert(std::is_same<Unit, mozilla::Utf8Unit>::value ||
std::is_same<Unit, char16_t>::value, std::is_same<Unit, char16_t>::value,
"should only have UTF-8 or UTF-16 source char"); "should only have UTF-8 or UTF-16 source char");
return sizeof(Unit); return sizeof(Unit);
} }
uint8_t match(const BinAST&) { uint8_t operator()(const BinAST&) {
MOZ_CRASH("BinAST source has no source-char size"); MOZ_CRASH("BinAST source has no source-char size");
return 0; return 0;
} }
uint8_t match(const Missing&) { uint8_t operator()(const Missing&) {
MOZ_CRASH("missing source has no source-char size"); MOZ_CRASH("missing source has no source-char size");
return 0; return 0;
} }
@ -882,18 +884,18 @@ class ScriptSource {
private: private:
struct UncompressedLengthMatcher { struct UncompressedLengthMatcher {
template <typename Unit> template <typename Unit>
size_t match(const Uncompressed<Unit>& u) { size_t operator()(const Uncompressed<Unit>& u) {
return u.length(); return u.length();
} }
template <typename Unit> template <typename Unit>
size_t match(const Compressed<Unit>& u) { size_t operator()(const Compressed<Unit>& u) {
return u.uncompressedLength; return u.uncompressedLength;
} }
size_t match(const BinAST& b) { return b.string.length(); } size_t operator()(const BinAST& b) { return b.string.length(); }
size_t match(const Missing& m) { size_t operator()(const Missing& m) {
MOZ_CRASH("ScriptSource::length on a missing source"); MOZ_CRASH("ScriptSource::length on a missing source");
return 0; return 0;
} }
@ -908,21 +910,21 @@ class ScriptSource {
private: private:
struct CompressedLengthOrZeroMatcher { struct CompressedLengthOrZeroMatcher {
template <typename Unit> template <typename Unit>
size_t match(const Uncompressed<Unit>&) { size_t operator()(const Uncompressed<Unit>&) {
return 0; return 0;
} }
template <typename Unit> template <typename Unit>
size_t match(const Compressed<Unit>& c) { size_t operator()(const Compressed<Unit>& c) {
return c.raw.length(); return c.raw.length();
} }
size_t match(const BinAST&) { size_t operator()(const BinAST&) {
MOZ_CRASH("trying to get compressed length for BinAST data"); MOZ_CRASH("trying to get compressed length for BinAST data");
return 0; return 0;
} }
size_t match(const Missing&) { size_t operator()(const Missing&) {
MOZ_CRASH("missing source data"); MOZ_CRASH("missing source data");
return 0; return 0;
} }
@ -998,26 +1000,26 @@ class ScriptSource {
: source_(source), compressed_(compressed) {} : source_(source), compressed_(compressed) {}
template <typename Unit> template <typename Unit>
void match(const Uncompressed<Unit>&) { void operator()(const Uncompressed<Unit>&) {
source_->setCompressedSource<Unit>(std::move(compressed_), source_->setCompressedSource<Unit>(std::move(compressed_),
source_->length()); source_->length());
} }
template <typename Unit> template <typename Unit>
void match(const Compressed<Unit>&) { void operator()(const Compressed<Unit>&) {
MOZ_CRASH( MOZ_CRASH(
"can't set compressed source when source is already " "can't set compressed source when source is already "
"compressed -- ScriptSource::tryCompressOffThread " "compressed -- ScriptSource::tryCompressOffThread "
"shouldn't have queued up this task?"); "shouldn't have queued up this task?");
} }
void match(const BinAST&) { void operator()(const BinAST&) {
MOZ_CRASH( MOZ_CRASH(
"doesn't make sense to set compressed source for BinAST " "doesn't make sense to set compressed source for BinAST "
"data"); "data");
} }
void match(const Missing&) { void operator()(const Missing&) {
MOZ_CRASH( MOZ_CRASH(
"doesn't make sense to set compressed source for " "doesn't make sense to set compressed source for "
"missing source -- ScriptSource::tryCompressOffThread " "missing source -- ScriptSource::tryCompressOffThread "

View File

@ -1298,16 +1298,16 @@ static inline bool captureIsSatisfied(JSContext* cx, JSPrincipals* principals,
Matcher(JSContext* cx, JSPrincipals* principals, const JSAtom* source) Matcher(JSContext* cx, JSPrincipals* principals, const JSAtom* source)
: cx_(cx), framePrincipals_(principals), frameSource_(source) {} : cx_(cx), framePrincipals_(principals), frameSource_(source) {}
bool match(JS::FirstSubsumedFrame& target) { bool operator()(JS::FirstSubsumedFrame& target) {
auto subsumes = cx_->runtime()->securityCallbacks->subsumes; auto subsumes = cx_->runtime()->securityCallbacks->subsumes;
return (!subsumes || subsumes(target.principals, framePrincipals_)) && return (!subsumes || subsumes(target.principals, framePrincipals_)) &&
(!target.ignoreSelfHosted || (!target.ignoreSelfHosted ||
frameSource_ != cx_->names().selfHosted); frameSource_ != cx_->names().selfHosted);
} }
bool match(JS::MaxFrames& target) { return target.maxFrames == 1; } bool operator()(JS::MaxFrames& target) { return target.maxFrames == 1; }
bool match(JS::AllFrames&) { return false; } bool operator()(JS::AllFrames&) { return false; }
}; };
Matcher m(cx, principals, source); Matcher m(cx, principals, source);
@ -1869,12 +1869,12 @@ struct MOZ_STACK_CLASS AtomizingMatcher {
explicit AtomizingMatcher(JSContext* cx, size_t length) explicit AtomizingMatcher(JSContext* cx, size_t length)
: cx(cx), length(length) {} : cx(cx), length(length) {}
JSAtom* match(JSAtom* atom) { JSAtom* operator()(JSAtom* atom) {
MOZ_ASSERT(atom); MOZ_ASSERT(atom);
return atom; return atom;
} }
JSAtom* match(const char16_t* chars) { JSAtom* operator()(const char16_t* chars) {
MOZ_ASSERT(chars); MOZ_ASSERT(chars);
return AtomizeChars(cx, chars, length); return AtomizeChars(cx, chars, length);
} }

View File

@ -1021,7 +1021,7 @@ LiveSavedFrameCache::FramePtr::create(AbstractFramePtr afp) {
struct LiveSavedFrameCache::FramePtr::HasCachedMatcher { struct LiveSavedFrameCache::FramePtr::HasCachedMatcher {
template <typename Frame> template <typename Frame>
bool match(Frame* f) const { bool operator()(Frame* f) const {
return f->hasCachedSavedFrame(); return f->hasCachedSavedFrame();
} }
}; };
@ -1032,7 +1032,7 @@ inline bool LiveSavedFrameCache::FramePtr::hasCachedSavedFrame() const {
struct LiveSavedFrameCache::FramePtr::SetHasCachedMatcher { struct LiveSavedFrameCache::FramePtr::SetHasCachedMatcher {
template <typename Frame> template <typename Frame>
void match(Frame* f) { void operator()(Frame* f) {
f->setHasCachedSavedFrame(); f->setHasCachedSavedFrame();
} }
}; };
@ -1043,7 +1043,7 @@ inline void LiveSavedFrameCache::FramePtr::setHasCachedSavedFrame() {
struct LiveSavedFrameCache::FramePtr::ClearHasCachedMatcher { struct LiveSavedFrameCache::FramePtr::ClearHasCachedMatcher {
template <typename Frame> template <typename Frame>
void match(Frame* f) { void operator()(Frame* f) {
f->clearHasCachedSavedFrame(); f->clearHasCachedSavedFrame();
} }
}; };

View File

@ -72,7 +72,7 @@ struct CopyToBufferMatcher {
return i; return i;
} }
size_t match(JSAtom* atom) { size_t operator()(JSAtom* atom) {
if (!atom) { if (!atom) {
return 0; return 0;
} }
@ -86,7 +86,7 @@ struct CopyToBufferMatcher {
length); length);
} }
size_t match(const char16_t* chars) { size_t operator()(const char16_t* chars) {
if (!chars) { if (!chars) {
return 0; return 0;
} }
@ -103,9 +103,11 @@ size_t JS::ubi::AtomOrTwoByteChars::copyToBuffer(
} }
struct LengthMatcher { struct LengthMatcher {
size_t match(JSAtom* atom) { return atom ? atom->length() : 0; } size_t operator()(JSAtom* atom) { return atom ? atom->length() : 0; }
size_t match(const char16_t* chars) { return chars ? js_strlen(chars) : 0; } size_t operator()(const char16_t* chars) {
return chars ? js_strlen(chars) : 0;
}
}; };
size_t JS::ubi::AtomOrTwoByteChars::length() { size_t JS::ubi::AtomOrTwoByteChars::length() {

View File

@ -10,10 +10,10 @@
#include <stdint.h> #include <stdint.h>
#include "mozilla/Assertions.h" #include "mozilla/Assertions.h"
#include "mozilla/Move.h"
#include "mozilla/OperatorNewExtensions.h" #include "mozilla/OperatorNewExtensions.h"
#include "mozilla/TemplateLib.h" #include "mozilla/TemplateLib.h"
#include "mozilla/TypeTraits.h" #include "mozilla/TypeTraits.h"
#include <utility>
#ifndef mozilla_Variant_h #ifndef mozilla_Variant_h
# define mozilla_Variant_h # define mozilla_Variant_h
@ -174,9 +174,8 @@ struct VariantImplementation<Tag, N, T> {
} }
template <typename Matcher, typename ConcreteVariant> template <typename Matcher, typename ConcreteVariant>
static auto match(Matcher&& aMatcher, ConcreteVariant& aV) static decltype(auto) match(Matcher&& aMatcher, ConcreteVariant& aV) {
-> decltype(aMatcher.match(aV.template as<N>())) { return aMatcher(aV.template as<N>());
return aMatcher.match(aV.template as<N>());
} }
}; };
@ -229,22 +228,21 @@ struct VariantImplementation<Tag, N, T, Ts...> {
} }
template <typename Matcher, typename ConcreteVariant> template <typename Matcher, typename ConcreteVariant>
static auto match(Matcher&& aMatcher, ConcreteVariant& aV) static decltype(auto) match(Matcher&& aMatcher, ConcreteVariant& aV) {
-> decltype(aMatcher.match(aV.template as<N>())) {
if (aV.template is<N>()) { if (aV.template is<N>()) {
return aMatcher.match(aV.template as<N>()); return aMatcher(aV.template as<N>());
} else { } else {
// If you're seeing compilation errors here like "no matching // If you're seeing compilation errors here like "no matching
// function for call to 'match'" then that means that the // function for call to 'match'" then that means that the
// Matcher doesn't exhaust all variant types. There must exist a // Matcher doesn't exhaust all variant types. There must exist a
// Matcher::match(T&) for every variant type T. // Matcher::operator()(T&) for every variant type T.
// //
// If you're seeing compilation errors here like "cannot // If you're seeing compilation errors here like "cannot
// initialize return object of type <...> with an rvalue of type // initialize return object of type <...> with an rvalue of type
// <...>" then that means that the Matcher::match(T&) overloads // <...>" then that means that the Matcher::operator()(T&) overloads
// are returning different types. They must all return the same // are returning different types. They must all return the same
// Matcher::ReturnType type. // Matcher::ReturnType type.
return Next::match(aMatcher, aV); return Next::match(std::forward<Matcher>(aMatcher), aV);
} }
} }
}; };
@ -423,19 +421,25 @@ struct VariantIndex {
* } * }
* } * }
* *
* // Good! * // Instead, a single function object (that can deal with all possible
* // options) may be provided:
* struct FooMatcher * struct FooMatcher
* { * {
* // The return type of all matchers must be identical. * // The return type of all matchers must be identical.
* char* match(A& a) { ... } * char* operator()(A& a) { ... }
* char* match(B& b) { ... } * char* operator()(B& b) { ... }
* char* match(C& c) { ... } * char* operator()(C& c) { ... }
* char* match(D& d) { ... } // Compile-time error to forget D! * char* operator()(D& d) { ... } // Compile-time error to forget D!
* } * }
* char* foo(Variant<A, B, C, D>& v) { * char* foo(Variant<A, B, C, D>& v) {
* return v.match(FooMatcher()); * return v.match(FooMatcher());
* } * }
* *
* // In some situations, a single generic lambda may also be appropriate:
* char* foo(Variant<A, B, C, D>& v) {
* return v.match([](auto&){...});
* }
*
* ## Examples * ## Examples
* *
* A tree is either an empty leaf, or a node with a value and two children: * A tree is either an empty leaf, or a node with a value and two children:
@ -684,15 +688,14 @@ class MOZ_INHERIT_TYPE_ANNOTATIONS_FROM_TEMPLATE_ARGS MOZ_NON_PARAM Variant {
/** Match on an immutable const reference. */ /** Match on an immutable const reference. */
template <typename Matcher> template <typename Matcher>
auto match(Matcher&& aMatcher) const decltype(auto) match(Matcher&& aMatcher) const {
-> decltype(Impl::match(aMatcher, *this)) { return Impl::match(std::forward<Matcher>(aMatcher), *this);
return Impl::match(aMatcher, *this);
} }
/** Match on a mutable non-const reference. */ /** Match on a mutable non-const reference. */
template <typename Matcher> template <typename Matcher>
auto match(Matcher&& aMatcher) -> decltype(Impl::match(aMatcher, *this)) { decltype(auto) match(Matcher&& aMatcher) {
return Impl::match(aMatcher, *this); return Impl::match(std::forward<Matcher>(aMatcher), *this);
} }
}; };

View File

@ -372,9 +372,9 @@ struct Describer {
static const char* medium; static const char* medium;
static const char* big; static const char* big;
const char* match(const uint8_t&) { return little; } const char* operator()(const uint8_t&) { return little; }
const char* match(const uint32_t&) { return medium; } const char* operator()(const uint32_t&) { return medium; }
const char* match(const uint64_t&) { return big; } const char* operator()(const uint64_t&) { return big; }
}; };
const char* Describer::little = "little"; const char* Describer::little = "little";
@ -404,6 +404,41 @@ static void testMatching() {
MOZ_RELEASE_ASSERT(constRef3.match(desc) == Describer::big); MOZ_RELEASE_ASSERT(constRef3.match(desc) == Describer::big);
} }
static void testMatchingLambda() {
printf("testMatchingLambda\n");
using V = Variant<uint8_t, uint32_t, uint64_t>;
auto desc = [](auto& a) {
switch (sizeof(a)) {
case 1:
return Describer::little;
case 4:
return Describer::medium;
case 8:
return Describer::big;
default:
MOZ_RELEASE_ASSERT(false);
return "";
}
};
V v1(uint8_t(1));
V v2(uint32_t(2));
V v3(uint64_t(3));
MOZ_RELEASE_ASSERT(v1.match(desc) == Describer::little);
MOZ_RELEASE_ASSERT(v2.match(desc) == Describer::medium);
MOZ_RELEASE_ASSERT(v3.match(desc) == Describer::big);
const V& constRef1 = v1;
const V& constRef2 = v2;
const V& constRef3 = v3;
MOZ_RELEASE_ASSERT(constRef1.match(desc) == Describer::little);
MOZ_RELEASE_ASSERT(constRef2.match(desc) == Describer::medium);
MOZ_RELEASE_ASSERT(constRef3.match(desc) == Describer::big);
}
static void testRvalueMatcher() { static void testRvalueMatcher() {
printf("testRvalueMatcher\n"); printf("testRvalueMatcher\n");
using V = Variant<uint8_t, uint32_t, uint64_t>; using V = Variant<uint8_t, uint32_t, uint64_t>;
@ -422,6 +457,7 @@ int main() {
testDestructor(); testDestructor();
testEquality(); testEquality();
testMatching(); testMatching();
testMatchingLambda();
testRvalueMatcher(); testRvalueMatcher();
printf("TestVariant OK!\n"); printf("TestVariant OK!\n");

View File

@ -912,13 +912,13 @@ class MOZ_STACK_CLASS PrefWrapper : public PrefWrapperBase {
bool IsTypeInt() const { return IsType(PrefType::Int); } bool IsTypeInt() const { return IsType(PrefType::Int); }
bool IsTypeBool() const { return IsType(PrefType::Bool); } bool IsTypeBool() const { return IsType(PrefType::Bool); }
#define FORWARD(retType, method) \ #define FORWARD(retType, method) \
retType method() const { \ retType method() const { \
struct Matcher { \ struct Matcher { \
retType match(const Pref* aPref) { return aPref->method(); } \ retType operator()(const Pref* aPref) { return aPref->method(); } \
retType match(SharedPref& aPref) { return aPref.method(); } \ retType operator()(SharedPref& aPref) { return aPref.method(); } \
}; \ }; \
return match(Matcher()); \ return match(Matcher()); \
} }
FORWARD(bool, DefaultChanged) FORWARD(bool, DefaultChanged)
@ -931,15 +931,15 @@ class MOZ_STACK_CLASS PrefWrapper : public PrefWrapperBase {
FORWARD(PrefType, Type) FORWARD(PrefType, Type)
#undef FORWARD #undef FORWARD
#define FORWARD(retType, method) \ #define FORWARD(retType, method) \
retType method(PrefValueKind aKind = PrefValueKind::User) const { \ retType method(PrefValueKind aKind = PrefValueKind::User) const { \
struct Matcher { \ struct Matcher { \
PrefValueKind mKind; \ PrefValueKind mKind; \
\ \
retType match(const Pref* aPref) { return aPref->method(mKind); } \ retType operator()(const Pref* aPref) { return aPref->method(mKind); } \
retType match(SharedPref& aPref) { return aPref.method(mKind); } \ retType operator()(SharedPref& aPref) { return aPref.method(mKind); } \
}; \ }; \
return match(Matcher{aKind}); \ return match(Matcher{aKind}); \
} }
FORWARD(bool, GetBoolValue) FORWARD(bool, GetBoolValue)
@ -1299,11 +1299,11 @@ class PrefsIter {
do { \ do { \
struct Matcher { \ struct Matcher { \
PrefsIter& mIter; \ PrefsIter& mIter; \
type match(HashElem& pos) { \ type operator()(HashElem& pos) { \
HashElem& end MOZ_MAYBE_UNUSED = mIter.mEnd.as<HashElem>(); \ HashElem& end MOZ_MAYBE_UNUSED = mIter.mEnd.as<HashElem>(); \
__VA_ARGS__; \ __VA_ARGS__; \
} \ } \
type match(SharedElem& pos) { \ type operator()(SharedElem& pos) { \
SharedElem& end MOZ_MAYBE_UNUSED = mIter.mEnd.as<SharedElem>(); \ SharedElem& end MOZ_MAYBE_UNUSED = mIter.mEnd.as<SharedElem>(); \
__VA_ARGS__; \ __VA_ARGS__; \
} \ } \
@ -1960,8 +1960,8 @@ class nsPrefBranch final : public nsIPrefBranch,
PrefName& operator=(const PrefName&) = delete; PrefName& operator=(const PrefName&) = delete;
struct PtrMatcher { struct PtrMatcher {
static const char* match(const char* aVal) { return aVal; } const char* operator()(const char* aVal) { return aVal; }
static const char* match(const nsCString& aVal) { return aVal.get(); } const char* operator()(const nsCString& aVal) { return aVal.get(); }
}; };
struct CStringMatcher { struct CStringMatcher {
@ -1969,26 +1969,20 @@ class nsPrefBranch final : public nsIPrefBranch,
// method argument through to our matcher methods. // method argument through to our matcher methods.
nsACString& mStr; nsACString& mStr;
void match(const char* aVal) { mStr.Assign(aVal); } void operator()(const char* aVal) { mStr.Assign(aVal); }
void match(const nsCString& aVal) { mStr.Assign(aVal); } void operator()(const nsCString& aVal) { mStr.Assign(aVal); }
}; };
struct LenMatcher { struct LenMatcher {
static size_t match(const char* aVal) { return strlen(aVal); } size_t operator()(const char* aVal) { return strlen(aVal); }
static size_t match(const nsCString& aVal) { return aVal.Length(); } size_t operator()(const nsCString& aVal) { return aVal.Length(); }
}; };
const char* get() const { const char* get() const { return match(PtrMatcher{}); }
static PtrMatcher m;
return match(m);
}
void get(nsACString& aStr) const { match(CStringMatcher{aStr}); } void get(nsACString& aStr) const { match(CStringMatcher{aStr}); }
size_t Length() const { size_t Length() const { return match(LenMatcher{}); }
static LenMatcher m;
return match(m);
}
}; };
virtual ~nsPrefBranch(); virtual ~nsPrefBranch();

View File

@ -738,8 +738,10 @@ DocInfo::DocInfo(nsPIDOMWindowOuter* aWindow)
bool DocInfo::IsTopLevel() const { bool DocInfo::IsTopLevel() const {
if (mIsTopLevel.isNothing()) { if (mIsTopLevel.isNothing()) {
struct Matcher { struct Matcher {
bool match(Window aWin) { return aWin->IsTopLevelWindow(); } bool operator()(Window aWin) { return aWin->IsTopLevelWindow(); }
bool match(LoadInfo aLoadInfo) { return aLoadInfo->GetIsTopLevelLoad(); } bool operator()(LoadInfo aLoadInfo) {
return aLoadInfo->GetIsTopLevelLoad();
}
}; };
mIsTopLevel.emplace(mObj.match(Matcher())); mIsTopLevel.emplace(mObj.match(Matcher()));
} }
@ -778,8 +780,8 @@ bool WindowShouldMatchActiveTab(nsPIDOMWindowOuter* aWin) {
bool DocInfo::ShouldMatchActiveTabPermission() const { bool DocInfo::ShouldMatchActiveTabPermission() const {
struct Matcher { struct Matcher {
bool match(Window aWin) { return WindowShouldMatchActiveTab(aWin); } bool operator()(Window aWin) { return WindowShouldMatchActiveTab(aWin); }
bool match(LoadInfo aLoadInfo) { return false; } bool operator()(LoadInfo aLoadInfo) { return false; }
}; };
return mObj.match(Matcher()); return mObj.match(Matcher());
} }
@ -790,8 +792,8 @@ uint64_t DocInfo::FrameID() const {
mFrameID.emplace(0); mFrameID.emplace(0);
} else { } else {
struct Matcher { struct Matcher {
uint64_t match(Window aWin) { return aWin->WindowID(); } uint64_t operator()(Window aWin) { return aWin->WindowID(); }
uint64_t match(LoadInfo aLoadInfo) { uint64_t operator()(LoadInfo aLoadInfo) {
return aLoadInfo->GetOuterWindowID(); return aLoadInfo->GetOuterWindowID();
} }
}; };
@ -807,11 +809,11 @@ nsIPrincipal* DocInfo::Principal() const {
explicit Matcher(const DocInfo& aThis) : mThis(aThis) {} explicit Matcher(const DocInfo& aThis) : mThis(aThis) {}
const DocInfo& mThis; const DocInfo& mThis;
nsIPrincipal* match(Window aWin) { nsIPrincipal* operator()(Window aWin) {
RefPtr<Document> doc = aWin->GetDoc(); RefPtr<Document> doc = aWin->GetDoc();
return doc->NodePrincipal(); return doc->NodePrincipal();
} }
nsIPrincipal* match(LoadInfo aLoadInfo) { nsIPrincipal* operator()(LoadInfo aLoadInfo) {
if (!(mThis.URL().InheritsPrincipal() || if (!(mThis.URL().InheritsPrincipal() ||
aLoadInfo->GetForceInheritPrincipal())) { aLoadInfo->GetForceInheritPrincipal())) {
return nullptr; return nullptr;

View File

@ -189,11 +189,11 @@ class MOZ_STACK_CLASS EntryWrapper final {
explicit EntryWrapper(const StaticModule* aEntry) : mEntry(aEntry) {} explicit EntryWrapper(const StaticModule* aEntry) : mEntry(aEntry) {}
#define MATCH(type, ifFactory, ifStatic) \ #define MATCH(type, ifFactory, ifStatic) \
struct Matcher { \ struct Matcher { \
type match(nsFactoryEntry* entry) { ifFactory; } \ type operator()(nsFactoryEntry* entry) { ifFactory; } \
type match(const StaticModule* entry) { ifStatic; } \ type operator()(const StaticModule* entry) { ifStatic; } \
}; \ }; \
return mEntry.match((Matcher())) return mEntry.match((Matcher()))
const nsID& CID() { const nsID& CID() {