OLD | NEW |
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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 /** | 191 /** |
192 * @param {!SDK.ExecutionContext} executionContext | 192 * @param {!SDK.ExecutionContext} executionContext |
193 * @param {!Workspace.UISourceCode} uiSourceCode | 193 * @param {!Workspace.UISourceCode} uiSourceCode |
194 */ | 194 */ |
195 evaluateScriptSnippet(executionContext, uiSourceCode) { | 195 evaluateScriptSnippet(executionContext, uiSourceCode) { |
196 console.assert(uiSourceCode.project().type() === Workspace.projectTypes.Snip
pets); | 196 console.assert(uiSourceCode.project().type() === Workspace.projectTypes.Snip
pets); |
197 var breakpointLocations = this._removeBreakpoints(uiSourceCode); | 197 var breakpointLocations = this._removeBreakpoints(uiSourceCode); |
198 this._releaseSnippetScript(uiSourceCode); | 198 this._releaseSnippetScript(uiSourceCode); |
199 this._restoreBreakpoints(uiSourceCode, breakpointLocations); | 199 this._restoreBreakpoints(uiSourceCode, breakpointLocations); |
200 | 200 |
201 var target = executionContext.target(); | 201 var runtimeModel = executionContext.runtimeModel; |
202 var runtimeModel = target.runtimeModel; | 202 var debuggerModel = executionContext.debuggerModel; |
203 var debuggerModel = /** @type {!SDK.DebuggerModel} */ (SDK.DebuggerModel.fro
mTarget(target)); | |
204 var evaluationIndex = this._nextEvaluationIndex(); | 203 var evaluationIndex = this._nextEvaluationIndex(); |
205 var mapping = this._mappingForDebuggerModel.get(debuggerModel); | 204 var mapping = this._mappingForDebuggerModel.get(debuggerModel); |
206 mapping._setEvaluationIndex(evaluationIndex, uiSourceCode); | 205 mapping._setEvaluationIndex(evaluationIndex, uiSourceCode); |
207 var evaluationUrl = mapping._evaluationSourceURL(uiSourceCode); | 206 var evaluationUrl = mapping._evaluationSourceURL(uiSourceCode); |
208 uiSourceCode.requestContent().then(compileSnippet.bind(this)); | 207 uiSourceCode.requestContent().then(compileSnippet.bind(this)); |
209 | 208 |
210 /** | 209 /** |
211 * @this {Snippets.ScriptSnippetModel} | 210 * @this {Snippets.ScriptSnippetModel} |
212 */ | 211 */ |
213 function compileSnippet() { | 212 function compileSnippet() { |
214 var expression = uiSourceCode.workingCopy(); | 213 var expression = uiSourceCode.workingCopy(); |
215 Common.console.show(); | 214 Common.console.show(); |
216 runtimeModel.compileScript(expression, '', true, executionContext.id, comp
ileCallback.bind(this)); | 215 runtimeModel.compileScript(expression, '', true, executionContext.id, comp
ileCallback.bind(this)); |
217 } | 216 } |
218 | 217 |
219 /** | 218 /** |
220 * @param {!Protocol.Runtime.ScriptId=} scriptId | 219 * @param {!Protocol.Runtime.ScriptId=} scriptId |
221 * @param {?Protocol.Runtime.ExceptionDetails=} exceptionDetails | 220 * @param {?Protocol.Runtime.ExceptionDetails=} exceptionDetails |
222 * @this {Snippets.ScriptSnippetModel} | 221 * @this {Snippets.ScriptSnippetModel} |
223 */ | 222 */ |
224 function compileCallback(scriptId, exceptionDetails) { | 223 function compileCallback(scriptId, exceptionDetails) { |
225 var mapping = this._mappingForDebuggerModel.get(debuggerModel); | |
226 if (mapping.evaluationIndex(uiSourceCode) !== evaluationIndex) | 224 if (mapping.evaluationIndex(uiSourceCode) !== evaluationIndex) |
227 return; | 225 return; |
228 | 226 |
229 var script = /** @type {!SDK.Script} */ ( | 227 var script = /** @type {!SDK.Script} */ ( |
230 executionContext.debuggerModel.scriptForId(/** @type {string} */ (scri
ptId || exceptionDetails.scriptId))); | 228 debuggerModel.scriptForId(/** @type {string} */ (scriptId || exception
Details.scriptId))); |
231 mapping._addScript(script, uiSourceCode); | 229 mapping._addScript(script, uiSourceCode); |
232 if (!scriptId) { | 230 if (!scriptId) { |
233 this._printRunOrCompileScriptResultFailure( | 231 this._printRunOrCompileScriptResultFailure( |
234 target, /** @type {!Protocol.Runtime.ExceptionDetails} */ (exception
Details), evaluationUrl); | 232 runtimeModel, /** @type {!Protocol.Runtime.ExceptionDetails} */ (exc
eptionDetails), evaluationUrl); |
235 return; | 233 return; |
236 } | 234 } |
237 | 235 |
238 var breakpointLocations = this._removeBreakpoints(uiSourceCode); | 236 var breakpointLocations = this._removeBreakpoints(uiSourceCode); |
239 this._restoreBreakpoints(uiSourceCode, breakpointLocations); | 237 this._restoreBreakpoints(uiSourceCode, breakpointLocations); |
240 | 238 |
241 this._runScript(scriptId, executionContext, evaluationUrl); | 239 this._runScript(scriptId, executionContext, evaluationUrl); |
242 } | 240 } |
243 } | 241 } |
244 | 242 |
245 /** | 243 /** |
246 * @param {!Protocol.Runtime.ScriptId} scriptId | 244 * @param {!Protocol.Runtime.ScriptId} scriptId |
247 * @param {!SDK.ExecutionContext} executionContext | 245 * @param {!SDK.ExecutionContext} executionContext |
248 * @param {?string=} sourceURL | 246 * @param {?string=} sourceURL |
249 */ | 247 */ |
250 _runScript(scriptId, executionContext, sourceURL) { | 248 _runScript(scriptId, executionContext, sourceURL) { |
251 var target = executionContext.target(); | 249 var runtimeModel = executionContext.runtimeModel; |
252 target.runtimeModel.runScript( | 250 runtimeModel.runScript( |
253 scriptId, executionContext.id, 'console', /* silent */ false, /* include
CommandLineAPI */ true, | 251 scriptId, executionContext.id, 'console', /* silent */ false, /* include
CommandLineAPI */ true, |
254 /* returnByValue */ false, /* generatePreview */ true, /* awaitPromise *
/ undefined, | 252 /* returnByValue */ false, /* generatePreview */ true, /* awaitPromise *
/ undefined, runCallback.bind(this)); |
255 runCallback.bind(this, target)); | |
256 | 253 |
257 /** | 254 /** |
258 * @param {!SDK.Target} target | |
259 * @param {?Protocol.Runtime.RemoteObject} result | 255 * @param {?Protocol.Runtime.RemoteObject} result |
260 * @param {?Protocol.Runtime.ExceptionDetails=} exceptionDetails | 256 * @param {?Protocol.Runtime.ExceptionDetails=} exceptionDetails |
261 * @this {Snippets.ScriptSnippetModel} | 257 * @this {Snippets.ScriptSnippetModel} |
262 */ | 258 */ |
263 function runCallback(target, result, exceptionDetails) { | 259 function runCallback(result, exceptionDetails) { |
264 if (!exceptionDetails) | 260 if (!exceptionDetails) |
265 this._printRunScriptResult(target, result, scriptId, sourceURL); | 261 this._printRunScriptResult(runtimeModel, result, scriptId, sourceURL); |
266 else | 262 else |
267 this._printRunOrCompileScriptResultFailure(target, exceptionDetails, sou
rceURL); | 263 this._printRunOrCompileScriptResultFailure(runtimeModel, exceptionDetail
s, sourceURL); |
268 } | 264 } |
269 } | 265 } |
270 | 266 |
271 /** | 267 /** |
272 * @param {!SDK.Target} target | 268 * @param {!SDK.RuntimeModel} runtimeModel |
273 * @param {?Protocol.Runtime.RemoteObject} result | 269 * @param {?Protocol.Runtime.RemoteObject} result |
274 * @param {!Protocol.Runtime.ScriptId} scriptId | 270 * @param {!Protocol.Runtime.ScriptId} scriptId |
275 * @param {?string=} sourceURL | 271 * @param {?string=} sourceURL |
276 */ | 272 */ |
277 _printRunScriptResult(target, result, scriptId, sourceURL) { | 273 _printRunScriptResult(runtimeModel, result, scriptId, sourceURL) { |
278 var consoleMessage = new ConsoleModel.ConsoleMessage( | 274 var consoleMessage = new ConsoleModel.ConsoleMessage( |
279 target, ConsoleModel.ConsoleMessage.MessageSource.JS, ConsoleModel.Conso
leMessage.MessageLevel.Info, '', | 275 runtimeModel.target(), ConsoleModel.ConsoleMessage.MessageSource.JS, |
280 undefined, sourceURL, undefined, undefined, undefined, [result], undefin
ed, undefined, undefined, scriptId); | 276 ConsoleModel.ConsoleMessage.MessageLevel.Info, '', undefined, sourceURL,
undefined, undefined, undefined, |
| 277 [result], undefined, undefined, undefined, scriptId); |
281 ConsoleModel.consoleModel.addMessage(consoleMessage); | 278 ConsoleModel.consoleModel.addMessage(consoleMessage); |
282 } | 279 } |
283 | 280 |
284 /** | 281 /** |
285 * @param {!SDK.Target} target | 282 * @param {!SDK.RuntimeModel} runtimeModel |
286 * @param {!Protocol.Runtime.ExceptionDetails} exceptionDetails | 283 * @param {!Protocol.Runtime.ExceptionDetails} exceptionDetails |
287 * @param {?string=} sourceURL | 284 * @param {?string=} sourceURL |
288 */ | 285 */ |
289 _printRunOrCompileScriptResultFailure(target, exceptionDetails, sourceURL) { | 286 _printRunOrCompileScriptResultFailure(runtimeModel, exceptionDetails, sourceUR
L) { |
290 ConsoleModel.consoleModel.addMessage(ConsoleModel.ConsoleMessage.fromExcepti
on( | 287 ConsoleModel.consoleModel.addMessage(ConsoleModel.ConsoleMessage.fromExcepti
on( |
291 target, exceptionDetails, undefined, undefined, sourceURL || undefined))
; | 288 runtimeModel, exceptionDetails, undefined, undefined, sourceURL || undef
ined)); |
292 } | 289 } |
293 | 290 |
294 /** | 291 /** |
295 * @param {!Workspace.UISourceCode} uiSourceCode | 292 * @param {!Workspace.UISourceCode} uiSourceCode |
296 * @return {!Array.<!{breakpoint: !Bindings.BreakpointManager.Breakpoint, uiLo
cation: !Workspace.UILocation}>} | 293 * @return {!Array.<!{breakpoint: !Bindings.BreakpointManager.Breakpoint, uiLo
cation: !Workspace.UILocation}>} |
297 */ | 294 */ |
298 _removeBreakpoints(uiSourceCode) { | 295 _removeBreakpoints(uiSourceCode) { |
299 var breakpointLocations = Bindings.breakpointManager.breakpointLocationsForU
ISourceCode(uiSourceCode); | 296 var breakpointLocations = Bindings.breakpointManager.breakpointLocationsForU
ISourceCode(uiSourceCode); |
300 for (var i = 0; i < breakpointLocations.length; ++i) | 297 for (var i = 0; i < breakpointLocations.length; ++i) |
301 breakpointLocations[i].breakpoint.remove(); | 298 breakpointLocations[i].breakpoint.remove(); |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 */ | 610 */ |
614 deleteFile(uiSourceCode) { | 611 deleteFile(uiSourceCode) { |
615 this._model.deleteScriptSnippet(uiSourceCode); | 612 this._model.deleteScriptSnippet(uiSourceCode); |
616 } | 613 } |
617 }; | 614 }; |
618 | 615 |
619 /** | 616 /** |
620 * @type {!Snippets.ScriptSnippetModel} | 617 * @type {!Snippets.ScriptSnippetModel} |
621 */ | 618 */ |
622 Snippets.scriptSnippetModel = new Snippets.ScriptSnippetModel(Workspace.workspac
e); | 619 Snippets.scriptSnippetModel = new Snippets.ScriptSnippetModel(Workspace.workspac
e); |
OLD | NEW |