mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1582892. Expose the number of strings in a Web IDL enum in a nice way. r=edgar
Differential Revision: https://phabricator.services.mozilla.com/D49536 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
ae5334abca
commit
a0b4a1fee2
@ -672,12 +672,11 @@ void ChromeUtils::ClearRecentJSDevError(GlobalObject&) {
|
||||
return WebIDLProcType::_webidl
|
||||
|
||||
static WebIDLProcType ProcTypeToWebIDL(mozilla::ProcType aType) {
|
||||
// |strings| contains an extra non-enum value, so subtract one.
|
||||
// Max is the value of the last enum, not the length, so add one.
|
||||
static_assert(ArrayLength(WebIDLProcTypeValues::strings) - 1 ==
|
||||
static_cast<size_t>(ProcType::Max) + 1,
|
||||
"In order for this static cast to be okay, "
|
||||
"WebIDLProcType must match ProcType exactly");
|
||||
static_assert(
|
||||
WebIDLProcTypeValues::Count == static_cast<size_t>(ProcType::Max) + 1,
|
||||
"In order for this static cast to be okay, "
|
||||
"WebIDLProcType must match ProcType exactly");
|
||||
|
||||
switch (aType) {
|
||||
PROCTYPE_TO_WEBIDL_CASE(Web, Web);
|
||||
|
@ -10098,17 +10098,25 @@ class CGEnum(CGThing):
|
||||
"""
|
||||
extern const EnumEntry ${entry_array}[${entry_count}];
|
||||
|
||||
static_assert(static_cast<size_t>(${name}::EndGuard_) == ${entry_count} - 1,
|
||||
"Mismatch between enum strings and enum values");
|
||||
static constexpr size_t Count = ${real_entry_count};
|
||||
|
||||
// Our "${entry_array}" contains an extra entry with a null string.
|
||||
static_assert(mozilla::ArrayLength(${entry_array}) - 1 == Count,
|
||||
"Mismatch between enum strings and enum count");
|
||||
|
||||
static_assert(static_cast<size_t>(${name}::EndGuard_) == Count,
|
||||
"Mismatch between enum value and enum count");
|
||||
|
||||
inline Span<const char> GetString(${name} stringId) {
|
||||
MOZ_ASSERT(static_cast<${type}>(stringId) < static_cast<${type}>(${name}::EndGuard_));
|
||||
MOZ_ASSERT(static_cast<${type}>(stringId) < Count);
|
||||
const EnumEntry& entry = ${entry_array}[static_cast<${type}>(stringId)];
|
||||
return MakeSpan(entry.value, entry.length);
|
||||
}
|
||||
""",
|
||||
entry_array=ENUM_ENTRY_VARIABLE_NAME,
|
||||
entry_count=self.nEnumStrings(),
|
||||
# -1 because nEnumStrings() includes a string for EndGuard_
|
||||
real_entry_count=self.nEnumStrings() - 1,
|
||||
name=self.enum.identifier.name,
|
||||
type=self.underlyingType())
|
||||
strings = CGNamespace(
|
||||
@ -14931,6 +14939,7 @@ class CGBindingRoot(CGThing):
|
||||
cgthings.extend(CGEnum(e) for e in enums)
|
||||
|
||||
bindingDeclareHeaders["mozilla/Span.h"] = enums
|
||||
bindingDeclareHeaders["mozilla/ArrayUtils.h"] = enums
|
||||
|
||||
hasCode = (descriptors or callbackDescriptors or dictionaries or
|
||||
callbacks)
|
||||
|
5
dom/cache/CacheStorage.cpp
vendored
5
dom/cache/CacheStorage.cpp
vendored
@ -470,9 +470,8 @@ already_AddRefed<CacheStorage> CacheStorage::Constructor(
|
||||
static_assert(
|
||||
CHROME_ONLY_NAMESPACE == (uint32_t)CacheStorageNamespace::Chrome,
|
||||
"Chrome namespace should match webidl Chrome enum");
|
||||
static_assert(
|
||||
NUMBER_OF_NAMESPACES == (uint32_t)CacheStorageNamespace::EndGuard_,
|
||||
"Number of namespace should match webidl endguard enum");
|
||||
static_assert(NUMBER_OF_NAMESPACES == CacheStorageNamespaceValues::Count,
|
||||
"Number of namespace should match webidl count");
|
||||
|
||||
Namespace ns = static_cast<Namespace>(aNamespace);
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
|
14
dom/cache/DBSchema.cpp
vendored
14
dom/cache/DBSchema.cpp
vendored
@ -229,7 +229,7 @@ static_assert(int(HeadersGuardEnum::None) == 0 &&
|
||||
int(HeadersGuardEnum::Request_no_cors) == 2 &&
|
||||
int(HeadersGuardEnum::Response) == 3 &&
|
||||
int(HeadersGuardEnum::Immutable) == 4 &&
|
||||
int(HeadersGuardEnum::EndGuard_) == 5,
|
||||
HeadersGuardEnumValues::Count == 5,
|
||||
"HeadersGuardEnum values are as expected");
|
||||
static_assert(int(ReferrerPolicy::_empty) == 0 &&
|
||||
int(ReferrerPolicy::No_referrer) == 1 &&
|
||||
@ -240,18 +240,18 @@ static_assert(int(ReferrerPolicy::_empty) == 0 &&
|
||||
int(ReferrerPolicy::Same_origin) == 6 &&
|
||||
int(ReferrerPolicy::Strict_origin) == 7 &&
|
||||
int(ReferrerPolicy::Strict_origin_when_cross_origin) == 8 &&
|
||||
int(ReferrerPolicy::EndGuard_) == 9,
|
||||
ReferrerPolicyValues::Count == 9,
|
||||
"ReferrerPolicy values are as expected");
|
||||
static_assert(int(RequestMode::Same_origin) == 0 &&
|
||||
int(RequestMode::No_cors) == 1 &&
|
||||
int(RequestMode::Cors) == 2 &&
|
||||
int(RequestMode::Navigate) == 3 &&
|
||||
int(RequestMode::EndGuard_) == 4,
|
||||
RequestModeValues::Count == 4,
|
||||
"RequestMode values are as expected");
|
||||
static_assert(int(RequestCredentials::Omit) == 0 &&
|
||||
int(RequestCredentials::Same_origin) == 1 &&
|
||||
int(RequestCredentials::Include) == 2 &&
|
||||
int(RequestCredentials::EndGuard_) == 3,
|
||||
RequestCredentialsValues::Count == 3,
|
||||
"RequestCredentials values are as expected");
|
||||
static_assert(int(RequestCache::Default) == 0 &&
|
||||
int(RequestCache::No_store) == 1 &&
|
||||
@ -259,19 +259,19 @@ static_assert(int(RequestCache::Default) == 0 &&
|
||||
int(RequestCache::No_cache) == 3 &&
|
||||
int(RequestCache::Force_cache) == 4 &&
|
||||
int(RequestCache::Only_if_cached) == 5 &&
|
||||
int(RequestCache::EndGuard_) == 6,
|
||||
RequestCacheValues::Count == 6,
|
||||
"RequestCache values are as expected");
|
||||
static_assert(int(RequestRedirect::Follow) == 0 &&
|
||||
int(RequestRedirect::Error) == 1 &&
|
||||
int(RequestRedirect::Manual) == 2 &&
|
||||
int(RequestRedirect::EndGuard_) == 3,
|
||||
RequestRedirectValues::Count == 3,
|
||||
"RequestRedirect values are as expected");
|
||||
static_assert(int(ResponseType::Basic) == 0 && int(ResponseType::Cors) == 1 &&
|
||||
int(ResponseType::Default) == 2 &&
|
||||
int(ResponseType::Error) == 3 &&
|
||||
int(ResponseType::Opaque) == 4 &&
|
||||
int(ResponseType::Opaqueredirect) == 5 &&
|
||||
int(ResponseType::EndGuard_) == 6,
|
||||
ResponseTypeValues::Count == 6,
|
||||
"ResponseType values are as expected");
|
||||
|
||||
// If the static_asserts below fails, it means that you have changed the
|
||||
|
@ -56,7 +56,7 @@ ConsoleLogLevel PrefToValue(const nsAString& aPref) {
|
||||
return ConsoleLogLevel::All;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(index < (int)ConsoleLogLevel::EndGuard_);
|
||||
MOZ_ASSERT(index < (int)ConsoleLogLevelValues::Count);
|
||||
return static_cast<ConsoleLogLevel>(index);
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ class MediaSession final : public nsISupports, public nsWrapperCache {
|
||||
nsCOMPtr<nsPIDOMWindowInner> mParent;
|
||||
|
||||
RefPtr<MediaMetadata> mMediaMetadata;
|
||||
static const size_t ACTIONS = ArrayLength(MediaSessionActionValues::strings);
|
||||
static const size_t ACTIONS = MediaSessionActionValues::Count;
|
||||
RefPtr<MediaSessionActionHandler> mActionHandlers[ACTIONS] = {nullptr};
|
||||
};
|
||||
|
||||
|
@ -19,9 +19,7 @@ static const nsLiteralCString kPermissionTypes[] = {
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
// `-1` for the last null entry.
|
||||
const size_t kPermissionNameCount =
|
||||
MOZ_ARRAY_LENGTH(PermissionNameValues::strings) - 1;
|
||||
const size_t kPermissionNameCount = PermissionNameValues::Count;
|
||||
|
||||
static_assert(MOZ_ARRAY_LENGTH(kPermissionTypes) == kPermissionNameCount,
|
||||
"kPermissionTypes and PermissionName count should match");
|
||||
|
@ -43,7 +43,7 @@ static_assert(nsIServiceWorkerInfo::STATE_REDUNDANT ==
|
||||
"ServiceWorkerState enumeration value should match state values "
|
||||
"from nsIServiceWorkerInfo.");
|
||||
static_assert(nsIServiceWorkerInfo::STATE_UNKNOWN ==
|
||||
static_cast<uint16_t>(ServiceWorkerState::EndGuard_),
|
||||
ServiceWorkerStateValues::Count,
|
||||
"ServiceWorkerState enumeration value should match state values "
|
||||
"from nsIServiceWorkerInfo.");
|
||||
|
||||
|
@ -127,7 +127,7 @@ static_assert(
|
||||
static_cast<uint32_t>(RequestRedirect::Manual),
|
||||
"RequestRedirect enumeration value should make Necko Redirect mode value.");
|
||||
static_assert(
|
||||
3 == static_cast<uint32_t>(RequestRedirect::EndGuard_),
|
||||
3 == RequestRedirectValues::Count,
|
||||
"RequestRedirect enumeration value should make Necko Redirect mode value.");
|
||||
|
||||
static_assert(
|
||||
@ -155,7 +155,7 @@ static_assert(
|
||||
static_cast<uint32_t>(RequestCache::Only_if_cached),
|
||||
"RequestCache enumeration value should match Necko Cache mode value.");
|
||||
static_assert(
|
||||
6 == static_cast<uint32_t>(RequestCache::EndGuard_),
|
||||
6 == RequestCacheValues::Count,
|
||||
"RequestCache enumeration value should match Necko Cache mode value.");
|
||||
|
||||
static_assert(static_cast<uint16_t>(ServiceWorkerUpdateViaCache::Imports) ==
|
||||
|
@ -539,8 +539,7 @@ already_AddRefed<Promise> WebAuthnManager::GetAssertion(
|
||||
NS_ConvertUTF16toUTF8 cStr(str);
|
||||
int i = FindEnumStringIndexImpl(
|
||||
cStr.get(), cStr.Length(), AuthenticatorTransportValues::strings);
|
||||
if (i < 0 ||
|
||||
i >= static_cast<int>(AuthenticatorTransport::EndGuard_)) {
|
||||
if (i < 0) {
|
||||
continue; // Unknown enum
|
||||
}
|
||||
AuthenticatorTransport t = static_cast<AuthenticatorTransport>(i);
|
||||
|
@ -350,12 +350,13 @@ nsresult ExtensionPolicyService::InjectContentScripts(
|
||||
DocInfo docInfo(win);
|
||||
|
||||
using RunAt = dom::ContentScriptRunAt;
|
||||
namespace RunAtValues = dom::ContentScriptRunAtValues;
|
||||
using Scripts = AutoTArray<RefPtr<WebExtensionContentScript>, 8>;
|
||||
|
||||
constexpr uint8_t n = uint8_t(RunAt::EndGuard_);
|
||||
Scripts scripts[n];
|
||||
Scripts scripts[RunAtValues::Count];
|
||||
|
||||
auto GetScripts = [&](RunAt aRunAt) -> Scripts&& {
|
||||
static_assert(sizeof(aRunAt) == 1, "Our cast is wrong");
|
||||
return std::move(scripts[uint8_t(aRunAt)]);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user