Bug 1661476 - Prevent Result<const V, E> or Result<V, const E> from being instantiated. r=froydnj

Also, remove the existing uses of Result<const nsCString, nsresult> in URLPreloader
and Result<CryptoScheme, const nsCString> in SampleIterator.

Differential Revision: https://phabricator.services.mozilla.com/D88419
This commit is contained in:
Simon Giesecke 2020-08-28 14:16:35 +00:00
Родитель 307030428e
Коммит ff85972891
5 изменённых файлов: 47 добавлений и 37 удалений

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

@ -298,7 +298,7 @@ CencSampleEncryptionInfoEntry* SampleIterator::GetSampleEncryptionEntry() {
: &entries->ElementAt(groupIndex - 1);
}
Result<CryptoScheme, const nsCString> SampleIterator::GetEncryptionScheme() {
Result<CryptoScheme, nsCString> SampleIterator::GetEncryptionScheme() {
// See ISO/IEC 23001-7 for information on the metadata being checked.
MoofParser* moofParser = mIndex->mMoofParser.get();
if (!moofParser) {

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

@ -45,7 +45,7 @@ class SampleIterator {
//
// Returns: Ok(CryptoScheme) if a crypto scheme, including None, can be
// determined, or Err(nsCString) if there is an issue determining the scheme.
Result<CryptoScheme, const nsCString> GetEncryptionScheme();
Result<CryptoScheme, nsCString> GetEncryptionScheme();
void Next();
RefPtr<Index> mIndex;

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

@ -436,8 +436,8 @@ void URLPreloader::BeginBackgroundRead() {
}
}
Result<const nsCString, nsresult> URLPreloader::ReadInternal(
const CacheKey& key, ReadType readType) {
Result<nsCString, nsresult> URLPreloader::ReadInternal(const CacheKey& key,
ReadType readType) {
if (mStartupFinished) {
URLEntry entry(key);
@ -451,16 +451,16 @@ Result<const nsCString, nsresult> URLPreloader::ReadInternal(
return entry->ReadOrWait(readType);
}
Result<const nsCString, nsresult> URLPreloader::ReadURIInternal(
nsIURI* uri, ReadType readType) {
Result<nsCString, nsresult> URLPreloader::ReadURIInternal(nsIURI* uri,
ReadType readType) {
CacheKey key;
MOZ_TRY_VAR(key, ResolveURI(uri));
return ReadInternal(key, readType);
}
/* static */ Result<const nsCString, nsresult> URLPreloader::Read(
const CacheKey& key, ReadType readType) {
/* static */ Result<nsCString, nsresult> URLPreloader::Read(const CacheKey& key,
ReadType readType) {
// If we're being called before the preloader has been initialized (i.e.,
// before the profile has been initialized), just fall back to a synchronous
// read. This happens when we're reading .ini and preference files that are
@ -472,7 +472,7 @@ Result<const nsCString, nsresult> URLPreloader::ReadURIInternal(
return GetSingleton().ReadInternal(key, readType);
}
/* static */ Result<const nsCString, nsresult> URLPreloader::ReadURI(
/* static */ Result<nsCString, nsresult> URLPreloader::ReadURI(
nsIURI* uri, ReadType readType) {
if (!sInitialized) {
return Err(NS_ERROR_NOT_INITIALIZED);
@ -481,12 +481,12 @@ Result<const nsCString, nsresult> URLPreloader::ReadURIInternal(
return GetSingleton().ReadURIInternal(uri, readType);
}
/* static */ Result<const nsCString, nsresult> URLPreloader::ReadFile(
/* static */ Result<nsCString, nsresult> URLPreloader::ReadFile(
nsIFile* file, ReadType readType) {
return Read(CacheKey(file), readType);
}
/* static */ Result<const nsCString, nsresult> URLPreloader::Read(
/* static */ Result<nsCString, nsresult> URLPreloader::Read(
FileLocation& location, ReadType readType) {
if (location.IsZip()) {
if (location.GetBaseZip()) {
@ -501,7 +501,7 @@ Result<const nsCString, nsresult> URLPreloader::ReadURIInternal(
return ReadFile(file, readType);
}
/* static */ Result<const nsCString, nsresult> URLPreloader::ReadZip(
/* static */ Result<nsCString, nsresult> URLPreloader::ReadZip(
CacheAwareZipReader* archive, const nsACString& path, ReadType readType) {
// If the zip archive belongs to an Omnijar location, map it to a cache
// entry, and cache it as normal. Otherwise, simply read the entry
@ -592,7 +592,7 @@ Result<FileLocation, nsresult> URLPreloader::CacheKey::ToFileLocation() {
return FileLocation(zip, mPath.get());
}
Result<const nsCString, nsresult> URLPreloader::URLEntry::Read() {
Result<nsCString, nsresult> URLPreloader::URLEntry::Read() {
FileLocation location;
MOZ_TRY_VAR(location, ToFileLocation());
@ -600,8 +600,8 @@ Result<const nsCString, nsresult> URLPreloader::URLEntry::Read() {
return mData;
}
/* static */ Result<const nsCString, nsresult>
URLPreloader::URLEntry::ReadLocation(FileLocation& location) {
/* static */ Result<nsCString, nsresult> URLPreloader::URLEntry::ReadLocation(
FileLocation& location) {
FileLocation::Data data;
MOZ_TRY(location.GetData(data));
@ -615,7 +615,7 @@ URLPreloader::URLEntry::ReadLocation(FileLocation& location) {
return std::move(result);
}
Result<const nsCString, nsresult> URLPreloader::URLEntry::ReadOrWait(
Result<nsCString, nsresult> URLPreloader::URLEntry::ReadOrWait(
ReadType readType) {
auto now = TimeStamp::Now();
LOG(Info, "Reading %s\n", mPath.get());

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

@ -66,32 +66,31 @@ class URLPreloader final : public nsIObserver, public nsIMemoryReporter {
// representations. If the preloader has not yet been initialized, or the
// given location is not supported by the cache, the entries will be read
// synchronously, and not stored in the cache.
static Result<const nsCString, nsresult> Read(FileLocation& location,
static Result<nsCString, nsresult> Read(FileLocation& location,
ReadType readType = Forget);
static Result<const nsCString, nsresult> ReadURI(nsIURI* uri,
static Result<nsCString, nsresult> ReadURI(nsIURI* uri,
ReadType readType = Forget);
static Result<const nsCString, nsresult> ReadFile(nsIFile* file,
static Result<nsCString, nsresult> ReadFile(nsIFile* file,
ReadType readType = Forget);
static Result<const nsCString, nsresult> ReadZip(CacheAwareZipReader* archive,
static Result<nsCString, nsresult> ReadZip(CacheAwareZipReader* archive,
const nsACString& path,
ReadType readType = Forget);
private:
struct CacheKey;
Result<const nsCString, nsresult> ReadInternal(const CacheKey& key,
Result<nsCString, nsresult> ReadInternal(const CacheKey& key,
ReadType readType);
Result<const nsCString, nsresult> ReadURIInternal(nsIURI* uri,
Result<nsCString, nsresult> ReadURIInternal(nsIURI* uri, ReadType readType);
Result<nsCString, nsresult> ReadFileInternal(nsIFile* file,
ReadType readType);
Result<const nsCString, nsresult> ReadFileInternal(nsIFile* file,
ReadType readType);
static Result<const nsCString, nsresult> Read(const CacheKey& key,
static Result<nsCString, nsresult> Read(const CacheKey& key,
ReadType readType);
static bool sInitialized;
@ -239,9 +238,8 @@ class URLPreloader final : public nsIObserver, public nsIMemoryReporter {
}
}
Result<const nsCString, nsresult> Read();
static Result<const nsCString, nsresult> ReadLocation(
FileLocation& location);
Result<nsCString, nsresult> Read();
static Result<nsCString, nsresult> ReadLocation(FileLocation& location);
size_t SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf) const {
return (mallocSizeOf(this) +
@ -252,7 +250,7 @@ class URLPreloader final : public nsIObserver, public nsIMemoryReporter {
// Reads the contents of the file referenced by this entry, or wait for
// an off-thread read operation to finish if it is currently pending,
// and return the file's contents.
Result<const nsCString, nsresult> ReadOrWait(ReadType readType);
Result<nsCString, nsresult> ReadOrWait(ReadType readType);
nsCString mData;

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

@ -319,9 +319,21 @@ auto ToResult(Result<V, E>&& aValue)
* `nullptr` to indicate errors.
* What screwups? See <https://bugzilla.mozilla.org/show_bug.cgi?id=912928> for
* a partial list.
*
* Result<const V, E> or Result<V, const E> are not meaningful. The success or
* error values in a Result instance are non-modifiable in-place anyway. This
* guarantee must also be maintained when evolving Result. They can be
* unwrap()ped, but this loses const qualification. However, Result<const V, E>
* or Result<V, const E> may be misleading and prevent movability. Just use
* Result<V, E>. (Result<const V*, E> may make sense though, just Result<const
* V* const, E> is not possible.)
*/
template <typename V, typename E>
class MOZ_MUST_USE_TYPE Result final {
// See class comment on Result<const V, E> and Result<V, const E>.
static_assert(!std::is_const_v<V>);
static_assert(!std::is_const_v<E>);
using Impl = typename detail::SelectResultImpl<V, E>::Type;
Impl mImpl;