Bug 1963845 - Use Span for EnumTable. r=emilio,smaug

This patch makes the usage of `EnumTable`s safer
by using `Span`s instead of relying on an empty
element at the end.
Also the name has been changed from `EnumTable`
to `EnumTableEntry` to be more precise.

Differential Revision: https://phabricator.services.mozilla.com/D247453
This commit is contained in:
Jan-Niklas Jaeschke
2025-05-06 07:59:38 +00:00
committed by jjaschke@mozilla.com
parent 6db653dc92
commit b3debf824d
28 changed files with 252 additions and 255 deletions

View File

@@ -1125,10 +1125,10 @@ const DOMTokenListSupportedToken Element::sAnchorAndFormRelValues[] = {
"noreferrer", "noopener", "opener", nullptr}; "noreferrer", "noopener", "opener", nullptr};
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#lazy-loading-attribute // https://html.spec.whatwg.org/multipage/urls-and-fetching.html#lazy-loading-attribute
static constexpr nsAttrValue::EnumTable kLoadingTable[] = { static constexpr nsAttrValue::EnumTableEntry kLoadingTable[] = {
{"eager", Element::Loading::Eager}, {"eager", Element::Loading::Eager},
{"lazy", Element::Loading::Lazy}, {"lazy", Element::Loading::Lazy},
{nullptr, 0}}; };
void Element::GetLoading(nsAString& aValue) const { void Element::GetLoading(nsAString& aValue) const {
GetEnumAttr(nsGkAtoms::loading, kLoadingTable[0].tag, aValue); GetEnumAttr(nsGkAtoms::loading, kLoadingTable[0].tag, aValue);
@@ -1137,7 +1137,8 @@ void Element::GetLoading(nsAString& aValue) const {
bool Element::ParseLoadingAttribute(const nsAString& aValue, bool Element::ParseLoadingAttribute(const nsAString& aValue,
nsAttrValue& aResult) { nsAttrValue& aResult) {
return aResult.ParseEnumValue(aValue, kLoadingTable, return aResult.ParseEnumValue(aValue, kLoadingTable,
/* aCaseSensitive = */ false, kLoadingTable); /* aCaseSensitive = */ false,
&kLoadingTable[0]);
} }
Element::Loading Element::LoadingState() const { Element::Loading Element::LoadingState() const {
@@ -1150,14 +1151,13 @@ Element::Loading Element::LoadingState() const {
namespace { namespace {
// <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>. // <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>.
static constexpr nsAttrValue::EnumTable kFetchPriorityEnumTable[] = { static constexpr nsAttrValue::EnumTableEntry kFetchPriorityEnumTable[] = {
{kFetchPriorityAttributeValueHigh, FetchPriority::High}, {kFetchPriorityAttributeValueHigh, FetchPriority::High},
{kFetchPriorityAttributeValueLow, FetchPriority::Low}, {kFetchPriorityAttributeValueLow, FetchPriority::Low},
{kFetchPriorityAttributeValueAuto, FetchPriority::Auto}, {kFetchPriorityAttributeValueAuto, FetchPriority::Auto}};
{nullptr, 0}};
// <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>. // <https://html.spec.whatwg.org/multipage/urls-and-fetching.html#fetch-priority-attributes>.
static const nsAttrValue::EnumTable* static constexpr const nsAttrValue::EnumTableEntry*
kFetchPriorityEnumTableInvalidValueDefault = &kFetchPriorityEnumTable[2]; kFetchPriorityEnumTableInvalidValueDefault = &kFetchPriorityEnumTable[2];
} // namespace } // namespace
@@ -3874,12 +3874,11 @@ bool Element::Matches(const nsACString& aSelector, ErrorResult& aResult) {
return Servo_SelectorList_Matches(this, list); return Servo_SelectorList_Matches(this, list);
} }
static const nsAttrValue::EnumTable kCORSAttributeTable[] = { static constexpr nsAttrValue::EnumTableEntry kCORSAttributeTable[] = {
// Order matters here // Order matters here
// See ParseCORSValue // See ParseCORSValue
{"anonymous", CORS_ANONYMOUS}, {"anonymous", CORS_ANONYMOUS},
{"use-credentials", CORS_USE_CREDENTIALS}, {"use-credentials", CORS_USE_CREDENTIALS}};
{nullptr, 0}};
/* static */ /* static */
void Element::ParseCORSValue(const nsAString& aValue, nsAttrValue& aResult) { void Element::ParseCORSValue(const nsAString& aValue, nsAttrValue& aResult) {

View File

@@ -239,7 +239,7 @@ void MiscContainer::Evict() {
} }
} }
nsTArray<const nsAttrValue::EnumTable*>* nsAttrValue::sEnumTableArray = nullptr; nsTArray<nsAttrValue::EnumTableSpan>* nsAttrValue::sEnumTableArray = nullptr;
nsAttrValue::nsAttrValue() : mBits(0) {} nsAttrValue::nsAttrValue() : mBits(0) {}
@@ -262,7 +262,7 @@ nsAttrValue::~nsAttrValue() { ResetIfSet(); }
/* static */ /* static */
void nsAttrValue::Init() { void nsAttrValue::Init() {
MOZ_ASSERT(!sEnumTableArray, "nsAttrValue already initialized"); MOZ_ASSERT(!sEnumTableArray, "nsAttrValue already initialized");
sEnumTableArray = new nsTArray<const EnumTable*>; sEnumTableArray = new nsTArray<EnumTableSpan>;
} }
/* static */ /* static */
@@ -791,19 +791,17 @@ void nsAttrValue::GetEnumString(nsAString& aResult, bool aRealTag) const {
? static_cast<uint32_t>(GetIntInternal()) ? static_cast<uint32_t>(GetIntInternal())
: GetMiscContainer()->mValue.mEnumValue; : GetMiscContainer()->mValue.mEnumValue;
int16_t val = allEnumBits >> NS_ATTRVALUE_ENUMTABLEINDEX_BITS; int16_t val = allEnumBits >> NS_ATTRVALUE_ENUMTABLEINDEX_BITS;
const EnumTable* table = sEnumTableArray->ElementAt( EnumTableSpan table = sEnumTableArray->ElementAt(
allEnumBits & NS_ATTRVALUE_ENUMTABLEINDEX_MASK); allEnumBits & NS_ATTRVALUE_ENUMTABLEINDEX_MASK);
for (const auto& entry : table) {
while (table->tag) { if (entry.value == val) {
if (table->value == val) { aResult.AssignASCII(entry.tag);
aResult.AssignASCII(table->tag);
if (!aRealTag && if (!aRealTag &&
allEnumBits & NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER) { allEnumBits & NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER) {
nsContentUtils::ASCIIToUpper(aResult); nsContentUtils::ASCIIToUpper(aResult);
} }
return; return;
} }
table++;
} }
MOZ_ASSERT_UNREACHABLE("couldn't find value in EnumTable"); MOZ_ASSERT_UNREACHABLE("couldn't find value in EnumTable");
@@ -1528,8 +1526,19 @@ mozilla::StringBuffer* nsAttrValue::GetStoredStringBuffer() const {
return nullptr; return nullptr;
} }
int16_t nsAttrValue::GetEnumTableIndex(const EnumTable* aTable) { /**
int16_t index = sEnumTableArray->IndexOf(aTable); * Compares two `EnumTableItem` spans by comparing their data pointer.
*/
struct EnumTablesHaveEqualContent {
bool Equals(const nsAttrValue::EnumTableSpan& aSpan1,
const nsAttrValue::EnumTableSpan& aSpan2) const {
return aSpan1.Elements() == aSpan2.Elements();
}
};
int16_t nsAttrValue::GetEnumTableIndex(EnumTableSpan aTable) {
int16_t index =
sEnumTableArray->IndexOf(aTable, 0, EnumTablesHaveEqualContent());
if (index < 0) { if (index < 0) {
index = sEnumTableArray->Length(); index = sEnumTableArray->Length();
NS_ASSERTION(index <= NS_ATTRVALUE_ENUMTABLEINDEX_MAXVALUE, NS_ASSERTION(index <= NS_ATTRVALUE_ENUMTABLEINDEX_MAXVALUE,
@@ -1540,47 +1549,43 @@ int16_t nsAttrValue::GetEnumTableIndex(const EnumTable* aTable) {
return index; return index;
} }
int32_t nsAttrValue::EnumTableEntryToValue(const EnumTable* aEnumTable, int32_t nsAttrValue::EnumTableEntryToValue(EnumTableSpan aEnumTable,
const EnumTable* aTableEntry) { const EnumTableEntry& aTableEntry) {
int16_t index = GetEnumTableIndex(aEnumTable); int16_t index = GetEnumTableIndex(aEnumTable);
int32_t value = int32_t value =
(aTableEntry->value << NS_ATTRVALUE_ENUMTABLEINDEX_BITS) + index; (aTableEntry.value << NS_ATTRVALUE_ENUMTABLEINDEX_BITS) + index;
return value; return value;
} }
bool nsAttrValue::ParseEnumValue(const nsAString& aValue, bool nsAttrValue::ParseEnumValue(const nsAString& aValue,
const EnumTable* aTable, bool aCaseSensitive, EnumTableSpan aTable,
const EnumTable* aDefaultValue) { bool aCaseSensitive,
const EnumTableEntry* aDefaultValue) {
ResetIfSet(); ResetIfSet();
const EnumTable* tableEntry = aTable; for (const auto& tableEntry : aTable) {
if (aCaseSensitive ? aValue.EqualsASCII(tableEntry.tag)
while (tableEntry->tag) { : aValue.LowerCaseEqualsASCII(tableEntry.tag)) {
if (aCaseSensitive ? aValue.EqualsASCII(tableEntry->tag)
: aValue.LowerCaseEqualsASCII(tableEntry->tag)) {
int32_t value = EnumTableEntryToValue(aTable, tableEntry); int32_t value = EnumTableEntryToValue(aTable, tableEntry);
bool equals = aCaseSensitive || aValue.EqualsASCII(tableEntry->tag); bool equals = aCaseSensitive || aValue.EqualsASCII(tableEntry.tag);
if (!equals) { if (!equals) {
nsAutoString tag; nsAutoString tag;
tag.AssignASCII(tableEntry->tag); tag.AssignASCII(tableEntry.tag);
nsContentUtils::ASCIIToUpper(tag); nsContentUtils::ASCIIToUpper(tag);
if ((equals = tag.Equals(aValue))) { if ((equals = tag.Equals(aValue))) {
value |= NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER; value |= NS_ATTRVALUE_ENUMTABLE_VALUE_NEEDS_TO_UPPER;
} }
} }
SetIntValueAndType(value, eEnum, equals ? nullptr : &aValue); SetIntValueAndType(value, eEnum, equals ? nullptr : &aValue);
NS_ASSERTION(GetEnumValue() == tableEntry->value, NS_ASSERTION(GetEnumValue() == tableEntry.value,
"failed to store enum properly"); "failed to store enum properly");
return true; return true;
} }
tableEntry++;
} }
if (aDefaultValue) { if (aDefaultValue) {
MOZ_ASSERT(aTable <= aDefaultValue && aDefaultValue < tableEntry, SetIntValueAndType(EnumTableEntryToValue(aTable, *aDefaultValue), eEnum,
"aDefaultValue not inside aTable?");
SetIntValueAndType(EnumTableEntryToValue(aTable, aDefaultValue), eEnum,
&aValue); &aValue);
return true; return true;
} }

View File

@@ -314,22 +314,21 @@ class nsAttrValue {
* Structure for a mapping from int (enum) values to strings. When you use * Structure for a mapping from int (enum) values to strings. When you use
* it you generally create an array of them. * it you generally create an array of them.
* Instantiate like this: * Instantiate like this:
* EnumTable myTable[] = { * EnumTableEntry myTable[] = {
* { "string1", 1 }, * { "string1", 1 },
* { "string2", 2 }, * { "string2", 2 }
* { nullptr, 0 }
* } * }
*/ */
struct EnumTable { struct EnumTableEntry {
// EnumTable can be initialized either with an int16_t value // EnumTable can be initialized either with an int16_t value
// or a value of an enumeration type that can fit within an int16_t. // or a value of an enumeration type that can fit within an int16_t.
constexpr EnumTable(const char* aTag, int16_t aValue) constexpr EnumTableEntry(const char* aTag, int16_t aValue)
: tag(aTag), value(aValue) {} : tag(aTag), value(aValue) {}
template <typename T, template <typename T,
typename = typename std::enable_if<std::is_enum<T>::value>::type> typename = typename std::enable_if<std::is_enum<T>::value>::type>
constexpr EnumTable(const char* aTag, T aValue) constexpr EnumTableEntry(const char* aTag, T aValue)
: tag(aTag), value(static_cast<int16_t>(aValue)) { : tag(aTag), value(static_cast<int16_t>(aValue)) {
static_assert(mozilla::EnumTypeFitsWithin<T, int16_t>::value, static_assert(mozilla::EnumTypeFitsWithin<T, int16_t>::value,
"aValue must be an enum that fits within int16_t"); "aValue must be an enum that fits within int16_t");
@@ -343,6 +342,7 @@ class nsAttrValue {
int16_t value; int16_t value;
}; };
using EnumTableSpan = mozilla::Span<const EnumTableEntry>;
/** /**
* Parse into an enum value. * Parse into an enum value.
* *
@@ -354,9 +354,9 @@ class nsAttrValue {
* cause aDefaultValue->value to be stored as the enumeration value. * cause aDefaultValue->value to be stored as the enumeration value.
* @return whether the enum value was found or not * @return whether the enum value was found or not
*/ */
bool ParseEnumValue(const nsAString& aValue, const EnumTable* aTable, bool ParseEnumValue(const nsAString& aValue, EnumTableSpan aTable,
bool aCaseSensitive, bool aCaseSensitive,
const EnumTable* aDefaultValue = nullptr); const EnumTableEntry* aDefaultValue = nullptr);
/** /**
* Parse a string into a dimension value. This is similar to * Parse a string into a dimension value. This is similar to
@@ -512,7 +512,7 @@ class nsAttrValue {
* @param aTable the EnumTable to get the index of. * @param aTable the EnumTable to get the index of.
* @return the index of the EnumTable. * @return the index of the EnumTable.
*/ */
int16_t GetEnumTableIndex(const EnumTable* aTable); int16_t GetEnumTableIndex(EnumTableSpan aTable);
inline void SetPtrValueAndType(void* aValue, ValueBaseType aType); inline void SetPtrValueAndType(void* aValue, ValueBaseType aType);
void SetIntValueAndType(int32_t aValue, ValueType aType, void SetIntValueAndType(int32_t aValue, ValueType aType,
@@ -541,8 +541,8 @@ class nsAttrValue {
const nsAString& aValue) const; const nsAString& aValue) const;
// Given an enum table and a particular entry in that table, return // Given an enum table and a particular entry in that table, return
// the actual integer value we should store. // the actual integer value we should store.
int32_t EnumTableEntryToValue(const EnumTable* aEnumTable, int32_t EnumTableEntryToValue(EnumTableSpan aEnumTable,
const EnumTable* aTableEntry); const EnumTableEntry& aTableEntry);
template <typename F> template <typename F>
bool SubstringCheck(const nsAString& aValue, bool SubstringCheck(const nsAString& aValue,
@@ -551,7 +551,7 @@ class nsAttrValue {
static MiscContainer* AllocMiscContainer(); static MiscContainer* AllocMiscContainer();
static void DeallocMiscContainer(MiscContainer* aCont); static void DeallocMiscContainer(MiscContainer* aCont);
static nsTArray<const EnumTable*>* sEnumTableArray; static nsTArray<EnumTableSpan>* sEnumTableArray;
/** /**
* Helper for ParseHTMLDimension and ParseNonzeroHTMLDimension. * Helper for ParseHTMLDimension and ParseNonzeroHTMLDimension.

View File

@@ -572,62 +572,66 @@ enum AutocompleteCategory {
#undef AUTOCOMPLETE_CATEGORY #undef AUTOCOMPLETE_CATEGORY
}; };
static const nsAttrValue::EnumTable kAutocompleteUnsupportedFieldNameTable[] = { static constexpr nsAttrValue::EnumTableEntry
kAutocompleteUnsupportedFieldNameTable[]{
#define AUTOCOMPLETE_UNSUPPORTED_FIELD_NAME(name_, value_) \ #define AUTOCOMPLETE_UNSUPPORTED_FIELD_NAME(name_, value_) \
{value_, eAutocompleteUnsupportedFieldName_##name_}, {value_, eAutocompleteUnsupportedFieldName_##name_},
#include "AutocompleteFieldList.h" #include "AutocompleteFieldList.h"
#undef AUTOCOMPLETE_UNSUPPORTED_FIELD_NAME #undef AUTOCOMPLETE_UNSUPPORTED_FIELD_NAME
{nullptr, 0}}; };
static const nsAttrValue::EnumTable kAutocompleteNoPersistFieldNameTable[] = { static constexpr nsAttrValue::EnumTableEntry
kAutocompleteNoPersistFieldNameTable[] = {
#define AUTOCOMPLETE_NO_PERSIST_FIELD_NAME(name_, value_) \ #define AUTOCOMPLETE_NO_PERSIST_FIELD_NAME(name_, value_) \
{value_, eAutocompleteNoPersistFieldName_##name_}, {value_, eAutocompleteNoPersistFieldName_##name_},
#include "AutocompleteFieldList.h" #include "AutocompleteFieldList.h"
#undef AUTOCOMPLETE_NO_PERSIST_FIELD_NAME #undef AUTOCOMPLETE_NO_PERSIST_FIELD_NAME
{nullptr, 0}}; };
static constexpr nsAttrValue::EnumTableEntry
static const nsAttrValue::EnumTable
kAutocompleteUnsupportedContactFieldHintTable[] = { kAutocompleteUnsupportedContactFieldHintTable[] = {
#define AUTOCOMPLETE_UNSUPPORTED_FIELD_CONTACT_HINT(name_, value_) \ #define AUTOCOMPLETE_UNSUPPORTED_FIELD_CONTACT_HINT(name_, value_) \
{value_, eAutocompleteUnsupportedFieldContactHint_##name_}, {value_, eAutocompleteUnsupportedFieldContactHint_##name_},
#include "AutocompleteFieldList.h" #include "AutocompleteFieldList.h"
#undef AUTOCOMPLETE_UNSUPPORTED_FIELD_CONTACT_HINT #undef AUTOCOMPLETE_UNSUPPORTED_FIELD_CONTACT_HINT
{nullptr, 0}}; };
static const nsAttrValue::EnumTable kAutocompleteFieldNameTable[] = { static constexpr nsAttrValue::EnumTableEntry kAutocompleteFieldNameTable[] = {
#define AUTOCOMPLETE_FIELD_NAME(name_, value_) \ #define AUTOCOMPLETE_FIELD_NAME(name_, value_) \
{value_, eAutocompleteFieldName_##name_}, {value_, eAutocompleteFieldName_##name_},
#include "AutocompleteFieldList.h" #include "AutocompleteFieldList.h"
#undef AUTOCOMPLETE_FIELD_NAME #undef AUTOCOMPLETE_FIELD_NAME
{nullptr, 0}}; };
static const nsAttrValue::EnumTable kAutocompleteContactFieldNameTable[] = { static constexpr nsAttrValue::EnumTableEntry
kAutocompleteContactFieldNameTable[] = {
#define AUTOCOMPLETE_CONTACT_FIELD_NAME(name_, value_) \ #define AUTOCOMPLETE_CONTACT_FIELD_NAME(name_, value_) \
{value_, eAutocompleteFieldName_##name_}, {value_, eAutocompleteFieldName_##name_},
#include "AutocompleteFieldList.h" #include "AutocompleteFieldList.h"
#undef AUTOCOMPLETE_CONTACT_FIELD_NAME #undef AUTOCOMPLETE_CONTACT_FIELD_NAME
{nullptr, 0}}; };
static const nsAttrValue::EnumTable kAutocompleteFieldHintTable[] = { static constexpr nsAttrValue::EnumTableEntry kAutocompleteFieldHintTable[] = {
#define AUTOCOMPLETE_FIELD_HINT(name_, value_) \ #define AUTOCOMPLETE_FIELD_HINT(name_, value_) \
{value_, eAutocompleteFieldHint_##name_}, {value_, eAutocompleteFieldHint_##name_},
#include "AutocompleteFieldList.h" #include "AutocompleteFieldList.h"
#undef AUTOCOMPLETE_FIELD_HINT #undef AUTOCOMPLETE_FIELD_HINT
{nullptr, 0}}; };
static const nsAttrValue::EnumTable kAutocompleteContactFieldHintTable[] = { static constexpr nsAttrValue::EnumTableEntry
kAutocompleteContactFieldHintTable[] = {
#define AUTOCOMPLETE_FIELD_CONTACT_HINT(name_, value_) \ #define AUTOCOMPLETE_FIELD_CONTACT_HINT(name_, value_) \
{value_, eAutocompleteFieldContactHint_##name_}, {value_, eAutocompleteFieldContactHint_##name_},
#include "AutocompleteFieldList.h" #include "AutocompleteFieldList.h"
#undef AUTOCOMPLETE_FIELD_CONTACT_HINT #undef AUTOCOMPLETE_FIELD_CONTACT_HINT
{nullptr, 0}}; };
static const nsAttrValue::EnumTable kAutocompleteCredentialTypeTable[] = { static constexpr nsAttrValue::EnumTableEntry
kAutocompleteCredentialTypeTable[] = {
#define AUTOCOMPLETE_CREDENTIAL_TYPE(name_, value_) \ #define AUTOCOMPLETE_CREDENTIAL_TYPE(name_, value_) \
{value_, eAutocompleteCredentialType_##name_}, {value_, eAutocompleteCredentialType_##name_},
#include "AutocompleteFieldList.h" #include "AutocompleteFieldList.h"
#undef AUTOCOMPLETE_CREDENTIAL_TYPE #undef AUTOCOMPLETE_CREDENTIAL_TYPE
{nullptr, 0}}; };
namespace { namespace {

View File

@@ -91,15 +91,6 @@ static void PrintReqURL(imgIRequest* req) {
} }
#endif /* DEBUG_chb */ #endif /* DEBUG_chb */
const nsAttrValue::EnumTable nsImageLoadingContent::kDecodingTable[] = {
{"auto", nsImageLoadingContent::ImageDecodingType::Auto},
{"async", nsImageLoadingContent::ImageDecodingType::Async},
{"sync", nsImageLoadingContent::ImageDecodingType::Sync},
{nullptr, 0}};
const nsAttrValue::EnumTable* nsImageLoadingContent::kDecodingTableDefault =
&nsImageLoadingContent::kDecodingTable[0];
nsImageLoadingContent::nsImageLoadingContent() nsImageLoadingContent::nsImageLoadingContent()
: mObserverList(nullptr), : mObserverList(nullptr),
mOutstandingDecodePromises(0), mOutstandingDecodePromises(0),

View File

@@ -263,8 +263,13 @@ class nsImageLoadingContent : public nsIImageLoadingContent {
Sync, Sync,
}; };
static const nsAttrValue::EnumTable kDecodingTable[]; static constexpr nsAttrValue::EnumTableEntry kDecodingTable[] = {
static const nsAttrValue::EnumTable* kDecodingTableDefault; {"auto", nsImageLoadingContent::ImageDecodingType::Auto},
{"async", nsImageLoadingContent::ImageDecodingType::Async},
{"sync", nsImageLoadingContent::ImageDecodingType::Sync},
};
static constexpr const nsAttrValue::EnumTableEntry* kDecodingTableDefault =
&nsImageLoadingContent::kDecodingTable[0];
private: private:
/** /**

View File

@@ -22,12 +22,12 @@ HTMLBRElement::~HTMLBRElement() = default;
NS_IMPL_ELEMENT_CLONE(HTMLBRElement) NS_IMPL_ELEMENT_CLONE(HTMLBRElement)
static const nsAttrValue::EnumTable kClearTable[] = { static constexpr nsAttrValue::EnumTableEntry kClearTable[] = {
{"left", StyleClear::Left}, {"left", StyleClear::Left},
{"right", StyleClear::Right}, {"right", StyleClear::Right},
{"all", StyleClear::Both}, {"all", StyleClear::Both},
{"both", StyleClear::Both}, {"both", StyleClear::Both},
{nullptr, 0}}; };
bool HTMLBRElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, bool HTMLBRElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
const nsAString& aValue, const nsAString& aValue,

View File

@@ -38,14 +38,15 @@ NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(Button)
namespace mozilla::dom { namespace mozilla::dom {
static const nsAttrValue::EnumTable kButtonTypeTable[] = { static constexpr nsAttrValue::EnumTableEntry kButtonTypeTable[] = {
{"button", FormControlType::ButtonButton}, {"button", FormControlType::ButtonButton},
{"reset", FormControlType::ButtonReset}, {"reset", FormControlType::ButtonReset},
{"submit", FormControlType::ButtonSubmit}, {"submit", FormControlType::ButtonSubmit},
{nullptr, 0}}; };
// Default type is 'submit'. // Default type is 'submit'.
static const nsAttrValue::EnumTable* kButtonDefaultType = &kButtonTypeTable[2]; static constexpr const nsAttrValue::EnumTableEntry* kButtonDefaultType =
&kButtonTypeTable[2];
// Construction, destruction // Construction, destruction
HTMLButtonElement::HTMLButtonElement( HTMLButtonElement::HTMLButtonElement(

View File

@@ -19,17 +19,19 @@ NS_IMPL_NS_NEW_HTML_ELEMENT(Dialog)
namespace mozilla::dom { namespace mozilla::dom {
static constexpr nsAttrValue::EnumTable kClosedbyTable[] = { static constexpr nsAttrValue::EnumTableEntry kClosedbyTable[] = {
{"", HTMLDialogElement::ClosedBy::Auto}, {"", HTMLDialogElement::ClosedBy::Auto},
{"none", HTMLDialogElement::ClosedBy::None}, {"none", HTMLDialogElement::ClosedBy::None},
{"any", HTMLDialogElement::ClosedBy::Any}, {"any", HTMLDialogElement::ClosedBy::Any},
{"closerequest", HTMLDialogElement::ClosedBy::CloseRequest}, {"closerequest", HTMLDialogElement::ClosedBy::CloseRequest},
{nullptr, 0},
}; };
static const nsAttrValue::EnumTable* kClosedbyAuto = &kClosedbyTable[0]; static constexpr const nsAttrValue::EnumTableEntry* kClosedbyAuto =
static const nsAttrValue::EnumTable* kClosedbyDefault = &kClosedbyTable[1]; &kClosedbyTable[0];
static const nsAttrValue::EnumTable* kClosedbyModalDefault = &kClosedbyTable[3]; static constexpr const nsAttrValue::EnumTableEntry* kClosedbyDefault =
&kClosedbyTable[1];
static constexpr const nsAttrValue::EnumTableEntry* kClosedbyModalDefault =
&kClosedbyTable[3];
HTMLDialogElement::~HTMLDialogElement() = default; HTMLDialogElement::~HTMLDialogElement() = default;

View File

@@ -95,12 +95,12 @@ namespace mozilla::dom {
static const uint8_t NS_FORM_AUTOCOMPLETE_ON = 1; static const uint8_t NS_FORM_AUTOCOMPLETE_ON = 1;
static const uint8_t NS_FORM_AUTOCOMPLETE_OFF = 0; static const uint8_t NS_FORM_AUTOCOMPLETE_OFF = 0;
static const nsAttrValue::EnumTable kFormAutocompleteTable[] = { static constexpr nsAttrValue::EnumTableEntry kFormAutocompleteTable[] = {
{"on", NS_FORM_AUTOCOMPLETE_ON}, {"on", NS_FORM_AUTOCOMPLETE_ON},
{"off", NS_FORM_AUTOCOMPLETE_OFF}, {"off", NS_FORM_AUTOCOMPLETE_OFF},
{nullptr, 0}}; };
// Default autocomplete value is 'on'. // Default autocomplete value is 'on'.
static const nsAttrValue::EnumTable* kFormDefaultAutocomplete = static constexpr const nsAttrValue::EnumTableEntry* kFormDefaultAutocomplete =
&kFormAutocompleteTable[0]; &kFormAutocompleteTable[0];
HTMLFormElement::HTMLFormElement( HTMLFormElement::HTMLFormElement(

View File

@@ -14,23 +14,23 @@
#define NS_FORM_ENCTYPE_MULTIPART 1 #define NS_FORM_ENCTYPE_MULTIPART 1
#define NS_FORM_ENCTYPE_TEXTPLAIN 2 #define NS_FORM_ENCTYPE_TEXTPLAIN 2
static const nsAttrValue::EnumTable kFormMethodTable[] = { static constexpr nsAttrValue::EnumTableEntry kFormMethodTable[] = {
{"get", NS_FORM_METHOD_GET}, {"get", NS_FORM_METHOD_GET},
{"post", NS_FORM_METHOD_POST}, {"post", NS_FORM_METHOD_POST},
{"dialog", NS_FORM_METHOD_DIALOG}, {"dialog", NS_FORM_METHOD_DIALOG}};
{nullptr, 0}};
// Default method is 'get'. // Default method is 'get'.
static const nsAttrValue::EnumTable* kFormDefaultMethod = &kFormMethodTable[0]; static constexpr const nsAttrValue::EnumTableEntry* kFormDefaultMethod =
&kFormMethodTable[0];
static const nsAttrValue::EnumTable kFormEnctypeTable[] = { static constexpr nsAttrValue::EnumTableEntry kFormEnctypeTable[] = {
{"multipart/form-data", NS_FORM_ENCTYPE_MULTIPART}, {"multipart/form-data", NS_FORM_ENCTYPE_MULTIPART},
{"application/x-www-form-urlencoded", NS_FORM_ENCTYPE_URLENCODED}, {"application/x-www-form-urlencoded", NS_FORM_ENCTYPE_URLENCODED},
{"text/plain", NS_FORM_ENCTYPE_TEXTPLAIN}, {"text/plain", NS_FORM_ENCTYPE_TEXTPLAIN},
{nullptr, 0}}; };
// Default method is 'application/x-www-form-urlencoded'. // Default method is 'application/x-www-form-urlencoded'.
static const nsAttrValue::EnumTable* kFormDefaultEnctype = static constexpr const nsAttrValue::EnumTableEntry* kFormDefaultEnctype =
&kFormEnctypeTable[1]; &kFormEnctypeTable[1];
#endif // mozilla_dom_HTMLFormSubmissionConstants_h #endif // mozilla_dom_HTMLFormSubmissionConstants_h

View File

@@ -27,11 +27,11 @@ bool HTMLHRElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
const nsAString& aValue, const nsAString& aValue,
nsIPrincipal* aMaybeScriptedPrincipal, nsIPrincipal* aMaybeScriptedPrincipal,
nsAttrValue& aResult) { nsAttrValue& aResult) {
static const nsAttrValue::EnumTable kAlignTable[] = { static const nsAttrValue::EnumTableEntry kAlignTable[] = {
{"left", StyleTextAlign::Left}, {"left", StyleTextAlign::Left},
{"right", StyleTextAlign::Right}, {"right", StyleTextAlign::Right},
{"center", StyleTextAlign::Center}, {"center", StyleTextAlign::Center},
{nullptr, 0}}; };
if (aNamespaceID == kNameSpaceID_None) { if (aNamespaceID == kNameSpaceID_None) {
if (aAttribute == nsGkAtoms::width) { if (aAttribute == nsGkAtoms::width) {

View File

@@ -151,7 +151,7 @@ namespace mozilla::dom {
static int32_t gSelectTextFieldOnFocus; static int32_t gSelectTextFieldOnFocus;
UploadLastDir* HTMLInputElement::gUploadLastDir; UploadLastDir* HTMLInputElement::gUploadLastDir;
static const nsAttrValue::EnumTable kInputTypeTable[] = { static constexpr nsAttrValue::EnumTableEntry kInputTypeTable[] = {
{"button", FormControlType::InputButton}, {"button", FormControlType::InputButton},
{"checkbox", FormControlType::InputCheckbox}, {"checkbox", FormControlType::InputCheckbox},
{"color", FormControlType::InputColor}, {"color", FormControlType::InputColor},
@@ -176,19 +176,20 @@ static const nsAttrValue::EnumTable kInputTypeTable[] = {
// "text" must be last for ParseAttribute to work right. If you add things // "text" must be last for ParseAttribute to work right. If you add things
// before it, please update kInputDefaultType. // before it, please update kInputDefaultType.
{"text", FormControlType::InputText}, {"text", FormControlType::InputText},
{nullptr, 0}}; };
// Default type is 'text'. // Default type is 'text'.
static const nsAttrValue::EnumTable* kInputDefaultType = static constexpr const nsAttrValue::EnumTableEntry* kInputDefaultType =
&kInputTypeTable[std::size(kInputTypeTable) - 2]; &kInputTypeTable[std::size(kInputTypeTable) - 1];
static const nsAttrValue::EnumTable kCaptureTable[] = { static constexpr nsAttrValue::EnumTableEntry kCaptureTable[] = {
{"user", nsIFilePicker::captureUser}, {"user", nsIFilePicker::captureUser},
{"environment", nsIFilePicker::captureEnv}, {"environment", nsIFilePicker::captureEnv},
{"", nsIFilePicker::captureDefault}, {"", nsIFilePicker::captureDefault},
{nullptr, nsIFilePicker::captureNone}}; };
static const nsAttrValue::EnumTable* kCaptureDefault = &kCaptureTable[2]; static constexpr const nsAttrValue::EnumTableEntry* kCaptureDefault =
&kCaptureTable[2];
using namespace blink; using namespace blink;
@@ -5444,18 +5445,14 @@ bool HTMLInputElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
const nsAString& aValue, const nsAString& aValue,
nsIPrincipal* aMaybeScriptedPrincipal, nsIPrincipal* aMaybeScriptedPrincipal,
nsAttrValue& aResult) { nsAttrValue& aResult) {
// We can't make these static_asserts because kInputDefaultType and static_assert(
// kInputTypeTable aren't constexpr.
MOZ_ASSERT(
FormControlType(kInputDefaultType->value) == FormControlType::InputText, FormControlType(kInputDefaultType->value) == FormControlType::InputText,
"Someone forgot to update kInputDefaultType when adding a new " "Someone forgot to update kInputDefaultType when adding a new "
"input type."); "input type.");
MOZ_ASSERT(kInputTypeTable[std::size(kInputTypeTable) - 1].tag == nullptr, static_assert(
"Last entry in the table must be the nullptr guard"); FormControlType(kInputTypeTable[std::size(kInputTypeTable) - 1].value) ==
MOZ_ASSERT(
FormControlType(kInputTypeTable[std::size(kInputTypeTable) - 2].value) ==
FormControlType::InputText, FormControlType::InputText,
"Next to last entry in the table must be the \"text\" entry"); "Last entry in the table must be the \"text\" entry");
if (aNamespaceID == kNameSpaceID_None) { if (aNamespaceID == kNameSpaceID_None) {
if (aAttribute == nsGkAtoms::type) { if (aAttribute == nsGkAtoms::type) {
@@ -5465,7 +5462,8 @@ bool HTMLInputElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
// There's no public way to set an nsAttrValue to an enum value, but we // There's no public way to set an nsAttrValue to an enum value, but we
// can just re-parse with a table that doesn't have any types other than // can just re-parse with a table that doesn't have any types other than
// "text" in it. // "text" in it.
aResult.ParseEnumValue(aValue, kInputDefaultType, false, MOZ_ASSERT(&Span(kInputTypeTable).Last<1>()[0] == kInputDefaultType);
aResult.ParseEnumValue(aValue, Span(kInputTypeTable).Last<1>(), false,
kInputDefaultType); kInputDefaultType);
} }

View File

@@ -20,18 +20,19 @@ HTMLLIElement::~HTMLLIElement() = default;
NS_IMPL_ELEMENT_CLONE(HTMLLIElement) NS_IMPL_ELEMENT_CLONE(HTMLLIElement)
// https://html.spec.whatwg.org/#lists // https://html.spec.whatwg.org/#lists
const nsAttrValue::EnumTable HTMLLIElement::kULTypeTable[] = { const nsAttrValue::EnumTableEntry HTMLLIElement::kULTypeTable[] = {
{"none", ListStyle::None}, {"none", ListStyle::None},
{"disc", ListStyle::Disc}, {"disc", ListStyle::Disc},
{"circle", ListStyle::Circle}, {"circle", ListStyle::Circle},
{"square", ListStyle::Square}, {"square", ListStyle::Square},
{nullptr, 0}}; };
// https://html.spec.whatwg.org/#lists // https://html.spec.whatwg.org/#lists
const nsAttrValue::EnumTable HTMLLIElement::kOLTypeTable[] = { const nsAttrValue::EnumTableEntry HTMLLIElement::kOLTypeTable[] = {
{"A", ListStyle::UpperAlpha}, {"a", ListStyle::LowerAlpha}, {"A", ListStyle::UpperAlpha}, {"a", ListStyle::LowerAlpha},
{"I", ListStyle::UpperRoman}, {"i", ListStyle::LowerRoman}, {"I", ListStyle::UpperRoman}, {"i", ListStyle::LowerRoman},
{"1", ListStyle::Decimal}, {nullptr, 0}}; {"1", ListStyle::Decimal},
};
bool HTMLLIElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, bool HTMLLIElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
const nsAString& aValue, const nsAString& aValue,

View File

@@ -39,8 +39,8 @@ class HTMLLIElement final : public nsGenericHTMLElement {
SetHTMLIntAttr(nsGkAtoms::value, aValue, rv); SetHTMLIntAttr(nsGkAtoms::value, aValue, rv);
} }
static const nsAttrValue::EnumTable kULTypeTable[]; static const nsAttrValue::EnumTableEntry kULTypeTable[4];
static const nsAttrValue::EnumTable kOLTypeTable[]; static const nsAttrValue::EnumTableEntry kOLTypeTable[5];
protected: protected:
virtual ~HTMLLIElement(); virtual ~HTMLLIElement();

View File

@@ -33,11 +33,11 @@ bool HTMLLegendElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
nsIPrincipal* aMaybeScriptedPrincipal, nsIPrincipal* aMaybeScriptedPrincipal,
nsAttrValue& aResult) { nsAttrValue& aResult) {
// this contains center, because IE4 does // this contains center, because IE4 does
static const nsAttrValue::EnumTable kAlignTable[] = { static constexpr nsAttrValue::EnumTableEntry kAlignTable[] = {
{"left", LegendAlignValue::Left}, {"left", LegendAlignValue::Left},
{"right", LegendAlignValue::Right}, {"right", LegendAlignValue::Right},
{"center", LegendAlignValue::Center}, {"center", LegendAlignValue::Center},
{nullptr, 0}}; };
if (aAttribute == nsGkAtoms::align && aNamespaceID == kNameSpaceID_None) { if (aAttribute == nsGkAtoms::align && aNamespaceID == kNameSpaceID_None) {
return aResult.ParseEnumValue(aValue, kAlignTable, false); return aResult.ParseEnumValue(aValue, kAlignTable, false);

View File

@@ -22,17 +22,21 @@ HTMLMarqueeElement::~HTMLMarqueeElement() = default;
NS_IMPL_ELEMENT_CLONE(HTMLMarqueeElement) NS_IMPL_ELEMENT_CLONE(HTMLMarqueeElement)
static const nsAttrValue::EnumTable kBehaviorTable[] = { static constexpr nsAttrValue::EnumTableEntry kBehaviorTable[] = {
{"scroll", 1}, {"slide", 2}, {"alternate", 3}, {nullptr, 0}}; {"scroll", 1}, {"slide", 2}, {"alternate", 3}
};
// Default behavior value is "scroll". // Default behavior value is "scroll".
static const nsAttrValue::EnumTable* kDefaultBehavior = &kBehaviorTable[0]; static constexpr const nsAttrValue::EnumTableEntry* kDefaultBehavior =
&kBehaviorTable[0];
static const nsAttrValue::EnumTable kDirectionTable[] = { static constexpr nsAttrValue::EnumTableEntry kDirectionTable[] = {
{"left", 1}, {"right", 2}, {"up", 3}, {"down", 4}, {nullptr, 0}}; {"left", 1}, {"right", 2}, {"up", 3}, {"down", 4}};
// Default direction value is "left". // Default direction value is "left".
static const nsAttrValue::EnumTable* kDefaultDirection = &kDirectionTable[0]; static constexpr const nsAttrValue::EnumTableEntry* kDefaultDirection =
&kDirectionTable[0];
JSObject* HTMLMarqueeElement::WrapNode(JSContext* aCx, JSObject* HTMLMarqueeElement::WrapNode(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) { JS::Handle<JSObject*> aGivenProto) {

View File

@@ -4947,12 +4947,12 @@ bool HTMLMediaElement::ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
nsIPrincipal* aMaybeScriptedPrincipal, nsIPrincipal* aMaybeScriptedPrincipal,
nsAttrValue& aResult) { nsAttrValue& aResult) {
// Mappings from 'preload' attribute strings to an enumeration. // Mappings from 'preload' attribute strings to an enumeration.
static const nsAttrValue::EnumTable kPreloadTable[] = { static const nsAttrValue::EnumTableEntry kPreloadTable[] = {
{"", HTMLMediaElement::PRELOAD_ATTR_EMPTY}, {"", HTMLMediaElement::PRELOAD_ATTR_EMPTY},
{"none", HTMLMediaElement::PRELOAD_ATTR_NONE}, {"none", HTMLMediaElement::PRELOAD_ATTR_NONE},
{"metadata", HTMLMediaElement::PRELOAD_ATTR_METADATA}, {"metadata", HTMLMediaElement::PRELOAD_ATTR_METADATA},
{"auto", HTMLMediaElement::PRELOAD_ATTR_AUTO}, {"auto", HTMLMediaElement::PRELOAD_ATTR_AUTO},
{nullptr, 0}}; };
if (aNamespaceID == kNameSpaceID_None) { if (aNamespaceID == kNameSpaceID_None) {
if (aAttribute == nsGkAtoms::crossorigin) { if (aAttribute == nsGkAtoms::crossorigin) {

View File

@@ -24,10 +24,10 @@ JSObject* HTMLTableCaptionElement::WrapNode(JSContext* aCx,
NS_IMPL_ELEMENT_CLONE(HTMLTableCaptionElement) NS_IMPL_ELEMENT_CLONE(HTMLTableCaptionElement)
static const nsAttrValue::EnumTable kCaptionAlignTable[] = { static constexpr nsAttrValue::EnumTableEntry kCaptionAlignTable[] = {
{"top", StyleCaptionSide::Top}, {"top", StyleCaptionSide::Top},
{"bottom", StyleCaptionSide::Bottom}, {"bottom", StyleCaptionSide::Bottom},
{nullptr, 0}}; };
bool HTMLTableCaptionElement::ParseAttribute( bool HTMLTableCaptionElement::ParseAttribute(
int32_t aNamespaceID, nsAtom* aAttribute, const nsAString& aValue, int32_t aNamespaceID, nsAtom* aAttribute, const nsAString& aValue,

View File

@@ -101,12 +101,12 @@ void HTMLTableCellElement::GetAlign(DOMString& aValue) {
} }
} }
static const nsAttrValue::EnumTable kCellScopeTable[] = { static constexpr nsAttrValue::EnumTableEntry kCellScopeTable[] = {
{"row", StyleCellScope::Row}, {"row", StyleCellScope::Row},
{"col", StyleCellScope::Col}, {"col", StyleCellScope::Col},
{"rowgroup", StyleCellScope::Rowgroup}, {"rowgroup", StyleCellScope::Rowgroup},
{"colgroup", StyleCellScope::Colgroup}, {"colgroup", StyleCellScope::Colgroup},
{nullptr, 0}}; };
void HTMLTableCellElement::GetScope(DOMString& aScope) { void HTMLTableCellElement::GetScope(DOMString& aScope) {
GetEnumAttr(nsGkAtoms::scope, nullptr, aScope); GetEnumAttr(nsGkAtoms::scope, nullptr, aScope);

View File

@@ -19,12 +19,10 @@ NS_IMPL_NS_NEW_HTML_ELEMENT(Template)
namespace mozilla::dom { namespace mozilla::dom {
static constexpr nsAttrValue::EnumTable kShadowRootModeTable[] = { static constexpr nsAttrValue::EnumTableEntry kShadowRootModeTable[] = {
{"open", ShadowRootMode::Open}, {"open", ShadowRootMode::Open},
{"closed", ShadowRootMode::Closed}, {"closed", ShadowRootMode::Closed},
{nullptr, {}}}; };
const nsAttrValue::EnumTable* kShadowRootModeDefault = &kShadowRootModeTable[2];
HTMLTemplateElement::HTMLTemplateElement( HTMLTemplateElement::HTMLTemplateElement(
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)

View File

@@ -48,18 +48,18 @@ nsGenericHTMLElement* NS_NewHTMLTrackElement(
namespace mozilla::dom { namespace mozilla::dom {
// Map html attribute string values to TextTrackKind enums. // Map html attribute string values to TextTrackKind enums.
static constexpr nsAttrValue::EnumTable kKindTable[] = { static constexpr nsAttrValue::EnumTableEntry kKindTable[] = {
{"subtitles", static_cast<int16_t>(TextTrackKind::Subtitles)}, {"subtitles", static_cast<int16_t>(TextTrackKind::Subtitles)},
{"captions", static_cast<int16_t>(TextTrackKind::Captions)}, {"captions", static_cast<int16_t>(TextTrackKind::Captions)},
{"descriptions", static_cast<int16_t>(TextTrackKind::Descriptions)}, {"descriptions", static_cast<int16_t>(TextTrackKind::Descriptions)},
{"chapters", static_cast<int16_t>(TextTrackKind::Chapters)}, {"chapters", static_cast<int16_t>(TextTrackKind::Chapters)},
{"metadata", static_cast<int16_t>(TextTrackKind::Metadata)}, {"metadata", static_cast<int16_t>(TextTrackKind::Metadata)},
{nullptr, 0}}; };
// Invalid values are treated as "metadata" in ParseAttribute, but if no value // Invalid values are treated as "metadata" in ParseAttribute, but if no value
// at all is specified, it's treated as "subtitles" in GetKind // at all is specified, it's treated as "subtitles" in GetKind
static constexpr const nsAttrValue::EnumTable* kKindTableInvalidValueDefault = static constexpr const nsAttrValue::EnumTableEntry*
&kKindTable[4]; kKindTableInvalidValueDefault = &kKindTable[4];
class WindowDestroyObserver final : public nsIObserver { class WindowDestroyObserver final : public nsIObserver {
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS

View File

@@ -107,16 +107,12 @@ static const uint8_t NS_INPUTMODE_NUMERIC = 6;
static const uint8_t NS_INPUTMODE_DECIMAL = 7; static const uint8_t NS_INPUTMODE_DECIMAL = 7;
static const uint8_t NS_INPUTMODE_SEARCH = 8; static const uint8_t NS_INPUTMODE_SEARCH = 8;
static constexpr nsAttrValue::EnumTable kInputmodeTable[] = { static constexpr nsAttrValue::EnumTableEntry kInputmodeTable[] = {
{"none", NS_INPUTMODE_NONE}, {"none", NS_INPUTMODE_NONE}, {"text", NS_INPUTMODE_TEXT},
{"text", NS_INPUTMODE_TEXT}, {"tel", NS_INPUTMODE_TEL}, {"url", NS_INPUTMODE_URL},
{"tel", NS_INPUTMODE_TEL}, {"email", NS_INPUTMODE_EMAIL}, {"numeric", NS_INPUTMODE_NUMERIC},
{"url", NS_INPUTMODE_URL}, {"decimal", NS_INPUTMODE_DECIMAL}, {"search", NS_INPUTMODE_SEARCH},
{"email", NS_INPUTMODE_EMAIL}, };
{"numeric", NS_INPUTMODE_NUMERIC},
{"decimal", NS_INPUTMODE_DECIMAL},
{"search", NS_INPUTMODE_SEARCH},
{nullptr, 0}};
static const uint8_t NS_ENTERKEYHINT_ENTER = 1; static const uint8_t NS_ENTERKEYHINT_ENTER = 1;
static const uint8_t NS_ENTERKEYHINT_DONE = 2; static const uint8_t NS_ENTERKEYHINT_DONE = 2;
@@ -126,7 +122,7 @@ static const uint8_t NS_ENTERKEYHINT_PREVIOUS = 5;
static const uint8_t NS_ENTERKEYHINT_SEARCH = 6; static const uint8_t NS_ENTERKEYHINT_SEARCH = 6;
static const uint8_t NS_ENTERKEYHINT_SEND = 7; static const uint8_t NS_ENTERKEYHINT_SEND = 7;
static constexpr nsAttrValue::EnumTable kEnterKeyHintTable[] = { static constexpr nsAttrValue::EnumTableEntry kEnterKeyHintTable[] = {
{"enter", NS_ENTERKEYHINT_ENTER}, {"enter", NS_ENTERKEYHINT_ENTER},
{"done", NS_ENTERKEYHINT_DONE}, {"done", NS_ENTERKEYHINT_DONE},
{"go", NS_ENTERKEYHINT_GO}, {"go", NS_ENTERKEYHINT_GO},
@@ -134,14 +130,14 @@ static constexpr nsAttrValue::EnumTable kEnterKeyHintTable[] = {
{"previous", NS_ENTERKEYHINT_PREVIOUS}, {"previous", NS_ENTERKEYHINT_PREVIOUS},
{"search", NS_ENTERKEYHINT_SEARCH}, {"search", NS_ENTERKEYHINT_SEARCH},
{"send", NS_ENTERKEYHINT_SEND}, {"send", NS_ENTERKEYHINT_SEND},
{nullptr, 0}}; };
static const uint8_t NS_AUTOCAPITALIZE_NONE = 1; static const uint8_t NS_AUTOCAPITALIZE_NONE = 1;
static const uint8_t NS_AUTOCAPITALIZE_SENTENCES = 2; static const uint8_t NS_AUTOCAPITALIZE_SENTENCES = 2;
static const uint8_t NS_AUTOCAPITALIZE_WORDS = 3; static const uint8_t NS_AUTOCAPITALIZE_WORDS = 3;
static const uint8_t NS_AUTOCAPITALIZE_CHARACTERS = 4; static const uint8_t NS_AUTOCAPITALIZE_CHARACTERS = 4;
static constexpr nsAttrValue::EnumTable kAutocapitalizeTable[] = { static constexpr nsAttrValue::EnumTableEntry kAutocapitalizeTable[] = {
{"none", NS_AUTOCAPITALIZE_NONE}, {"none", NS_AUTOCAPITALIZE_NONE},
{"sentences", NS_AUTOCAPITALIZE_SENTENCES}, {"sentences", NS_AUTOCAPITALIZE_SENTENCES},
{"words", NS_AUTOCAPITALIZE_WORDS}, {"words", NS_AUTOCAPITALIZE_WORDS},
@@ -149,9 +145,9 @@ static constexpr nsAttrValue::EnumTable kAutocapitalizeTable[] = {
{"off", NS_AUTOCAPITALIZE_NONE}, {"off", NS_AUTOCAPITALIZE_NONE},
{"on", NS_AUTOCAPITALIZE_SENTENCES}, {"on", NS_AUTOCAPITALIZE_SENTENCES},
{"", 0}, {"", 0},
{nullptr, 0}}; };
static const nsAttrValue::EnumTable* kDefaultAutocapitalize = static constexpr const nsAttrValue::EnumTableEntry* kDefaultAutocapitalize =
&kAutocapitalizeTable[1]; &kAutocapitalizeTable[1];
nsresult nsGenericHTMLElement::CopyInnerTo(Element* aDst) { nsresult nsGenericHTMLElement::CopyInnerTo(Element* aDst) {
@@ -171,11 +167,10 @@ nsresult nsGenericHTMLElement::CopyInnerTo(Element* aDst) {
return NS_OK; return NS_OK;
} }
static constexpr nsAttrValue::EnumTable kDirTable[] = { static constexpr nsAttrValue::EnumTableEntry kDirTable[] = {
{"ltr", Directionality::Ltr}, {"ltr", Directionality::Ltr},
{"rtl", Directionality::Rtl}, {"rtl", Directionality::Rtl},
{"auto", Directionality::Auto}, {"auto", Directionality::Auto},
{nullptr, 0},
}; };
namespace { namespace {
@@ -186,14 +181,14 @@ static constexpr const char kPopoverAttributeValueAuto[] = "auto";
static constexpr const char kPopoverAttributeValueEmptyString[] = ""; static constexpr const char kPopoverAttributeValueEmptyString[] = "";
static constexpr const char kPopoverAttributeValueManual[] = "manual"; static constexpr const char kPopoverAttributeValueManual[] = "manual";
static constexpr nsAttrValue::EnumTable kPopoverTable[] = { static constexpr nsAttrValue::EnumTableEntry kPopoverTable[] = {
{kPopoverAttributeValueAuto, PopoverAttributeKeyword::Auto}, {kPopoverAttributeValueAuto, PopoverAttributeKeyword::Auto},
{kPopoverAttributeValueEmptyString, PopoverAttributeKeyword::EmptyString}, {kPopoverAttributeValueEmptyString, PopoverAttributeKeyword::EmptyString},
{kPopoverAttributeValueManual, PopoverAttributeKeyword::Manual}, {kPopoverAttributeValueManual, PopoverAttributeKeyword::Manual},
{nullptr, 0}}; };
// See <https://html.spec.whatwg.org/#the-popover-attribute>. // See <https://html.spec.whatwg.org/#the-popover-attribute>.
static const nsAttrValue::EnumTable* kPopoverTableInvalidValueDefault = static const nsAttrValue::EnumTableEntry* kPopoverTableInvalidValueDefault =
&kPopoverTable[2]; &kPopoverTable[2];
} // namespace } // namespace
@@ -1253,23 +1248,23 @@ nsMapRuleToAttributesFunc nsGenericHTMLElement::GetAttributeMappingFunction()
return &MapCommonAttributesInto; return &MapCommonAttributesInto;
} }
static constexpr nsAttrValue::EnumTable kDivAlignTable[] = { static constexpr nsAttrValue::EnumTableEntry kDivAlignTable[] = {
{"left", StyleTextAlign::MozLeft}, {"left", StyleTextAlign::MozLeft},
{"right", StyleTextAlign::MozRight}, {"right", StyleTextAlign::MozRight},
{"center", StyleTextAlign::MozCenter}, {"center", StyleTextAlign::MozCenter},
{"middle", StyleTextAlign::MozCenter}, {"middle", StyleTextAlign::MozCenter},
{"justify", StyleTextAlign::Justify}, {"justify", StyleTextAlign::Justify},
{nullptr, 0}}; };
static constexpr nsAttrValue::EnumTable kFrameborderTable[] = { static constexpr nsAttrValue::EnumTableEntry kFrameborderTable[] = {
{"yes", FrameBorderProperty::Yes}, {"yes", FrameBorderProperty::Yes},
{"no", FrameBorderProperty::No}, {"no", FrameBorderProperty::No},
{"1", FrameBorderProperty::One}, {"1", FrameBorderProperty::One},
{"0", FrameBorderProperty::Zero}, {"0", FrameBorderProperty::Zero},
{nullptr, 0}}; };
// TODO(emilio): Nobody uses the parsed attribute here. // TODO(emilio): Nobody uses the parsed attribute here.
static constexpr nsAttrValue::EnumTable kScrollingTable[] = { static constexpr nsAttrValue::EnumTableEntry kScrollingTable[] = {
{"yes", ScrollingAttribute::Yes}, {"yes", ScrollingAttribute::Yes},
{"no", ScrollingAttribute::No}, {"no", ScrollingAttribute::No},
{"on", ScrollingAttribute::On}, {"on", ScrollingAttribute::On},
@@ -1277,36 +1272,36 @@ static constexpr nsAttrValue::EnumTable kScrollingTable[] = {
{"scroll", ScrollingAttribute::Scroll}, {"scroll", ScrollingAttribute::Scroll},
{"noscroll", ScrollingAttribute::Noscroll}, {"noscroll", ScrollingAttribute::Noscroll},
{"auto", ScrollingAttribute::Auto}, {"auto", ScrollingAttribute::Auto},
{nullptr, 0}}; };
static constexpr nsAttrValue::EnumTable kTableVAlignTable[] = { static constexpr nsAttrValue::EnumTableEntry kTableVAlignTable[] = {
{"top", StyleVerticalAlignKeyword::Top}, {"top", StyleVerticalAlignKeyword::Top},
{"middle", StyleVerticalAlignKeyword::Middle}, {"middle", StyleVerticalAlignKeyword::Middle},
{"bottom", StyleVerticalAlignKeyword::Bottom}, {"bottom", StyleVerticalAlignKeyword::Bottom},
{"baseline", StyleVerticalAlignKeyword::Baseline}, {"baseline", StyleVerticalAlignKeyword::Baseline},
{nullptr, 0}}; };
static constexpr nsAttrValue::EnumTableEntry kAlignTable[] = {
{"left", StyleTextAlign::Left},
{"right", StyleTextAlign::Right},
{"top", StyleVerticalAlignKeyword::Top},
{"middle", StyleVerticalAlignKeyword::MozMiddleWithBaseline},
// Intentionally not bottom.
{"bottom", StyleVerticalAlignKeyword::Baseline},
{"center", StyleVerticalAlignKeyword::MozMiddleWithBaseline},
{"baseline", StyleVerticalAlignKeyword::Baseline},
{"texttop", StyleVerticalAlignKeyword::TextTop},
{"absmiddle", StyleVerticalAlignKeyword::Middle},
{"abscenter", StyleVerticalAlignKeyword::Middle},
{"absbottom", StyleVerticalAlignKeyword::Bottom},
};
bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString, bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
nsAttrValue& aResult) { nsAttrValue& aResult) {
static constexpr nsAttrValue::EnumTable kAlignTable[] = {
{"left", StyleTextAlign::Left},
{"right", StyleTextAlign::Right},
{"top", StyleVerticalAlignKeyword::Top},
{"middle", StyleVerticalAlignKeyword::MozMiddleWithBaseline},
// Intentionally not bottom.
{"bottom", StyleVerticalAlignKeyword::Baseline},
{"center", StyleVerticalAlignKeyword::MozMiddleWithBaseline},
{"baseline", StyleVerticalAlignKeyword::Baseline},
{"texttop", StyleVerticalAlignKeyword::TextTop},
{"absmiddle", StyleVerticalAlignKeyword::Middle},
{"abscenter", StyleVerticalAlignKeyword::Middle},
{"absbottom", StyleVerticalAlignKeyword::Bottom},
{nullptr, 0}};
static_assert(uint8_t(StyleTextAlign::Left) != static_assert(uint8_t(StyleTextAlign::Left) !=
uint8_t(StyleVerticalAlignKeyword::Top) && uint8_t(StyleVerticalAlignKeyword::Top) &&
uint8_t(StyleTextAlign::Left) != uint8_t(StyleTextAlign::Left) !=
@@ -1338,12 +1333,12 @@ bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
//---------------------------------------- //----------------------------------------
static constexpr nsAttrValue::EnumTable kTableHAlignTable[] = { static constexpr nsAttrValue::EnumTableEntry kTableHAlignTable[] = {
{"left", StyleTextAlign::Left}, {"left", StyleTextAlign::Left},
{"right", StyleTextAlign::Right}, {"right", StyleTextAlign::Right},
{"center", StyleTextAlign::Center}, {"center", StyleTextAlign::Center},
{"justify", StyleTextAlign::Justify}, {"justify", StyleTextAlign::Justify},
{nullptr, 0}}; };
bool nsGenericHTMLElement::ParseTableHAlignValue(const nsAString& aString, bool nsGenericHTMLElement::ParseTableHAlignValue(const nsAString& aString,
nsAttrValue& aResult) { nsAttrValue& aResult) {
@@ -1353,14 +1348,14 @@ bool nsGenericHTMLElement::ParseTableHAlignValue(const nsAString& aString,
//---------------------------------------- //----------------------------------------
// This table is used for td, th, tr, col, thead, tbody and tfoot. // This table is used for td, th, tr, col, thead, tbody and tfoot.
static constexpr nsAttrValue::EnumTable kTableCellHAlignTable[] = { static constexpr nsAttrValue::EnumTableEntry kTableCellHAlignTable[] = {
{"left", StyleTextAlign::MozLeft}, {"left", StyleTextAlign::MozLeft},
{"right", StyleTextAlign::MozRight}, {"right", StyleTextAlign::MozRight},
{"center", StyleTextAlign::MozCenter}, {"center", StyleTextAlign::MozCenter},
{"justify", StyleTextAlign::Justify}, {"justify", StyleTextAlign::Justify},
{"middle", StyleTextAlign::MozCenter}, {"middle", StyleTextAlign::MozCenter},
{"absmiddle", StyleTextAlign::Center}, {"absmiddle", StyleTextAlign::Center},
{nullptr, 0}}; };
bool nsGenericHTMLElement::ParseTableCellHAlignValue(const nsAString& aString, bool nsGenericHTMLElement::ParseTableCellHAlignValue(const nsAString& aString,
nsAttrValue& aResult) { nsAttrValue& aResult) {
@@ -1392,27 +1387,28 @@ bool nsGenericHTMLElement::ParseImageAttribute(nsAtom* aAttribute,
return false; return false;
} }
static constexpr nsAttrValue::EnumTableEntry kReferrerPolicyTable[] = {
{GetEnumString(ReferrerPolicy::No_referrer).get(),
static_cast<int16_t>(ReferrerPolicy::No_referrer)},
{GetEnumString(ReferrerPolicy::Origin).get(),
static_cast<int16_t>(ReferrerPolicy::Origin)},
{GetEnumString(ReferrerPolicy::Origin_when_cross_origin).get(),
static_cast<int16_t>(ReferrerPolicy::Origin_when_cross_origin)},
{GetEnumString(ReferrerPolicy::No_referrer_when_downgrade).get(),
static_cast<int16_t>(ReferrerPolicy::No_referrer_when_downgrade)},
{GetEnumString(ReferrerPolicy::Unsafe_url).get(),
static_cast<int16_t>(ReferrerPolicy::Unsafe_url)},
{GetEnumString(ReferrerPolicy::Strict_origin).get(),
static_cast<int16_t>(ReferrerPolicy::Strict_origin)},
{GetEnumString(ReferrerPolicy::Same_origin).get(),
static_cast<int16_t>(ReferrerPolicy::Same_origin)},
{GetEnumString(ReferrerPolicy::Strict_origin_when_cross_origin).get(),
static_cast<int16_t>(ReferrerPolicy::Strict_origin_when_cross_origin)},
};
bool nsGenericHTMLElement::ParseReferrerAttribute(const nsAString& aString, bool nsGenericHTMLElement::ParseReferrerAttribute(const nsAString& aString,
nsAttrValue& aResult) { nsAttrValue& aResult) {
using mozilla::dom::ReferrerInfo; using mozilla::dom::ReferrerInfo;
static constexpr nsAttrValue::EnumTable kReferrerPolicyTable[] = {
{GetEnumString(ReferrerPolicy::No_referrer).get(),
static_cast<int16_t>(ReferrerPolicy::No_referrer)},
{GetEnumString(ReferrerPolicy::Origin).get(),
static_cast<int16_t>(ReferrerPolicy::Origin)},
{GetEnumString(ReferrerPolicy::Origin_when_cross_origin).get(),
static_cast<int16_t>(ReferrerPolicy::Origin_when_cross_origin)},
{GetEnumString(ReferrerPolicy::No_referrer_when_downgrade).get(),
static_cast<int16_t>(ReferrerPolicy::No_referrer_when_downgrade)},
{GetEnumString(ReferrerPolicy::Unsafe_url).get(),
static_cast<int16_t>(ReferrerPolicy::Unsafe_url)},
{GetEnumString(ReferrerPolicy::Strict_origin).get(),
static_cast<int16_t>(ReferrerPolicy::Strict_origin)},
{GetEnumString(ReferrerPolicy::Same_origin).get(),
static_cast<int16_t>(ReferrerPolicy::Same_origin)},
{GetEnumString(ReferrerPolicy::Strict_origin_when_cross_origin).get(),
static_cast<int16_t>(ReferrerPolicy::Strict_origin_when_cross_origin)},
{nullptr, ReferrerPolicy::_empty}};
return aResult.ParseEnumValue(aString, kReferrerPolicyTable, false); return aResult.ParseEnumValue(aString, kReferrerPolicyTable, false);
} }
@@ -2940,14 +2936,14 @@ void nsGenericHTMLFormControlElement::SetFormAutofillState(
//---------------------------------------------------------------------- //----------------------------------------------------------------------
static constexpr nsAttrValue::EnumTable kPopoverTargetActionTable[] = { static constexpr nsAttrValue::EnumTableEntry kPopoverTargetActionTable[] = {
{"toggle", PopoverTargetAction::Toggle}, {"toggle", PopoverTargetAction::Toggle},
{"show", PopoverTargetAction::Show}, {"show", PopoverTargetAction::Show},
{"hide", PopoverTargetAction::Hide}, {"hide", PopoverTargetAction::Hide},
{nullptr, 0}}; };
static const nsAttrValue::EnumTable* kPopoverTargetActionDefault = static constexpr const nsAttrValue::EnumTableEntry*
&kPopoverTargetActionTable[0]; kPopoverTargetActionDefault = &kPopoverTargetActionTable[0];
nsGenericHTMLFormControlElementWithState:: nsGenericHTMLFormControlElementWithState::
nsGenericHTMLFormControlElementWithState( nsGenericHTMLFormControlElementWithState(

View File

@@ -34,19 +34,6 @@ namespace mozilla {
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Static members // Static members
nsAttrValue::EnumTable SMILAnimationFunction::sAccumulateTable[] = {
{"none", false}, {"sum", true}, {nullptr, 0}};
nsAttrValue::EnumTable SMILAnimationFunction::sAdditiveTable[] = {
{"replace", false}, {"sum", true}, {nullptr, 0}};
nsAttrValue::EnumTable SMILAnimationFunction::sCalcModeTable[] = {
{"linear", CALC_LINEAR},
{"discrete", CALC_DISCRETE},
{"paced", CALC_PACED},
{"spline", CALC_SPLINE},
{nullptr, 0}};
// Any negative number should be fine as a sentinel here, // Any negative number should be fine as a sentinel here,
// because valid distances are non-negative. // because valid distances are non-negative.
#define COMPUTE_DISTANCE_ERROR (-1) #define COMPUTE_DISTANCE_ERROR (-1)

View File

@@ -399,9 +399,22 @@ class SMILAnimationFunction {
// Members // Members
// ------- // -------
static nsAttrValue::EnumTable sAdditiveTable[]; static constexpr nsAttrValue::EnumTableEntry sAdditiveTable[] = {
static nsAttrValue::EnumTable sCalcModeTable[]; {"replace", false},
static nsAttrValue::EnumTable sAccumulateTable[]; {"sum", true},
};
static constexpr nsAttrValue::EnumTableEntry sAccumulateTable[] = {
{"none", false},
{"sum", true},
};
static constexpr nsAttrValue::EnumTableEntry sCalcModeTable[] = {
{"linear", CALC_LINEAR},
{"discrete", CALC_DISCRETE},
{"paced", CALC_PACED},
{"spline", CALC_SPLINE},
};
FallibleTArray<double> mKeyTimes; FallibleTArray<double> mKeyTimes;
FallibleTArray<SMILKeySpline> mKeySplines; FallibleTArray<SMILKeySpline> mKeySplines;

View File

@@ -192,15 +192,6 @@ void SMILTimedElement::RemoveInstanceTimes(InstanceTimeList& aArray,
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// Static members // Static members
const nsAttrValue::EnumTable SMILTimedElement::sFillModeTable[] = {
{"remove", FILL_REMOVE}, {"freeze", FILL_FREEZE}, {nullptr, 0}};
const nsAttrValue::EnumTable SMILTimedElement::sRestartModeTable[] = {
{"always", RESTART_ALWAYS},
{"whenNotActive", RESTART_WHENNOTACTIVE},
{"never", RESTART_NEVER},
{nullptr, 0}};
// The thresholds at which point we start filtering intervals and instance times // The thresholds at which point we start filtering intervals and instance times
// indiscriminately. // indiscriminately.
// See FilterIntervals and FilterInstanceTimes. // See FilterIntervals and FilterInstanceTimes.

View File

@@ -567,7 +567,10 @@ class SMILTimedElement {
enum SMILFillMode : uint8_t { FILL_REMOVE, FILL_FREEZE }; enum SMILFillMode : uint8_t { FILL_REMOVE, FILL_FREEZE };
SMILFillMode mFillMode; SMILFillMode mFillMode;
static const nsAttrValue::EnumTable sFillModeTable[]; static constexpr nsAttrValue::EnumTableEntry sFillModeTable[] = {
{"remove", FILL_REMOVE},
{"freeze", FILL_FREEZE},
};
enum SMILRestartMode : uint8_t { enum SMILRestartMode : uint8_t {
RESTART_ALWAYS, RESTART_ALWAYS,
@@ -575,7 +578,11 @@ class SMILTimedElement {
RESTART_NEVER RESTART_NEVER
}; };
SMILRestartMode mRestartMode; SMILRestartMode mRestartMode;
static const nsAttrValue::EnumTable sRestartModeTable[]; static constexpr nsAttrValue::EnumTableEntry sRestartModeTable[] = {
{"always", RESTART_ALWAYS},
{"whenNotActive", RESTART_WHENNOTACTIVE},
{"never", RESTART_NEVER},
};
InstanceTimeList mBeginInstances; InstanceTimeList mBeginInstances;
InstanceTimeList mEndInstances; InstanceTimeList mEndInstances;

View File

@@ -3872,18 +3872,13 @@ bool IsFontMimeType(const nsAString& aType) {
return false; return false;
} }
static const nsAttrValue::EnumTable kAsAttributeTable[] = { static constexpr nsAttrValue::EnumTableEntry kAsAttributeTable[] = {
{"", DESTINATION_INVALID}, {"", DESTINATION_INVALID}, {"audio", DESTINATION_AUDIO},
{"audio", DESTINATION_AUDIO}, {"font", DESTINATION_FONT}, {"image", DESTINATION_IMAGE},
{"font", DESTINATION_FONT}, {"script", DESTINATION_SCRIPT}, {"style", DESTINATION_STYLE},
{"image", DESTINATION_IMAGE}, {"track", DESTINATION_TRACK}, {"video", DESTINATION_VIDEO},
{"script", DESTINATION_SCRIPT}, {"fetch", DESTINATION_FETCH}, {"json", DESTINATION_JSON},
{"style", DESTINATION_STYLE}, };
{"track", DESTINATION_TRACK},
{"video", DESTINATION_VIDEO},
{"fetch", DESTINATION_FETCH},
{"json", DESTINATION_JSON},
{nullptr, 0}};
void ParseAsValue(const nsAString& aValue, nsAttrValue& aResult) { void ParseAsValue(const nsAString& aValue, nsAttrValue& aResult) {
DebugOnly<bool> success = DebugOnly<bool> success =