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

Side by Side Diff: Source/devtools/front_end/sdk/Script.js

Issue 299443016: DevTools: Decouple debugger model from UI entities (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Merge DebuggerScriptMapping into DebuggerWorkspaceBinding Created 6 years, 4 months 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) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 WebInspector.SDKObject.call(this, target); 43 WebInspector.SDKObject.call(this, target);
44 this.scriptId = scriptId; 44 this.scriptId = scriptId;
45 this.sourceURL = sourceURL; 45 this.sourceURL = sourceURL;
46 this.lineOffset = startLine; 46 this.lineOffset = startLine;
47 this.columnOffset = startColumn; 47 this.columnOffset = startColumn;
48 this.endLine = endLine; 48 this.endLine = endLine;
49 this.endColumn = endColumn; 49 this.endColumn = endColumn;
50 this._isContentScript = isContentScript; 50 this._isContentScript = isContentScript;
51 this.sourceMapURL = sourceMapURL; 51 this.sourceMapURL = sourceMapURL;
52 this.hasSourceURL = hasSourceURL; 52 this.hasSourceURL = hasSourceURL;
53 /** @type {!Set.<!WebInspector.Script.Location>} */
54 this._locations = new Set();
55 /** @type {!Array.<!WebInspector.SourceMapping>} */
56 this._sourceMappings = [];
57 } 53 }
58 54
59 WebInspector.Script.Events = { 55 WebInspector.Script.Events = {
60 ScriptEdited: "ScriptEdited", 56 ScriptEdited: "ScriptEdited",
61 SourceMapURLAdded: "SourceMapURLAdded", 57 SourceMapURLAdded: "SourceMapURLAdded",
62 } 58 }
63 59
64 WebInspector.Script.snippetSourceURLPrefix = "snippets:///"; 60 WebInspector.Script.snippetSourceURLPrefix = "snippets:///";
65 61
66 WebInspector.Script.sourceURLRegex = /\n[\040\t]*\/\/[@#]\ssourceURL=\s*(\S*?)\s *$/mg; 62 WebInspector.Script.sourceURLRegex = /\n[\040\t]*\/\/[@#]\ssourceURL=\s*(\S*?)\s *$/mg;
67 63
68 /** 64 /**
69 * @param {string} source 65 * @param {string} source
70 * @return {string} 66 * @return {string}
71 */ 67 */
72 WebInspector.Script._trimSourceURLComment = function(source) 68 WebInspector.Script._trimSourceURLComment = function(source)
73 { 69 {
74 return source.replace(WebInspector.Script.sourceURLRegex, ""); 70 return source.replace(WebInspector.Script.sourceURLRegex, "");
75 }, 71 }
76 72
77 73
78 WebInspector.Script.prototype = { 74 WebInspector.Script.prototype = {
79 /** 75 /**
80 * @return {boolean} 76 * @return {boolean}
81 */ 77 */
82 isContentScript: function() 78 isContentScript: function()
83 { 79 {
84 return this._isContentScript; 80 return this._isContentScript;
85 }, 81 },
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 for (var i = 0; i < searchMatches.length; ++i) { 143 for (var i = 0; i < searchMatches.length; ++i) {
148 var searchMatch = new WebInspector.ContentProvider.SearchMatch(s earchMatches[i].lineNumber, searchMatches[i].lineContent); 144 var searchMatch = new WebInspector.ContentProvider.SearchMatch(s earchMatches[i].lineNumber, searchMatches[i].lineContent);
149 result.push(searchMatch); 145 result.push(searchMatch);
150 } 146 }
151 callback(result || []); 147 callback(result || []);
152 } 148 }
153 149
154 if (this.scriptId) { 150 if (this.scriptId) {
155 // Script failed to parse. 151 // Script failed to parse.
156 this.target().debuggerAgent().searchInContent(this.scriptId, query, caseSensitive, isRegex, innerCallback); 152 this.target().debuggerAgent().searchInContent(this.scriptId, query, caseSensitive, isRegex, innerCallback);
157 } else 153 } else {
158 callback([]); 154 callback([]);
155 }
159 }, 156 },
160 157
161 /** 158 /**
162 * @param {string} source 159 * @param {string} source
163 * @return {string} 160 * @return {string}
164 */ 161 */
165 _appendSourceURLCommentIfNeeded: function(source) 162 _appendSourceURLCommentIfNeeded: function(source)
166 { 163 {
167 if (!this.hasSourceURL) 164 if (!this.hasSourceURL)
168 return source; 165 return source;
(...skipping 29 matching lines...) Expand all
198 // We append correct sourceURL to script for consistency only. It's not actually needed for things to work correctly. 195 // We append correct sourceURL to script for consistency only. It's not actually needed for things to work correctly.
199 newSource = this._appendSourceURLCommentIfNeeded(newSource); 196 newSource = this._appendSourceURLCommentIfNeeded(newSource);
200 197
201 if (this.scriptId) 198 if (this.scriptId)
202 this.target().debuggerAgent().setScriptSource(this.scriptId, newSour ce, undefined, didEditScriptSource.bind(this)); 199 this.target().debuggerAgent().setScriptSource(this.scriptId, newSour ce, undefined, didEditScriptSource.bind(this));
203 else 200 else
204 callback("Script failed to parse"); 201 callback("Script failed to parse");
205 }, 202 },
206 203
207 /** 204 /**
205 * @param {number} lineNumber
206 * @param {number=} columnNumber
207 * @return {!WebInspector.DebuggerModel.Location}
208 */
209 rawLocation: function(lineNumber, columnNumber)
210 {
211 return new WebInspector.DebuggerModel.Location(this.target(), this.scrip tId, lineNumber, columnNumber || 0);
212 },
213
214 /**
208 * @return {boolean} 215 * @return {boolean}
209 */ 216 */
210 isInlineScript: function() 217 isInlineScript: function()
211 { 218 {
212 var startsAtZero = !this.lineOffset && !this.columnOffset; 219 var startsAtZero = !this.lineOffset && !this.columnOffset;
213 return !!this.sourceURL && !startsAtZero; 220 return !!this.sourceURL && !startsAtZero;
214 }, 221 },
215 222
216 /** 223 /**
217 * @param {string} sourceMapURL 224 * @param {string} sourceMapURL
(...skipping 26 matching lines...) Expand all
244 * @return {boolean} 251 * @return {boolean}
245 */ 252 */
246 isFramework: function() 253 isFramework: function()
247 { 254 {
248 if (!WebInspector.experimentsSettings.frameworksDebuggingSupport.isEnabl ed()) 255 if (!WebInspector.experimentsSettings.frameworksDebuggingSupport.isEnabl ed())
249 return false; 256 return false;
250 var regex = WebInspector.settings.skipStackFramesPattern.asRegExp(); 257 var regex = WebInspector.settings.skipStackFramesPattern.asRegExp();
251 return regex ? regex.test(this.sourceURL) : false; 258 return regex ? regex.test(this.sourceURL) : false;
252 }, 259 },
253 260
254 /**
255 * @param {number} lineNumber
256 * @param {number=} columnNumber
257 * @return {!WebInspector.UILocation}
258 */
259 rawLocationToUILocation: function(lineNumber, columnNumber)
260 {
261 var uiLocation;
262 var rawLocation = new WebInspector.DebuggerModel.Location(this.target(), this.scriptId, lineNumber, columnNumber || 0);
263 for (var i = this._sourceMappings.length - 1; !uiLocation && i >= 0; --i )
264 uiLocation = this._sourceMappings[i].rawLocationToUILocation(rawLoca tion);
265 console.assert(uiLocation, "Script raw location can not be mapped to any ui location.");
266 return /** @type {!WebInspector.UILocation} */ (uiLocation);
267 },
268
269 /**
270 * @param {!WebInspector.SourceMapping} sourceMapping
271 */
272 pushSourceMapping: function(sourceMapping)
273 {
274 this._sourceMappings.push(sourceMapping);
275 this.updateLocations();
276 },
277
278 /**
279 * @return {!WebInspector.SourceMapping}
280 */
281 popSourceMapping: function()
282 {
283 var sourceMapping = this._sourceMappings.pop();
284 this.updateLocations();
285 return sourceMapping;
286 },
287
288 updateLocations: function()
289 {
290 var items = this._locations.values();
291 for (var i = 0; i < items.length; ++i)
292 items[i].update();
293 },
294
295 /**
296 * @param {!WebInspector.DebuggerModel.Location} rawLocation
297 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDel egate
298 * @return {!WebInspector.Script.Location}
299 */
300 createLiveLocation: function(rawLocation, updateDelegate)
301 {
302 console.assert(rawLocation.scriptId === this.scriptId);
303 var location = new WebInspector.Script.Location(this, rawLocation, updat eDelegate);
304 this._locations.add(location);
305 location.update();
306 return location;
307 },
308
309 __proto__: WebInspector.SDKObject.prototype 261 __proto__: WebInspector.SDKObject.prototype
310 } 262 }
311
312 /**
313 * @constructor
314 * @extends {WebInspector.LiveLocation}
315 * @param {!WebInspector.Script} script
316 * @param {!WebInspector.DebuggerModel.Location} rawLocation
317 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDelegat e
318 */
319 WebInspector.Script.Location = function(script, rawLocation, updateDelegate)
320 {
321 WebInspector.LiveLocation.call(this, rawLocation, updateDelegate);
322 this._script = script;
323 }
324
325 WebInspector.Script.Location.prototype = {
326 /**
327 * @return {!WebInspector.UILocation}
328 */
329 uiLocation: function()
330 {
331 var debuggerModelLocation = /** @type {!WebInspector.DebuggerModel.Locat ion} */ (this.rawLocation());
332 return this._script.rawLocationToUILocation(debuggerModelLocation.lineNu mber, debuggerModelLocation.columnNumber);
333 },
334
335 dispose: function()
336 {
337 WebInspector.LiveLocation.prototype.dispose.call(this);
338 this._script._locations.remove(this);
339 },
340
341 __proto__: WebInspector.LiveLocation.prototype
342 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698