Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: third_party/WebKit/Source/build/scripts/make_css_property_names.py

Issue 2228313002: Make a function to query whether a CSSPropertyID is valid and whether it has a name. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@asan
Patch Set: Adjust animation dchecks Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 import subprocess 3 import subprocess
4 import sys 4 import sys
5 5
6 import css_properties 6 import css_properties
7 import in_generator 7 import in_generator
8 import license 8 import license
9 9
10 10
(...skipping 26 matching lines...) Expand all
37 const int numCSSProperties = %(properties_count)s; 37 const int numCSSProperties = %(properties_count)s;
38 const int lastCSSProperty = %(last_property_id)d; 38 const int lastCSSProperty = %(last_property_id)d;
39 const int lastUnresolvedCSSProperty = %(last_unresolved_property_id)d; 39 const int lastUnresolvedCSSProperty = %(last_unresolved_property_id)d;
40 const size_t maxCSSPropertyNameLength = %(max_name_length)d; 40 const size_t maxCSSPropertyNameLength = %(max_name_length)d;
41 41
42 const char* getPropertyName(CSSPropertyID); 42 const char* getPropertyName(CSSPropertyID);
43 const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID); 43 const WTF::AtomicString& getPropertyNameAtomicString(CSSPropertyID);
44 WTF::String getPropertyNameString(CSSPropertyID); 44 WTF::String getPropertyNameString(CSSPropertyID);
45 WTF::String getJSPropertyName(CSSPropertyID); 45 WTF::String getJSPropertyName(CSSPropertyID);
46 46
47 inline bool propertyHasName(int id)
48 {
49 return id >= firstCSSProperty && id <= lastUnresolvedCSSProperty;
50 }
51
52
47 inline CSSPropertyID convertToCSSPropertyID(int value) 53 inline CSSPropertyID convertToCSSPropertyID(int value)
48 { 54 {
49 ASSERT(value >= CSSPropertyInvalid && value <= lastCSSProperty); 55 DCHECK_GE(value, CSSPropertyInvalid);
56 DCHECK_LE(value, lastCSSProperty);
sashab 2016/08/15 07:23:13 Maybe DCHECK(propertyHasName() || property == CSSP
meade_UTC10 2016/09/29 07:39:56 Done.
meade_UTC10 2016/09/30 06:17:37 Actually that doesn't work - lastCSSProperty != la
50 return static_cast<CSSPropertyID>(value); 57 return static_cast<CSSPropertyID>(value);
51 } 58 }
52 59
53 inline CSSPropertyID resolveCSSPropertyID(CSSPropertyID id) 60 inline CSSPropertyID resolveCSSPropertyID(CSSPropertyID id)
54 { 61 {
55 return convertToCSSPropertyID(id & ~512); 62 return convertToCSSPropertyID(id & ~512);
56 } 63 }
57 64
58 inline bool isPropertyAlias(CSSPropertyID id) { return id & 512; } 65 inline bool isPropertyAlias(CSSPropertyID id) { return id & 512; }
59 66
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 %%%% 118 %%%%
112 %(property_to_enum_map)s 119 %(property_to_enum_map)s
113 %%%% 120 %%%%
114 const Property* findProperty(register const char* str, register unsigned int len ) 121 const Property* findProperty(register const char* str, register unsigned int len )
115 { 122 {
116 return %(class_name)sHash::findPropertyImpl(str, len); 123 return %(class_name)sHash::findPropertyImpl(str, len);
117 } 124 }
118 125
119 const char* getPropertyName(CSSPropertyID id) 126 const char* getPropertyName(CSSPropertyID id)
120 { 127 {
121 ASSERT(id >= firstCSSProperty && id <= lastUnresolvedCSSProperty); 128 DCHECK(propertyHasName(id));
122 int index = id - firstCSSProperty; 129 int index = id - firstCSSProperty;
123 return propertyNameStringsPool + propertyNameStringsOffsets[index]; 130 return propertyNameStringsPool + propertyNameStringsOffsets[index];
124 } 131 }
125 132
126 const AtomicString& getPropertyNameAtomicString(CSSPropertyID id) 133 const AtomicString& getPropertyNameAtomicString(CSSPropertyID id)
127 { 134 {
128 ASSERT(id >= firstCSSProperty && id <= lastUnresolvedCSSProperty); 135 DCHECK(propertyHasName(id));
129 int index = id - firstCSSProperty; 136 int index = id - firstCSSProperty;
130 static AtomicString* propertyStrings = new AtomicString[lastUnresolvedCSSPro perty]; // Intentionally never destroyed. 137 static AtomicString* propertyStrings = new AtomicString[lastUnresolvedCSSPro perty]; // Intentionally never destroyed.
131 AtomicString& propertyString = propertyStrings[index]; 138 AtomicString& propertyString = propertyStrings[index];
132 if (propertyString.isNull()) 139 if (propertyString.isNull())
133 propertyString = AtomicString(propertyNameStringsPool + propertyNameStri ngsOffsets[index]); 140 propertyString = AtomicString(propertyNameStringsPool + propertyNameStri ngsOffsets[index]);
134 return propertyString; 141 return propertyString;
135 } 142 }
136 143
137 String getPropertyNameString(CSSPropertyID id) 144 String getPropertyNameString(CSSPropertyID id)
138 { 145 {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 # FIXME: If we could depend on Python 2.7, we would use subprocess.check _output 226 # FIXME: If we could depend on Python 2.7, we would use subprocess.check _output
220 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n'] 227 gperf_args = [self.gperf_path, '--key-positions=*', '-P', '-n']
221 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts. 228 gperf_args.extend(['-m', '50']) # Pick best of 50 attempts.
222 gperf_args.append('-D') # Allow duplicate hashes -> More compact code. 229 gperf_args.append('-D') # Allow duplicate hashes -> More compact code.
223 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr ocess.PIPE, universal_newlines=True) 230 gperf = subprocess.Popen(gperf_args, stdin=subprocess.PIPE, stdout=subpr ocess.PIPE, universal_newlines=True)
224 return gperf.communicate(gperf_input)[0] 231 return gperf.communicate(gperf_input)[0]
225 232
226 233
227 if __name__ == "__main__": 234 if __name__ == "__main__":
228 in_generator.Maker(CSSPropertyNamesWriter).main(sys.argv) 235 in_generator.Maker(CSSPropertyNamesWriter).main(sys.argv)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698