[inspector] add presubmit.py to compile inspector-related scripts
BUG=chromium:635948 R=dgozman@chromium.org,alph@chromium.org Review-Url: https://codereview.chromium.org/2354263003 Cr-Commit-Position: refs/heads/master@{#39846}
This commit is contained in:
parent
df490c3484
commit
e9ceb376e4
55
src/inspector/PRESUBMIT.py
Normal file
55
src/inspector/PRESUBMIT.py
Normal file
@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2016 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
"""v8_inspect presubmit script
|
||||
|
||||
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
|
||||
for more details about the presubmit API built into gcl.
|
||||
"""
|
||||
|
||||
compile_note = "Be sure to run your patch by the compile-scripts.py script prior to committing!"
|
||||
|
||||
|
||||
def _CompileScripts(input_api, output_api):
|
||||
local_paths = [f.LocalPath() for f in input_api.AffectedFiles()]
|
||||
|
||||
compilation_related_files = [
|
||||
"js_protocol.json"
|
||||
"compile-scripts.js",
|
||||
"injected-script-source.js",
|
||||
"debugger_script_externs.js",
|
||||
"injected_script_externs.js",
|
||||
"check_injected_script_source.js",
|
||||
"debugger-script.js"
|
||||
]
|
||||
|
||||
for file in compilation_related_files:
|
||||
if (any(file in path for path in local_paths)):
|
||||
script_path = input_api.os_path.join(input_api.PresubmitLocalPath(),
|
||||
"build", "compile-scripts.py")
|
||||
proc = input_api.subprocess.Popen(
|
||||
[input_api.python_executable, script_path],
|
||||
stdout=input_api.subprocess.PIPE,
|
||||
stderr=input_api.subprocess.STDOUT)
|
||||
out, _ = proc.communicate()
|
||||
if "ERROR" in out or "WARNING" in out or proc.returncode:
|
||||
return [output_api.PresubmitError(out)]
|
||||
if "NOTE" in out:
|
||||
return [output_api.PresubmitPromptWarning(out + compile_note)]
|
||||
return []
|
||||
return []
|
||||
|
||||
|
||||
def CheckChangeOnUpload(input_api, output_api):
|
||||
results = []
|
||||
results.extend(_CompileScripts(input_api, output_api))
|
||||
return results
|
||||
|
||||
|
||||
def CheckChangeOnCommit(input_api, output_api):
|
||||
results = []
|
||||
results.extend(_CompileScripts(input_api, output_api))
|
||||
return results
|
88
src/inspector/build/check_injected_script_source.py
Normal file
88
src/inspector/build/check_injected_script_source.py
Normal file
@ -0,0 +1,88 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) 2014 Google Inc. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# Copied from blink:
|
||||
# WebKit/Source/devtools/scripts/check_injected_script_source.py
|
||||
#
|
||||
|
||||
import re
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
def validate_injected_script(fileName):
|
||||
f = open(fileName, "r")
|
||||
lines = f.readlines()
|
||||
f.close()
|
||||
|
||||
proto_functions = "|".join([
|
||||
# Array.prototype.*
|
||||
"concat", "every", "filter", "forEach", "indexOf", "join", "lastIndexOf", "map", "pop",
|
||||
"push", "reduce", "reduceRight", "reverse", "shift", "slice", "some", "sort", "splice", "toLocaleString", "toString", "unshift",
|
||||
# Function.prototype.*
|
||||
"apply", "bind", "call", "isGenerator", "toSource",
|
||||
# Object.prototype.*
|
||||
"toString",
|
||||
])
|
||||
|
||||
global_functions = "|".join([
|
||||
"eval", "uneval", "isFinite", "isNaN", "parseFloat", "parseInt", "decodeURI", "decodeURIComponent",
|
||||
"encodeURI", "encodeURIComponent", "escape", "unescape", "Map", "Set"
|
||||
])
|
||||
|
||||
# Black list:
|
||||
# - instanceof, since e.g. "obj instanceof Error" may throw if Error is overridden and is not a function
|
||||
# - Object.prototype.toString()
|
||||
# - Array.prototype.*
|
||||
# - Function.prototype.*
|
||||
# - Math.*
|
||||
# - Global functions
|
||||
black_list_call_regex = re.compile(r"\sinstanceof\s+\w*|\bMath\.\w+\(|(?<!InjectedScriptHost)\.(" + proto_functions + r")\(|[^\.]\b(" + global_functions + r")\(")
|
||||
|
||||
errors_found = False
|
||||
for i, line in enumerate(lines):
|
||||
if line.find("suppressBlacklist") != -1:
|
||||
continue
|
||||
for match in re.finditer(black_list_call_regex, line):
|
||||
errors_found = True
|
||||
print "ERROR: Black listed expression in %s at line %02d column %02d: %s" % (os.path.basename(fileName), i + 1, match.start(), match.group(0))
|
||||
|
||||
if not errors_found:
|
||||
print "OK"
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) < 2:
|
||||
print('ERROR: Usage: %s path/to/injected-script-source.js' % argv[0])
|
||||
return 1
|
||||
|
||||
validate_injected_script(argv[1])
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main(sys.argv))
|
169
src/inspector/build/compile-scripts.py
Executable file
169
src/inspector/build/compile-scripts.py
Executable file
@ -0,0 +1,169 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2016 the V8 project authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
|
||||
import os
|
||||
import os.path as path
|
||||
import generate_protocol_externs
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
if len(sys.argv) == 2 and sys.argv[1] == '--help':
|
||||
print("Usage: %s" % path.basename(sys.argv[0]))
|
||||
sys.exit(0)
|
||||
|
||||
java_required_major = 1
|
||||
java_required_minor = 7
|
||||
|
||||
v8_inspector_path = path.dirname(path.dirname(path.abspath(__file__)))
|
||||
|
||||
protocol_externs_file = path.join(v8_inspector_path, 'protocol_externs.js')
|
||||
injected_script_source_name = path.join(v8_inspector_path,
|
||||
'injected-script-source.js')
|
||||
injected_script_externs_file = path.join(v8_inspector_path,
|
||||
'injected_script_externs.js')
|
||||
debugger_script_source_name = path.join(v8_inspector_path,
|
||||
'debugger-script.js')
|
||||
debugger_script_externs_file = path.join(v8_inspector_path,
|
||||
'debugger_script_externs.js')
|
||||
|
||||
generate_protocol_externs.generate_protocol_externs(protocol_externs_file,
|
||||
path.join(v8_inspector_path, 'js_protocol.json'))
|
||||
|
||||
error_warning_regex = re.compile(r'WARNING|ERROR')
|
||||
|
||||
closure_compiler_jar = path.join(v8_inspector_path, 'build',
|
||||
'closure-compiler', 'closure-compiler.jar')
|
||||
|
||||
common_closure_args = [
|
||||
'--checks_only',
|
||||
'--warning_level', 'VERBOSE'
|
||||
]
|
||||
|
||||
# Error reporting and checking.
|
||||
errors_found = False
|
||||
|
||||
def popen(arguments):
|
||||
return subprocess.Popen(arguments, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.STDOUT)
|
||||
|
||||
def error_excepthook(exctype, value, traceback):
|
||||
print 'ERROR:'
|
||||
sys.__excepthook__(exctype, value, traceback)
|
||||
sys.excepthook = error_excepthook
|
||||
|
||||
def has_errors(output):
|
||||
return re.search(error_warning_regex, output) != None
|
||||
|
||||
# Find java. Based on
|
||||
# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python.
|
||||
def which(program):
|
||||
def is_exe(fpath):
|
||||
return path.isfile(fpath) and os.access(fpath, os.X_OK)
|
||||
|
||||
fpath, fname = path.split(program)
|
||||
if fpath:
|
||||
if is_exe(program):
|
||||
return program
|
||||
else:
|
||||
for part in os.environ['PATH'].split(os.pathsep):
|
||||
part = part.strip('"')
|
||||
exe_file = path.join(part, program)
|
||||
if is_exe(exe_file):
|
||||
return exe_file
|
||||
return None
|
||||
|
||||
def find_java():
|
||||
exec_command = None
|
||||
has_server_jvm = True
|
||||
java_path = which('java')
|
||||
if not java_path:
|
||||
java_path = which('java.exe')
|
||||
|
||||
if not java_path:
|
||||
print 'NOTE: No Java executable found in $PATH.'
|
||||
sys.exit(0)
|
||||
|
||||
is_ok = False
|
||||
java_version_out, _ = popen([java_path, '-version']).communicate()
|
||||
java_build_regex = re.compile(r'^\w+ version "(\d+)\.(\d+)')
|
||||
# pylint: disable=E1103
|
||||
match = re.search(java_build_regex, java_version_out)
|
||||
if match:
|
||||
major = int(match.group(1))
|
||||
minor = int(match.group(2))
|
||||
is_ok = major >= java_required_major and minor >= java_required_minor
|
||||
if is_ok:
|
||||
exec_command = [java_path, '-Xms1024m', '-server',
|
||||
'-XX:+TieredCompilation']
|
||||
check_server_proc = popen(exec_command + ['-version'])
|
||||
check_server_proc.communicate()
|
||||
if check_server_proc.returncode != 0:
|
||||
# Not all Java installs have server JVMs.
|
||||
exec_command = exec_command.remove('-server')
|
||||
has_server_jvm = False
|
||||
|
||||
if not is_ok:
|
||||
print 'NOTE: Java executable version %d.%d or above not found in $PATH.' % (java_required_major, java_required_minor)
|
||||
sys.exit(0)
|
||||
print 'Java executable: %s%s' % (java_path, '' if has_server_jvm else ' (no server JVM)')
|
||||
return exec_command
|
||||
|
||||
java_exec = find_java()
|
||||
|
||||
spawned_compiler_command = java_exec + [
|
||||
'-jar',
|
||||
closure_compiler_jar
|
||||
] + common_closure_args
|
||||
|
||||
print 'Compiling injected-script-source.js...'
|
||||
|
||||
command = spawned_compiler_command + [
|
||||
'--externs', injected_script_externs_file,
|
||||
'--externs', protocol_externs_file,
|
||||
'--js', injected_script_source_name
|
||||
]
|
||||
|
||||
injected_script_compile_proc = popen(command)
|
||||
|
||||
print 'Compiling debugger-script.js...'
|
||||
|
||||
command = spawned_compiler_command + [
|
||||
'--externs', debugger_script_externs_file,
|
||||
'--js', debugger_script_source_name,
|
||||
'--new_type_inf'
|
||||
]
|
||||
|
||||
debugger_script_compile_proc = popen(command)
|
||||
|
||||
print 'Validating injected-script-source.js...'
|
||||
injectedscript_check_script_path = path.join(v8_inspector_path, 'build',
|
||||
'check_injected_script_source.py')
|
||||
validate_injected_script_proc = popen([sys.executable,
|
||||
injectedscript_check_script_path, injected_script_source_name])
|
||||
|
||||
print
|
||||
|
||||
(injected_script_compile_out, _) = injected_script_compile_proc.communicate()
|
||||
print 'injected-script-source.js compilation output:%s' % os.linesep
|
||||
print injected_script_compile_out
|
||||
errors_found |= has_errors(injected_script_compile_out)
|
||||
|
||||
(debugger_script_compiler_out, _) = debugger_script_compile_proc.communicate()
|
||||
print 'debugger-script.js compilation output:%s' % os.linesep
|
||||
print debugger_script_compiler_out
|
||||
errors_found |= has_errors(debugger_script_compiler_out)
|
||||
|
||||
(validate_injected_script_out, _) = validate_injected_script_proc.communicate()
|
||||
print 'Validate injected-script-source.js output:%s' % os.linesep
|
||||
print validate_injected_script_out if validate_injected_script_out else '<empty>'
|
||||
errors_found |= has_errors(validate_injected_script_out)
|
||||
|
||||
os.remove(protocol_externs_file)
|
||||
|
||||
if errors_found:
|
||||
print 'ERRORS DETECTED'
|
||||
sys.exit(1)
|
246
src/inspector/build/generate_protocol_externs.py
Executable file
246
src/inspector/build/generate_protocol_externs.py
Executable file
@ -0,0 +1,246 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) 2011 Google Inc. All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
import os
|
||||
import re
|
||||
import json
|
||||
|
||||
type_traits = {
|
||||
"any": "*",
|
||||
"string": "string",
|
||||
"integer": "number",
|
||||
"number": "number",
|
||||
"boolean": "boolean",
|
||||
"array": "!Array.<*>",
|
||||
"object": "!Object",
|
||||
}
|
||||
|
||||
promisified_domains = {
|
||||
"Accessibility",
|
||||
"Animation",
|
||||
"CSS",
|
||||
"Emulation",
|
||||
"Profiler"
|
||||
}
|
||||
|
||||
ref_types = {}
|
||||
|
||||
def full_qualified_type_id(domain_name, type_id):
|
||||
if type_id.find(".") == -1:
|
||||
return "%s.%s" % (domain_name, type_id)
|
||||
return type_id
|
||||
|
||||
|
||||
def fix_camel_case(name):
|
||||
prefix = ""
|
||||
if name[0] == "-":
|
||||
prefix = "Negative"
|
||||
name = name[1:]
|
||||
refined = re.sub(r'-(\w)', lambda pat: pat.group(1).upper(), name)
|
||||
refined = to_title_case(refined)
|
||||
return prefix + re.sub(r'(?i)HTML|XML|WML|API', lambda pat: pat.group(0).upper(), refined)
|
||||
|
||||
|
||||
def to_title_case(name):
|
||||
return name[:1].upper() + name[1:]
|
||||
|
||||
|
||||
def generate_enum(name, json):
|
||||
enum_members = []
|
||||
for member in json["enum"]:
|
||||
enum_members.append(" %s: \"%s\"" % (fix_camel_case(member), member))
|
||||
return "\n/** @enum {string} */\n%s = {\n%s\n};\n" % (name, (",\n".join(enum_members)))
|
||||
|
||||
|
||||
def param_type(domain_name, param):
|
||||
if "type" in param:
|
||||
if param["type"] == "array":
|
||||
items = param["items"]
|
||||
return "!Array.<%s>" % param_type(domain_name, items)
|
||||
else:
|
||||
return type_traits[param["type"]]
|
||||
if "$ref" in param:
|
||||
type_id = full_qualified_type_id(domain_name, param["$ref"])
|
||||
if type_id in ref_types:
|
||||
return ref_types[type_id]
|
||||
else:
|
||||
print "Type not found: " + type_id
|
||||
return "!! Type not found: " + type_id
|
||||
|
||||
|
||||
def load_schema(file, domains):
|
||||
input_file = open(file, "r")
|
||||
json_string = input_file.read()
|
||||
parsed_json = json.loads(json_string)
|
||||
domains.extend(parsed_json["domains"])
|
||||
|
||||
|
||||
def generate_protocol_externs(output_path, file1):
|
||||
domains = []
|
||||
load_schema(file1, domains)
|
||||
output_file = open(output_path, "w")
|
||||
|
||||
output_file.write(
|
||||
"""
|
||||
var InspectorBackend = {}
|
||||
|
||||
var Protocol = {};
|
||||
/** @typedef {string}*/
|
||||
Protocol.Error;
|
||||
""")
|
||||
|
||||
for domain in domains:
|
||||
domain_name = domain["domain"]
|
||||
if "types" in domain:
|
||||
for type in domain["types"]:
|
||||
type_id = full_qualified_type_id(domain_name, type["id"])
|
||||
ref_types[type_id] = "%sAgent.%s" % (domain_name, type["id"])
|
||||
|
||||
for domain in domains:
|
||||
domain_name = domain["domain"]
|
||||
promisified = domain_name in promisified_domains
|
||||
|
||||
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"]:
|
||||
output_file.write("\n/**\n")
|
||||
params = []
|
||||
has_return_value = "returns" in command
|
||||
explicit_parameters = promisified and has_return_value
|
||||
if ("parameters" in command):
|
||||
for in_param in command["parameters"]:
|
||||
# All parameters are not optional in case of promisified domain with return value.
|
||||
if (not explicit_parameters and "optional" in in_param):
|
||||
params.append("opt_%s" % in_param["name"])
|
||||
output_file.write(" * @param {%s=} opt_%s\n" % (param_type(domain_name, in_param), in_param["name"]))
|
||||
else:
|
||||
params.append(in_param["name"])
|
||||
output_file.write(" * @param {%s} %s\n" % (param_type(domain_name, in_param), in_param["name"]))
|
||||
returns = []
|
||||
returns.append("?Protocol.Error")
|
||||
if ("error" in command):
|
||||
returns.append("%s=" % param_type(domain_name, command["error"]))
|
||||
if (has_return_value):
|
||||
for out_param in command["returns"]:
|
||||
if ("optional" in out_param):
|
||||
returns.append("%s=" % param_type(domain_name, out_param))
|
||||
else:
|
||||
returns.append("%s" % param_type(domain_name, out_param))
|
||||
callback_return_type = "void="
|
||||
if explicit_parameters:
|
||||
callback_return_type = "T"
|
||||
elif promisified:
|
||||
callback_return_type = "T="
|
||||
output_file.write(" * @param {function(%s):%s} opt_callback\n" % (", ".join(returns), callback_return_type))
|
||||
if (promisified):
|
||||
output_file.write(" * @return {!Promise.<T>}\n")
|
||||
output_file.write(" * @template T\n")
|
||||
params.append("opt_callback")
|
||||
|
||||
output_file.write(" */\n")
|
||||
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("Protocol.%sAgent.prototype.invoke_%s = function(obj, opt_callback) {}\n" % (domain_name, command["name"]))
|
||||
|
||||
output_file.write("\n\n\nvar %sAgent = function(){};\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("/** @interface */\n")
|
||||
output_file.write("%sAgent.Dispatcher = function() {};\n" % domain_name)
|
||||
if "events" in domain:
|
||||
for event in domain["events"]:
|
||||
params = []
|
||||
if ("parameters" in event):
|
||||
output_file.write("/**\n")
|
||||
for param in event["parameters"]:
|
||||
if ("optional" in param):
|
||||
params.append("opt_%s" % param["name"])
|
||||
output_file.write(" * @param {%s=} opt_%s\n" % (param_type(domain_name, param), param["name"]))
|
||||
else:
|
||||
params.append(param["name"])
|
||||
output_file.write(" * @param {%s} %s\n" % (param_type(domain_name, param), param["name"]))
|
||||
output_file.write(" */\n")
|
||||
output_file.write("%sAgent.Dispatcher.prototype.%s = function(%s) {};\n" % (domain_name, event["name"], ", ".join(params)))
|
||||
|
||||
output_file.write("\n/** @constructor\n * @param {!Object.<string, !Object>} agentsMap\n */\n")
|
||||
output_file.write("Protocol.Agents = function(agentsMap){this._agentsMap;};\n")
|
||||
output_file.write("/**\n * @param {string} domain\n * @param {!Object} dispatcher\n */\n")
|
||||
output_file.write("Protocol.Agents.prototype.registerDispatcher = function(domain, dispatcher){};\n")
|
||||
for domain in domains:
|
||||
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.write("/**\n * @param {!%sAgent.Dispatcher} dispatcher\n */\n" % domain_name)
|
||||
output_file.write("Protocol.Agents.prototype.register%sDispatcher = function(dispatcher) {}\n" % domain_name)
|
||||
|
||||
|
||||
output_file.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
import os.path
|
||||
program_name = os.path.basename(__file__)
|
||||
if len(sys.argv) < 4 or sys.argv[1] != "-o":
|
||||
sys.stderr.write("Usage: %s -o OUTPUT_FILE INPUT_FILE\n" % program_name)
|
||||
exit(1)
|
||||
output_path = sys.argv[2]
|
||||
input_path = sys.argv[3]
|
||||
generate_protocol_externs(output_path, input_path)
|
@ -34,11 +34,12 @@
|
||||
var DebuggerScript = {};
|
||||
|
||||
/** @enum */
|
||||
DebuggerScript.PauseOnExceptionsState = {
|
||||
const PauseOnExceptionsState = {
|
||||
DontPauseOnExceptions: 0,
|
||||
PauseOnAllExceptions: 1,
|
||||
PauseOnUncaughtExceptions: 2
|
||||
};
|
||||
DebuggerScript.PauseOnExceptionsState = PauseOnExceptionsState;
|
||||
|
||||
DebuggerScript._pauseOnExceptionsState = DebuggerScript.PauseOnExceptionsState.DontPauseOnExceptions;
|
||||
Debug.clearBreakOnException();
|
||||
@ -422,7 +423,7 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror)
|
||||
var returnValue = isAtReturn ? frameDetails.returnValue() : undefined;
|
||||
|
||||
var scopeMirrors = frameMirror.allScopes(false);
|
||||
/** @type {!Array<ScopeType>} */
|
||||
/** @type {!Array<number>} */
|
||||
var scopeTypes = new Array(scopeMirrors.length);
|
||||
/** @type {?Array<!Object>} */
|
||||
var scopeObjects = new Array(scopeMirrors.length);
|
||||
|
@ -56,27 +56,28 @@ var JavaScriptCallFrameDetails;
|
||||
}} */
|
||||
var JavaScriptCallFrame;
|
||||
|
||||
/** @interface */
|
||||
function DebugClass()
|
||||
{
|
||||
/** @type {!LiveEditClass} */
|
||||
this.LiveEdit;
|
||||
}
|
||||
/**
|
||||
* @const
|
||||
*/
|
||||
var Debug = {};
|
||||
|
||||
DebugClass.prototype.setBreakOnException = function() {}
|
||||
Debug.setBreakOnException = function() {}
|
||||
|
||||
DebugClass.prototype.clearBreakOnException = function() {}
|
||||
Debug.clearBreakOnException = function() {}
|
||||
|
||||
DebugClass.prototype.setBreakOnUncaughtException = function() {}
|
||||
Debug.setBreakOnUncaughtException = function() {}
|
||||
|
||||
DebugClass.prototype.clearBreakOnUncaughtException = function() {}
|
||||
/**
|
||||
* @return {undefined}
|
||||
*/
|
||||
Debug.clearBreakOnUncaughtException = function() {}
|
||||
|
||||
DebugClass.prototype.clearStepping = function() {}
|
||||
Debug.clearStepping = function() {}
|
||||
|
||||
DebugClass.prototype.clearAllBreakPoints = function() {}
|
||||
Debug.clearAllBreakPoints = function() {}
|
||||
|
||||
/** @return {!Array<!Script>} */
|
||||
DebugClass.prototype.scripts = function() {}
|
||||
Debug.scripts = function() {}
|
||||
|
||||
/**
|
||||
* @param {number} scriptId
|
||||
@ -86,33 +87,31 @@ DebugClass.prototype.scripts = function() {}
|
||||
* @param {string=} groupId
|
||||
* @param {Debug.BreakPositionAlignment=} positionAlignment
|
||||
*/
|
||||
DebugClass.prototype.setScriptBreakPointById = function(scriptId, line, column, condition, groupId, positionAlignment) {}
|
||||
Debug.setScriptBreakPointById = function(scriptId, line, column, condition, groupId, positionAlignment) {}
|
||||
|
||||
/**
|
||||
* @param {number} breakId
|
||||
* @return {!Array<!SourceLocation>}
|
||||
*/
|
||||
DebugClass.prototype.findBreakPointActualLocations = function(breakId) {}
|
||||
Debug.findBreakPointActualLocations = function(breakId) {}
|
||||
|
||||
/**
|
||||
* @param {number} breakId
|
||||
* @param {boolean} remove
|
||||
* @return {!BreakPoint|undefined}
|
||||
*/
|
||||
DebugClass.prototype.findBreakPoint = function(breakId, remove) {}
|
||||
Debug.findBreakPoint = function(breakId, remove) {}
|
||||
|
||||
/** @return {!DebuggerFlags} */
|
||||
DebugClass.prototype.debuggerFlags = function() {}
|
||||
|
||||
/** @type {!DebugClass} */
|
||||
var Debug;
|
||||
Debug.debuggerFlags = function() {}
|
||||
|
||||
|
||||
/** @enum */
|
||||
Debug.BreakPositionAlignment = {
|
||||
const BreakPositionAlignment = {
|
||||
Statement: 0,
|
||||
BreakPosition: 1
|
||||
};
|
||||
Debug.BreakPositionAlignment = BreakPositionAlignment;
|
||||
|
||||
/** @enum */
|
||||
Debug.StepAction = { StepOut: 0,
|
||||
@ -121,9 +120,10 @@ Debug.StepAction = { StepOut: 0,
|
||||
StepFrame: 3 };
|
||||
|
||||
/** @enum */
|
||||
Debug.ScriptCompilationType = { Host: 0,
|
||||
Eval: 1,
|
||||
JSON: 2 };
|
||||
const ScriptCompilationType = { Host: 0,
|
||||
Eval: 1,
|
||||
JSON: 2 };
|
||||
Debug.ScriptCompilationType = ScriptCompilationType;
|
||||
|
||||
|
||||
/** @interface */
|
||||
@ -133,16 +133,14 @@ function DebuggerFlag() {}
|
||||
DebuggerFlag.prototype.setValue = function(value) {}
|
||||
|
||||
|
||||
/** @interface */
|
||||
function DebuggerFlags()
|
||||
{
|
||||
/** @type {!DebuggerFlag} */
|
||||
this.breakPointsActive;
|
||||
}
|
||||
/** @typedef {{
|
||||
* breakPointsActive: !DebuggerFlag
|
||||
* }}
|
||||
*/
|
||||
var DebuggerFlags;
|
||||
|
||||
|
||||
/** @interface */
|
||||
function LiveEditClass() {}
|
||||
/** @const */
|
||||
var LiveEdit = {}
|
||||
|
||||
/**
|
||||
* @param {!Script} script
|
||||
@ -150,35 +148,32 @@ function LiveEditClass() {}
|
||||
* @param {boolean} previewOnly
|
||||
* @return {!{stack_modified: (boolean|undefined)}}
|
||||
*/
|
||||
LiveEditClass.prototype.SetScriptSource = function(script, newSource, previewOnly, change_log) {}
|
||||
LiveEdit.SetScriptSource = function(script, newSource, previewOnly, change_log) {}
|
||||
|
||||
/** @constructor */
|
||||
function Failure() {}
|
||||
LiveEdit.Failure = Failure;
|
||||
|
||||
/** @interface */
|
||||
function LiveEditErrorDetails()
|
||||
{
|
||||
/** @type {string} */
|
||||
this.syntaxErrorMessage;
|
||||
/** @type {!{start: !{line: number, column: number}}} */
|
||||
this.position;
|
||||
}
|
||||
Debug.LiveEdit = LiveEdit;
|
||||
|
||||
/** @typedef {{
|
||||
* type: string,
|
||||
* syntaxErrorMessage: string,
|
||||
* position: !{start: !{line: number, column: number}},
|
||||
* }}
|
||||
*/
|
||||
var LiveEditErrorDetails;
|
||||
|
||||
/** @interface */
|
||||
function BreakpointInfo()
|
||||
{
|
||||
/** @type {number} */
|
||||
this.breakpointId;
|
||||
/** @type {number} */
|
||||
this.sourceID;
|
||||
/** @type {number|undefined} */
|
||||
this.lineNumber;
|
||||
/** @type {number|undefined} */
|
||||
this.columnNumber;
|
||||
/** @type {string|undefined} */
|
||||
this.condition;
|
||||
/** @type {boolean|undefined} */
|
||||
this.interstatementLocation;
|
||||
}
|
||||
/** @typedef {{
|
||||
* breakpointId: number,
|
||||
* sourceID: number,
|
||||
* lineNumber: (number|undefined),
|
||||
* columnNumber: (number|undefined),
|
||||
* condition: (string|undefined),
|
||||
* interstatementLocation: (boolean|undefined),
|
||||
* }}
|
||||
*/
|
||||
var BreakpointInfo;
|
||||
|
||||
|
||||
/** @interface */
|
||||
@ -244,53 +239,32 @@ var ScopeType = { Global: 0,
|
||||
Script: 6 };
|
||||
|
||||
|
||||
/** @interface */
|
||||
function SourceLocation()
|
||||
{
|
||||
/** @type {number} */
|
||||
this.script;
|
||||
/** @type {number} */
|
||||
this.position;
|
||||
/** @type {number} */
|
||||
this.line;
|
||||
/** @type {number} */
|
||||
this.column;
|
||||
/** @type {number} */
|
||||
this.start;
|
||||
/** @type {number} */
|
||||
this.end;
|
||||
}
|
||||
|
||||
|
||||
/** @interface */
|
||||
function Script()
|
||||
{
|
||||
/** @type {number} */
|
||||
this.id;
|
||||
/** @type {string|undefined} */
|
||||
this.context_data;
|
||||
/** @type {string|undefined} */
|
||||
this.source_url;
|
||||
/** @type {string|undefined} */
|
||||
this.source_mapping_url;
|
||||
/** @type {boolean} */
|
||||
this.is_debugger_script;
|
||||
/** @type {string} */
|
||||
this.source;
|
||||
/** @type {!Array<number>} */
|
||||
this.line_ends;
|
||||
/** @type {number} */
|
||||
this.line_offset;
|
||||
/** @type {number} */
|
||||
this.column_offset;
|
||||
}
|
||||
|
||||
/** @return {string} */
|
||||
Script.prototype.nameOrSourceURL = function() {}
|
||||
|
||||
/** @return {!Debug.ScriptCompilationType} */
|
||||
Script.prototype.compilationType = function() {}
|
||||
/** @typedef {{
|
||||
* script: number,
|
||||
* position: number,
|
||||
* line: number,
|
||||
* column:number,
|
||||
* start: number,
|
||||
* end: number,
|
||||
* }}
|
||||
*/
|
||||
var SourceLocation;
|
||||
|
||||
/** @typedef{{
|
||||
* id: number,
|
||||
* context_data: (string|undefined),
|
||||
* source_url: (string|undefined),
|
||||
* source_mapping_url: (string|undefined),
|
||||
* is_debugger_script: boolean,
|
||||
* source: string,
|
||||
* line_ends: !Array<number>,
|
||||
* line_offset: number,
|
||||
* column_offset: number,
|
||||
* nameOrSourceURL: function():string,
|
||||
* compilationType: function():!ScriptCompilationType,
|
||||
* }}
|
||||
*/
|
||||
var Script;
|
||||
|
||||
/** @interface */
|
||||
function ScopeDetails() {}
|
||||
@ -301,6 +275,9 @@ ScopeDetails.prototype.object = function() {}
|
||||
/** @return {string|undefined} */
|
||||
ScopeDetails.prototype.name = function() {}
|
||||
|
||||
/** @return {number} */
|
||||
ScopeDetails.prototype.type = function() {}
|
||||
|
||||
|
||||
/** @interface */
|
||||
function FrameDetails() {}
|
||||
@ -463,11 +440,7 @@ GeneratorMirror.prototype.func = function() {}
|
||||
* @interface
|
||||
* @extends {Mirror}
|
||||
*/
|
||||
function PropertyMirror()
|
||||
{
|
||||
/** @type {*} */
|
||||
this.value_;
|
||||
}
|
||||
function PropertyMirror() {}
|
||||
|
||||
/** @return {!Mirror} */
|
||||
PropertyMirror.prototype.value = function() {}
|
||||
@ -475,6 +448,8 @@ PropertyMirror.prototype.value = function() {}
|
||||
/** @return {string} */
|
||||
PropertyMirror.prototype.name = function() {}
|
||||
|
||||
/** @type {*} */
|
||||
PropertyMirror.prototype.value_;
|
||||
|
||||
/**
|
||||
* @interface
|
||||
|
@ -33,6 +33,7 @@
|
||||
* @param {!InjectedScriptHostClass} InjectedScriptHost
|
||||
* @param {!Window|!WorkerGlobalScope} inspectedGlobalObject
|
||||
* @param {number} injectedScriptId
|
||||
* @suppress {uselessCode}
|
||||
*/
|
||||
(function (InjectedScriptHost, inspectedGlobalObject, injectedScriptId) {
|
||||
|
||||
@ -799,7 +800,6 @@ InjectedScript.RemoteObject.prototype = {
|
||||
}
|
||||
|
||||
/**
|
||||
* @suppressReceiverCheck
|
||||
* @param {*} object
|
||||
* @param {*=} customObjectConfig
|
||||
* @return {*}
|
||||
|
@ -295,6 +295,7 @@ class SourceProcessor(SourceFileProcessor):
|
||||
|
||||
IGNORE_COPYRIGHTS = ['box2d.js',
|
||||
'cpplint.py',
|
||||
'check_injected_script_source.py',
|
||||
'copy.js',
|
||||
'corrections.js',
|
||||
'crypto.js',
|
||||
@ -303,6 +304,7 @@ class SourceProcessor(SourceFileProcessor):
|
||||
'earley-boyer.js',
|
||||
'fannkuch.js',
|
||||
'fasta.js',
|
||||
'generate_protocol_externs.py',
|
||||
'injected-script.cc',
|
||||
'injected-script.h',
|
||||
'injected-script-source.js',
|
||||
|
Loading…
Reference in New Issue
Block a user