| 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..a53f412b54c5ae5b2e9c89e786fa24e9786f140e 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)
|
| - 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 * @param {!Object.<string, !Object>} agentsMap\n */\n")
|
| + output_file.write("Protocol.Agents = function(agentsMap){this._agentsMap;};\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__":
|
|
|