Bug 1640839 - Stop generating count of WebIDL enum values, use standard enum traits instead. r=mccr8

Differential Revision: https://phabricator.services.mozilla.com/D201345
This commit is contained in:
Peter Van der Beken 2024-03-02 07:50:25 +00:00
Родитель 62bdf442eb
Коммит b4eccf070d
8 изменённых файлов: 40 добавлений и 65 удалений

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

@ -1368,7 +1368,8 @@ void ChromeUtils::ClearStyleSheetCache(GlobalObject&) {
static WebIDLProcType ProcTypeToWebIDL(mozilla::ProcType aType) {
// Max is the value of the last enum, not the length, so add one.
static_assert(
WebIDLProcTypeValues::Count == static_cast<size_t>(ProcType::Max) + 1,
static_cast<size_t>(MaxContiguousEnumValue<WebIDLProcType>::value) ==
static_cast<size_t>(ProcType::Max),
"In order for this static cast to be okay, "
"WebIDLProcType must match ProcType exactly");

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

@ -12371,21 +12371,7 @@ class CGEnum(CGThing):
def __init__(self, enum):
CGThing.__init__(self)
self.enum = enum
entryDecl = fill(
"""
static constexpr size_t Count = ${count};
static_assert(mozilla::ArrayLength(binding_detail::EnumStrings<${name}>::Values) == Count,
"Mismatch between enum strings and enum count");
""",
count=self.nEnumStrings(),
name=self.enum.identifier.name,
type=CGEnum.underlyingType(enum),
)
strings = CGList(
[
CGNamespace(
strings = CGNamespace(
"binding_detail",
CGGeneric(
declare=fill(
@ -12405,27 +12391,13 @@ class CGEnum(CGThing):
""",
name=self.enum.identifier.name,
count=self.nEnumStrings(),
entries="".join(
'"%s"_ns,\n' % val for val in self.enum.values()
entries="".join('"%s"_ns,\n' % val for val in self.enum.values()),
),
),
),
),
CGNamespace(
self.stringsNamespace(),
CGGeneric(
declare=entryDecl,
),
),
],
"\n",
)
toJSValue = CGEnumToJSValue(enum)
self.cgThings = CGList([strings, toJSValue], "\n")
def stringsNamespace(self):
return self.enum.identifier.name + "Values"
def nEnumStrings(self):
return len(self.enum.values())
@ -12475,6 +12447,8 @@ class CGMaxContiguousEnumValue(CGThing):
static_assert(static_cast<${ty}>(dom::${name}::${minValue}) == 0,
"We rely on this in ContiguousEnumValues");
static_assert(mozilla::ArrayLength(dom::binding_detail::EnumStrings<dom::${name}>::Values) - 1 == UnderlyingValue(value),
"Mismatch between enum strings and enum count");
};
""",
name=self.enum.identifier.name,

3
dom/cache/CacheStorage.cpp поставляемый
Просмотреть файл

@ -467,7 +467,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 == CacheStorageNamespaceValues::Count,
static_assert(
NUMBER_OF_NAMESPACES == ContiguousEnumSize<CacheStorageNamespace>::value,
"Number of namespace should match webidl count");
Namespace ns = static_cast<Namespace>(aNamespace);

14
dom/cache/DBSchema.cpp поставляемый
Просмотреть файл

@ -278,7 +278,7 @@ static_assert(int(HeadersGuardEnum::None) == 0 &&
int(HeadersGuardEnum::Request_no_cors) == 2 &&
int(HeadersGuardEnum::Response) == 3 &&
int(HeadersGuardEnum::Immutable) == 4 &&
HeadersGuardEnumValues::Count == 5,
ContiguousEnumSize<HeadersGuardEnum>::value == 5,
"HeadersGuardEnum values are as expected");
static_assert(int(ReferrerPolicy::_empty) == 0 &&
int(ReferrerPolicy::No_referrer) == 1 &&
@ -289,18 +289,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 &&
ReferrerPolicyValues::Count == 9,
ContiguousEnumSize<ReferrerPolicy>::value == 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 &&
RequestModeValues::Count == 4,
ContiguousEnumSize<RequestMode>::value == 4,
"RequestMode values are as expected");
static_assert(int(RequestCredentials::Omit) == 0 &&
int(RequestCredentials::Same_origin) == 1 &&
int(RequestCredentials::Include) == 2 &&
RequestCredentialsValues::Count == 3,
ContiguousEnumSize<RequestCredentials>::value == 3,
"RequestCredentials values are as expected");
static_assert(int(RequestCache::Default) == 0 &&
int(RequestCache::No_store) == 1 &&
@ -308,19 +308,19 @@ static_assert(int(RequestCache::Default) == 0 &&
int(RequestCache::No_cache) == 3 &&
int(RequestCache::Force_cache) == 4 &&
int(RequestCache::Only_if_cached) == 5 &&
RequestCacheValues::Count == 6,
ContiguousEnumSize<RequestCache>::value == 6,
"RequestCache values are as expected");
static_assert(int(RequestRedirect::Follow) == 0 &&
int(RequestRedirect::Error) == 1 &&
int(RequestRedirect::Manual) == 2 &&
RequestRedirectValues::Count == 3,
ContiguousEnumSize<RequestRedirect>::value == 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 &&
ResponseTypeValues::Count == 6,
ContiguousEnumSize<ResponseType>::value == 6,
"ResponseType values are as expected");
// If the static_asserts below fails, it means that you have changed the

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

@ -24,7 +24,7 @@ static const nsLiteralCString kPermissionTypes[] = {
// clang-format on
};
const size_t kPermissionNameCount = PermissionNameValues::Count;
const size_t kPermissionNameCount = ContiguousEnumSize<PermissionName>::value;
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 ==
ServiceWorkerStateValues::Count,
ContiguousEnumSize<ServiceWorkerState>::value,
"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 == RequestRedirectValues::Count,
3 == ContiguousEnumSize<RequestRedirect>::value,
"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 == RequestCacheValues::Count,
6 == ContiguousEnumSize<RequestCache>::value,
"RequestCache enumeration value should match Necko Cache mode value.");
static_assert(static_cast<uint16_t>(ServiceWorkerUpdateViaCache::Imports) ==

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

@ -406,10 +406,9 @@ nsresult ExtensionPolicyService::InjectContentScripts(
DocInfo docInfo(win);
using RunAt = dom::ContentScriptRunAt;
namespace RunAtValues = dom::ContentScriptRunAtValues;
using Scripts = AutoTArray<RefPtr<WebExtensionContentScript>, 8>;
Scripts scripts[RunAtValues::Count];
Scripts scripts[ContiguousEnumSize<RunAt>::value];
auto GetScripts = [&](RunAt aRunAt) -> Scripts&& {
static_assert(sizeof(aRunAt) == 1, "Our cast is wrong");