Index: third_party/WebKit/Source/devtools/front_end/sdk/Script.js |
diff --git a/third_party/WebKit/Source/devtools/front_end/sdk/Script.js b/third_party/WebKit/Source/devtools/front_end/sdk/Script.js |
index 1f465ff590c4573adaff3a724a8c6e66ab24e610..216d6780718035d4139c66b6ad3af9a245d5ac60 100644 |
--- a/third_party/WebKit/Source/devtools/front_end/sdk/Script.js |
+++ b/third_party/WebKit/Source/devtools/front_end/sdk/Script.js |
@@ -22,28 +22,41 @@ |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
- |
/** |
- * @constructor |
- * @extends {WebInspector.SDKObject} |
* @implements {WebInspector.ContentProvider} |
- * @param {!WebInspector.DebuggerModel} debuggerModel |
- * @param {string} scriptId |
- * @param {string} sourceURL |
- * @param {number} startLine |
- * @param {number} startColumn |
- * @param {number} endLine |
- * @param {number} endColumn |
- * @param {!RuntimeAgent.ExecutionContextId} executionContextId |
- * @param {string} hash |
- * @param {boolean} isContentScript |
- * @param {boolean} isLiveEdit |
- * @param {string=} sourceMapURL |
- * @param {boolean=} hasSourceURL |
+ * @unrestricted |
*/ |
-WebInspector.Script = function(debuggerModel, scriptId, sourceURL, startLine, startColumn, endLine, endColumn, executionContextId, hash, isContentScript, isLiveEdit, sourceMapURL, hasSourceURL) |
-{ |
- WebInspector.SDKObject.call(this, debuggerModel.target()); |
+WebInspector.Script = class extends WebInspector.SDKObject { |
+ /** |
+ * @param {!WebInspector.DebuggerModel} debuggerModel |
+ * @param {string} scriptId |
+ * @param {string} sourceURL |
+ * @param {number} startLine |
+ * @param {number} startColumn |
+ * @param {number} endLine |
+ * @param {number} endColumn |
+ * @param {!RuntimeAgent.ExecutionContextId} executionContextId |
+ * @param {string} hash |
+ * @param {boolean} isContentScript |
+ * @param {boolean} isLiveEdit |
+ * @param {string=} sourceMapURL |
+ * @param {boolean=} hasSourceURL |
+ */ |
+ constructor( |
+ debuggerModel, |
+ scriptId, |
+ sourceURL, |
+ startLine, |
+ startColumn, |
+ endLine, |
+ endColumn, |
+ executionContextId, |
+ hash, |
+ isContentScript, |
+ isLiveEdit, |
+ sourceMapURL, |
+ hasSourceURL) { |
+ super(debuggerModel.target()); |
this.debuggerModel = debuggerModel; |
this.scriptId = scriptId; |
this.sourceURL = sourceURL; |
@@ -57,291 +70,274 @@ WebInspector.Script = function(debuggerModel, scriptId, sourceURL, startLine, st |
this._isLiveEdit = isLiveEdit; |
this.sourceMapURL = sourceMapURL; |
this.hasSourceURL = hasSourceURL; |
-}; |
- |
-/** @enum {symbol} */ |
-WebInspector.Script.Events = { |
- ScriptEdited: Symbol("ScriptEdited"), |
- SourceMapURLAdded: Symbol("SourceMapURLAdded") |
-}; |
- |
-WebInspector.Script.sourceURLRegex = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$/m; |
+ } |
-/** |
- * @param {string} source |
- * @return {string} |
- */ |
-WebInspector.Script._trimSourceURLComment = function(source) |
-{ |
- var sourceURLIndex = source.lastIndexOf("//# sourceURL="); |
+ /** |
+ * @param {string} source |
+ * @return {string} |
+ */ |
+ static _trimSourceURLComment(source) { |
+ var sourceURLIndex = source.lastIndexOf('//# sourceURL='); |
if (sourceURLIndex === -1) { |
- sourceURLIndex = source.lastIndexOf("//@ sourceURL="); |
- if (sourceURLIndex === -1) |
- return source; |
+ sourceURLIndex = source.lastIndexOf('//@ sourceURL='); |
+ if (sourceURLIndex === -1) |
+ return source; |
} |
- var sourceURLLineIndex = source.lastIndexOf("\n", sourceURLIndex); |
+ var sourceURLLineIndex = source.lastIndexOf('\n', sourceURLIndex); |
if (sourceURLLineIndex === -1) |
- return source; |
- var sourceURLLine = source.substr(sourceURLLineIndex + 1).split("\n", 1)[0]; |
+ return source; |
+ var sourceURLLine = source.substr(sourceURLLineIndex + 1).split('\n', 1)[0]; |
if (sourceURLLine.search(WebInspector.Script.sourceURLRegex) === -1) |
- return source; |
+ return source; |
return source.substr(0, sourceURLLineIndex) + source.substr(sourceURLLineIndex + sourceURLLine.length + 1); |
-}; |
+ } |
-/** |
- * @param {!WebInspector.Script} script |
- * @param {string} source |
- */ |
-WebInspector.Script._reportDeprecatedCommentIfNeeded = function(script, source) |
-{ |
+ /** |
+ * @param {!WebInspector.Script} script |
+ * @param {string} source |
+ */ |
+ static _reportDeprecatedCommentIfNeeded(script, source) { |
var consoleModel = script.target().consoleModel; |
if (!consoleModel) |
- return; |
+ return; |
var linesToCheck = 5; |
- var offset = source.lastIndexOf("\n"); |
+ var offset = source.lastIndexOf('\n'); |
while (linesToCheck && offset !== -1) { |
- offset = source.lastIndexOf("\n", offset - 1); |
- --linesToCheck; |
+ offset = source.lastIndexOf('\n', offset - 1); |
+ --linesToCheck; |
} |
offset = offset !== -1 ? offset : 0; |
var sourceTail = source.substr(offset); |
if (sourceTail.length > 5000) |
- return; |
+ return; |
if (sourceTail.search(/^[\040\t]*\/\/@ source(mapping)?url=/mi) === -1) |
- return; |
- var text = WebInspector.UIString("'//@ sourceURL' and '//@ sourceMappingURL' are deprecated, please use '//# sourceURL=' and '//# sourceMappingURL=' instead."); |
- var msg = new WebInspector.ConsoleMessage(script.target(), WebInspector.ConsoleMessage.MessageSource.JS, WebInspector.ConsoleMessage.MessageLevel.Warning, text, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, script.scriptId); |
+ return; |
+ var text = WebInspector.UIString( |
+ '\'//@ sourceURL\' and \'//@ sourceMappingURL\' are deprecated, please use \'//# sourceURL=\' and \'//# sourceMappingURL=\' instead.'); |
+ var msg = new WebInspector.ConsoleMessage( |
+ script.target(), WebInspector.ConsoleMessage.MessageSource.JS, WebInspector.ConsoleMessage.MessageLevel.Warning, |
+ text, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, |
+ script.scriptId); |
consoleModel.addMessage(msg); |
-}; |
+ } |
-WebInspector.Script.prototype = { |
- /** |
- * @return {boolean} |
- */ |
- isContentScript: function() |
- { |
- return this._isContentScript; |
- }, |
+ /** |
+ * @return {boolean} |
+ */ |
+ isContentScript() { |
+ return this._isContentScript; |
+ } |
- /** |
- * @return {?WebInspector.ExecutionContext} |
- */ |
- executionContext: function() |
- { |
- return this.target().runtimeModel.executionContext(this._executionContextId); |
- }, |
+ /** |
+ * @return {?WebInspector.ExecutionContext} |
+ */ |
+ executionContext() { |
+ return this.target().runtimeModel.executionContext(this._executionContextId); |
+ } |
- /** |
- * @return {boolean} |
- */ |
- isLiveEdit: function() |
- { |
- return this._isLiveEdit; |
- }, |
+ /** |
+ * @return {boolean} |
+ */ |
+ isLiveEdit() { |
+ return this._isLiveEdit; |
+ } |
- /** |
- * @override |
- * @return {string} |
- */ |
- contentURL: function() |
- { |
- return this.sourceURL; |
- }, |
+ /** |
+ * @override |
+ * @return {string} |
+ */ |
+ contentURL() { |
+ return this.sourceURL; |
+ } |
+ |
+ /** |
+ * @override |
+ * @return {!WebInspector.ResourceType} |
+ */ |
+ contentType() { |
+ return WebInspector.resourceTypes.Script; |
+ } |
+ |
+ /** |
+ * @override |
+ * @return {!Promise<?string>} |
+ */ |
+ requestContent() { |
+ if (this._source) |
+ return Promise.resolve(this._source); |
+ if (!this.scriptId) |
+ return Promise.resolve(/** @type {?string} */ ('')); |
+ |
+ var callback; |
+ var promise = new Promise(fulfill => callback = fulfill); |
+ this.target().debuggerAgent().getScriptSource(this.scriptId, didGetScriptSource.bind(this)); |
+ return promise; |
/** |
- * @override |
- * @return {!WebInspector.ResourceType} |
+ * @this {WebInspector.Script} |
+ * @param {?Protocol.Error} error |
+ * @param {string} source |
*/ |
- contentType: function() |
- { |
- return WebInspector.resourceTypes.Script; |
- }, |
+ function didGetScriptSource(error, source) { |
+ if (!error) { |
+ WebInspector.Script._reportDeprecatedCommentIfNeeded(this, source); |
+ this._source = WebInspector.Script._trimSourceURLComment(source); |
+ } else { |
+ this._source = ''; |
+ } |
+ callback(this._source); |
+ } |
+ } |
+ /** |
+ * @override |
+ * @param {string} query |
+ * @param {boolean} caseSensitive |
+ * @param {boolean} isRegex |
+ * @param {function(!Array.<!DebuggerAgent.SearchMatch>)} callback |
+ */ |
+ searchInContent(query, caseSensitive, isRegex, callback) { |
/** |
- * @override |
- * @return {!Promise<?string>} |
+ * @param {?Protocol.Error} error |
+ * @param {!Array.<!DebuggerAgent.SearchMatch>} searchMatches |
*/ |
- requestContent: function() |
- { |
- if (this._source) |
- return Promise.resolve(this._source); |
- if (!this.scriptId) |
- return Promise.resolve(/** @type {?string} */("")); |
+ function innerCallback(error, searchMatches) { |
+ if (error) { |
+ console.error(error); |
+ callback([]); |
+ return; |
+ } |
+ var result = []; |
+ for (var i = 0; i < searchMatches.length; ++i) { |
+ var searchMatch = |
+ new WebInspector.ContentProvider.SearchMatch(searchMatches[i].lineNumber, searchMatches[i].lineContent); |
+ result.push(searchMatch); |
+ } |
+ callback(result || []); |
+ } |
- var callback; |
- var promise = new Promise(fulfill => callback = fulfill); |
- this.target().debuggerAgent().getScriptSource(this.scriptId, didGetScriptSource.bind(this)); |
- return promise; |
+ if (this.scriptId) { |
+ // Script failed to parse. |
+ this.target().debuggerAgent().searchInContent(this.scriptId, query, caseSensitive, isRegex, innerCallback); |
+ } else { |
+ callback([]); |
+ } |
+ } |
- /** |
- * @this {WebInspector.Script} |
- * @param {?Protocol.Error} error |
- * @param {string} source |
- */ |
- function didGetScriptSource(error, source) |
- { |
- if (!error) { |
- WebInspector.Script._reportDeprecatedCommentIfNeeded(this, source); |
- this._source = WebInspector.Script._trimSourceURLComment(source); |
- } else { |
- this._source = ""; |
- } |
- callback(this._source); |
- } |
- }, |
+ /** |
+ * @param {string} source |
+ * @return {string} |
+ */ |
+ _appendSourceURLCommentIfNeeded(source) { |
+ if (!this.hasSourceURL) |
+ return source; |
+ return source + '\n //# sourceURL=' + this.sourceURL; |
+ } |
+ /** |
+ * @param {string} newSource |
+ * @param {function(?Protocol.Error, !RuntimeAgent.ExceptionDetails=, !Array.<!DebuggerAgent.CallFrame>=, !RuntimeAgent.StackTrace=, boolean=)} callback |
+ */ |
+ editSource(newSource, callback) { |
/** |
- * @override |
- * @param {string} query |
- * @param {boolean} caseSensitive |
- * @param {boolean} isRegex |
- * @param {function(!Array.<!DebuggerAgent.SearchMatch>)} callback |
+ * @this {WebInspector.Script} |
+ * @param {?Protocol.Error} error |
+ * @param {!Array.<!DebuggerAgent.CallFrame>=} callFrames |
+ * @param {boolean=} stackChanged |
+ * @param {!RuntimeAgent.StackTrace=} asyncStackTrace |
+ * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails |
*/ |
- searchInContent: function(query, caseSensitive, isRegex, callback) |
- { |
- /** |
- * @param {?Protocol.Error} error |
- * @param {!Array.<!DebuggerAgent.SearchMatch>} searchMatches |
- */ |
- function innerCallback(error, searchMatches) |
- { |
- if (error) { |
- console.error(error); |
- callback([]); |
- return; |
- } |
- var result = []; |
- for (var i = 0; i < searchMatches.length; ++i) { |
- var searchMatch = new WebInspector.ContentProvider.SearchMatch(searchMatches[i].lineNumber, searchMatches[i].lineContent); |
- result.push(searchMatch); |
- } |
- callback(result || []); |
- } |
+ function didEditScriptSource(error, callFrames, stackChanged, asyncStackTrace, exceptionDetails) { |
+ if (!error && !exceptionDetails) |
+ this._source = newSource; |
+ var needsStepIn = !!stackChanged; |
+ callback(error, exceptionDetails, callFrames, asyncStackTrace, needsStepIn); |
+ } |
- if (this.scriptId) { |
- // Script failed to parse. |
- this.target().debuggerAgent().searchInContent(this.scriptId, query, caseSensitive, isRegex, innerCallback); |
- } else { |
- callback([]); |
- } |
- }, |
+ newSource = WebInspector.Script._trimSourceURLComment(newSource); |
+ // We append correct sourceURL to script for consistency only. It's not actually needed for things to work correctly. |
+ newSource = this._appendSourceURLCommentIfNeeded(newSource); |
- /** |
- * @param {string} source |
- * @return {string} |
- */ |
- _appendSourceURLCommentIfNeeded: function(source) |
- { |
- if (!this.hasSourceURL) |
- return source; |
- return source + "\n //# sourceURL=" + this.sourceURL; |
- }, |
+ if (this.scriptId) |
+ this.target().debuggerAgent().setScriptSource( |
+ this.scriptId, newSource, undefined, didEditScriptSource.bind(this)); |
+ else |
+ callback('Script failed to parse'); |
+ } |
- /** |
- * @param {string} newSource |
- * @param {function(?Protocol.Error, !RuntimeAgent.ExceptionDetails=, !Array.<!DebuggerAgent.CallFrame>=, !RuntimeAgent.StackTrace=, boolean=)} callback |
- */ |
- editSource: function(newSource, callback) |
- { |
- /** |
- * @this {WebInspector.Script} |
- * @param {?Protocol.Error} error |
- * @param {!Array.<!DebuggerAgent.CallFrame>=} callFrames |
- * @param {boolean=} stackChanged |
- * @param {!RuntimeAgent.StackTrace=} asyncStackTrace |
- * @param {!RuntimeAgent.ExceptionDetails=} exceptionDetails |
- */ |
- function didEditScriptSource(error, callFrames, stackChanged, asyncStackTrace, exceptionDetails) |
- { |
- if (!error && !exceptionDetails) |
- this._source = newSource; |
- var needsStepIn = !!stackChanged; |
- callback(error, exceptionDetails, callFrames, asyncStackTrace, needsStepIn); |
- } |
+ /** |
+ * @param {number} lineNumber |
+ * @param {number=} columnNumber |
+ * @return {!WebInspector.DebuggerModel.Location} |
+ */ |
+ rawLocation(lineNumber, columnNumber) { |
+ return new WebInspector.DebuggerModel.Location(this.debuggerModel, this.scriptId, lineNumber, columnNumber || 0); |
+ } |
- newSource = WebInspector.Script._trimSourceURLComment(newSource); |
- // We append correct sourceURL to script for consistency only. It's not actually needed for things to work correctly. |
- newSource = this._appendSourceURLCommentIfNeeded(newSource); |
+ /** |
+ * @return {boolean} |
+ */ |
+ isInlineScript() { |
+ var startsAtZero = !this.lineOffset && !this.columnOffset; |
+ return !!this.sourceURL && !startsAtZero; |
+ } |
- if (this.scriptId) |
- this.target().debuggerAgent().setScriptSource(this.scriptId, newSource, undefined, didEditScriptSource.bind(this)); |
- else |
- callback("Script failed to parse"); |
- }, |
+ /** |
+ * @param {string} sourceMapURL |
+ */ |
+ addSourceMapURL(sourceMapURL) { |
+ if (this.sourceMapURL) |
+ return; |
+ this.sourceMapURL = sourceMapURL; |
+ this.dispatchEventToListeners(WebInspector.Script.Events.SourceMapURLAdded, this.sourceMapURL); |
+ } |
- /** |
- * @param {number} lineNumber |
- * @param {number=} columnNumber |
- * @return {!WebInspector.DebuggerModel.Location} |
- */ |
- rawLocation: function(lineNumber, columnNumber) |
- { |
- return new WebInspector.DebuggerModel.Location(this.debuggerModel, this.scriptId, lineNumber, columnNumber || 0); |
- }, |
+ /** |
+ * @return {boolean} |
+ */ |
+ isAnonymousScript() { |
+ return !this.sourceURL; |
+ } |
- /** |
- * @return {boolean} |
- */ |
- isInlineScript: function() |
- { |
- var startsAtZero = !this.lineOffset && !this.columnOffset; |
- return !!this.sourceURL && !startsAtZero; |
- }, |
+ /** |
+ * @return {boolean} |
+ */ |
+ isInlineScriptWithSourceURL() { |
+ return !!this.hasSourceURL && this.isInlineScript(); |
+ } |
- /** |
- * @param {string} sourceMapURL |
- */ |
- addSourceMapURL: function(sourceMapURL) |
- { |
- if (this.sourceMapURL) |
- return; |
- this.sourceMapURL = sourceMapURL; |
- this.dispatchEventToListeners(WebInspector.Script.Events.SourceMapURLAdded, this.sourceMapURL); |
- }, |
+ /** |
+ * @param {!Array<!DebuggerAgent.ScriptPosition>} positions |
+ * @return {!Promise<boolean>} |
+ */ |
+ setBlackboxedRanges(positions) { |
+ return new Promise(setBlackboxedRanges.bind(this)); |
/** |
- * @return {boolean} |
+ * @param {function(?)} fulfill |
+ * @param {function(*)} reject |
+ * @this {WebInspector.Script} |
*/ |
- isAnonymousScript: function() |
- { |
- return !this.sourceURL; |
- }, |
+ function setBlackboxedRanges(fulfill, reject) { |
+ this.target().debuggerAgent().setBlackboxedRanges(this.scriptId, positions, callback); |
+ /** |
+ * @param {?Protocol.Error} error |
+ */ |
+ function callback(error) { |
+ if (error) |
+ console.error(error); |
+ fulfill(!error); |
+ } |
+ } |
+ } |
+}; |
- /** |
- * @return {boolean} |
- */ |
- isInlineScriptWithSourceURL: function() |
- { |
- return !!this.hasSourceURL && this.isInlineScript(); |
- }, |
+/** @enum {symbol} */ |
+WebInspector.Script.Events = { |
+ ScriptEdited: Symbol('ScriptEdited'), |
+ SourceMapURLAdded: Symbol('SourceMapURLAdded') |
+}; |
- /** |
- * @param {!Array<!DebuggerAgent.ScriptPosition>} positions |
- * @return {!Promise<boolean>} |
- */ |
- setBlackboxedRanges: function(positions) |
- { |
- return new Promise(setBlackboxedRanges.bind(this)); |
+WebInspector.Script.sourceURLRegex = /^[\040\t]*\/\/[@#] sourceURL=\s*(\S*?)\s*$/m; |
- /** |
- * @param {function(?)} fulfill |
- * @param {function(*)} reject |
- * @this {WebInspector.Script} |
- */ |
- function setBlackboxedRanges(fulfill, reject) |
- { |
- this.target().debuggerAgent().setBlackboxedRanges(this.scriptId, positions, callback); |
- /** |
- * @param {?Protocol.Error} error |
- */ |
- function callback(error) |
- { |
- if (error) |
- console.error(error); |
- fulfill(!error); |
- } |
- } |
- }, |
- __proto__: WebInspector.SDKObject.prototype |
-}; |