Title: [213007] trunk/Source/WebCore
Revision
213007
Author
[email protected]
Date
2017-02-25 11:02:14 -0800 (Sat, 25 Feb 2017)

Log Message

Improve how multiple codegen-properties are handled in CSSProperties.json
https://bugs.webkit.org/show_bug.cgi?id=168867

Reviewed by Zalan Bujtas.

To make upcoming metadata storage easier, it's better if property entries in CSSProperties.json
are always hashes. One property (line-height) used an array, in order to represent settings for
two different build flags (ENABLE_TEXT_AUTOSIZING and !ENABLE_TEXT_AUTOSIZING).

Fix by making "codegen-properties" optionally be an array. The relevant item is selected in
removeInactiveCodegenProperties() and used to replace the array.

Sort @internalProprerties when generating code, otherwise the contents of isInternalCSSProperty()
are unstable (the order in @allNames is not stable because it's the keys in a hash).

* css/CSSProperties.json:
* css/makeprop.pl:
(matchEnableFlags):
(removeInactiveCodegenProperties):
(isPropertyEnabled):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (213006 => 213007)


--- trunk/Source/WebCore/ChangeLog	2017-02-25 16:33:39 UTC (rev 213006)
+++ trunk/Source/WebCore/ChangeLog	2017-02-25 19:02:14 UTC (rev 213007)
@@ -1,3 +1,26 @@
+2017-02-24  Simon Fraser  <[email protected]>
+
+        Improve how multiple codegen-properties are handled in CSSProperties.json
+        https://bugs.webkit.org/show_bug.cgi?id=168867
+
+        Reviewed by Zalan Bujtas.
+
+        To make upcoming metadata storage easier, it's better if property entries in CSSProperties.json
+        are always hashes. One property (line-height) used an array, in order to represent settings for
+        two different build flags (ENABLE_TEXT_AUTOSIZING and !ENABLE_TEXT_AUTOSIZING).
+
+        Fix by making "codegen-properties" optionally be an array. The relevant item is selected in
+        removeInactiveCodegenProperties() and used to replace the array.
+
+        Sort @internalProprerties when generating code, otherwise the contents of isInternalCSSProperty()
+        are unstable (the order in @allNames is not stable because it's the keys in a hash).
+
+        * css/CSSProperties.json:
+        * css/makeprop.pl:
+        (matchEnableFlags):
+        (removeInactiveCodegenProperties):
+        (isPropertyEnabled):
+
 2017-02-24  Joseph Pecoraro  <[email protected]>
 
         [Resource Timing] Media elements initiated loads should set the initiatorType to their element name (video/audio)

Modified: trunk/Source/WebCore/css/CSSProperties.json (213006 => 213007)


--- trunk/Source/WebCore/css/CSSProperties.json	2017-02-25 16:33:39 UTC (rev 213006)
+++ trunk/Source/WebCore/css/CSSProperties.json	2017-02-25 19:02:14 UTC (rev 213007)
@@ -1397,23 +1397,20 @@
                 "svg": true
             }
         },
-        "line-height": [
-            {
-                "inherited": true,
-                "codegen-properties": {
+        "line-height": {
+            "inherited": true,
+            "codegen-properties": [
+                {
                     "custom": "All",
                     "enable-if": "ENABLE_TEXT_AUTOSIZING"
-                }
-            },
-            {
-                "inherited": true,
-                "codegen-properties": {
+                },
+                {
                     "getter": "specifiedLineHeight",
                     "conditional-converter": "LineHeight",
                     "enable-if": "!ENABLE_TEXT_AUTOSIZING"
                 }
-            }
-        ],
+            ]
+        },
         "list-style": {
             "inherited": true,
             "codegen-properties": {

Modified: trunk/Source/WebCore/css/makeprop.pl (213006 => 213007)


--- trunk/Source/WebCore/css/makeprop.pl	2017-02-25 16:33:39 UTC (rev 213006)
+++ trunk/Source/WebCore/css/makeprop.pl	2017-02-25 19:02:14 UTC (rev 213007)
@@ -32,7 +32,8 @@
 use JSON::PP;
 
 sub addProperty($$);
-sub isPropertyEnabled($);
+sub isPropertyEnabled($$);
+sub removeInactiveCodegenProperties($$);
 
 my $inputFile = "CSSProperties.json";
 
@@ -87,42 +88,86 @@
 for my $name (@allNames) {
     my $value = $propertiesHashRef->{$name};
     my $valueType = ref($value);
+    
     if ($valueType eq "HASH") {
-        if (isPropertyEnabled($value)) {
+        removeInactiveCodegenProperties($name, \%$value);
+        if (isPropertyEnabled($name, $value)) {
             addProperty($name, $value);
         }
-    } elsif ($valueType eq "ARRAY") {
-        for my $v (@$value) {
-            if (isPropertyEnabled($v)) {
-                addProperty($name, $v);
-                last;
-            }
-        }
     } else {
-        die "$name does not have a supported value type. Only dictionary and array types are supported.";
+        die "$name does not have a supported value type. Only dictionary types are supported.";
     }
 }
 
-sub isPropertyEnabled($)
+sub matchEnableFlags($)
 {
-    my ($optionsHashRef) = @_;
+    my ($enable_flag) = @_;
+    
+    if (exists($defines{$enable_flag})) {
+        return 1;
+    }
 
-    if (!exists($optionsHashRef->{"codegen-properties"})) {
+    if (substr($enable_flag, 0, 1) eq "!" && !exists($defines{substr($enable_flag, 1)})) {
         return 1;
     }
-    if ($optionsHashRef->{"codegen-properties"}{"skip-codegen"}) {
-        return 0;
+    
+    return 0;
+}
+
+sub removeInactiveCodegenProperties($$)
+{
+    my ($name, $propertyValue) = @_;
+
+    if (!exists($propertyValue->{"codegen-properties"})) {
+        return;
     }
-    if (!exists($optionsHashRef->{"codegen-properties"}{"enable-if"})) {
-        return 1;
+    
+    my $codegen_properties = $propertyValue->{"codegen-properties"};
+    my $valueType = ref($codegen_properties);
+
+    if ($valueType ne "ARRAY") {
+        return;
     }
-    if (exists($defines{$optionsHashRef->{"codegen-properties"}{"enable-if"}})) {
+
+    # Pick one based on "enable-if"
+    my $matching_codegen_options;
+    foreach my $entry (@{$codegen_properties}) {
+        if (!exists($entry->{"enable-if"})) {
+            print "Found 'codegen-properties' array with an unconditional entry under '$name'. This is probably unintentional.\n";
+            $matching_codegen_options = $entry;
+            last;
+        }
+
+        my $enable_flags = $entry->{"enable-if"};
+        if (matchEnableFlags($enable_flags)) {
+            $matching_codegen_options = $entry;
+            last;
+        }
+
+        $matching_codegen_options = $entry;
+    }
+    
+    $propertyValue->{"codegen-properties"} = $matching_codegen_options;
+}
+
+sub isPropertyEnabled($$)
+{
+    my ($name, $propertyValue) = @_;
+
+    if (!exists($propertyValue->{"codegen-properties"})) {
         return 1;
     }
-    if (substr($optionsHashRef->{"codegen-properties"}{"enable-if"}, 0, 1) eq "!" && !exists($defines{substr($optionsHashRef->{"codegen-properties"}{"enable-if"}, 1)})) {
+    
+    my $codegen_properties = $propertyValue->{"codegen-properties"};
+    if ($codegen_properties->{"skip-codegen"}) {
+        return 0;
+    }
+
+    if (!exists($codegen_properties->{"enable-if"})) {
         return 1;
     }
-    return 0;
+
+    return matchEnableFlags($codegen_properties->{"enable-if"});
 }
 
 sub addProperty($$)
@@ -265,7 +310,7 @@
     switch (id) {
 EOF
 
-foreach my $name (@internalProprerties) {
+foreach my $name (sort @internalProprerties) {
   print GPERF "    case CSSPropertyID::CSSProperty" . $nameToId{$name} . ":\n";
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to