diff --git a/dom/media/mp4/Index.cpp b/dom/media/mp4/Index.cpp index 9da7de9869b9..978f960a2d3a 100644 --- a/dom/media/mp4/Index.cpp +++ b/dom/media/mp4/Index.cpp @@ -298,7 +298,7 @@ CencSampleEncryptionInfoEntry* SampleIterator::GetSampleEncryptionEntry() { : &entries->ElementAt(groupIndex - 1); } -Result SampleIterator::GetEncryptionScheme() { +Result SampleIterator::GetEncryptionScheme() { // See ISO/IEC 23001-7 for information on the metadata being checked. MoofParser* moofParser = mIndex->mMoofParser.get(); if (!moofParser) { diff --git a/dom/media/mp4/Index.h b/dom/media/mp4/Index.h index 3dd554e69428..db9acbd73582 100644 --- a/dom/media/mp4/Index.h +++ b/dom/media/mp4/Index.h @@ -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 GetEncryptionScheme(); + Result GetEncryptionScheme(); void Next(); RefPtr mIndex; diff --git a/js/xpconnect/loader/URLPreloader.cpp b/js/xpconnect/loader/URLPreloader.cpp index a77d39e98aed..e540469988fa 100644 --- a/js/xpconnect/loader/URLPreloader.cpp +++ b/js/xpconnect/loader/URLPreloader.cpp @@ -436,8 +436,8 @@ void URLPreloader::BeginBackgroundRead() { } } -Result URLPreloader::ReadInternal( - const CacheKey& key, ReadType readType) { +Result URLPreloader::ReadInternal(const CacheKey& key, + ReadType readType) { if (mStartupFinished) { URLEntry entry(key); @@ -451,16 +451,16 @@ Result URLPreloader::ReadInternal( return entry->ReadOrWait(readType); } -Result URLPreloader::ReadURIInternal( - nsIURI* uri, ReadType readType) { +Result URLPreloader::ReadURIInternal(nsIURI* uri, + ReadType readType) { CacheKey key; MOZ_TRY_VAR(key, ResolveURI(uri)); return ReadInternal(key, readType); } -/* static */ Result URLPreloader::Read( - const CacheKey& key, ReadType readType) { +/* static */ Result 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 URLPreloader::ReadURIInternal( return GetSingleton().ReadInternal(key, readType); } -/* static */ Result URLPreloader::ReadURI( +/* static */ Result URLPreloader::ReadURI( nsIURI* uri, ReadType readType) { if (!sInitialized) { return Err(NS_ERROR_NOT_INITIALIZED); @@ -481,12 +481,12 @@ Result URLPreloader::ReadURIInternal( return GetSingleton().ReadURIInternal(uri, readType); } -/* static */ Result URLPreloader::ReadFile( +/* static */ Result URLPreloader::ReadFile( nsIFile* file, ReadType readType) { return Read(CacheKey(file), readType); } -/* static */ Result URLPreloader::Read( +/* static */ Result URLPreloader::Read( FileLocation& location, ReadType readType) { if (location.IsZip()) { if (location.GetBaseZip()) { @@ -501,7 +501,7 @@ Result URLPreloader::ReadURIInternal( return ReadFile(file, readType); } -/* static */ Result URLPreloader::ReadZip( +/* static */ Result 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 URLPreloader::CacheKey::ToFileLocation() { return FileLocation(zip, mPath.get()); } -Result URLPreloader::URLEntry::Read() { +Result URLPreloader::URLEntry::Read() { FileLocation location; MOZ_TRY_VAR(location, ToFileLocation()); @@ -600,8 +600,8 @@ Result URLPreloader::URLEntry::Read() { return mData; } -/* static */ Result -URLPreloader::URLEntry::ReadLocation(FileLocation& location) { +/* static */ Result 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 URLPreloader::URLEntry::ReadOrWait( +Result URLPreloader::URLEntry::ReadOrWait( ReadType readType) { auto now = TimeStamp::Now(); LOG(Info, "Reading %s\n", mPath.get()); diff --git a/js/xpconnect/loader/URLPreloader.h b/js/xpconnect/loader/URLPreloader.h index c168c42d92cb..f866e2e8c805 100644 --- a/js/xpconnect/loader/URLPreloader.h +++ b/js/xpconnect/loader/URLPreloader.h @@ -66,33 +66,32 @@ 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 Read(FileLocation& location, - ReadType readType = Forget); + static Result Read(FileLocation& location, + ReadType readType = Forget); - static Result ReadURI(nsIURI* uri, - ReadType readType = Forget); + static Result ReadURI(nsIURI* uri, + ReadType readType = Forget); - static Result ReadFile(nsIFile* file, - ReadType readType = Forget); + static Result ReadFile(nsIFile* file, + ReadType readType = Forget); - static Result ReadZip(CacheAwareZipReader* archive, - const nsACString& path, - ReadType readType = Forget); + static Result ReadZip(CacheAwareZipReader* archive, + const nsACString& path, + ReadType readType = Forget); private: struct CacheKey; - Result ReadInternal(const CacheKey& key, - ReadType readType); + Result ReadInternal(const CacheKey& key, + ReadType readType); - Result ReadURIInternal(nsIURI* uri, - ReadType readType); + Result ReadURIInternal(nsIURI* uri, ReadType readType); - Result ReadFileInternal(nsIFile* file, - ReadType readType); + Result ReadFileInternal(nsIFile* file, + ReadType readType); - static Result Read(const CacheKey& key, - ReadType readType); + static Result Read(const CacheKey& key, + ReadType readType); static bool sInitialized; @@ -239,9 +238,8 @@ class URLPreloader final : public nsIObserver, public nsIMemoryReporter { } } - Result Read(); - static Result ReadLocation( - FileLocation& location); + Result Read(); + static Result 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 ReadOrWait(ReadType readType); + Result ReadOrWait(ReadType readType); nsCString mData; diff --git a/mfbt/Result.h b/mfbt/Result.h index cf6b8d78e480..97932b589b97 100644 --- a/mfbt/Result.h +++ b/mfbt/Result.h @@ -319,9 +319,21 @@ auto ToResult(Result&& aValue) * `nullptr` to indicate errors. * What screwups? See for * a partial list. + * + * Result or Result 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 + * or Result may be misleading and prevent movability. Just use + * Result. (Result may make sense though, just Result is not possible.) */ template class MOZ_MUST_USE_TYPE Result final { + // See class comment on Result and Result. + static_assert(!std::is_const_v); + static_assert(!std::is_const_v); + using Impl = typename detail::SelectResultImpl::Type; Impl mImpl;