소스 검색

LibWeb: Ensure the number of pseudo elements stays up-to-date

The ::placeholder pseudo element was added in commit 1fbad9c, but the
total number of pseudo elements was not updated. Instead of this manual
bookkeeping, add a dummy value at the end of the enumeration for the
count.
Timothy Flynn 2 년 전
부모
커밋
fddbc2e378
3개의 변경된 파일9개의 추가작업 그리고 2개의 파일을 삭제
  1. 5 1
      Userland/Libraries/LibWeb/CSS/Selector.h
  2. 1 1
      Userland/Libraries/LibWeb/DOM/Element.h
  3. 3 0
      Userland/Libraries/LibWeb/Dump.cpp

+ 5 - 1
Userland/Libraries/LibWeb/CSS/Selector.h

@@ -29,8 +29,10 @@ public:
         ProgressValue,
         ProgressBar,
         Placeholder,
+
+        // Keep this last.
+        PseudoElementCount,
     };
-    static auto constexpr PseudoElementCount = to_underlying(PseudoElement::ProgressBar) + 1;
 
     struct SimpleSelector {
         enum class Type {
@@ -227,6 +229,8 @@ constexpr StringView pseudo_element_name(Selector::PseudoElement pseudo_element)
         return "-webkit-progress-value"sv;
     case Selector::PseudoElement::Placeholder:
         return "placeholder"sv;
+    case Selector::PseudoElement::PseudoElementCount:
+        break;
     }
     VERIFY_NOT_REACHED();
 }

+ 1 - 1
Userland/Libraries/LibWeb/DOM/Element.h

@@ -206,7 +206,7 @@ private:
 
     Vector<FlyString> m_classes;
 
-    Array<JS::GCPtr<Layout::Node>, CSS::Selector::PseudoElementCount> m_pseudo_element_nodes;
+    Array<JS::GCPtr<Layout::Node>, to_underlying(CSS::Selector::PseudoElement::PseudoElementCount)> m_pseudo_element_nodes;
 };
 
 template<>

+ 3 - 0
Userland/Libraries/LibWeb/Dump.cpp

@@ -508,6 +508,9 @@ void dump_selector(StringBuilder& builder, CSS::Selector const& selector)
                 case CSS::Selector::PseudoElement::Placeholder:
                     pseudo_element_description = "placeholder";
                     break;
+                case CSS::Selector::PseudoElement::PseudoElementCount:
+                    VERIFY_NOT_REACHED();
+                    break;
                 }
 
                 builder.appendff(" pseudo_element={}", pseudo_element_description);