Bug 1702415 - Replace aSourceFile with aSourceFilePath; r=dom-storage-reviewers,jstutte,asuth

This patch adjusts other similar names as well:
MakeRelativeSourceFileName -> MakeSourceFileRelativePath
relativeSourceFile -> sourceFileRelativePath
thisFileRelativeSourceFileName -> thisSourceFileRelativePath

Differential Revision: https://phabricator.services.mozilla.com/D113076
This commit is contained in:
Jan Varga 2021-04-23 12:02:58 +00:00
Родитель f1ca31a347
Коммит 3323c1e8c3
3 изменённых файлов: 58 добавлений и 55 удалений

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

@ -312,33 +312,33 @@ void ScopedLogExtraInfo::AddInfo() {
namespace detail {
nsDependentCSubstring GetSourceTreeBase() {
static constexpr auto thisFileRelativeSourceFileName =
static constexpr auto thisSourceFileRelativePath =
"/dom/quota/QuotaCommon.cpp"_ns;
static constexpr auto path = nsLiteralCString(__FILE__);
MOZ_ASSERT(StringEndsWith(path, thisFileRelativeSourceFileName));
MOZ_ASSERT(StringEndsWith(path, thisSourceFileRelativePath));
return Substring(path, 0,
path.Length() - thisFileRelativeSourceFileName.Length());
path.Length() - thisSourceFileRelativePath.Length());
}
nsDependentCSubstring MakeRelativeSourceFileName(
const nsACString& aSourceFile) {
nsDependentCSubstring MakeSourceFileRelativePath(
const nsACString& aSourceFilePath) {
static constexpr auto error = "ERROR"_ns;
static const auto sourceTreeBase = GetSourceTreeBase();
if (MOZ_LIKELY(StringBeginsWith(aSourceFile, sourceTreeBase))) {
return Substring(aSourceFile, sourceTreeBase.Length() + 1);
if (MOZ_LIKELY(StringBeginsWith(aSourceFilePath, sourceTreeBase))) {
return Substring(aSourceFilePath, sourceTreeBase.Length() + 1);
}
nsCString::const_iterator begin, end;
if (RFindInReadable("/"_ns, aSourceFile.BeginReading(begin),
aSourceFile.EndReading(end))) {
if (RFindInReadable("/"_ns, aSourceFilePath.BeginReading(begin),
aSourceFilePath.EndReading(end))) {
// Use the basename as a fallback, to avoid exposing any user parts of the
// path.
++begin;
return Substring(begin, aSourceFile.EndReading(end));
return Substring(begin, aSourceFilePath.EndReading(end));
}
return nsDependentCSubstring{static_cast<mozilla::Span<const char>>(
@ -348,7 +348,7 @@ nsDependentCSubstring MakeRelativeSourceFileName(
} // namespace detail
void LogError(const nsACString& aExpr, const Maybe<nsresult> aRv,
const nsACString& aSourceFile, const int32_t aSourceLine,
const nsACString& aSourceFilePath, const int32_t aSourceLine,
const Severity aSeverity) {
#if defined(EARLY_BETA_OR_EARLIER) || defined(DEBUG)
nsAutoCString extraInfosString;
@ -368,8 +368,8 @@ void LogError(const nsACString& aExpr, const Maybe<nsresult> aRv,
!rvName.IsEmpty() ? rvName.get() : "", !rvName.IsEmpty() ? ")" : "");
}
const auto relativeSourceFile =
detail::MakeRelativeSourceFileName(aSourceFile);
const auto sourceFileRelativePath =
detail::MakeSourceFileRelativePath(aSourceFilePath);
const auto severityString = [&aSeverity]() -> nsLiteralCString {
switch (aSeverity) {
@ -400,7 +400,7 @@ void LogError(const nsACString& aExpr, const Maybe<nsresult> aRv,
: static_cast<const nsCString&>(nsAutoCString(
aExpr + extraInfosString)))
.get(),
nsPromiseFlatCString(relativeSourceFile).get(), aSourceLine);
nsPromiseFlatCString(sourceFileRelativePath).get(), aSourceLine);
#endif
#if defined(EARLY_BETA_OR_EARLIER) || defined(DEBUG)
@ -409,7 +409,7 @@ void LogError(const nsACString& aExpr, const Maybe<nsresult> aRv,
if (console) {
NS_ConvertUTF8toUTF16 message("QM_TRY failure ("_ns + severityString +
")"_ns + ": '"_ns + aExpr + "' at "_ns +
relativeSourceFile + ":"_ns +
sourceFileRelativePath + ":"_ns +
IntToCString(aSourceLine) + extraInfosString);
// The concatenation above results in a message like:
@ -431,7 +431,7 @@ void LogError(const nsACString& aExpr, const Maybe<nsresult> aRv,
// directory, but we probably don't need to.
// res.AppendElement(EventExtraEntry{"module"_ns, aModule});
res.AppendElement(
EventExtraEntry{"source_file"_ns, nsCString(relativeSourceFile)});
EventExtraEntry{"source_file"_ns, nsCString(sourceFileRelativePath)});
res.AppendElement(
EventExtraEntry{"source_line"_ns, IntToCString(aSourceLine)});
res.AppendElement(EventExtraEntry{
@ -465,7 +465,7 @@ void LogError(const nsACString& aExpr, const Maybe<nsresult> aRv,
#ifdef DEBUG
Result<bool, nsresult> WarnIfFileIsUnknown(nsIFile& aFile,
const char* aSourceFile,
const char* aSourceFilePath,
const int32_t aSourceLine) {
nsString leafName;
nsresult rv = aFile.GetLeafName(leafName);
@ -502,7 +502,7 @@ Result<bool, nsresult> WarnIfFileIsUnknown(nsIFile& aFile,
nsPrintfCString("Something (%s) in the directory that doesn't belong!",
NS_ConvertUTF16toUTF8(leafName).get())
.get(),
nullptr, aSourceFile, aSourceLine);
nullptr, aSourceFilePath, aSourceLine);
return true;
}

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

@ -1194,7 +1194,8 @@ namespace detail {
nsDependentCSubstring GetSourceTreeBase();
nsDependentCSubstring MakeRelativeSourceFileName(const nsACString& aSourceFile);
nsDependentCSubstring MakeSourceFileRelativePath(
const nsACString& aSourceFilePath);
} // namespace detail
@ -1205,12 +1206,12 @@ enum class Severity {
};
void LogError(const nsACString& aExpr, Maybe<nsresult> aRv,
const nsACString& aSourceFile, int32_t aSourceLine,
const nsACString& aSourceFilePath, int32_t aSourceLine,
Severity aSeverity);
#ifdef DEBUG
Result<bool, nsresult> WarnIfFileIsUnknown(nsIFile& aFile,
const char* aSourceFile,
const char* aSourceFilePath,
int32_t aSourceLine);
#endif
@ -1284,41 +1285,42 @@ struct MOZ_STACK_CLASS ScopedLogExtraInfo {
#if defined(EARLY_BETA_OR_EARLIER) || defined(DEBUG)
template <typename T>
MOZ_COLD void HandleError(const char* aExpr, const T& aRv,
const char* aSourceFile, int32_t aSourceLine,
const char* aSourceFilePath, int32_t aSourceLine,
const Severity aSeverity) {
if constexpr (std::is_same_v<T, nsresult>) {
mozilla::dom::quota::LogError(nsDependentCString(aExpr), Some(aRv),
nsDependentCString(aSourceFile), aSourceLine,
aSeverity);
nsDependentCString(aSourceFilePath),
aSourceLine, aSeverity);
} else {
mozilla::dom::quota::LogError(nsDependentCString(aExpr), Nothing{},
nsDependentCString(aSourceFile), aSourceLine,
aSeverity);
nsDependentCString(aSourceFilePath),
aSourceLine, aSeverity);
}
}
#else
template <typename T>
MOZ_ALWAYS_INLINE constexpr void HandleError(const char* aExpr, const T& aRv,
const char* aSourceFile,
const char* aSourceFilePath,
int32_t aSourceLine,
const Severity aSeverity) {}
#endif
template <typename T>
Nothing HandleErrorReturnNothing(const char* aExpr, const T& aRv,
const char* aSourceFile, int32_t aSourceLine,
const char* aSourceFilePath,
int32_t aSourceLine,
const Severity aSeverity) {
HandleError(aExpr, aRv, aSourceFile, aSourceLine, aSeverity);
HandleError(aExpr, aRv, aSourceFilePath, aSourceLine, aSeverity);
return Nothing();
}
template <typename T, typename CleanupFunc>
Nothing HandleErrorWithCleanupReturnNothing(const char* aExpr, const T& aRv,
const char* aSourceFile,
const char* aSourceFilePath,
int32_t aSourceLine,
const Severity aSeverity,
CleanupFunc&& aCleanupFunc) {
HandleError(aExpr, aRv, aSourceFile, aSourceLine, aSeverity);
HandleError(aExpr, aRv, aSourceFilePath, aSourceLine, aSeverity);
std::forward<CleanupFunc>(aCleanupFunc)(aRv);
return Nothing();
}

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

@ -1758,17 +1758,16 @@ TEST(QuotaCommon_CallWithDelayedRetriesIfAccessDenied, FailuresAndSuccess)
EXPECT_TRUE(res.isOk());
}
static constexpr auto thisFileRelativeSourceFileName =
static constexpr auto thisSourceFileRelativePath =
"dom/quota/test/gtest/TestQuotaCommon.cpp"_ns;
TEST(QuotaCommon_MakeRelativeSourceFileName, ThisDomQuotaFile)
TEST(QuotaCommon_MakeSourceFileRelativePath, ThisSourceFile)
{
const nsCString relativeSourceFilePath{
mozilla::dom::quota::detail::MakeRelativeSourceFileName(
const nsCString sourceFileRelativePath{
mozilla::dom::quota::detail::MakeSourceFileRelativePath(
nsLiteralCString(__FILE__))};
EXPECT_STREQ(relativeSourceFilePath.get(),
thisFileRelativeSourceFileName.get());
EXPECT_STREQ(sourceFileRelativePath.get(), thisSourceFileRelativePath.get());
}
static nsCString MakeFullPath(const nsACString& aRelativePath) {
@ -1780,38 +1779,40 @@ static nsCString MakeFullPath(const nsACString& aRelativePath) {
return path;
}
TEST(QuotaCommon_MakeRelativeSourceFileName, DomIndexedDBFile)
TEST(QuotaCommon_MakeSourceFileRelativePath, DomIndexedDBSourceFile)
{
static constexpr auto domIndexedDBFileRelativePath =
static constexpr auto domIndexedDBSourceFileRelativePath =
"dom/indexedDB/ActorsParent.cpp"_ns;
const nsCString relativeSourceFilePath{
mozilla::dom::quota::detail::MakeRelativeSourceFileName(
MakeFullPath(domIndexedDBFileRelativePath))};
const nsCString sourceFileRelativePath{
mozilla::dom::quota::detail::MakeSourceFileRelativePath(
MakeFullPath(domIndexedDBSourceFileRelativePath))};
EXPECT_STREQ(relativeSourceFilePath.get(),
domIndexedDBFileRelativePath.get());
EXPECT_STREQ(sourceFileRelativePath.get(),
domIndexedDBSourceFileRelativePath.get());
}
TEST(QuotaCommon_MakeRelativeSourceFileName, NonDomFile)
TEST(QuotaCommon_MakeSourceFileRelativePath, NonDomSourceFile)
{
static constexpr auto nonDomFileRelativePath =
static constexpr auto nonDomSourceFileRelativePath =
"storage/mozStorageService.cpp"_ns;
const nsCString relativeSourceFilePath{
mozilla::dom::quota::detail::MakeRelativeSourceFileName(
MakeFullPath(nonDomFileRelativePath))};
const nsCString sourceFileRelativePath{
mozilla::dom::quota::detail::MakeSourceFileRelativePath(
MakeFullPath(nonDomSourceFileRelativePath))};
EXPECT_STREQ(relativeSourceFilePath.get(), nonDomFileRelativePath.get());
EXPECT_STREQ(sourceFileRelativePath.get(),
nonDomSourceFileRelativePath.get());
}
TEST(QuotaCommon_MakeRelativeSourceFileName, OtherFile)
TEST(QuotaCommon_MakeSourceFileRelativePath, OtherSourceFile)
{
constexpr auto otherName = "/foo/bar/Test.cpp"_ns;
const nsCString relativeSourceFilePath{
mozilla::dom::quota::detail::MakeRelativeSourceFileName(otherName)};
constexpr auto otherSourceFilePath = "/foo/bar/Test.cpp"_ns;
const nsCString sourceFileRelativePath{
mozilla::dom::quota::detail::MakeSourceFileRelativePath(
otherSourceFilePath)};
EXPECT_STREQ(relativeSourceFilePath.get(), "Test.cpp");
EXPECT_STREQ(sourceFileRelativePath.get(), "Test.cpp");
}
#ifdef __clang__