ソースを参照

LibWeb: Generate property_maximum_value_count()

This will allow the CSS Parser to check if a property has been give too
many arguments, and if so, reject it as invalid.
Sam Atkins 3 年 前
コミット
a1bc89b814

+ 26 - 0
Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp

@@ -252,6 +252,32 @@ bool property_has_quirk(PropertyID property_id, Quirk quirk)
     }
     }
 }
 }
 
 
+size_t property_maximum_value_count(PropertyID property_id)
+{
+    switch (property_id) {
+)~~~");
+
+    properties.for_each_member([&](auto& name, auto& value) {
+        VERIFY(value.is_object());
+        if (value.as_object().has("max-values")) {
+            auto max_values = value.as_object().get("max-values");
+            VERIFY(max_values.is_number() && !max_values.is_double());
+            auto property_generator = generator.fork();
+            property_generator.set("name:titlecase", title_casify(name));
+            property_generator.set("max_values", max_values.to_string());
+            property_generator.append(R"~~~(
+    case PropertyID::@name:titlecase@:
+        return @max_values@;
+)~~~");
+        }
+    });
+
+    generator.append(R"~~~(
+    default:
+        return 1;
+    }
+}
+
 } // namespace Web::CSS
 } // namespace Web::CSS
 
 
 )~~~");
 )~~~");

+ 2 - 0
Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_h.cpp

@@ -106,6 +106,8 @@ bool is_inherited_property(PropertyID);
 bool is_pseudo_property(PropertyID);
 bool is_pseudo_property(PropertyID);
 RefPtr<StyleValue> property_initial_value(PropertyID);
 RefPtr<StyleValue> property_initial_value(PropertyID);
 
 
+size_t property_maximum_value_count(PropertyID);
+
 constexpr PropertyID first_property_id = PropertyID::@first_property_id@;
 constexpr PropertyID first_property_id = PropertyID::@first_property_id@;
 constexpr PropertyID last_property_id = PropertyID::@last_property_id@;
 constexpr PropertyID last_property_id = PropertyID::@last_property_id@;
 constexpr PropertyID first_shorthand_property_id = PropertyID::@first_shorthand_property_id@;
 constexpr PropertyID first_shorthand_property_id = PropertyID::@first_shorthand_property_id@;