Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: Source/devtools/front_end/bindings/CompilerScriptMapping.js

Issue 697563003: DevTools: do not show compiled script while source maps are being loaded. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: w/ tests Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 /** @type {!Object.<string, !WebInspector.SourceMap>} */ 48 /** @type {!Object.<string, !WebInspector.SourceMap>} */
49 this._sourceMapForSourceMapURL = {}; 49 this._sourceMapForSourceMapURL = {};
50 /** @type {!Object.<string, !Array.<function(?WebInspector.SourceMap)>>} */ 50 /** @type {!Object.<string, !Array.<function(?WebInspector.SourceMap)>>} */
51 this._pendingSourceMapLoadingCallbacks = {}; 51 this._pendingSourceMapLoadingCallbacks = {};
52 /** @type {!Object.<string, !WebInspector.SourceMap>} */ 52 /** @type {!Object.<string, !WebInspector.SourceMap>} */
53 this._sourceMapForScriptId = {}; 53 this._sourceMapForScriptId = {};
54 /** @type {!Map.<!WebInspector.SourceMap, !WebInspector.Script>} */ 54 /** @type {!Map.<!WebInspector.SourceMap, !WebInspector.Script>} */
55 this._scriptForSourceMap = new Map(); 55 this._scriptForSourceMap = new Map();
56 /** @type {!Map.<string, !WebInspector.SourceMap>} */ 56 /** @type {!Map.<string, !WebInspector.SourceMap>} */
57 this._sourceMapForURL = new Map(); 57 this._sourceMapForURL = new Map();
58 /** @type {!Map.<string, !WebInspector.UISourceCode>} */
59 this._stubUISourceCodes = new Map();
60
61 this._stubProjectID = "compiler-script-project";
62 this._stubProjectDelegate = new WebInspector.ContentProviderBasedProjectDele gate(this._workspace, this._stubProjectID, WebInspector.projectTypes.Service);
58 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjec tCleared, this._debuggerReset, this); 63 debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjec tCleared, this._debuggerReset, this);
59 } 64 }
60 65
61 WebInspector.CompilerScriptMapping.prototype = { 66 WebInspector.CompilerScriptMapping.prototype = {
62 /** 67 /**
63 * @param {!WebInspector.DebuggerModel.Location} rawLocation 68 * @param {!WebInspector.DebuggerModel.Location} rawLocation
64 * @return {?WebInspector.UILocation} 69 * @return {?WebInspector.UILocation}
65 */ 70 */
66 rawLocationToUILocation: function(rawLocation) 71 rawLocationToUILocation: function(rawLocation)
67 { 72 {
68 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat ion} */ (rawLocation); 73 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat ion} */ (rawLocation);
74
75 var stubUISourceCode = this._stubUISourceCodes.get(debuggerModelLocation .scriptId);
76 if (stubUISourceCode)
77 return new WebInspector.UILocation(stubUISourceCode, 0, 0);
78
69 var sourceMap = this._sourceMapForScriptId[debuggerModelLocation.scriptI d]; 79 var sourceMap = this._sourceMapForScriptId[debuggerModelLocation.scriptI d];
70 if (!sourceMap) 80 if (!sourceMap)
71 return null; 81 return null;
72 var lineNumber = debuggerModelLocation.lineNumber; 82 var lineNumber = debuggerModelLocation.lineNumber;
73 var columnNumber = debuggerModelLocation.columnNumber || 0; 83 var columnNumber = debuggerModelLocation.columnNumber || 0;
74 var entry = sourceMap.findEntry(lineNumber, columnNumber); 84 var entry = sourceMap.findEntry(lineNumber, columnNumber);
75 if (!entry || entry.length === 2) 85 if (!entry || entry.length === 2)
76 return null; 86 return null;
77 var url = /** @type {string} */ (entry[2]); 87 var url = /** @type {string} */ (entry[2]);
78 var uiSourceCode = this._workspace.uiSourceCodeForURL(url); 88 var uiSourceCode = this._workspace.uiSourceCodeForURL(url);
79 if (!uiSourceCode) 89 if (!uiSourceCode)
80 return null; 90 return null;
81 return uiSourceCode.uiLocation(/** @type {number} */ (entry[3]), /** @ty pe {number} */ (entry[4])); 91 return uiSourceCode.uiLocation(/** @type {number} */ (entry[3]), /** @ty pe {number} */ (entry[4]));
82 }, 92 },
83 93
84 /** 94 /**
85 * @param {!WebInspector.UISourceCode} uiSourceCode 95 * @param {!WebInspector.UISourceCode} uiSourceCode
86 * @param {number} lineNumber 96 * @param {number} lineNumber
87 * @param {number} columnNumber 97 * @param {number} columnNumber
88 * @return {?WebInspector.DebuggerModel.Location} 98 * @return {?WebInspector.DebuggerModel.Location}
89 */ 99 */
90 uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber) 100 uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
91 { 101 {
102 if (uiSourceCode.project().type() === WebInspector.projectTypes.Service)
103 return null;
92 if (!uiSourceCode.url) 104 if (!uiSourceCode.url)
93 return null; 105 return null;
94 var sourceMap = this._sourceMapForURL.get(uiSourceCode.url); 106 var sourceMap = this._sourceMapForURL.get(uiSourceCode.url);
95 if (!sourceMap) 107 if (!sourceMap)
96 return null; 108 return null;
97 var script = /** @type {!WebInspector.Script} */ (this._scriptForSourceM ap.get(sourceMap)); 109 var script = /** @type {!WebInspector.Script} */ (this._scriptForSourceM ap.get(sourceMap));
98 console.assert(script); 110 console.assert(script);
99 var mappingSearchLinesCount = 5; 111 var mappingSearchLinesCount = 5;
100 // We do not require precise (breakpoint) location but limit the number of lines to search or mapping. 112 // We do not require precise (breakpoint) location but limit the number of lines to search or mapping.
101 var entry = sourceMap.findEntryReversed(uiSourceCode.url, lineNumber, ma ppingSearchLinesCount); 113 var entry = sourceMap.findEntryReversed(uiSourceCode.url, lineNumber, ma ppingSearchLinesCount);
102 if (!entry) 114 if (!entry)
103 return null; 115 return null;
104 return this._debuggerModel.createRawLocation(script, /** @type {number} */ (entry[0]), /** @type {number} */ (entry[1])); 116 return this._debuggerModel.createRawLocation(script, /** @type {number} */ (entry[0]), /** @type {number} */ (entry[1]));
105 }, 117 },
106 118
107 /** 119 /**
108 * @param {!WebInspector.Script} script 120 * @param {!WebInspector.Script} script
109 */ 121 */
110 addScript: function(script) 122 addScript: function(script)
111 { 123 {
112 if (!script.sourceMapURL) { 124 if (!script.sourceMapURL) {
113 script.addEventListener(WebInspector.Script.Events.SourceMapURLAdded , this._sourceMapURLAdded.bind(this)); 125 script.addEventListener(WebInspector.Script.Events.SourceMapURLAdded , this._sourceMapURLAdded.bind(this));
114 return; 126 return;
115 } 127 }
128
116 this._processScript(script); 129 this._processScript(script);
117 }, 130 },
118 131
119 /** 132 /**
120 * @param {!WebInspector.Event} event 133 * @param {!WebInspector.Event} event
121 */ 134 */
122 _sourceMapURLAdded: function(event) 135 _sourceMapURLAdded: function(event)
123 { 136 {
124 var script = /** @type {!WebInspector.Script} */ (event.target); 137 var script = /** @type {!WebInspector.Script} */ (event.target);
125 if (!script.sourceMapURL) 138 if (!script.sourceMapURL)
126 return; 139 return;
127 this._processScript(script); 140 this._processScript(script);
128 }, 141 },
129 142
130 /** 143 /**
131 * @param {!WebInspector.Script} script 144 * @param {!WebInspector.Script} script
132 */ 145 */
133 _processScript: function(script) 146 _processScript: function(script)
134 { 147 {
148 // Create stub UISourceCode for the time source mapping is being loaded.
149 var url = script.sourceURL;
150 var splitURL = WebInspector.ParsedURL.splitURLIntoPathComponents(url);
151 var projectName = splitURL[0];
152 var parentPath = splitURL.slice(1, -1).join("/");
153 var name = splitURL.peekLast() || "";
154 var uiSourceCodePath = this._stubProjectDelegate.addContentProvider(pare ntPath, name, url, url, new WebInspector.StaticContentProvider(WebInspector.reso urceTypes.Script, "\n\n\n\n\n// Please wait a bit.\n// Compiled script is not sh own while source map is being loaded!", url));
155 var stubUISourceCode = /** @type {!WebInspector.UISourceCode} */ (this._ workspace.uiSourceCode(this._stubProjectID, uiSourceCodePath));
156 this._stubUISourceCodes.set(script.scriptId, stubUISourceCode);
157
135 this._debuggerWorkspaceBinding.pushSourceMapping(script, this); 158 this._debuggerWorkspaceBinding.pushSourceMapping(script, this);
136 this._loadSourceMapForScript(script, sourceMapLoaded.bind(this)); 159 this._loadSourceMapForScript(script, sourceMapLoaded.bind(this));
137 160
138 /** 161 /**
139 * @param {?WebInspector.SourceMap} sourceMap 162 * @param {?WebInspector.SourceMap} sourceMap
140 * @this {WebInspector.CompilerScriptMapping} 163 * @this {WebInspector.CompilerScriptMapping}
141 */ 164 */
142 function sourceMapLoaded(sourceMap) 165 function sourceMapLoaded(sourceMap)
143 { 166 {
144 if (!sourceMap) 167 this._stubUISourceCodes.delete(script.scriptId);
168 this._stubProjectDelegate.removeFile(uiSourceCodePath);
169
170 if (!sourceMap) {
171 this._debuggerWorkspaceBinding.updateLocations(script);
145 return; 172 return;
173 }
146 174
147 if (this._scriptForSourceMap.get(sourceMap)) { 175 if (this._scriptForSourceMap.get(sourceMap)) {
148 this._sourceMapForScriptId[script.scriptId] = sourceMap; 176 this._sourceMapForScriptId[script.scriptId] = sourceMap;
149 this._debuggerWorkspaceBinding.updateLocations(script); 177 this._debuggerWorkspaceBinding.updateLocations(script);
150 return; 178 return;
151 } 179 }
152 180
153 this._sourceMapForScriptId[script.scriptId] = sourceMap; 181 this._sourceMapForScriptId[script.scriptId] = sourceMap;
154 this._scriptForSourceMap.set(sourceMap, script); 182 this._scriptForSourceMap.set(sourceMap, script);
155 183
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 this._sourceMapForScriptId = {}; 341 this._sourceMapForScriptId = {};
314 this._scriptForSourceMap.clear(); 342 this._scriptForSourceMap.clear();
315 this._sourceMapForURL.clear(); 343 this._sourceMapForURL.clear();
316 }, 344 },
317 345
318 dispose: function() 346 dispose: function()
319 { 347 {
320 this._workspace.removeEventListener(WebInspector.Workspace.Events.UISour ceCodeAdded, this._uiSourceCodeAddedToWorkspace, this); 348 this._workspace.removeEventListener(WebInspector.Workspace.Events.UISour ceCodeAdded, this._uiSourceCodeAddedToWorkspace, this);
321 } 349 }
322 } 350 }
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/inspector/workspace-test.js ('k') | Source/devtools/front_end/common/StaticContentProvider.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698