Bug 1366511: Part 3 - Add mozilla::ToResult() to convert other result types to equivalent Result. r=nbp,ehsan

Also adds a mozilla/ResultExtensions.h header to define the appropriate
conversion functions for nsresult and PRResult. This is in a separate header
since those types are not available in Spidermonkey, and this is the pattern
other *Extensions.h headers follow.

Also removes equivalent NS_TRY macros and WrapNSResult inlines that served the
same purpose in existing code, and are no longer necessary.

MozReview-Commit-ID: A85PCAeyWhx
This commit is contained in:
Kris Maglione
2017-08-29 21:28:31 -07:00
parent b3bfcf48cf
commit a723c8955d
12 changed files with 178 additions and 218 deletions

View File

@@ -362,12 +362,12 @@ Result<nsCOMPtr<nsIFile>, nsresult>
ScriptPreloader::GetCacheFile(const nsAString& suffix)
{
nsCOMPtr<nsIFile> cacheFile;
NS_TRY(mProfD->Clone(getter_AddRefs(cacheFile)));
MOZ_TRY(mProfD->Clone(getter_AddRefs(cacheFile)));
NS_TRY(cacheFile->AppendNative(NS_LITERAL_CSTRING("startupCache")));
MOZ_TRY(cacheFile->AppendNative(NS_LITERAL_CSTRING("startupCache")));
Unused << cacheFile->Create(nsIFile::DIRECTORY_TYPE, 0777);
NS_TRY(cacheFile->Append(mBaseName + suffix));
MOZ_TRY(cacheFile->Append(mBaseName + suffix));
return Move(cacheFile);
}
@@ -377,18 +377,18 @@ static const uint8_t MAGIC[] = "mozXDRcachev001";
Result<Ok, nsresult>
ScriptPreloader::OpenCache()
{
NS_TRY(NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(mProfD)));
MOZ_TRY(NS_GetSpecialDirectory("ProfLDS", getter_AddRefs(mProfD)));
nsCOMPtr<nsIFile> cacheFile;
MOZ_TRY_VAR(cacheFile, GetCacheFile(NS_LITERAL_STRING(".bin")));
bool exists;
NS_TRY(cacheFile->Exists(&exists));
MOZ_TRY(cacheFile->Exists(&exists));
if (exists) {
NS_TRY(cacheFile->MoveTo(nullptr, mBaseName + NS_LITERAL_STRING("-current.bin")));
MOZ_TRY(cacheFile->MoveTo(nullptr, mBaseName + NS_LITERAL_STRING("-current.bin")));
} else {
NS_TRY(cacheFile->SetLeafName(mBaseName + NS_LITERAL_STRING("-current.bin")));
NS_TRY(cacheFile->Exists(&exists));
MOZ_TRY(cacheFile->SetLeafName(mBaseName + NS_LITERAL_STRING("-current.bin")));
MOZ_TRY(cacheFile->Exists(&exists));
if (!exists) {
return Err(NS_ERROR_FILE_NOT_FOUND);
}
@@ -627,14 +627,14 @@ ScriptPreloader::WriteCache()
MOZ_TRY_VAR(cacheFile, GetCacheFile(NS_LITERAL_STRING("-new.bin")));
bool exists;
NS_TRY(cacheFile->Exists(&exists));
MOZ_TRY(cacheFile->Exists(&exists));
if (exists) {
NS_TRY(cacheFile->Remove(false));
MOZ_TRY(cacheFile->Remove(false));
}
{
AutoFDClose fd;
NS_TRY(cacheFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, 0644, &fd.rwget()));
MOZ_TRY(cacheFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE, 0644, &fd.rwget()));
// We also need to hold mMonitor while we're touching scripts in
// mScripts, or they may be freed before we're done with them.
@@ -675,7 +675,7 @@ ScriptPreloader::WriteCache()
}
}
NS_TRY(cacheFile->MoveTo(nullptr, mBaseName + NS_LITERAL_STRING(".bin")));
MOZ_TRY(cacheFile->MoveTo(nullptr, mBaseName + NS_LITERAL_STRING(".bin")));
return Ok();
}