OLD | NEW |
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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 promise_returns.append("%s: %s" % (out_param["name"]
, type)) | 152 promise_returns.append("%s: %s" % (out_param["name"]
, type)) |
153 output_file.write(" * @return {!Promise.<!{%s}>}\n" % ",
".join(promise_returns)) | 153 output_file.write(" * @return {!Promise.<!{%s}>}\n" % ",
".join(promise_returns)) |
154 else: | 154 else: |
155 output_file.write(" * @param {function(%s):void=} opt_callba
ck\n" % ", ".join(returns)) | 155 output_file.write(" * @param {function(%s):void=} opt_callba
ck\n" % ", ".join(returns)) |
156 params.append("opt_callback") | 156 params.append("opt_callback") |
157 output_file.write(" */\n") | 157 output_file.write(" */\n") |
158 output_file.write("Protocol.%sAgent.prototype.%s = function(%s)
{}\n" % (domain_name, command["name"], ", ".join(params))) | 158 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)) | 159 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"])) | 160 output_file.write("Protocol.%sAgent.prototype.invoke_%s = functi
on(obj, opt_callback) {}\n" % (domain_name, command["name"])) |
161 | 161 |
162 output_file.write("\n\n\nvar %sAgent = new Protocol.%sAgent();\n" % (dom
ain_name, domain_name)) | 162 output_file.write("\n\n\nvar %sAgent = {};\n" % domain_name) |
163 | 163 |
164 if "types" in domain: | 164 if "types" in domain: |
165 for type in domain["types"]: | 165 for type in domain["types"]: |
166 if type["type"] == "object": | 166 if type["type"] == "object": |
167 typedef_args = [] | 167 typedef_args = [] |
168 if "properties" in type: | 168 if "properties" in type: |
169 for property in type["properties"]: | 169 for property in type["properties"]: |
170 suffix = "" | 170 suffix = "" |
171 if ("optional" in property): | 171 if ("optional" in property): |
172 suffix = "|undefined" | 172 suffix = "|undefined" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 if __name__ == "__main__": | 226 if __name__ == "__main__": |
227 import sys | 227 import sys |
228 import os.path | 228 import os.path |
229 program_name = os.path.basename(__file__) | 229 program_name = os.path.basename(__file__) |
230 if len(sys.argv) < 4 or sys.argv[1] != "-o": | 230 if len(sys.argv) < 4 or sys.argv[1] != "-o": |
231 sys.stderr.write("Usage: %s -o OUTPUT_FILE INPUT_FILE\n" % program_name) | 231 sys.stderr.write("Usage: %s -o OUTPUT_FILE INPUT_FILE\n" % program_name) |
232 exit(1) | 232 exit(1) |
233 output_path = sys.argv[2] | 233 output_path = sys.argv[2] |
234 input_path = sys.argv[3] | 234 input_path = sys.argv[3] |
235 generate_protocol_externs(output_path, input_path) | 235 generate_protocol_externs(output_path, input_path) |
OLD | NEW |