Bug 1916234 - Remove global constructor from dom/html/nsGenericHTMLElement.cpp r=emilio
Making static array constexpr and adjusting methods / codegen accordingly. Differential Revision: https://phabricator.services.mozilla.com/D220813
This commit is contained in:
@@ -1493,7 +1493,7 @@ inline Maybe<Enum> StringToEnum(const StringT& aString) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename Enum>
|
template <typename Enum>
|
||||||
inline const nsCString& GetEnumString(Enum stringId) {
|
inline constexpr const nsLiteralCString& GetEnumString(Enum stringId) {
|
||||||
MOZ_RELEASE_ASSERT(
|
MOZ_RELEASE_ASSERT(
|
||||||
static_cast<size_t>(stringId) <
|
static_cast<size_t>(stringId) <
|
||||||
mozilla::ArrayLength(binding_detail::EnumStrings<Enum>::Values));
|
mozilla::ArrayLength(binding_detail::EnumStrings<Enum>::Values));
|
||||||
|
|||||||
@@ -12458,22 +12458,22 @@ class CGEnum(CGThing):
|
|||||||
declare=fill(
|
declare=fill(
|
||||||
"""
|
"""
|
||||||
template <> struct EnumStrings<${name}> {
|
template <> struct EnumStrings<${name}> {
|
||||||
static const nsLiteralCString Values[${count}];
|
static constexpr nsLiteralCString Values[${count}] {
|
||||||
};
|
|
||||||
""",
|
|
||||||
name=self.enum.identifier.name,
|
|
||||||
count=self.nEnumStrings(),
|
|
||||||
),
|
|
||||||
define=fill(
|
|
||||||
"""
|
|
||||||
const nsLiteralCString EnumStrings<${name}>::Values[${count}] = {
|
|
||||||
$*{entries}
|
$*{entries}
|
||||||
};
|
};
|
||||||
|
};
|
||||||
""",
|
""",
|
||||||
name=self.enum.identifier.name,
|
name=self.enum.identifier.name,
|
||||||
count=self.nEnumStrings(),
|
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()),
|
||||||
),
|
),
|
||||||
|
define=fill(
|
||||||
|
"""
|
||||||
|
constexpr nsLiteralCString EnumStrings<${name}>::Values[${count}];
|
||||||
|
""",
|
||||||
|
name=self.enum.identifier.name,
|
||||||
|
count=self.nEnumStrings(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
toJSValue = CGEnumToJSValue(enum)
|
toJSValue = CGEnumToJSValue(enum)
|
||||||
|
|||||||
@@ -13,9 +13,6 @@
|
|||||||
#include "nsStringFwd.h"
|
#include "nsStringFwd.h"
|
||||||
|
|
||||||
namespace mozilla::dom {
|
namespace mozilla::dom {
|
||||||
const char* kFetchPriorityAttributeValueHigh = "high";
|
|
||||||
const char* kFetchPriorityAttributeValueLow = "low";
|
|
||||||
const char* kFetchPriorityAttributeValueAuto = "auto";
|
|
||||||
|
|
||||||
FetchPriority ToFetchPriority(RequestPriority aRequestPriority) {
|
FetchPriority ToFetchPriority(RequestPriority aRequestPriority) {
|
||||||
switch (aRequestPriority) {
|
switch (aRequestPriority) {
|
||||||
|
|||||||
@@ -37,9 +37,9 @@ void LogPriorityMapping(LazyLogModule& aLazyLogModule,
|
|||||||
FetchPriority aFetchPriority,
|
FetchPriority aFetchPriority,
|
||||||
int32_t aSupportsPriority);
|
int32_t aSupportsPriority);
|
||||||
|
|
||||||
extern const char* kFetchPriorityAttributeValueHigh;
|
constexpr const char kFetchPriorityAttributeValueHigh[] = "high";
|
||||||
extern const char* kFetchPriorityAttributeValueLow;
|
constexpr const char kFetchPriorityAttributeValueLow[] = "low";
|
||||||
extern const char* kFetchPriorityAttributeValueAuto;
|
constexpr const char kFetchPriorityAttributeValueAuto[] = "auto";
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ 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 const nsAttrValue::EnumTable kInputmodeTable[] = {
|
static constexpr nsAttrValue::EnumTable kInputmodeTable[] = {
|
||||||
{"none", NS_INPUTMODE_NONE},
|
{"none", NS_INPUTMODE_NONE},
|
||||||
{"text", NS_INPUTMODE_TEXT},
|
{"text", NS_INPUTMODE_TEXT},
|
||||||
{"tel", NS_INPUTMODE_TEL},
|
{"tel", NS_INPUTMODE_TEL},
|
||||||
@@ -123,7 +123,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 const nsAttrValue::EnumTable kEnterKeyHintTable[] = {
|
static constexpr nsAttrValue::EnumTable 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},
|
||||||
@@ -138,7 +138,7 @@ 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 const nsAttrValue::EnumTable kAutocapitalizeTable[] = {
|
static constexpr nsAttrValue::EnumTable 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},
|
||||||
@@ -168,7 +168,7 @@ nsresult nsGenericHTMLElement::CopyInnerTo(Element* aDst) {
|
|||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const nsAttrValue::EnumTable kDirTable[] = {
|
static constexpr nsAttrValue::EnumTable kDirTable[] = {
|
||||||
{"ltr", Directionality::Ltr},
|
{"ltr", Directionality::Ltr},
|
||||||
{"rtl", Directionality::Rtl},
|
{"rtl", Directionality::Rtl},
|
||||||
{"auto", Directionality::Auto},
|
{"auto", Directionality::Auto},
|
||||||
@@ -179,11 +179,11 @@ namespace {
|
|||||||
// See <https://html.spec.whatwg.org/#the-popover-attribute>.
|
// See <https://html.spec.whatwg.org/#the-popover-attribute>.
|
||||||
enum class PopoverAttributeKeyword : uint8_t { Auto, EmptyString, Manual };
|
enum class PopoverAttributeKeyword : uint8_t { Auto, EmptyString, Manual };
|
||||||
|
|
||||||
static const char* kPopoverAttributeValueAuto = "auto";
|
static constexpr const char kPopoverAttributeValueAuto[] = "auto";
|
||||||
static const char* kPopoverAttributeValueEmptyString = "";
|
static constexpr const char kPopoverAttributeValueEmptyString[] = "";
|
||||||
static const char* kPopoverAttributeValueManual = "manual";
|
static constexpr const char kPopoverAttributeValueManual[] = "manual";
|
||||||
|
|
||||||
static const nsAttrValue::EnumTable kPopoverTable[] = {
|
static constexpr nsAttrValue::EnumTable kPopoverTable[] = {
|
||||||
{kPopoverAttributeValueAuto, PopoverAttributeKeyword::Auto},
|
{kPopoverAttributeValueAuto, PopoverAttributeKeyword::Auto},
|
||||||
{kPopoverAttributeValueEmptyString, PopoverAttributeKeyword::EmptyString},
|
{kPopoverAttributeValueEmptyString, PopoverAttributeKeyword::EmptyString},
|
||||||
{kPopoverAttributeValueManual, PopoverAttributeKeyword::Manual},
|
{kPopoverAttributeValueManual, PopoverAttributeKeyword::Manual},
|
||||||
@@ -210,7 +210,7 @@ FetchPriority nsGenericHTMLElement::ToFetchPriority(const nsAString& aValue) {
|
|||||||
|
|
||||||
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 const nsAttrValue::EnumTable kFetchPriorityEnumTable[] = {
|
static constexpr nsAttrValue::EnumTable kFetchPriorityEnumTable[] = {
|
||||||
{kFetchPriorityAttributeValueHigh, FetchPriority::High},
|
{kFetchPriorityAttributeValueHigh, FetchPriority::High},
|
||||||
{kFetchPriorityAttributeValueLow, FetchPriority::Low},
|
{kFetchPriorityAttributeValueLow, FetchPriority::Low},
|
||||||
{kFetchPriorityAttributeValueAuto, FetchPriority::Auto},
|
{kFetchPriorityAttributeValueAuto, FetchPriority::Auto},
|
||||||
@@ -1109,7 +1109,7 @@ nsMapRuleToAttributesFunc nsGenericHTMLElement::GetAttributeMappingFunction()
|
|||||||
return &MapCommonAttributesInto;
|
return &MapCommonAttributesInto;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const nsAttrValue::EnumTable kDivAlignTable[] = {
|
static constexpr nsAttrValue::EnumTable kDivAlignTable[] = {
|
||||||
{"left", StyleTextAlign::MozLeft},
|
{"left", StyleTextAlign::MozLeft},
|
||||||
{"right", StyleTextAlign::MozRight},
|
{"right", StyleTextAlign::MozRight},
|
||||||
{"center", StyleTextAlign::MozCenter},
|
{"center", StyleTextAlign::MozCenter},
|
||||||
@@ -1117,7 +1117,7 @@ static const nsAttrValue::EnumTable kDivAlignTable[] = {
|
|||||||
{"justify", StyleTextAlign::Justify},
|
{"justify", StyleTextAlign::Justify},
|
||||||
{nullptr, 0}};
|
{nullptr, 0}};
|
||||||
|
|
||||||
static const nsAttrValue::EnumTable kFrameborderTable[] = {
|
static constexpr nsAttrValue::EnumTable kFrameborderTable[] = {
|
||||||
{"yes", FrameBorderProperty::Yes},
|
{"yes", FrameBorderProperty::Yes},
|
||||||
{"no", FrameBorderProperty::No},
|
{"no", FrameBorderProperty::No},
|
||||||
{"1", FrameBorderProperty::One},
|
{"1", FrameBorderProperty::One},
|
||||||
@@ -1125,7 +1125,7 @@ static const nsAttrValue::EnumTable kFrameborderTable[] = {
|
|||||||
{nullptr, 0}};
|
{nullptr, 0}};
|
||||||
|
|
||||||
// TODO(emilio): Nobody uses the parsed attribute here.
|
// TODO(emilio): Nobody uses the parsed attribute here.
|
||||||
static const nsAttrValue::EnumTable kScrollingTable[] = {
|
static constexpr nsAttrValue::EnumTable kScrollingTable[] = {
|
||||||
{"yes", ScrollingAttribute::Yes},
|
{"yes", ScrollingAttribute::Yes},
|
||||||
{"no", ScrollingAttribute::No},
|
{"no", ScrollingAttribute::No},
|
||||||
{"on", ScrollingAttribute::On},
|
{"on", ScrollingAttribute::On},
|
||||||
@@ -1135,7 +1135,7 @@ static const nsAttrValue::EnumTable kScrollingTable[] = {
|
|||||||
{"auto", ScrollingAttribute::Auto},
|
{"auto", ScrollingAttribute::Auto},
|
||||||
{nullptr, 0}};
|
{nullptr, 0}};
|
||||||
|
|
||||||
static const nsAttrValue::EnumTable kTableVAlignTable[] = {
|
static constexpr nsAttrValue::EnumTable kTableVAlignTable[] = {
|
||||||
{"top", StyleVerticalAlignKeyword::Top},
|
{"top", StyleVerticalAlignKeyword::Top},
|
||||||
{"middle", StyleVerticalAlignKeyword::Middle},
|
{"middle", StyleVerticalAlignKeyword::Middle},
|
||||||
{"bottom", StyleVerticalAlignKeyword::Bottom},
|
{"bottom", StyleVerticalAlignKeyword::Bottom},
|
||||||
@@ -1144,7 +1144,7 @@ static const nsAttrValue::EnumTable kTableVAlignTable[] = {
|
|||||||
|
|
||||||
bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
|
bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
|
||||||
nsAttrValue& aResult) {
|
nsAttrValue& aResult) {
|
||||||
static const nsAttrValue::EnumTable kAlignTable[] = {
|
static constexpr nsAttrValue::EnumTable kAlignTable[] = {
|
||||||
{"left", StyleTextAlign::Left},
|
{"left", StyleTextAlign::Left},
|
||||||
{"right", StyleTextAlign::Right},
|
{"right", StyleTextAlign::Right},
|
||||||
|
|
||||||
@@ -1194,7 +1194,7 @@ bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
|
|||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
|
||||||
static const nsAttrValue::EnumTable kTableHAlignTable[] = {
|
static constexpr nsAttrValue::EnumTable kTableHAlignTable[] = {
|
||||||
{"left", StyleTextAlign::Left},
|
{"left", StyleTextAlign::Left},
|
||||||
{"right", StyleTextAlign::Right},
|
{"right", StyleTextAlign::Right},
|
||||||
{"center", StyleTextAlign::Center},
|
{"center", StyleTextAlign::Center},
|
||||||
@@ -1209,7 +1209,7 @@ 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 const nsAttrValue::EnumTable kTableCellHAlignTable[] = {
|
static constexpr nsAttrValue::EnumTable kTableCellHAlignTable[] = {
|
||||||
{"left", StyleTextAlign::MozLeft},
|
{"left", StyleTextAlign::MozLeft},
|
||||||
{"right", StyleTextAlign::MozRight},
|
{"right", StyleTextAlign::MozRight},
|
||||||
{"center", StyleTextAlign::MozCenter},
|
{"center", StyleTextAlign::MozCenter},
|
||||||
@@ -1251,9 +1251,7 @@ bool nsGenericHTMLElement::ParseImageAttribute(nsAtom* aAttribute,
|
|||||||
bool nsGenericHTMLElement::ParseReferrerAttribute(const nsAString& aString,
|
bool nsGenericHTMLElement::ParseReferrerAttribute(const nsAString& aString,
|
||||||
nsAttrValue& aResult) {
|
nsAttrValue& aResult) {
|
||||||
using mozilla::dom::ReferrerInfo;
|
using mozilla::dom::ReferrerInfo;
|
||||||
// This is a bit sketchy, we assume GetEnumString(…).get() points to a static
|
static constexpr nsAttrValue::EnumTable kReferrerPolicyTable[] = {
|
||||||
// buffer, relying on the fact that GetEnumString(…) returns a literal string.
|
|
||||||
static const nsAttrValue::EnumTable kReferrerPolicyTable[] = {
|
|
||||||
{GetEnumString(ReferrerPolicy::No_referrer).get(),
|
{GetEnumString(ReferrerPolicy::No_referrer).get(),
|
||||||
static_cast<int16_t>(ReferrerPolicy::No_referrer)},
|
static_cast<int16_t>(ReferrerPolicy::No_referrer)},
|
||||||
{GetEnumString(ReferrerPolicy::Origin).get(),
|
{GetEnumString(ReferrerPolicy::Origin).get(),
|
||||||
@@ -2770,7 +2768,7 @@ void nsGenericHTMLFormControlElement::SetFormAutofillState(
|
|||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
static const nsAttrValue::EnumTable kPopoverTargetActionTable[] = {
|
static constexpr nsAttrValue::EnumTable kPopoverTargetActionTable[] = {
|
||||||
{"toggle", PopoverTargetAction::Toggle},
|
{"toggle", PopoverTargetAction::Toggle},
|
||||||
{"show", PopoverTargetAction::Show},
|
{"show", PopoverTargetAction::Show},
|
||||||
{"hide", PopoverTargetAction::Hide},
|
{"hide", PopoverTargetAction::Hide},
|
||||||
|
|||||||
@@ -439,6 +439,11 @@ void nsTSubstring<T>::AssignASCII(const char* aData, size_type aLength) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void nsTSubstring<T>::AssignASCII(const nsLiteralCString& aData) {
|
||||||
|
AssignASCII(aData.get(), aData.Length());
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool nsTSubstring<T>::AssignASCII(const char* aData, size_type aLength,
|
bool nsTSubstring<T>::AssignASCII(const char* aData, size_type aLength,
|
||||||
const fallible_t& aFallible) {
|
const fallible_t& aFallible) {
|
||||||
@@ -800,6 +805,11 @@ void nsTSubstring<T>::AppendASCII(const char* aData, size_type aLength) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void nsTSubstring<T>::AppendASCII(const nsLiteralCString& aData) {
|
||||||
|
AppendASCII(aData.get(), aData.Length());
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool nsTSubstring<T>::AppendASCII(const char* aData,
|
bool nsTSubstring<T>::AppendASCII(const char* aData,
|
||||||
const fallible_t& aFallible) {
|
const fallible_t& aFallible) {
|
||||||
|
|||||||
@@ -457,6 +457,9 @@ class nsTSubstring : public mozilla::detail::nsTStringRepr<T> {
|
|||||||
void NS_FASTCALL AssignASCII(const char* aData) {
|
void NS_FASTCALL AssignASCII(const char* aData) {
|
||||||
AssignASCII(aData, strlen(aData));
|
AssignASCII(aData, strlen(aData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NS_FASTCALL AssignASCII(const nsLiteralCString& aData);
|
||||||
|
|
||||||
[[nodiscard]] bool NS_FASTCALL AssignASCII(const char* aData,
|
[[nodiscard]] bool NS_FASTCALL AssignASCII(const char* aData,
|
||||||
const fallible_t& aFallible) {
|
const fallible_t& aFallible) {
|
||||||
return AssignASCII(aData, strlen(aData), aFallible);
|
return AssignASCII(aData, strlen(aData), aFallible);
|
||||||
@@ -720,6 +723,8 @@ class nsTSubstring : public mozilla::detail::nsTStringRepr<T> {
|
|||||||
|
|
||||||
void AppendASCII(const char* aData, size_type aLength = size_type(-1));
|
void AppendASCII(const char* aData, size_type aLength = size_type(-1));
|
||||||
|
|
||||||
|
void AppendASCII(const nsLiteralCString& aData);
|
||||||
|
|
||||||
[[nodiscard]] bool AppendASCII(const char* aData,
|
[[nodiscard]] bool AppendASCII(const char* aData,
|
||||||
const fallible_t& aFallible);
|
const fallible_t& aFallible);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user