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

Unified Diff: Source/devtools/scripts/generate_protocol_externs.py

Issue 185463010: DevTools: Introduce Target class which holds connection & models (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@gr-RuntimeAgent
Patch Set: Solve compilation issues Created 6 years, 9 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
Index: Source/devtools/scripts/generate_protocol_externs.py
diff --git a/Source/devtools/scripts/generate_protocol_externs.py b/Source/devtools/scripts/generate_protocol_externs.py
index 55b00136cc6ecf363fb336c5b7bb12cbb31fa65a..6171ab52f448dbe1ea893b2dd42c95f368ec0302 100755
--- a/Source/devtools/scripts/generate_protocol_externs.py
+++ b/Source/devtools/scripts/generate_protocol_externs.py
@@ -108,32 +108,9 @@ Protocol.Error;
for domain in json_api:
domain_name = domain["domain"]
- output_file.write("\n\n\nvar %sAgent = {};\n" % domain_name)
vsevik 2014/03/06 14:49:45 Why did this move?
sergeyv 2014/03/06 16:18:34 I've done this move, cause now we need to create A
- if "types" in domain:
- for type in domain["types"]:
- if type["type"] == "object":
- typedef_args = []
- if "properties" in type:
- for property in type["properties"]:
- suffix = ""
- if ("optional" in property):
- suffix = "|undefined"
- if "enum" in property:
- enum_name = "%sAgent.%s%s" % (domain_name, type["id"], to_title_case(property["name"]))
- output_file.write(generate_enum(enum_name, property))
- typedef_args.append("%s:(%s%s)" % (property["name"], enum_name, suffix))
- else:
- typedef_args.append("%s:(%s%s)" % (property["name"], param_type(domain_name, property), suffix))
- if (typedef_args):
- output_file.write("\n/** @typedef {!{%s}} */\n%sAgent.%s;\n" % (", ".join(typedef_args), domain_name, type["id"]))
- else:
- output_file.write("\n/** @typedef {!Object} */\n%sAgent.%s;\n" % (domain_name, type["id"]))
- elif type["type"] == "string" and "enum" in type:
- output_file.write(generate_enum("%sAgent.%s" % (domain_name, type["id"]), type))
- elif type["type"] == "array":
- output_file.write("\n/** @typedef {!Array.<!%s>} */\n%sAgent.%s;\n" % (param_type(domain_name, type["items"]), domain_name, type["id"]))
- else:
- output_file.write("\n/** @typedef {%s} */\n%sAgent.%s;\n" % (type_traits[type["type"]], domain_name, type["id"]))
+
+ output_file.write("\n\n/**\n * @constructor\n*/\n")
+ output_file.write("Protocol.%sAgent = function(){};\n" % domain_name)
if "commands" in domain:
for command in domain["commands"]:
@@ -159,9 +136,37 @@ Protocol.Error;
output_file.write(" * @param {function(%s):void=} opt_callback\n" % ", ".join(returns))
output_file.write(" */\n")
params.append("opt_callback")
- output_file.write("%sAgent.%s = function(%s) {}\n" % (domain_name, command["name"], ", ".join(params)))
+ output_file.write("Protocol.%sAgent.prototype.%s = function(%s) {}\n" % (domain_name, command["name"], ", ".join(params)))
output_file.write("/** @param {function(%s):void=} opt_callback */\n" % ", ".join(returns))
- output_file.write("%sAgent.invoke_%s = function(obj, opt_callback) {}\n" % (domain_name, command["name"]))
+ output_file.write("Protocol.%sAgent.prototype.invoke_%s = function(obj, opt_callback) {}\n" % (domain_name, command["name"]))
+
+ output_file.write("\n\n\nvar %sAgent = new Protocol.%sAgent();\n" % (domain_name, domain_name))
+
+ if "types" in domain:
+ for type in domain["types"]:
+ if type["type"] == "object":
+ typedef_args = []
+ if "properties" in type:
+ for property in type["properties"]:
+ suffix = ""
+ if ("optional" in property):
+ suffix = "|undefined"
+ if "enum" in property:
+ enum_name = "%sAgent.%s%s" % (domain_name, type["id"], to_title_case(property["name"]))
+ output_file.write(generate_enum(enum_name, property))
+ typedef_args.append("%s:(%s%s)" % (property["name"], enum_name, suffix))
+ else:
+ typedef_args.append("%s:(%s%s)" % (property["name"], param_type(domain_name, property), suffix))
+ if (typedef_args):
+ output_file.write("\n/** @typedef {!{%s}} */\n%sAgent.%s;\n" % (", ".join(typedef_args), domain_name, type["id"]))
+ else:
+ output_file.write("\n/** @typedef {!Object} */\n%sAgent.%s;\n" % (domain_name, type["id"]))
+ elif type["type"] == "string" and "enum" in type:
+ output_file.write(generate_enum("%sAgent.%s" % (domain_name, type["id"]), type))
+ elif type["type"] == "array":
+ output_file.write("\n/** @typedef {!Array.<!%s>} */\n%sAgent.%s;\n" % (param_type(domain_name, type["items"]), domain_name, type["id"]))
+ else:
+ output_file.write("\n/** @typedef {%s} */\n%sAgent.%s;\n" % (type_traits[type["type"]], domain_name, type["id"]))
output_file.write("/** @interface */\n")
output_file.write("%sAgent.Dispatcher = function() {};\n" % domain_name)
@@ -181,6 +186,19 @@ Protocol.Error;
output_file.write("%sAgent.Dispatcher.prototype.%s = function(%s) {};\n" % (domain_name, event["name"], ", ".join(params)))
output_file.write("/**\n * @param {%sAgent.Dispatcher} dispatcher\n */\n" % domain_name)
output_file.write("InspectorBackend.register%sDispatcher = function(dispatcher) {}\n" % domain_name)
+
+ output_file.write("\n/** @constructor */\n")
+ output_file.write("Protocol.Agents = function(){};\n")
+
+ for domain in json_api:
+ domain_name = domain["domain"]
+ uppercase_length = 0
+ while uppercase_length < len(domain_name) and domain_name[uppercase_length].isupper():
+ uppercase_length += 1
+
+ output_file.write("/** @return {!Protocol.%sAgent}*/\n" % domain_name)
+ output_file.write("Protocol.Agents.prototype.%s = function(){};\n" % (domain_name[:uppercase_length].lower() + domain_name[uppercase_length:] + "Agent"))
+
output_file.close()
if __name__ == "__main__":
« Source/devtools/front_end/Target.js ('K') | « Source/devtools/scripts/frontend_modules.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698