зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
62bdf442eb
Коммит
b4eccf070d
|
@ -1368,7 +1368,8 @@ void ChromeUtils::ClearStyleSheetCache(GlobalObject&) {
|
||||||
static WebIDLProcType ProcTypeToWebIDL(mozilla::ProcType aType) {
|
static WebIDLProcType ProcTypeToWebIDL(mozilla::ProcType aType) {
|
||||||
// Max is the value of the last enum, not the length, so add one.
|
// Max is the value of the last enum, not the length, so add one.
|
||||||
static_assert(
|
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, "
|
"In order for this static cast to be okay, "
|
||||||
"WebIDLProcType must match ProcType exactly");
|
"WebIDLProcType must match ProcType exactly");
|
||||||
|
|
||||||
|
|
|
@ -12371,61 +12371,33 @@ class CGEnum(CGThing):
|
||||||
def __init__(self, enum):
|
def __init__(self, enum):
|
||||||
CGThing.__init__(self)
|
CGThing.__init__(self)
|
||||||
self.enum = enum
|
self.enum = enum
|
||||||
entryDecl = fill(
|
strings = CGNamespace(
|
||||||
"""
|
"binding_detail",
|
||||||
static constexpr size_t Count = ${count};
|
CGGeneric(
|
||||||
|
declare=fill(
|
||||||
static_assert(mozilla::ArrayLength(binding_detail::EnumStrings<${name}>::Values) == Count,
|
"""
|
||||||
"Mismatch between enum strings and enum count");
|
template <> struct EnumStrings<${name}> {
|
||||||
|
static const nsLiteralCString Values[${count}];
|
||||||
""",
|
};
|
||||||
count=self.nEnumStrings(),
|
""",
|
||||||
name=self.enum.identifier.name,
|
name=self.enum.identifier.name,
|
||||||
type=CGEnum.underlyingType(enum),
|
count=self.nEnumStrings(),
|
||||||
)
|
|
||||||
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()
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
CGNamespace(
|
define=fill(
|
||||||
self.stringsNamespace(),
|
"""
|
||||||
CGGeneric(
|
const nsLiteralCString EnumStrings<${name}>::Values[${count}] = {
|
||||||
declare=entryDecl,
|
$*{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)
|
toJSValue = CGEnumToJSValue(enum)
|
||||||
self.cgThings = CGList([strings, toJSValue], "\n")
|
self.cgThings = CGList([strings, toJSValue], "\n")
|
||||||
|
|
||||||
def stringsNamespace(self):
|
|
||||||
return self.enum.identifier.name + "Values"
|
|
||||||
|
|
||||||
def nEnumStrings(self):
|
def nEnumStrings(self):
|
||||||
return len(self.enum.values())
|
return len(self.enum.values())
|
||||||
|
|
||||||
|
@ -12475,6 +12447,8 @@ class CGMaxContiguousEnumValue(CGThing):
|
||||||
|
|
||||||
static_assert(static_cast<${ty}>(dom::${name}::${minValue}) == 0,
|
static_assert(static_cast<${ty}>(dom::${name}::${minValue}) == 0,
|
||||||
"We rely on this in ContiguousEnumValues");
|
"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,
|
name=self.enum.identifier.name,
|
||||||
|
|
|
@ -467,8 +467,9 @@ already_AddRefed<CacheStorage> CacheStorage::Constructor(
|
||||||
static_assert(
|
static_assert(
|
||||||
CHROME_ONLY_NAMESPACE == (uint32_t)CacheStorageNamespace::Chrome,
|
CHROME_ONLY_NAMESPACE == (uint32_t)CacheStorageNamespace::Chrome,
|
||||||
"Chrome namespace should match webidl Chrome enum");
|
"Chrome namespace should match webidl Chrome enum");
|
||||||
static_assert(NUMBER_OF_NAMESPACES == CacheStorageNamespaceValues::Count,
|
static_assert(
|
||||||
"Number of namespace should match webidl count");
|
NUMBER_OF_NAMESPACES == ContiguousEnumSize<CacheStorageNamespace>::value,
|
||||||
|
"Number of namespace should match webidl count");
|
||||||
|
|
||||||
Namespace ns = static_cast<Namespace>(aNamespace);
|
Namespace ns = static_cast<Namespace>(aNamespace);
|
||||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(aGlobal.GetAsSupports());
|
||||||
|
|
|
@ -278,7 +278,7 @@ static_assert(int(HeadersGuardEnum::None) == 0 &&
|
||||||
int(HeadersGuardEnum::Request_no_cors) == 2 &&
|
int(HeadersGuardEnum::Request_no_cors) == 2 &&
|
||||||
int(HeadersGuardEnum::Response) == 3 &&
|
int(HeadersGuardEnum::Response) == 3 &&
|
||||||
int(HeadersGuardEnum::Immutable) == 4 &&
|
int(HeadersGuardEnum::Immutable) == 4 &&
|
||||||
HeadersGuardEnumValues::Count == 5,
|
ContiguousEnumSize<HeadersGuardEnum>::value == 5,
|
||||||
"HeadersGuardEnum values are as expected");
|
"HeadersGuardEnum values are as expected");
|
||||||
static_assert(int(ReferrerPolicy::_empty) == 0 &&
|
static_assert(int(ReferrerPolicy::_empty) == 0 &&
|
||||||
int(ReferrerPolicy::No_referrer) == 1 &&
|
int(ReferrerPolicy::No_referrer) == 1 &&
|
||||||
|
@ -289,18 +289,18 @@ static_assert(int(ReferrerPolicy::_empty) == 0 &&
|
||||||
int(ReferrerPolicy::Same_origin) == 6 &&
|
int(ReferrerPolicy::Same_origin) == 6 &&
|
||||||
int(ReferrerPolicy::Strict_origin) == 7 &&
|
int(ReferrerPolicy::Strict_origin) == 7 &&
|
||||||
int(ReferrerPolicy::Strict_origin_when_cross_origin) == 8 &&
|
int(ReferrerPolicy::Strict_origin_when_cross_origin) == 8 &&
|
||||||
ReferrerPolicyValues::Count == 9,
|
ContiguousEnumSize<ReferrerPolicy>::value == 9,
|
||||||
"ReferrerPolicy values are as expected");
|
"ReferrerPolicy values are as expected");
|
||||||
static_assert(int(RequestMode::Same_origin) == 0 &&
|
static_assert(int(RequestMode::Same_origin) == 0 &&
|
||||||
int(RequestMode::No_cors) == 1 &&
|
int(RequestMode::No_cors) == 1 &&
|
||||||
int(RequestMode::Cors) == 2 &&
|
int(RequestMode::Cors) == 2 &&
|
||||||
int(RequestMode::Navigate) == 3 &&
|
int(RequestMode::Navigate) == 3 &&
|
||||||
RequestModeValues::Count == 4,
|
ContiguousEnumSize<RequestMode>::value == 4,
|
||||||
"RequestMode values are as expected");
|
"RequestMode values are as expected");
|
||||||
static_assert(int(RequestCredentials::Omit) == 0 &&
|
static_assert(int(RequestCredentials::Omit) == 0 &&
|
||||||
int(RequestCredentials::Same_origin) == 1 &&
|
int(RequestCredentials::Same_origin) == 1 &&
|
||||||
int(RequestCredentials::Include) == 2 &&
|
int(RequestCredentials::Include) == 2 &&
|
||||||
RequestCredentialsValues::Count == 3,
|
ContiguousEnumSize<RequestCredentials>::value == 3,
|
||||||
"RequestCredentials values are as expected");
|
"RequestCredentials values are as expected");
|
||||||
static_assert(int(RequestCache::Default) == 0 &&
|
static_assert(int(RequestCache::Default) == 0 &&
|
||||||
int(RequestCache::No_store) == 1 &&
|
int(RequestCache::No_store) == 1 &&
|
||||||
|
@ -308,19 +308,19 @@ static_assert(int(RequestCache::Default) == 0 &&
|
||||||
int(RequestCache::No_cache) == 3 &&
|
int(RequestCache::No_cache) == 3 &&
|
||||||
int(RequestCache::Force_cache) == 4 &&
|
int(RequestCache::Force_cache) == 4 &&
|
||||||
int(RequestCache::Only_if_cached) == 5 &&
|
int(RequestCache::Only_if_cached) == 5 &&
|
||||||
RequestCacheValues::Count == 6,
|
ContiguousEnumSize<RequestCache>::value == 6,
|
||||||
"RequestCache values are as expected");
|
"RequestCache values are as expected");
|
||||||
static_assert(int(RequestRedirect::Follow) == 0 &&
|
static_assert(int(RequestRedirect::Follow) == 0 &&
|
||||||
int(RequestRedirect::Error) == 1 &&
|
int(RequestRedirect::Error) == 1 &&
|
||||||
int(RequestRedirect::Manual) == 2 &&
|
int(RequestRedirect::Manual) == 2 &&
|
||||||
RequestRedirectValues::Count == 3,
|
ContiguousEnumSize<RequestRedirect>::value == 3,
|
||||||
"RequestRedirect values are as expected");
|
"RequestRedirect values are as expected");
|
||||||
static_assert(int(ResponseType::Basic) == 0 && int(ResponseType::Cors) == 1 &&
|
static_assert(int(ResponseType::Basic) == 0 && int(ResponseType::Cors) == 1 &&
|
||||||
int(ResponseType::Default) == 2 &&
|
int(ResponseType::Default) == 2 &&
|
||||||
int(ResponseType::Error) == 3 &&
|
int(ResponseType::Error) == 3 &&
|
||||||
int(ResponseType::Opaque) == 4 &&
|
int(ResponseType::Opaque) == 4 &&
|
||||||
int(ResponseType::Opaqueredirect) == 5 &&
|
int(ResponseType::Opaqueredirect) == 5 &&
|
||||||
ResponseTypeValues::Count == 6,
|
ContiguousEnumSize<ResponseType>::value == 6,
|
||||||
"ResponseType values are as expected");
|
"ResponseType values are as expected");
|
||||||
|
|
||||||
// If the static_asserts below fails, it means that you have changed the
|
// If the static_asserts below fails, it means that you have changed the
|
||||||
|
|
|
@ -24,7 +24,7 @@ static const nsLiteralCString kPermissionTypes[] = {
|
||||||
// clang-format on
|
// clang-format on
|
||||||
};
|
};
|
||||||
|
|
||||||
const size_t kPermissionNameCount = PermissionNameValues::Count;
|
const size_t kPermissionNameCount = ContiguousEnumSize<PermissionName>::value;
|
||||||
|
|
||||||
static_assert(MOZ_ARRAY_LENGTH(kPermissionTypes) == kPermissionNameCount,
|
static_assert(MOZ_ARRAY_LENGTH(kPermissionTypes) == kPermissionNameCount,
|
||||||
"kPermissionTypes and PermissionName count should match");
|
"kPermissionTypes and PermissionName count should match");
|
||||||
|
|
|
@ -43,7 +43,7 @@ static_assert(nsIServiceWorkerInfo::STATE_REDUNDANT ==
|
||||||
"ServiceWorkerState enumeration value should match state values "
|
"ServiceWorkerState enumeration value should match state values "
|
||||||
"from nsIServiceWorkerInfo.");
|
"from nsIServiceWorkerInfo.");
|
||||||
static_assert(nsIServiceWorkerInfo::STATE_UNKNOWN ==
|
static_assert(nsIServiceWorkerInfo::STATE_UNKNOWN ==
|
||||||
ServiceWorkerStateValues::Count,
|
ContiguousEnumSize<ServiceWorkerState>::value,
|
||||||
"ServiceWorkerState enumeration value should match state values "
|
"ServiceWorkerState enumeration value should match state values "
|
||||||
"from nsIServiceWorkerInfo.");
|
"from nsIServiceWorkerInfo.");
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,7 @@ static_assert(
|
||||||
static_cast<uint32_t>(RequestRedirect::Manual),
|
static_cast<uint32_t>(RequestRedirect::Manual),
|
||||||
"RequestRedirect enumeration value should make Necko Redirect mode value.");
|
"RequestRedirect enumeration value should make Necko Redirect mode value.");
|
||||||
static_assert(
|
static_assert(
|
||||||
3 == RequestRedirectValues::Count,
|
3 == ContiguousEnumSize<RequestRedirect>::value,
|
||||||
"RequestRedirect enumeration value should make Necko Redirect mode value.");
|
"RequestRedirect enumeration value should make Necko Redirect mode value.");
|
||||||
|
|
||||||
static_assert(
|
static_assert(
|
||||||
|
@ -155,7 +155,7 @@ static_assert(
|
||||||
static_cast<uint32_t>(RequestCache::Only_if_cached),
|
static_cast<uint32_t>(RequestCache::Only_if_cached),
|
||||||
"RequestCache enumeration value should match Necko Cache mode value.");
|
"RequestCache enumeration value should match Necko Cache mode value.");
|
||||||
static_assert(
|
static_assert(
|
||||||
6 == RequestCacheValues::Count,
|
6 == ContiguousEnumSize<RequestCache>::value,
|
||||||
"RequestCache enumeration value should match Necko Cache mode value.");
|
"RequestCache enumeration value should match Necko Cache mode value.");
|
||||||
|
|
||||||
static_assert(static_cast<uint16_t>(ServiceWorkerUpdateViaCache::Imports) ==
|
static_assert(static_cast<uint16_t>(ServiceWorkerUpdateViaCache::Imports) ==
|
||||||
|
|
|
@ -406,10 +406,9 @@ nsresult ExtensionPolicyService::InjectContentScripts(
|
||||||
DocInfo docInfo(win);
|
DocInfo docInfo(win);
|
||||||
|
|
||||||
using RunAt = dom::ContentScriptRunAt;
|
using RunAt = dom::ContentScriptRunAt;
|
||||||
namespace RunAtValues = dom::ContentScriptRunAtValues;
|
|
||||||
using Scripts = AutoTArray<RefPtr<WebExtensionContentScript>, 8>;
|
using Scripts = AutoTArray<RefPtr<WebExtensionContentScript>, 8>;
|
||||||
|
|
||||||
Scripts scripts[RunAtValues::Count];
|
Scripts scripts[ContiguousEnumSize<RunAt>::value];
|
||||||
|
|
||||||
auto GetScripts = [&](RunAt aRunAt) -> Scripts&& {
|
auto GetScripts = [&](RunAt aRunAt) -> Scripts&& {
|
||||||
static_assert(sizeof(aRunAt) == 1, "Our cast is wrong");
|
static_assert(sizeof(aRunAt) == 1, "Our cast is wrong");
|
||||||
|
|
Загрузка…
Ссылка в новой задаче