CompilerScriptMapping.js [plain text]
WebInspector.CompilerScriptMapping = function(workspace, networkWorkspaceProvider)
{
this._workspace = workspace;
this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, this._uiSourceCodeAddedToWorkspace, this);
this._networkWorkspaceProvider = networkWorkspaceProvider;
this._sourceMapForSourceMapURL = {};
this._sourceMapForScriptId = {};
this._scriptForSourceMap = new Map();
this._sourceMapForURL = {};
WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this);
}
WebInspector.CompilerScriptMapping.prototype = {
rawLocationToUILocation: function(rawLocation)
{
var debuggerModelLocation = (rawLocation);
var sourceMap = this._sourceMapForScriptId[debuggerModelLocation.scriptId];
var lineNumber = debuggerModelLocation.lineNumber;
var columnNumber = debuggerModelLocation.columnNumber || 0;
var entry = sourceMap.findEntry(lineNumber, columnNumber);
if (!entry || entry.length === 2)
return null;
var url = entry[2];
var uiSourceCode = this._workspace.uiSourceCodeForURL(url);
if (!uiSourceCode)
return null;
return new WebInspector.UILocation(uiSourceCode, entry[3], entry[4]);
},
uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
{
if (!uiSourceCode.url)
return null;
var sourceMap = this._sourceMapForURL[uiSourceCode.url];
if (!sourceMap)
return null;
var entry = sourceMap.findEntryReversed(uiSourceCode.url, lineNumber);
return WebInspector.debuggerModel.createRawLocation(this._scriptForSourceMap.get(sourceMap), entry[0], entry[1]);
},
isIdentity: function()
{
return false;
},
addScript: function(script)
{
var sourceMap = this.loadSourceMapForScript(script);
if (!sourceMap)
return;
if (this._scriptForSourceMap.get(sourceMap)) {
this._sourceMapForScriptId[script.scriptId] = sourceMap;
script.pushSourceMapping(this);
return;
}
this._sourceMapForScriptId[script.scriptId] = sourceMap;
this._scriptForSourceMap.put(sourceMap, script);
var sourceURLs = sourceMap.sources();
for (var i = 0; i < sourceURLs.length; ++i) {
var sourceURL = sourceURLs[i];
if (this._sourceMapForURL[sourceURL])
continue;
this._sourceMapForURL[sourceURL] = sourceMap;
if (!this._workspace.hasMappingForURL(sourceURL) && !this._workspace.uiSourceCodeForURL(sourceURL)) {
var sourceContent = sourceMap.sourceContent(sourceURL);
var contentProvider;
if (sourceContent)
contentProvider = new WebInspector.StaticContentProvider(WebInspector.resourceTypes.Script, sourceContent);
else
contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL);
this._networkWorkspaceProvider.addFileForURL(sourceURL, contentProvider, true);
}
var uiSourceCode = this._workspace.uiSourceCodeForURL(sourceURL);
if (uiSourceCode) {
this._bindUISourceCode(uiSourceCode);
uiSourceCode.isContentScript = script.isContentScript;
}
}
script.pushSourceMapping(this);
},
_bindUISourceCode: function(uiSourceCode)
{
uiSourceCode.setSourceMapping(this);
},
_uiSourceCodeAddedToWorkspace: function(event)
{
var uiSourceCode = (event.data);
if (!uiSourceCode.url || !this._sourceMapForURL[uiSourceCode.url])
return;
this._bindUISourceCode(uiSourceCode);
},
loadSourceMapForScript: function(script)
{
if (!script.sourceMapURL)
return null;
var scriptURL = WebInspector.ParsedURL.completeURL(WebInspector.inspectedPageURL, script.sourceURL);
if (!scriptURL)
return null;
var sourceMapURL = WebInspector.ParsedURL.completeURL(scriptURL, script.sourceMapURL);
if (!sourceMapURL)
return null;
var sourceMap = this._sourceMapForSourceMapURL[sourceMapURL];
if (sourceMap)
return sourceMap;
sourceMap = WebInspector.SourceMap.load(sourceMapURL, scriptURL);
if (!sourceMap)
return null;
this._sourceMapForSourceMapURL[sourceMapURL] = sourceMap;
return sourceMap;
},
_debuggerReset: function()
{
this._sourceMapForSourceMapURL = {};
this._sourceMapForScriptId = {};
this._scriptForSourceMap = new Map();
this._sourceMapForURL = {};
}
}