WebInspector.Script = function(scriptId, sourceURL, startLine, startColumn, endLine, endColumn, isContentScript, sourceMapURL, hasSourceURL)
{
this.scriptId = scriptId;
this.sourceURL = sourceURL;
this.lineOffset = startLine;
this.columnOffset = startColumn;
this.endLine = endLine;
this.endColumn = endColumn;
this.isContentScript = isContentScript;
this.sourceMapURL = sourceMapURL;
this.hasSourceURL = hasSourceURL;
this._locations = new Set();
this._sourceMappings = [];
}
WebInspector.Script.Events = {
ScriptEdited: "ScriptEdited",
}
WebInspector.Script.snippetSourceURLPrefix = "snippets:///";
WebInspector.Script.prototype = {
contentURL: function()
{
return this.sourceURL;
},
contentType: function()
{
return WebInspector.resourceTypes.Script;
},
requestContent: function(callback)
{
if (this._source) {
callback(this._source, false, "text/javascript");
return;
}
function didGetScriptSource(error, source)
{
this._source = error ? "" : source;
callback(this._source, false, "text/javascript");
}
if (this.scriptId) {
DebuggerAgent.getScriptSource(this.scriptId, didGetScriptSource.bind(this));
} else
callback("", false, "text/javascript");
},
searchInContent: function(query, caseSensitive, isRegex, callback)
{
function innerCallback(error, searchMatches)
{
if (error)
console.error(error);
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 || []);
}
if (this.scriptId) {
DebuggerAgent.searchInContent(this.scriptId, query, caseSensitive, isRegex, innerCallback.bind(this));
} else
callback([]);
},
editSource: function(newSource, callback)
{
function didEditScriptSource(error, callFrames, debugData)
{
if (!error)
this._source = newSource;
callback(error, callFrames);
if (!error)
this.dispatchEventToListeners(WebInspector.Script.Events.ScriptEdited, newSource);
}
if (this.scriptId) {
DebuggerAgent.setScriptSource(this.scriptId, newSource, undefined, didEditScriptSource.bind(this));
} else
callback("Script failed to parse");
},
isInlineScript: function()
{
var startsAtZero = !this.lineOffset && !this.columnOffset;
return !!this.sourceURL && !startsAtZero;
},
isAnonymousScript: function()
{
return !this.sourceURL;
},
setIsDynamicScript: function(isDynamicScript)
{
this._isDynamicScript = isDynamicScript;
},
isDynamicScript: function()
{
return !!this._isDynamicScript;
},
isSnippet: function()
{
return this.sourceURL && this.sourceURL.startsWith(WebInspector.Script.snippetSourceURLPrefix);
},
rawLocationToUILocation: function(lineNumber, columnNumber)
{
var uiLocation;
var rawLocation = new WebInspector.DebuggerModel.Location(this.scriptId, lineNumber, columnNumber || 0);
for (var i = this._sourceMappings.length - 1; !uiLocation && i >= 0; --i)
uiLocation = this._sourceMappings[i].rawLocationToUILocation(rawLocation);
console.assert(uiLocation, "Script raw location can not be mapped to any ui location.");
return uiLocation.uiSourceCode.overrideLocation(uiLocation);
},
pushSourceMapping: function(sourceMapping)
{
this._sourceMappings.push(sourceMapping);
this.updateLocations();
},
popSourceMapping: function()
{
this._sourceMappings.pop();
this.updateLocations();
},
updateLocations: function()
{
var items = this._locations.items();
for (var i = 0; i < items.length; ++i)
items[i].update();
},
createLiveLocation: function(rawLocation, updateDelegate)
{
console.assert(rawLocation.scriptId === this.scriptId);
var location = new WebInspector.Script.Location(this, rawLocation, updateDelegate);
this._locations.add(location);
location.update();
return location;
},
__proto__: WebInspector.Object.prototype
}
WebInspector.Script.Location = function(script, rawLocation, updateDelegate)
{
WebInspector.LiveLocation.call(this, rawLocation, updateDelegate);
this._script = script;
}
WebInspector.Script.Location.prototype = {
uiLocation: function()
{
var debuggerModelLocation = (this.rawLocation());
return this._script.rawLocationToUILocation(debuggerModelLocation.lineNumber, debuggerModelLocation.columnNumber);
},
dispose: function()
{
WebInspector.LiveLocation.prototype.dispose.call(this);
this._script._locations.remove(this);
},
__proto__: WebInspector.LiveLocation.prototype
}