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 19 matching lines...) Expand all Loading... | |
30 | 30 |
31 /** | 31 /** |
32 * @constructor | 32 * @constructor |
33 * @extends {WebInspector.SDKModel} | 33 * @extends {WebInspector.SDKModel} |
34 * @param {!WebInspector.Target} target | 34 * @param {!WebInspector.Target} target |
35 */ | 35 */ |
36 WebInspector.RuntimeModel = function(target) | 36 WebInspector.RuntimeModel = function(target) |
37 { | 37 { |
38 WebInspector.SDKModel.call(this, WebInspector.RuntimeModel, target); | 38 WebInspector.SDKModel.call(this, WebInspector.RuntimeModel, target); |
39 | 39 |
40 /** | |
41 * @param {!WebInspector.DebuggerModel.Location} raw | |
42 * @suppress {missingProperties} | |
43 */ | |
44 this._locationResolver = raw => { | |
pfeldman
2015/08/13 21:15:46
SDK can't depend on the bindings, source mappings
wes
2015/08/14 00:55:05
This was literally a hack I threw in the other day
pfeldman
2015/08/17 21:15:52
Your _locationResolver looks very similar to the s
wes
2015/08/25 18:13:18
Already gone. :3
| |
45 if (!WebInspector.debuggerWorkspaceBinding) return; | |
46 var loc = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation( raw); | |
47 return { | |
48 source: loc.uiSourceCode.contentURL(), | |
49 line: loc.lineNumber, | |
50 column: loc.columnNumber | |
51 }; | |
52 }; | |
40 this._agent = target.runtimeAgent(); | 53 this._agent = target.runtimeAgent(); |
41 this.target().registerRuntimeDispatcher(new WebInspector.RuntimeDispatcher(t his)); | 54 this.target().registerRuntimeDispatcher(new WebInspector.RuntimeDispatcher(t his)); |
42 if (target.hasJSContext()) | 55 if (target.hasJSContext()) |
43 this._agent.enable(); | 56 this._agent.enable(); |
44 /** | 57 /** |
45 * @type {!Object.<number, !WebInspector.ExecutionContext>} | 58 * @type {!Object.<number, !WebInspector.ExecutionContext>} |
46 */ | 59 */ |
47 this._executionContextById = {}; | 60 this._executionContextById = {}; |
48 | 61 |
49 if (!Runtime.experiments.isEnabled("customObjectFormatters")) | 62 if (!Runtime.experiments.isEnabled("customObjectFormatters")) |
(...skipping 24 matching lines...) Expand all Loading... | |
74 | 87 |
75 /** | 88 /** |
76 * @param {!RuntimeAgent.ExecutionContextDescription} context | 89 * @param {!RuntimeAgent.ExecutionContextDescription} context |
77 */ | 90 */ |
78 _executionContextCreated: function(context) | 91 _executionContextCreated: function(context) |
79 { | 92 { |
80 // The private script context should be hidden behind an experiment. | 93 // The private script context should be hidden behind an experiment. |
81 if (context.name == WebInspector.RuntimeModel._privateScript && !context .origin && !Runtime.experiments.isEnabled("privateScriptInspection")) { | 94 if (context.name == WebInspector.RuntimeModel._privateScript && !context .origin && !Runtime.experiments.isEnabled("privateScriptInspection")) { |
82 return; | 95 return; |
83 } | 96 } |
84 var executionContext = new WebInspector.ExecutionContext(this.target(), context.id, context.name, context.origin, !!context.isPageContext, context.frame Id); | 97 var executionContext = new WebInspector.ExecutionContext(this.target(), this._locationResolver, context.id, context.name, context.origin, !!context.isPa geContext, context.frameId); |
85 this._executionContextById[executionContext.id] = executionContext; | 98 this._executionContextById[executionContext.id] = executionContext; |
86 this.dispatchEventToListeners(WebInspector.RuntimeModel.Events.Execution ContextCreated, executionContext); | 99 this.dispatchEventToListeners(WebInspector.RuntimeModel.Events.Execution ContextCreated, executionContext); |
87 }, | 100 }, |
88 | 101 |
89 /** | 102 /** |
90 * @param {number} executionContextId | 103 * @param {number} executionContextId |
91 */ | 104 */ |
92 _executionContextDestroyed: function(executionContextId) | 105 _executionContextDestroyed: function(executionContextId) |
93 { | 106 { |
94 var executionContext = this._executionContextById[executionContextId]; | 107 var executionContext = this._executionContextById[executionContextId]; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 { | 206 { |
194 this._runtimeModel._executionContextsCleared(); | 207 this._runtimeModel._executionContextsCleared(); |
195 } | 208 } |
196 | 209 |
197 } | 210 } |
198 | 211 |
199 /** | 212 /** |
200 * @constructor | 213 * @constructor |
201 * @extends {WebInspector.SDKObject} | 214 * @extends {WebInspector.SDKObject} |
202 * @param {!WebInspector.Target} target | 215 * @param {!WebInspector.Target} target |
216 * @param {function(!WebInspector.DebuggerModel.Location): ({source: string, lin e: number, column: number}|undefined)} locationResolver | |
203 * @param {number|undefined} id | 217 * @param {number|undefined} id |
204 * @param {string} name | 218 * @param {string} name |
205 * @param {string} origin | 219 * @param {string} origin |
206 * @param {boolean} isPageContext | 220 * @param {boolean} isPageContext |
207 * @param {string=} frameId | 221 * @param {string=} frameId |
208 */ | 222 */ |
209 WebInspector.ExecutionContext = function(target, id, name, origin, isPageContext , frameId) | 223 WebInspector.ExecutionContext = function(target, locationResolver, id, name, ori gin, isPageContext, frameId) |
210 { | 224 { |
211 WebInspector.SDKObject.call(this, target); | 225 WebInspector.SDKObject.call(this, target); |
226 this._locationResolver = locationResolver; | |
212 this.id = id; | 227 this.id = id; |
213 this.name = name; | 228 this.name = name; |
214 this.origin = origin; | 229 this.origin = origin; |
215 this.isMainWorldContext = isPageContext; | 230 this.isMainWorldContext = isPageContext; |
216 this.runtimeModel = target.runtimeModel; | 231 this.runtimeModel = target.runtimeModel; |
217 this.debuggerModel = WebInspector.DebuggerModel.fromTarget(target); | 232 this.debuggerModel = WebInspector.DebuggerModel.fromTarget(target); |
218 this.frameId = frameId; | 233 this.frameId = frameId; |
219 } | 234 } |
220 | 235 |
221 /** | 236 /** |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 return; | 330 return; |
316 } | 331 } |
317 | 332 |
318 if (returnByValue) | 333 if (returnByValue) |
319 callback(null, !!wasThrown, wasThrown ? null : result, exception Details); | 334 callback(null, !!wasThrown, wasThrown ? null : result, exception Details); |
320 else | 335 else |
321 callback(this.runtimeModel.createRemoteObject(result), !!wasThro wn, undefined, exceptionDetails); | 336 callback(this.runtimeModel.createRemoteObject(result), !!wasThro wn, undefined, exceptionDetails); |
322 } | 337 } |
323 this.target().runtimeAgent().evaluate(expression, objectGroup, includeCo mmandLineAPI, doNotPauseOnExceptionsAndMuteConsole, this.id, returnByValue, gene ratePreview, evalCallback.bind(this)); | 338 this.target().runtimeAgent().evaluate(expression, objectGroup, includeCo mmandLineAPI, doNotPauseOnExceptionsAndMuteConsole, this.id, returnByValue, gene ratePreview, evalCallback.bind(this)); |
324 }, | 339 }, |
340 | |
341 /** | |
342 * @return {({source: string, line: number, column: number}|undefined)} | |
343 */ | |
344 pauseLocation: function() { | |
345 var frame = this.debuggerModel.selectedCallFrame(); | |
346 var raw; | |
347 if (frame && (raw = frame.location())) { | |
348 return this._locationResolver(raw); | |
349 } | |
350 return; | |
351 }, | |
325 | 352 |
326 /** | 353 /** |
327 * @param {string} expressionString | 354 * @param {string} expressionString |
355 * @param {string} text | |
356 * @param {number} cursorOffset | |
328 * @param {string} prefix | 357 * @param {string} prefix |
329 * @param {boolean} force | 358 * @param {boolean} force |
330 * @param {function(!Array.<string>, number=)} completionsReadyCallback | 359 * @param {function(!Array.<string>, number=)} completionsReadyCallback |
331 */ | 360 */ |
332 completionsForExpression: function(expressionString, prefix, force, completi onsReadyCallback) | 361 completionsForExpression: function(expressionString, text, cursorOffset, pre fix, force, completionsReadyCallback) |
333 { | 362 { |
363 var location = this.pauseLocation(); | |
pfeldman
2015/08/13 21:15:46
You should transpile expressionString prior to get
wes
2015/08/14 00:55:05
Is expressionString supposed to be an identifier f
pfeldman
2015/08/17 21:15:52
This would also go into your module
wes
2015/08/25 18:13:18
And so it has.
| |
364 | |
365 function handleDebuggerCompletionsComplete(vals) { | |
366 if (!vals) { | |
367 completionsReadyCallback([]); | |
368 } | |
369 completionsReadyCallback(vals.map(function(v) { return v.text; })); | |
370 } | |
371 | |
372 //If possible, ceede to the language service | |
373 if (location) { //paused - get active mime from pause location | |
374 var mime = WebInspector.ResourceType.mimeFromUrl(location.source); | |
375 | |
376 if (WebInspector.languageService.handles.debuggerCompletions(mime)) { | |
377 WebInspector.languageService.debuggerCompletions(mime, text, cur sorOffset, prefix, location).then(handleDebuggerCompletionsComplete); | |
378 return; | |
379 } | |
380 } else { //not paused - get active mime from source pane | |
381 var activeDocMime = WebInspector.ResourceType.fromActivePanel(); | |
382 | |
383 if (WebInspector.languageService.handles.debuggerCompletions(activeD ocMime)) { | |
384 WebInspector.languageService.debuggerCompletions(activeDocMime, text, cursorOffset, prefix, undefined).then(handleDebuggerCompletionsComplete); | |
385 return; | |
386 } | |
387 } | |
388 | |
334 var lastIndex = expressionString.length - 1; | 389 var lastIndex = expressionString.length - 1; |
335 | 390 |
336 var dotNotation = (expressionString[lastIndex] === "."); | 391 var dotNotation = (expressionString[lastIndex] === "."); |
337 var bracketNotation = (expressionString[lastIndex] === "["); | 392 var bracketNotation = (expressionString[lastIndex] === "["); |
338 | 393 |
339 if (dotNotation || bracketNotation) | 394 if (dotNotation || bracketNotation) |
340 expressionString = expressionString.substr(0, lastIndex); | 395 expressionString = expressionString.substr(0, lastIndex); |
341 | 396 |
342 if (expressionString && parseInt(expressionString, 10) == expressionStri ng) { | 397 if (expressionString && parseInt(expressionString, 10) == expressionStri ng) { |
343 // User is entering float value, do not suggest anything. | 398 // User is entering float value, do not suggest anything. |
344 completionsReadyCallback([]); | 399 completionsReadyCallback([]); |
345 return; | 400 return; |
346 } | 401 } |
347 | 402 |
348 if (!prefix && !expressionString && !force) { | 403 if (!prefix && !expressionString && !force) { |
349 completionsReadyCallback([]); | 404 completionsReadyCallback([]); |
350 return; | 405 return; |
351 } | 406 } |
352 | 407 |
353 if (!expressionString && this.debuggerModel.selectedCallFrame()) | 408 var frame = this.debuggerModel.selectedCallFrame(); |
354 this.debuggerModel.selectedCallFrame().variableNames(receivedPropert yNames.bind(this)); | 409 if (!expressionString && frame) |
410 frame.variableNames(receivedPropertyNames.bind(this)); | |
355 else | 411 else |
356 this.evaluate(expressionString, "completion", true, true, false, fal se, evaluated.bind(this)); | 412 this.evaluate(expressionString, "completion", true, true, false, fal se, evaluated.bind(this)); |
357 | 413 |
358 /** | 414 /** |
359 * @this {WebInspector.ExecutionContext} | 415 * @this {WebInspector.ExecutionContext} |
360 */ | 416 */ |
361 function evaluated(result, wasThrown) | 417 function evaluated(result, wasThrown) |
362 { | 418 { |
363 if (!result || wasThrown) { | 419 if (!result || wasThrown) { |
364 completionsReadyCallback([]); | 420 completionsReadyCallback([]); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 /** | 609 /** |
554 * @return {!RuntimeAgent.RemoteObjectId} | 610 * @return {!RuntimeAgent.RemoteObjectId} |
555 */ | 611 */ |
556 objectId: function() | 612 objectId: function() |
557 { | 613 { |
558 return this._objectId; | 614 return this._objectId; |
559 }, | 615 }, |
560 | 616 |
561 __proto__: WebInspector.SDKObject.prototype | 617 __proto__: WebInspector.SDKObject.prototype |
562 } | 618 } |
OLD | NEW |