Commit e9ceb376 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[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}
parent df490c34
#!/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
#!/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))
#!/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)
This diff is collapsed.
......@@ -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',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment