Changeset 112070 in webkit
- Timestamp:
- Mar 26, 2012 2:55:15 AM (12 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r112069 r112070 1 2012-03-22 Pavel Podivilov <podivilov@chromium.org> 2 3 Web Inspector: move resource loading logic from SourceMapParser to CompilerScriptMapping. 4 https://bugs.webkit.org/show_bug.cgi?id=81897 5 6 Reviewed by Vsevolod Vlasov. 7 8 * http/tests/inspector/compiler-script-mapping.html: 9 1 10 2012-03-26 Pavel Feldman <pfeldman@chromium.org> 2 11 -
trunk/LayoutTests/http/tests/inspector/compiler-script-mapping.html
r111655 r112070 10 10 function checkMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, sourceColumnNumber, mapping) 11 11 { 12 var sourceLocation = mapping.compiledLocationToSourceLocation(compiledLineNumber, compiledColumnNumber);13 InspectorTest.assertEquals(sourceURL, sourceLocation.sourceURL);14 InspectorTest.assertEquals(sourceLineNumber, sourceLocation.lineNumber);15 InspectorTest.assertEquals(sourceColumnNumber, sourceLocation.columnNumber);12 var entry = mapping.findEntry(compiledLineNumber, compiledColumnNumber); 13 InspectorTest.assertEquals(sourceURL, entry[2]); 14 InspectorTest.assertEquals(sourceLineNumber, entry[3]); 15 InspectorTest.assertEquals(sourceColumnNumber, entry[4]); 16 16 } 17 17 18 18 function checkReverseMapping(compiledLineNumber, compiledColumnNumber, sourceURL, sourceLineNumber, mapping) 19 19 { 20 var compiledLocation = mapping.sourceLocationToCompiledLocation(sourceURL, sourceLineNumber);21 InspectorTest.assertEquals(compiledLineNumber, compiledLocation[0]);22 InspectorTest.assertEquals(compiledColumnNumber, compiledLocation[1]);20 var entry = mapping.findEntryReversed(sourceURL, sourceLineNumber); 21 InspectorTest.assertEquals(compiledLineNumber, entry[0]); 22 InspectorTest.assertEquals(compiledColumnNumber, entry[1]); 23 23 } 24 24 … … 46 46 "sources":["example.js"] 47 47 }; 48 var mapping = new WebInspector.SourceMapParser(); 49 mapping._parseMappingPayload(mappingPayload); 48 var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload); 50 49 51 50 checkMapping(0, 9, "example.js", 0, 9, mapping); … … 61 60 checkReverseMapping(0, 29, "example.js", 4, mapping); 62 61 checkReverseMapping(0, 29, "example.js", 5, mapping); 63 InspectorTest.assertTrue(!mapping.sourceLocationToCompiledLocation("example.js", 6));64 62 65 63 next(); … … 72 70 "sources":["example.js"] 73 71 }; 74 var mapping = new WebInspector.SourceMapParser(); 75 mapping._parseMappingPayload(mappingPayload); 72 var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload); 76 73 checkMapping(0, 0, "example.js", 0, 0, mapping); 77 74 checkMapping(0, 2, "example.js", 0, 2, mapping); … … 85 82 "sources":["example.js"] 86 83 }; 87 var mapping = new WebInspector.SourceMapParser(); 88 mapping._parseMappingPayload(mappingPayload); 84 var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload); 89 85 checkMapping(0, 0, "example.js", 0, 0, mapping); 90 86 checkReverseMapping(3, 1, "example.js", 1, mapping); … … 109 105 } 110 106 ]}; 111 var mapping = new WebInspector.SourceMapParser(); 112 mapping._parseMappingPayload(mappingPayload); 107 var mapping = new WebInspector.SourceMapParser("source-map.json", mappingPayload); 113 108 InspectorTest.assertEquals(2, mapping.sources().length); 114 109 checkMapping(0, 0, "source1.js", 0, 0, mapping); -
trunk/Source/WebCore/ChangeLog
r112066 r112070 1 2012-03-22 Pavel Podivilov <podivilov@chromium.org> 2 3 Web Inspector: move resource loading logic from SourceMapParser to CompilerScriptMapping. 4 https://bugs.webkit.org/show_bug.cgi?id=81897 5 6 Reviewed by Vsevolod Vlasov. 7 8 SourceMapParser should only deal with payload parsing. 9 10 * inspector/front-end/CompilerScriptMapping.js: 11 (WebInspector.CompilerScriptMapping.prototype.rawLocationToUILocation): 12 (WebInspector.CompilerScriptMapping.prototype.addScript): 13 (WebInspector.CompilerScriptMapping.prototype.loadSourceMapForScript): 14 (WebInspector.SourceMapPayload): 15 (WebInspector.SourceMapParser): 16 (WebInspector.SourceMapParser.prototype.sourceContent): 17 (WebInspector.SourceMapParser.prototype.findEntry): 18 (WebInspector.SourceMapParser.prototype.findEntryReversed): 19 * inspector/front-end/ContentProviders.js: 20 (WebInspector.CompilerSourceMappingContentProvider): 21 (WebInspector.CompilerSourceMappingContentProvider.prototype.requestContent): 22 1 23 2012-03-26 Ilya Tikhonovsky <loislo@chromium.org> 2 24 -
trunk/Source/WebCore/inspector/front-end/CompilerScriptMapping.js
r111694 r112070 50 50 { 51 51 var sourceMap = this._sourceMapForScriptId[rawLocation.scriptId]; 52 var location = sourceMap.compiledLocationToSourceLocation(rawLocation.lineNumber, rawLocation.columnNumber || 0); 53 var uiSourceCode = this._uiSourceCodeByURL[location.sourceURL]; 54 return new WebInspector.UILocation(uiSourceCode, location.lineNumber, location.columnNumber); 52 var entry = sourceMap.findEntry(rawLocation.lineNumber, rawLocation.columnNumber || 0); 53 return new WebInspector.UILocation(this._uiSourceCodeByURL[entry[2]], entry[3], entry[4]); 55 54 }, 56 55 … … 64 63 { 65 64 var sourceMap = this._sourceMapForUISourceCode.get(uiSourceCode); 66 var location = sourceMap.sourceLocationToCompiledLocation(uiSourceCode.url, lineNumber);67 return WebInspector.debuggerModel.createRawLocation(this._scriptForSourceMap.get(sourceMap), location[0], location[1]);65 var entry = sourceMap.findEntryReversed(uiSourceCode.url, lineNumber); 66 return WebInspector.debuggerModel.createRawLocation(this._scriptForSourceMap.get(sourceMap), entry[0], entry[1]); 68 67 }, 69 68 … … 113 112 if (this._uiSourceCodeByURL[sourceURL]) 114 113 continue; 115 var contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL, sourceMap); 114 var sourceContent = sourceMap.sourceContent(sourceURL); 115 var contentProvider; 116 if (sourceContent) 117 contentProvider = new WebInspector.StaticContentProvider("text/javascript", sourceContent); 118 else 119 contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL); 116 120 var uiSourceCode = new WebInspector.UISourceCode(sourceURL, sourceURL, contentProvider); 117 121 uiSourceCode.isContentScript = script.isContentScript; … … 141 145 return sourceMap; 142 146 143 sourceMap = new WebInspector.SourceMapParser(script.sourceMapURL, script.sourceURL); 144 if (!sourceMap.load()) 147 try { 148 // FIXME: make sendRequest async. 149 var response = InspectorFrontendHost.loadResourceSynchronously(sourceMapURL); 150 if (response.slice(0, 3) === ")]}") 151 response = response.substring(response.indexOf('\n')); 152 var payload = /** @type {WebInspector.SourceMapPayload} */ JSON.parse(response); 153 sourceMap = new WebInspector.SourceMapParser(sourceMapURL, payload); 154 } catch(e) { 155 console.error(e.message); 145 156 return null; 146 157 } 147 158 this._sourceMapByURL[sourceMapURL] = sourceMap; 148 159 return sourceMap; … … 167 178 * @constructor 168 179 */ 169 WebInspector.SourceMapPa rserPayload = function()180 WebInspector.SourceMapPayload = function() 170 181 { 182 this.sections = []; 171 183 this.mappings = ""; 172 184 this.sourceRoot = ""; … … 179 191 * @constructor 180 192 * @param {string} sourceMappingURL 181 * @param { string} scriptSourceOrigin182 */ 183 WebInspector.SourceMapParser = function(sourceMappingURL, scriptSourceOrigin)193 * @param {WebInspector.SourceMapPayload} payload 194 */ 195 WebInspector.SourceMapParser = function(sourceMappingURL, payload) 184 196 { 185 197 if (!WebInspector.SourceMapParser.prototype._base64Map) { … … 190 202 } 191 203 192 this._sourceMappingURL = this._canonicalizeURL(sourceMappingURL, scriptSourceOrigin);204 this._sourceMappingURL = sourceMappingURL; 193 205 this._mappings = []; 194 206 this._reverseMappingsBySourceURL = {}; 195 207 this._sourceContentByURL = {}; 208 this._parseMappingPayload(payload); 196 209 } 197 210 198 211 WebInspector.SourceMapParser.prototype = { 199 /**200 * @return {boolean}201 */202 load: function()203 {204 try {205 // FIXME: make sendRequest async.206 var response = InspectorFrontendHost.loadResourceSynchronously(this._sourceMappingURL);207 if (response.slice(0, 3) === ")]}")208 response = response.substring(response.indexOf('\n'));209 this._parseMappingPayload(JSON.parse(response));210 return true211 } catch(e) {212 console.error(e.message);213 return false;214 }215 },216 217 /**218 * @param {number} lineNumber219 * @param {number} columnNumber220 * @return {Object}221 */222 compiledLocationToSourceLocation: function(lineNumber, columnNumber)223 {224 var mapping = this._findMapping(lineNumber, columnNumber);225 return { sourceURL: mapping[2], lineNumber: mapping[3], columnNumber: mapping[4] };226 },227 228 sourceLocationToCompiledLocation: function(sourceURL, lineNumber)229 {230 var mappings = this._reverseMappingsBySourceURL[sourceURL];231 for ( ; lineNumber < mappings.length; ++lineNumber) {232 var mapping = mappings[lineNumber];233 if (mapping)234 return [mapping[0], mapping[1]];235 }236 },237 238 212 /** 239 213 * @return {Array.<string>} … … 247 221 }, 248 222 249 /** 250 * @param {string} sourceURL 251 * @return {string} 252 */ 253 loadSourceCode: function(sourceURL) 254 { 255 if (this._sourceContentByURL[sourceURL]) 256 return this._sourceContentByURL[sourceURL]; 257 258 try { 259 // FIXME: make sendRequest async. 260 return InspectorFrontendHost.loadResourceSynchronously(sourceURL); 261 } catch(e) { 262 console.error(e.message); 263 return ""; 264 } 265 }, 266 267 _findMapping: function(lineNumber, columnNumber) 223 sourceContent: function(sourceURL) 224 { 225 return this._sourceContentByURL[sourceURL]; 226 }, 227 228 findEntry: function(lineNumber, columnNumber) 268 229 { 269 230 var first = 0; … … 283 244 }, 284 245 246 findEntryReversed: function(sourceURL, lineNumber) 247 { 248 var mappings = this._reverseMappingsBySourceURL[sourceURL]; 249 for ( ; lineNumber < mappings.length; ++lineNumber) { 250 var mapping = mappings[lineNumber]; 251 if (mapping) 252 return mapping; 253 } 254 return this._mappings[0]; 255 }, 256 285 257 _parseMappingPayload: function(mappingPayload) 286 258 { -
trunk/Source/WebCore/inspector/front-end/ContentProviders.js
r103711 r112070 244 244 * @implements {WebInspector.ContentProvider} 245 245 */ 246 WebInspector.CompilerSourceMappingContentProvider = function(sourceURL , compilerSourceMapping)246 WebInspector.CompilerSourceMappingContentProvider = function(sourceURL) 247 247 { 248 248 this._mimeType = "text/javascript"; 249 249 this._sourceURL = sourceURL; 250 this._compilerSourceMapping = compilerSourceMapping;251 250 } 252 251 … … 257 256 requestContent: function(callback) 258 257 { 259 var sourceCode = this._compilerSourceMapping.loadSourceCode(this._sourceURL); 258 var sourceCode = ""; 259 try { 260 // FIXME: make sendRequest async. 261 sourceCode = InspectorFrontendHost.loadResourceSynchronously(this._sourceURL); 262 } catch(e) { 263 console.error(e.message); 264 } 260 265 callback(this._mimeType, sourceCode); 261 266 },
Note: See TracChangeset
for help on using the changeset viewer.