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

Side by Side Diff: Source/devtools/scripts/generate_protocol_externs.py

Issue 1196193016: DevTools: [CSS] promisify CSS domain (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: address comments Created 5 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/timeline/TimelineModel.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2011 Google Inc. All rights reserved. 2 # Copyright (c) 2011 Google Inc. All rights reserved.
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 22 matching lines...) Expand all
33 "any": "*", 33 "any": "*",
34 "string": "string", 34 "string": "string",
35 "integer": "number", 35 "integer": "number",
36 "number": "number", 36 "number": "number",
37 "boolean": "boolean", 37 "boolean": "boolean",
38 "array": "!Array.<*>", 38 "array": "!Array.<*>",
39 "object": "!Object", 39 "object": "!Object",
40 } 40 }
41 41
42 promisified_domains = { 42 promisified_domains = {
43 "Profiler" 43 "Profiler",
44 "CSS"
44 } 45 }
45 46
46 ref_types = {} 47 ref_types = {}
47 48
48 def full_qualified_type_id(domain_name, type_id): 49 def full_qualified_type_id(domain_name, type_id):
49 if type_id.find(".") == -1: 50 if type_id.find(".") == -1:
50 return "%s.%s" % (domain_name, type_id) 51 return "%s.%s" % (domain_name, type_id)
51 return type_id 52 return type_id
52 53
53 54
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 domain_name = domain["domain"] 114 domain_name = domain["domain"]
114 promisified = domain_name in promisified_domains 115 promisified = domain_name in promisified_domains
115 116
116 output_file.write("\n\n/**\n * @constructor\n*/\n") 117 output_file.write("\n\n/**\n * @constructor\n*/\n")
117 output_file.write("Protocol.%sAgent = function(){};\n" % domain_name) 118 output_file.write("Protocol.%sAgent = function(){};\n" % domain_name)
118 119
119 if "commands" in domain: 120 if "commands" in domain:
120 for command in domain["commands"]: 121 for command in domain["commands"]:
121 output_file.write("\n/**\n") 122 output_file.write("\n/**\n")
122 params = [] 123 params = []
124 has_return_value = "returns" in command
125 explicit_parameters = promisified and has_return_value
123 if ("parameters" in command): 126 if ("parameters" in command):
124 for in_param in command["parameters"]: 127 for in_param in command["parameters"]:
125 if ("optional" in in_param): 128 # All parameters are not optional in case of promisified domain with return value.
129 if (not explicit_parameters and "optional" in in_param):
126 params.append("opt_%s" % in_param["name"]) 130 params.append("opt_%s" % in_param["name"])
127 output_file.write(" * @param {%s=} opt_%s\n" % (para m_type(domain_name, in_param), in_param["name"])) 131 output_file.write(" * @param {%s=} opt_%s\n" % (para m_type(domain_name, in_param), in_param["name"]))
128 else: 132 else:
129 params.append(in_param["name"]) 133 params.append(in_param["name"])
130 output_file.write(" * @param {%s} %s\n" % (param_typ e(domain_name, in_param), in_param["name"])) 134 output_file.write(" * @param {%s} %s\n" % (param_typ e(domain_name, in_param), in_param["name"]))
131 returns = [] 135 returns = []
132 if (not promisified): 136 returns.append("?Protocol.Error")
133 returns.append("?Protocol.Error") 137 if ("error" in command):
134 if ("error" in command): 138 returns.append("%s=" % param_type(domain_name, command["erro r"]))
135 returns.append("%s=" % param_type(domain_name, command[" error"])) 139 if (has_return_value):
136 if ("returns" in command):
137 for out_param in command["returns"]: 140 for out_param in command["returns"]:
138 if ("optional" in out_param): 141 if ("optional" in out_param):
139 returns.append("%s=" % param_type(domain_name, out_p aram)) 142 returns.append("%s=" % param_type(domain_name, out_p aram))
140 else: 143 else:
141 returns.append("%s" % param_type(domain_name, out_pa ram)) 144 returns.append("%s" % param_type(domain_name, out_pa ram))
145 callback_return_type = "void="
146 if explicit_parameters:
147 callback_return_type = "T"
148 elif promisified:
149 callback_return_type = "T="
150 output_file.write(" * @param {function(%s):%s} opt_callback\n" % (", ".join(returns), callback_return_type))
142 if (promisified): 151 if (promisified):
143 returns_len = len(command["returns"]) if "returns" in comman d else 0 152 output_file.write(" * @return {!Promise.<T>}\n")
144 if returns_len == 0: 153 output_file.write(" * @template T\n")
145 output_file.write(" * @return {!Promise.<undefined>}\n") 154 params.append("opt_callback")
146 else: 155
147 promise_returns = []
148 for out_param in command["returns"]:
149 type = param_type(domain_name, out_param)
150 if "optional" in out_param:
151 type = "(%s|undefined)" % type
152 promise_returns.append("%s: %s" % (out_param["name"] , type))
153 output_file.write(" * @return {!Promise.<!{%s}>}\n" % ", ".join(promise_returns))
154 else:
155 output_file.write(" * @param {function(%s):void=} opt_callba ck\n" % ", ".join(returns))
156 params.append("opt_callback")
157 output_file.write(" */\n") 156 output_file.write(" */\n")
158 output_file.write("Protocol.%sAgent.prototype.%s = function(%s) {}\n" % (domain_name, command["name"], ", ".join(params))) 157 output_file.write("Protocol.%sAgent.prototype.%s = function(%s) {}\n" % (domain_name, command["name"], ", ".join(params)))
159 output_file.write("/** @param {function(%s):void=} opt_callback */\n" % ", ".join(returns)) 158 output_file.write("/** @param {function(%s):void=} opt_callback */\n" % ", ".join(returns))
160 output_file.write("Protocol.%sAgent.prototype.invoke_%s = functi on(obj, opt_callback) {}\n" % (domain_name, command["name"])) 159 output_file.write("Protocol.%sAgent.prototype.invoke_%s = functi on(obj, opt_callback) {}\n" % (domain_name, command["name"]))
161 160
162 output_file.write("\n\n\nvar %sAgent = {};\n" % domain_name) 161 output_file.write("\n\n\nvar %sAgent = {};\n" % domain_name)
163 162
164 if "types" in domain: 163 if "types" in domain:
165 for type in domain["types"]: 164 for type in domain["types"]:
166 if type["type"] == "object": 165 if type["type"] == "object":
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 if __name__ == "__main__": 225 if __name__ == "__main__":
227 import sys 226 import sys
228 import os.path 227 import os.path
229 program_name = os.path.basename(__file__) 228 program_name = os.path.basename(__file__)
230 if len(sys.argv) < 4 or sys.argv[1] != "-o": 229 if len(sys.argv) < 4 or sys.argv[1] != "-o":
231 sys.stderr.write("Usage: %s -o OUTPUT_FILE INPUT_FILE\n" % program_name) 230 sys.stderr.write("Usage: %s -o OUTPUT_FILE INPUT_FILE\n" % program_name)
232 exit(1) 231 exit(1)
233 output_path = sys.argv[2] 232 output_path = sys.argv[2]
234 input_path = sys.argv[3] 233 input_path = sys.argv[3]
235 generate_protocol_externs(output_path, input_path) 234 generate_protocol_externs(output_path, input_path)
OLDNEW
« no previous file with comments | « Source/devtools/front_end/timeline/TimelineModel.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698