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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/snippets/ScriptSnippetModel.js

Issue 2173233002: [DevTools] Better locations for snippets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/bindings/PresentationConsoleMessageHelper.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 var breakpointLocations = this._removeBreakpoints(uiSourceCode); 218 var breakpointLocations = this._removeBreakpoints(uiSourceCode);
219 this._releaseSnippetScript(uiSourceCode); 219 this._releaseSnippetScript(uiSourceCode);
220 this._restoreBreakpoints(uiSourceCode, breakpointLocations); 220 this._restoreBreakpoints(uiSourceCode, breakpointLocations);
221 221
222 var target = executionContext.target(); 222 var target = executionContext.target();
223 var runtimeModel = target.runtimeModel; 223 var runtimeModel = target.runtimeModel;
224 var evaluationIndex = this._nextEvaluationIndex(); 224 var evaluationIndex = this._nextEvaluationIndex();
225 var mapping = this._mappingForTarget.get(target); 225 var mapping = this._mappingForTarget.get(target);
226 mapping._setEvaluationIndex(evaluationIndex, uiSourceCode); 226 mapping._setEvaluationIndex(evaluationIndex, uiSourceCode);
227 var evaluationUrl = mapping._evaluationSourceURL(uiSourceCode); 227 var evaluationUrl = mapping._evaluationSourceURL(uiSourceCode);
228 var expression = uiSourceCode.workingCopy(); 228 uiSourceCode.requestContent().then(compileSnippet.bind(this));
229 WebInspector.console.show(); 229
230 runtimeModel.compileScript(expression, "", true, executionContext.id, co mpileCallback.bind(this)); 230 /**
231 * @this {WebInspector.ScriptSnippetModel}
232 */
233 function compileSnippet()
234 {
235 var expression = uiSourceCode.workingCopy();
236 WebInspector.console.show();
237 runtimeModel.compileScript(expression, "", true, executionContext.id , compileCallback.bind(this));
238 }
231 239
232 /** 240 /**
233 * @param {!RuntimeAgent.ScriptId=} scriptId 241 * @param {!RuntimeAgent.ScriptId=} scriptId
234 * @param {?RuntimeAgent.ExceptionDetails=} exceptionDetails 242 * @param {?RuntimeAgent.ExceptionDetails=} exceptionDetails
235 * @this {WebInspector.ScriptSnippetModel} 243 * @this {WebInspector.ScriptSnippetModel}
236 */ 244 */
237 function compileCallback(scriptId, exceptionDetails) 245 function compileCallback(scriptId, exceptionDetails)
238 { 246 {
239 var mapping = this._mappingForTarget.get(target); 247 var mapping = this._mappingForTarget.get(target);
240 if (mapping.evaluationIndex(uiSourceCode) !== evaluationIndex) 248 if (mapping.evaluationIndex(uiSourceCode) !== evaluationIndex)
241 return; 249 return;
242 250
251 mapping._addScript(executionContext.debuggerModel.scriptForId(script Id || exceptionDetails.scriptId), uiSourceCode);
243 if (!scriptId) { 252 if (!scriptId) {
244 this._printRunOrCompileScriptResultFailure(target, exceptionDeta ils, evaluationUrl); 253 this._printRunOrCompileScriptResultFailure(target, exceptionDeta ils, evaluationUrl);
245 return; 254 return;
246 } 255 }
247 256
248 mapping._addScript(executionContext.debuggerModel.scriptForId(script Id), uiSourceCode);
249 var breakpointLocations = this._removeBreakpoints(uiSourceCode); 257 var breakpointLocations = this._removeBreakpoints(uiSourceCode);
250 this._restoreBreakpoints(uiSourceCode, breakpointLocations); 258 this._restoreBreakpoints(uiSourceCode, breakpointLocations);
251 259
252 this._runScript(scriptId, executionContext, evaluationUrl); 260 this._runScript(scriptId, executionContext, evaluationUrl);
253 } 261 }
254 }, 262 },
255 263
256 /** 264 /**
257 * @param {!RuntimeAgent.ScriptId} scriptId 265 * @param {!RuntimeAgent.ScriptId} scriptId
258 * @param {!WebInspector.ExecutionContext} executionContext 266 * @param {!WebInspector.ExecutionContext} executionContext
259 * @param {?string=} sourceURL 267 * @param {?string=} sourceURL
260 */ 268 */
261 _runScript: function(scriptId, executionContext, sourceURL) 269 _runScript: function(scriptId, executionContext, sourceURL)
262 { 270 {
263 var target = executionContext.target(); 271 var target = executionContext.target();
264 target.runtimeModel.runScript(scriptId, executionContext.id, "console", false, true, runCallback.bind(this, target)); 272 target.runtimeModel.runScript(scriptId, executionContext.id, "console", false, true, runCallback.bind(this, target));
265 273
266 /** 274 /**
267 * @param {!WebInspector.Target} target 275 * @param {!WebInspector.Target} target
268 * @param {?RuntimeAgent.RemoteObject} result 276 * @param {?RuntimeAgent.RemoteObject} result
269 * @param {?RuntimeAgent.ExceptionDetails=} exceptionDetails 277 * @param {?RuntimeAgent.ExceptionDetails=} exceptionDetails
270 * @this {WebInspector.ScriptSnippetModel} 278 * @this {WebInspector.ScriptSnippetModel}
271 */ 279 */
272 function runCallback(target, result, exceptionDetails) 280 function runCallback(target, result, exceptionDetails)
273 { 281 {
274 if (!exceptionDetails) 282 if (!exceptionDetails)
275 this._printRunScriptResult(target, result, sourceURL); 283 this._printRunScriptResult(target, result, scriptId, sourceURL);
276 else 284 else
277 this._printRunOrCompileScriptResultFailure(target, exceptionDeta ils, sourceURL); 285 this._printRunOrCompileScriptResultFailure(target, exceptionDeta ils, sourceURL);
278 } 286 }
279 }, 287 },
280 288
281 /** 289 /**
282 * @param {!WebInspector.Target} target 290 * @param {!WebInspector.Target} target
283 * @param {?RuntimeAgent.RemoteObject} result 291 * @param {?RuntimeAgent.RemoteObject} result
292 * @param {!RuntimeAgent.ScriptId} scriptId
284 * @param {?string=} sourceURL 293 * @param {?string=} sourceURL
285 */ 294 */
286 _printRunScriptResult: function(target, result, sourceURL) 295 _printRunScriptResult: function(target, result, scriptId, sourceURL)
287 { 296 {
288 var consoleMessage = new WebInspector.ConsoleMessage( 297 var consoleMessage = new WebInspector.ConsoleMessage(
289 target, 298 target,
290 WebInspector.ConsoleMessage.MessageSource.JS, 299 WebInspector.ConsoleMessage.MessageSource.JS,
291 WebInspector.ConsoleMessage.MessageLevel.Log, 300 WebInspector.ConsoleMessage.MessageLevel.Log,
292 "", 301 "",
293 undefined, 302 undefined,
294 sourceURL, 303 sourceURL,
295 undefined, 304 undefined,
296 undefined, 305 undefined,
297 undefined, 306 undefined,
298 [result], 307 [result],
299 undefined); 308 undefined,
309 undefined,
310 undefined,
311 scriptId);
300 target.consoleModel.addMessage(consoleMessage); 312 target.consoleModel.addMessage(consoleMessage);
301 }, 313 },
302 314
303 /** 315 /**
304 * @param {!WebInspector.Target} target 316 * @param {!WebInspector.Target} target
305 * @param {?RuntimeAgent.ExceptionDetails=} exceptionDetails 317 * @param {?RuntimeAgent.ExceptionDetails=} exceptionDetails
306 * @param {?string=} sourceURL 318 * @param {?string=} sourceURL
307 */ 319 */
308 _printRunOrCompileScriptResultFailure: function(target, exceptionDetails, so urceURL) 320 _printRunOrCompileScriptResultFailure: function(target, exceptionDetails, so urceURL)
309 { 321 {
310 var consoleMessage = new WebInspector.ConsoleMessage( 322 var consoleMessage = new WebInspector.ConsoleMessage(
311 target, 323 target,
312 exceptionDetails.source, 324 exceptionDetails.source,
313 WebInspector.ConsoleMessage.MessageLevel.Error, 325 WebInspector.ConsoleMessage.MessageLevel.Error,
314 exceptionDetails.text, 326 exceptionDetails.text,
315 undefined, 327 undefined,
316 sourceURL, 328 sourceURL,
317 exceptionDetails.lineNumber, 329 exceptionDetails.lineNumber,
318 exceptionDetails.columnNumber, 330 exceptionDetails.columnNumber,
319 undefined, 331 undefined,
320 undefined, 332 undefined,
321 exceptionDetails.stackTrace); 333 exceptionDetails.stackTrace,
334 undefined,
335 undefined,
336 exceptionDetails.stackTrace ? undefined : exceptionDetails.scriptId) ;
322 target.consoleModel.addMessage(consoleMessage); 337 target.consoleModel.addMessage(consoleMessage);
323 }, 338 },
324 339
325 /** 340 /**
326 * @param {!WebInspector.UISourceCode} uiSourceCode 341 * @param {!WebInspector.UISourceCode} uiSourceCode
327 * @return {!Array.<!{breakpoint: !WebInspector.BreakpointManager.Breakpoint , uiLocation: !WebInspector.UILocation}>} 342 * @return {!Array.<!{breakpoint: !WebInspector.BreakpointManager.Breakpoint , uiLocation: !WebInspector.UILocation}>}
328 */ 343 */
329 _removeBreakpoints: function(uiSourceCode) 344 _removeBreakpoints: function(uiSourceCode)
330 { 345 {
331 var breakpointLocations = WebInspector.breakpointManager.breakpointLocat ionsForUISourceCode(uiSourceCode); 346 var breakpointLocations = WebInspector.breakpointManager.breakpointLocat ionsForUISourceCode(uiSourceCode);
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 this._model.deleteScriptSnippet(url); 683 this._model.deleteScriptSnippet(url);
669 }, 684 },
670 685
671 __proto__: WebInspector.ContentProviderBasedProject.prototype 686 __proto__: WebInspector.ContentProviderBasedProject.prototype
672 } 687 }
673 688
674 /** 689 /**
675 * @type {!WebInspector.ScriptSnippetModel} 690 * @type {!WebInspector.ScriptSnippetModel}
676 */ 691 */
677 WebInspector.scriptSnippetModel = new WebInspector.ScriptSnippetModel(WebInspect or.workspace); 692 WebInspector.scriptSnippetModel = new WebInspector.ScriptSnippetModel(WebInspect or.workspace);
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/bindings/PresentationConsoleMessageHelper.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698