ResolveResult.h (1794B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef js_loader_ResolveResult_h 8 #define js_loader_ResolveResult_h 9 10 #include "mozilla/ResultVariant.h" 11 #include "mozilla/NotNull.h" 12 #include "nsIURI.h" 13 14 namespace JS::loader { 15 16 enum class ResolveError : uint8_t { 17 Failure, 18 FailureMayBeBare, 19 BlockedByNullEntry, 20 BlockedByAfterPrefix, 21 BlockedByBacktrackingPrefix, 22 InvalidBareSpecifier, 23 Length 24 }; 25 26 struct ResolveErrorInfo { 27 static const char* GetString(ResolveError aError) { 28 switch (aError) { 29 case ResolveError::Failure: 30 return "ModuleResolveFailureNoWarn"; 31 case ResolveError::FailureMayBeBare: 32 return "ModuleResolveFailureWarnRelative"; 33 case ResolveError::BlockedByNullEntry: 34 return "ImportMapResolutionBlockedByNullEntry"; 35 case ResolveError::BlockedByAfterPrefix: 36 return "ImportMapResolutionBlockedByAfterPrefix"; 37 case ResolveError::BlockedByBacktrackingPrefix: 38 return "ImportMapResolutionBlockedByBacktrackingPrefix"; 39 case ResolveError::InvalidBareSpecifier: 40 return "ImportMapResolveInvalidBareSpecifierWarnRelative"; 41 default: 42 MOZ_CRASH("Unexpected ResolveError value"); 43 } 44 } 45 }; 46 47 /** 48 * ResolveResult is used to store the result of 'resolving a module specifier', 49 * which could be an URI on success or a ResolveError on failure. 50 */ 51 using ResolveResult = 52 mozilla::Result<mozilla::NotNull<nsCOMPtr<nsIURI>>, ResolveError>; 53 54 } // namespace JS::loader 55 56 #endif // js_loader_ResolveResult_h