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

Unified Diff: headless/lib/browser/client_api_generator.py

Issue 2219843002: headless: Make API generator more robust against weird enum literals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | headless/lib/browser/client_api_generator_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: headless/lib/browser/client_api_generator.py
diff --git a/headless/lib/browser/client_api_generator.py b/headless/lib/browser/client_api_generator.py
index 40f1206d17b206eb0adf31233bd0ced994c0b3b8..e5276c4091904403fb12d9c49e65178a5293b481 100644
--- a/headless/lib/browser/client_api_generator.py
+++ b/headless/lib/browser/client_api_generator.py
@@ -59,9 +59,17 @@ def CamelCaseToHackerStyle(name):
return name.lower()
-def MangleEnum(value):
- # Rename NULL enumeration values to avoid a clash with the actual NULL.
- return 'NONE' if value == 'NULL' else value
+def SanitizeLiteral(literal):
+ return {
+ # Rename null enumeration values to avoid a clash with the NULL macro.
+ 'null': 'none',
+ # Rename mathematical constants to avoid colliding with C macros.
+ 'Infinity': 'InfinityValue',
+ '-Infinity': 'NegativeInfinityValue',
+ 'NaN': 'NaNValue',
+ # Turn negative zero into a safe identifier.
+ '-0': 'NegativeZeroValue',
+ }.get(literal, literal)
def InitializeJinjaEnv(cache_dir):
@@ -77,7 +85,7 @@ def InitializeJinjaEnv(cache_dir):
'to_title_case': ToTitleCase,
'dash_to_camelcase': DashToCamelCase,
'camelcase_to_hacker_style': CamelCaseToHackerStyle,
- 'mangle_enum': MangleEnum,
+ 'sanitize_literal': SanitizeLiteral,
})
jinja_env.add_extension('jinja2.ext.loopcontrols')
return jinja_env
« no previous file with comments | « no previous file | headless/lib/browser/client_api_generator_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698