зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
46b1ffeb92
Коммит
18308210a8
|
@ -1493,7 +1493,7 @@ inline Maybe<Enum> StringToEnum(const StringT& aString) {
|
|||
}
|
||||
|
||||
template <typename Enum>
|
||||
inline const nsCString& GetEnumString(Enum stringId) {
|
||||
inline constexpr const nsLiteralCString& GetEnumString(Enum stringId) {
|
||||
MOZ_RELEASE_ASSERT(
|
||||
static_cast<size_t>(stringId) <
|
||||
mozilla::ArrayLength(binding_detail::EnumStrings<Enum>::Values));
|
||||
|
|
|
@ -12458,22 +12458,22 @@ class CGEnum(CGThing):
|
|||
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}
|
||||
static constexpr nsLiteralCString Values[${count}] {
|
||||
$*{entries}
|
||||
};
|
||||
};
|
||||
""",
|
||||
name=self.enum.identifier.name,
|
||||
count=self.nEnumStrings(),
|
||||
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)
|
||||
|
|
|
@ -13,9 +13,6 @@
|
|||
#include "nsStringFwd.h"
|
||||
|
||||
namespace mozilla::dom {
|
||||
const char* kFetchPriorityAttributeValueHigh = "high";
|
||||
const char* kFetchPriorityAttributeValueLow = "low";
|
||||
const char* kFetchPriorityAttributeValueAuto = "auto";
|
||||
|
||||
FetchPriority ToFetchPriority(RequestPriority aRequestPriority) {
|
||||
switch (aRequestPriority) {
|
||||
|
|
|
@ -37,9 +37,9 @@ void LogPriorityMapping(LazyLogModule& aLazyLogModule,
|
|||
FetchPriority aFetchPriority,
|
||||
int32_t aSupportsPriority);
|
||||
|
||||
extern const char* kFetchPriorityAttributeValueHigh;
|
||||
extern const char* kFetchPriorityAttributeValueLow;
|
||||
extern const char* kFetchPriorityAttributeValueAuto;
|
||||
constexpr const char kFetchPriorityAttributeValueHigh[] = "high";
|
||||
constexpr const char kFetchPriorityAttributeValueLow[] = "low";
|
||||
constexpr const char kFetchPriorityAttributeValueAuto[] = "auto";
|
||||
|
||||
} // namespace dom
|
||||
} // 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_SEARCH = 8;
|
||||
|
||||
static const nsAttrValue::EnumTable kInputmodeTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kInputmodeTable[] = {
|
||||
{"none", NS_INPUTMODE_NONE},
|
||||
{"text", NS_INPUTMODE_TEXT},
|
||||
{"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_SEND = 7;
|
||||
|
||||
static const nsAttrValue::EnumTable kEnterKeyHintTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kEnterKeyHintTable[] = {
|
||||
{"enter", NS_ENTERKEYHINT_ENTER},
|
||||
{"done", NS_ENTERKEYHINT_DONE},
|
||||
{"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_CHARACTERS = 4;
|
||||
|
||||
static const nsAttrValue::EnumTable kAutocapitalizeTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kAutocapitalizeTable[] = {
|
||||
{"none", NS_AUTOCAPITALIZE_NONE},
|
||||
{"sentences", NS_AUTOCAPITALIZE_SENTENCES},
|
||||
{"words", NS_AUTOCAPITALIZE_WORDS},
|
||||
|
@ -168,7 +168,7 @@ nsresult nsGenericHTMLElement::CopyInnerTo(Element* aDst) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
static const nsAttrValue::EnumTable kDirTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kDirTable[] = {
|
||||
{"ltr", Directionality::Ltr},
|
||||
{"rtl", Directionality::Rtl},
|
||||
{"auto", Directionality::Auto},
|
||||
|
@ -179,11 +179,11 @@ namespace {
|
|||
// See <https://html.spec.whatwg.org/#the-popover-attribute>.
|
||||
enum class PopoverAttributeKeyword : uint8_t { Auto, EmptyString, Manual };
|
||||
|
||||
static const char* kPopoverAttributeValueAuto = "auto";
|
||||
static const char* kPopoverAttributeValueEmptyString = "";
|
||||
static const char* kPopoverAttributeValueManual = "manual";
|
||||
static constexpr const char kPopoverAttributeValueAuto[] = "auto";
|
||||
static constexpr const char kPopoverAttributeValueEmptyString[] = "";
|
||||
static constexpr const char kPopoverAttributeValueManual[] = "manual";
|
||||
|
||||
static const nsAttrValue::EnumTable kPopoverTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kPopoverTable[] = {
|
||||
{kPopoverAttributeValueAuto, PopoverAttributeKeyword::Auto},
|
||||
{kPopoverAttributeValueEmptyString, PopoverAttributeKeyword::EmptyString},
|
||||
{kPopoverAttributeValueManual, PopoverAttributeKeyword::Manual},
|
||||
|
@ -210,7 +210,7 @@ FetchPriority nsGenericHTMLElement::ToFetchPriority(const nsAString& aValue) {
|
|||
|
||||
namespace {
|
||||
// <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},
|
||||
{kFetchPriorityAttributeValueLow, FetchPriority::Low},
|
||||
{kFetchPriorityAttributeValueAuto, FetchPriority::Auto},
|
||||
|
@ -1109,7 +1109,7 @@ nsMapRuleToAttributesFunc nsGenericHTMLElement::GetAttributeMappingFunction()
|
|||
return &MapCommonAttributesInto;
|
||||
}
|
||||
|
||||
static const nsAttrValue::EnumTable kDivAlignTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kDivAlignTable[] = {
|
||||
{"left", StyleTextAlign::MozLeft},
|
||||
{"right", StyleTextAlign::MozRight},
|
||||
{"center", StyleTextAlign::MozCenter},
|
||||
|
@ -1117,7 +1117,7 @@ static const nsAttrValue::EnumTable kDivAlignTable[] = {
|
|||
{"justify", StyleTextAlign::Justify},
|
||||
{nullptr, 0}};
|
||||
|
||||
static const nsAttrValue::EnumTable kFrameborderTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kFrameborderTable[] = {
|
||||
{"yes", FrameBorderProperty::Yes},
|
||||
{"no", FrameBorderProperty::No},
|
||||
{"1", FrameBorderProperty::One},
|
||||
|
@ -1125,7 +1125,7 @@ static const nsAttrValue::EnumTable kFrameborderTable[] = {
|
|||
{nullptr, 0}};
|
||||
|
||||
// TODO(emilio): Nobody uses the parsed attribute here.
|
||||
static const nsAttrValue::EnumTable kScrollingTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kScrollingTable[] = {
|
||||
{"yes", ScrollingAttribute::Yes},
|
||||
{"no", ScrollingAttribute::No},
|
||||
{"on", ScrollingAttribute::On},
|
||||
|
@ -1135,7 +1135,7 @@ static const nsAttrValue::EnumTable kScrollingTable[] = {
|
|||
{"auto", ScrollingAttribute::Auto},
|
||||
{nullptr, 0}};
|
||||
|
||||
static const nsAttrValue::EnumTable kTableVAlignTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kTableVAlignTable[] = {
|
||||
{"top", StyleVerticalAlignKeyword::Top},
|
||||
{"middle", StyleVerticalAlignKeyword::Middle},
|
||||
{"bottom", StyleVerticalAlignKeyword::Bottom},
|
||||
|
@ -1144,7 +1144,7 @@ static const nsAttrValue::EnumTable kTableVAlignTable[] = {
|
|||
|
||||
bool nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
|
||||
nsAttrValue& aResult) {
|
||||
static const nsAttrValue::EnumTable kAlignTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kAlignTable[] = {
|
||||
{"left", StyleTextAlign::Left},
|
||||
{"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},
|
||||
{"right", StyleTextAlign::Right},
|
||||
{"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.
|
||||
static const nsAttrValue::EnumTable kTableCellHAlignTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kTableCellHAlignTable[] = {
|
||||
{"left", StyleTextAlign::MozLeft},
|
||||
{"right", StyleTextAlign::MozRight},
|
||||
{"center", StyleTextAlign::MozCenter},
|
||||
|
@ -1251,9 +1251,7 @@ bool nsGenericHTMLElement::ParseImageAttribute(nsAtom* aAttribute,
|
|||
bool nsGenericHTMLElement::ParseReferrerAttribute(const nsAString& aString,
|
||||
nsAttrValue& aResult) {
|
||||
using mozilla::dom::ReferrerInfo;
|
||||
// This is a bit sketchy, we assume GetEnumString(…).get() points to a static
|
||||
// buffer, relying on the fact that GetEnumString(…) returns a literal string.
|
||||
static const nsAttrValue::EnumTable kReferrerPolicyTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kReferrerPolicyTable[] = {
|
||||
{GetEnumString(ReferrerPolicy::No_referrer).get(),
|
||||
static_cast<int16_t>(ReferrerPolicy::No_referrer)},
|
||||
{GetEnumString(ReferrerPolicy::Origin).get(),
|
||||
|
@ -2770,7 +2768,7 @@ void nsGenericHTMLFormControlElement::SetFormAutofillState(
|
|||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static const nsAttrValue::EnumTable kPopoverTargetActionTable[] = {
|
||||
static constexpr nsAttrValue::EnumTable kPopoverTargetActionTable[] = {
|
||||
{"toggle", PopoverTargetAction::Toggle},
|
||||
{"show", PopoverTargetAction::Show},
|
||||
{"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>
|
||||
bool nsTSubstring<T>::AssignASCII(const char* aData, size_type aLength,
|
||||
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>
|
||||
bool nsTSubstring<T>::AppendASCII(const char* aData,
|
||||
const fallible_t& aFallible) {
|
||||
|
|
|
@ -457,6 +457,9 @@ class nsTSubstring : public mozilla::detail::nsTStringRepr<T> {
|
|||
void NS_FASTCALL AssignASCII(const char* aData) {
|
||||
AssignASCII(aData, strlen(aData));
|
||||
}
|
||||
|
||||
void NS_FASTCALL AssignASCII(const nsLiteralCString& aData);
|
||||
|
||||
[[nodiscard]] bool NS_FASTCALL AssignASCII(const char* aData,
|
||||
const fallible_t& 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 nsLiteralCString& aData);
|
||||
|
||||
[[nodiscard]] bool AppendASCII(const char* aData,
|
||||
const fallible_t& aFallible);
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче