diff --git a/dom/base/ChromeUtils.cpp b/dom/base/ChromeUtils.cpp index cdf0ea21085d..0df1cd3c9b74 100644 --- a/dom/base/ChromeUtils.cpp +++ b/dom/base/ChromeUtils.cpp @@ -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(ProcType::Max) + 1, + static_cast(MaxContiguousEnumValue::value) == + static_cast(ProcType::Max), "In order for this static cast to be okay, " "WebIDLProcType must match ProcType exactly"); diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 00c37ceca6eb..aa74838b984b 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -12371,61 +12371,33 @@ 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( - "binding_detail", - CGGeneric( - declare=fill( - """ - template <> struct EnumStrings<${name}> { - static const nsLiteralCString Values[${count}]; - }; - """, - name=self.enum.identifier.name, - count=self.nEnumStrings(), - ), - define=fill( - """ - const nsLiteralCString EnumStrings<${name}>::Values[${count}] = { - $*{entries} - }; - """, - name=self.enum.identifier.name, - count=self.nEnumStrings(), - entries="".join( - '"%s"_ns,\n' % val for val in self.enum.values() - ), - ), - ), + strings = CGNamespace( + "binding_detail", + CGGeneric( + declare=fill( + """ + template <> struct EnumStrings<${name}> { + static const nsLiteralCString Values[${count}]; + }; + """, + name=self.enum.identifier.name, + count=self.nEnumStrings(), ), - CGNamespace( - self.stringsNamespace(), - CGGeneric( - declare=entryDecl, - ), + define=fill( + """ + const nsLiteralCString EnumStrings<${name}>::Values[${count}] = { + $*{entries} + }; + """, + name=self.enum.identifier.name, + count=self.nEnumStrings(), + entries="".join('"%s"_ns,\n' % val for val in self.enum.values()), ), - ], - "\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::Values) - 1 == UnderlyingValue(value), + "Mismatch between enum strings and enum count"); }; """, name=self.enum.identifier.name, diff --git a/dom/cache/CacheStorage.cpp b/dom/cache/CacheStorage.cpp index e2622fafa2f2..b5647ba7910f 100644 --- a/dom/cache/CacheStorage.cpp +++ b/dom/cache/CacheStorage.cpp @@ -467,8 +467,9 @@ already_AddRefed 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, - "Number of namespace should match webidl count"); + static_assert( + NUMBER_OF_NAMESPACES == ContiguousEnumSize::value, + "Number of namespace should match webidl count"); Namespace ns = static_cast(aNamespace); nsCOMPtr global = do_QueryInterface(aGlobal.GetAsSupports()); diff --git a/dom/cache/DBSchema.cpp b/dom/cache/DBSchema.cpp index a7e16fda227d..0c2c9cd4fbf7 100644 --- a/dom/cache/DBSchema.cpp +++ b/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::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::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::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::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::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::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::value == 6, "ResponseType values are as expected"); // If the static_asserts below fails, it means that you have changed the diff --git a/dom/permission/PermissionUtils.cpp b/dom/permission/PermissionUtils.cpp index 26e3ec015760..604fa0116783 100644 --- a/dom/permission/PermissionUtils.cpp +++ b/dom/permission/PermissionUtils.cpp @@ -24,7 +24,7 @@ static const nsLiteralCString kPermissionTypes[] = { // clang-format on }; -const size_t kPermissionNameCount = PermissionNameValues::Count; +const size_t kPermissionNameCount = ContiguousEnumSize::value; static_assert(MOZ_ARRAY_LENGTH(kPermissionTypes) == kPermissionNameCount, "kPermissionTypes and PermissionName count should match"); diff --git a/dom/serviceworkers/ServiceWorkerInfo.cpp b/dom/serviceworkers/ServiceWorkerInfo.cpp index e9c095b0b4ae..2689af6ee9af 100644 --- a/dom/serviceworkers/ServiceWorkerInfo.cpp +++ b/dom/serviceworkers/ServiceWorkerInfo.cpp @@ -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::value, "ServiceWorkerState enumeration value should match state values " "from nsIServiceWorkerInfo."); diff --git a/dom/serviceworkers/ServiceWorkerManager.cpp b/dom/serviceworkers/ServiceWorkerManager.cpp index b0dcfca8930f..842939d78511 100644 --- a/dom/serviceworkers/ServiceWorkerManager.cpp +++ b/dom/serviceworkers/ServiceWorkerManager.cpp @@ -127,7 +127,7 @@ static_assert( static_cast(RequestRedirect::Manual), "RequestRedirect enumeration value should make Necko Redirect mode value."); static_assert( - 3 == RequestRedirectValues::Count, + 3 == ContiguousEnumSize::value, "RequestRedirect enumeration value should make Necko Redirect mode value."); static_assert( @@ -155,7 +155,7 @@ static_assert( static_cast(RequestCache::Only_if_cached), "RequestCache enumeration value should match Necko Cache mode value."); static_assert( - 6 == RequestCacheValues::Count, + 6 == ContiguousEnumSize::value, "RequestCache enumeration value should match Necko Cache mode value."); static_assert(static_cast(ServiceWorkerUpdateViaCache::Imports) == diff --git a/toolkit/components/extensions/ExtensionPolicyService.cpp b/toolkit/components/extensions/ExtensionPolicyService.cpp index 031abca444da..6299a08c7d35 100644 --- a/toolkit/components/extensions/ExtensionPolicyService.cpp +++ b/toolkit/components/extensions/ExtensionPolicyService.cpp @@ -406,10 +406,9 @@ nsresult ExtensionPolicyService::InjectContentScripts( DocInfo docInfo(win); using RunAt = dom::ContentScriptRunAt; - namespace RunAtValues = dom::ContentScriptRunAtValues; using Scripts = AutoTArray, 8>; - Scripts scripts[RunAtValues::Count]; + Scripts scripts[ContiguousEnumSize::value]; auto GetScripts = [&](RunAt aRunAt) -> Scripts&& { static_assert(sizeof(aRunAt) == 1, "Our cast is wrong");