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
Родитель d0f1336b84
Коммит e2d15a1cfb
23 изменённых файлов: 402 добавлений и 333 удалений

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -212,13 +212,19 @@ class OriginScope {
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));
@ -245,19 +251,19 @@ class OriginScope {
explicit OriginMatcher(const Origin& aOther) : mOther(aOther) {}
bool match(const Origin& aThis) {
bool operator()(const Origin& aThis) {
return aThis.GetOrigin().Equals(mOther.GetOrigin());
}
bool match(const Prefix& aThis) {
bool operator()(const Prefix& aThis) {
return aThis.GetOriginNoSuffix().Equals(mOther.GetOriginNoSuffix());
}
bool match(const Pattern& aThis) {
bool operator()(const Pattern& aThis) {
return aThis.GetPattern().Matches(mOther.GetAttributes());
}
bool match(const Null& aThis) {
bool operator()(const Null& aThis) {
// Null covers everything.
return true;
}
@ -272,22 +278,22 @@ class OriginScope {
explicit PrefixMatcher(const Prefix& aOther) : mOther(aOther) {}
bool match(const Origin& aThis) {
bool operator()(const Origin& aThis) {
return aThis.GetOriginNoSuffix().Equals(mOther.GetOriginNoSuffix());
}
bool match(const Prefix& aThis) {
bool operator()(const Prefix& aThis) {
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
// pattern overlaps any origin prefix (an origin prefix targets all
// origin attributes).
return true;
}
bool match(const Null& aThis) {
bool operator()(const Null& aThis) {
// Null covers everything.
return true;
}
@ -302,22 +308,22 @@ class OriginScope {
explicit PatternMatcher(const Pattern& aOther) : mOther(aOther) {}
bool match(const Origin& aThis) {
bool operator()(const Origin& aThis) {
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
// pattern overlaps any origin prefix (an origin prefix targets all
// origin attributes).
return true;
}
bool match(const Pattern& aThis) {
bool operator()(const Pattern& aThis) {
return aThis.GetPattern().Overlaps(mOther.GetPattern());
}
bool match(const Null& aThis) {
bool operator()(const Null& aThis) {
// Null covers everything.
return true;
}

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -10,10 +10,10 @@
#include <stdint.h>
#include "mozilla/Assertions.h"
#include "mozilla/Move.h"
#include "mozilla/OperatorNewExtensions.h"
#include "mozilla/TemplateLib.h"
#include "mozilla/TypeTraits.h"
#include <utility>
#ifndef mozilla_Variant_h
# define mozilla_Variant_h
@ -174,9 +174,8 @@ struct VariantImplementation<Tag, N, T> {
}
template <typename Matcher, typename ConcreteVariant>
static auto match(Matcher&& aMatcher, ConcreteVariant& aV)
-> decltype(aMatcher.match(aV.template as<N>())) {
return aMatcher.match(aV.template as<N>());
static decltype(auto) match(Matcher&& aMatcher, ConcreteVariant& aV) {
return aMatcher(aV.template as<N>());
}
};
@ -229,22 +228,21 @@ struct VariantImplementation<Tag, N, T, Ts...> {
}
template <typename Matcher, typename ConcreteVariant>
static auto match(Matcher&& aMatcher, ConcreteVariant& aV)
-> decltype(aMatcher.match(aV.template as<N>())) {
static decltype(auto) match(Matcher&& aMatcher, ConcreteVariant& aV) {
if (aV.template is<N>()) {
return aMatcher.match(aV.template as<N>());
return aMatcher(aV.template as<N>());
} else {
// If you're seeing compilation errors here like "no matching
// function for call to 'match'" then that means that the
// 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
// 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
// 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
* {
* // The return type of all matchers must be identical.
* char* match(A& a) { ... }
* char* match(B& b) { ... }
* char* match(C& c) { ... }
* char* match(D& d) { ... } // Compile-time error to forget D!
* char* operator()(A& a) { ... }
* char* operator()(B& b) { ... }
* char* operator()(C& c) { ... }
* char* operator()(D& d) { ... } // Compile-time error to forget D!
* }
* char* foo(Variant<A, B, C, D>& v) {
* 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
*
* 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. */
template <typename Matcher>
auto match(Matcher&& aMatcher) const
-> decltype(Impl::match(aMatcher, *this)) {
return Impl::match(aMatcher, *this);
decltype(auto) match(Matcher&& aMatcher) const {
return Impl::match(std::forward<Matcher>(aMatcher), *this);
}
/** Match on a mutable non-const reference. */
template <typename Matcher>
auto match(Matcher&& aMatcher) -> decltype(Impl::match(aMatcher, *this)) {
return Impl::match(aMatcher, *this);
decltype(auto) match(Matcher&& aMatcher) {
return Impl::match(std::forward<Matcher>(aMatcher), *this);
}
};

Просмотреть файл

@ -372,9 +372,9 @@ struct Describer {
static const char* medium;
static const char* big;
const char* match(const uint8_t&) { return little; }
const char* match(const uint32_t&) { return medium; }
const char* match(const uint64_t&) { return big; }
const char* operator()(const uint8_t&) { return little; }
const char* operator()(const uint32_t&) { return medium; }
const char* operator()(const uint64_t&) { return big; }
};
const char* Describer::little = "little";
@ -404,6 +404,41 @@ static void testMatching() {
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() {
printf("testRvalueMatcher\n");
using V = Variant<uint8_t, uint32_t, uint64_t>;
@ -422,6 +457,7 @@ int main() {
testDestructor();
testEquality();
testMatching();
testMatchingLambda();
testRvalueMatcher();
printf("TestVariant OK!\n");

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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