OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * @constructor |
| 7 * @extends {WebInspector.ExecutionContext} |
| 8 * @param {!WebInspector.ExecutionContext} executionContext |
| 9 */ |
| 10 WebInspector.MultiLingualExecutionContext = function(executionContext) |
| 11 { |
| 12 WebInspector.ExecutionContext.call(this, executionContext.runtimeModel.targe
t(), executionContext.id, executionContext.name, executionContext.origin, execut
ionContext.isMainWorldContext, executionContext.frameId); |
| 13 } |
| 14 |
| 15 WebInspector.MultiLingualExecutionContext.prototype = { |
| 16 /** |
| 17 * @param {!WebInspector.DebuggerModel.Location=} raw |
| 18 */ |
| 19 _locationResolver: function(raw) { |
| 20 if (!raw) return; |
| 21 var loc = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(
raw); |
| 22 return { |
| 23 source: loc.uiSourceCode.uri(), |
| 24 line: loc.lineNumber, |
| 25 column: loc.columnNumber |
| 26 }; |
| 27 }, |
| 28 |
| 29 /** |
| 30 * @override |
| 31 * @param {string} expression |
| 32 * @param {string} objectGroup |
| 33 * @param {boolean} includeCommandLineAPI |
| 34 * @param {boolean} doNotPauseOnExceptionsAndMuteConsole |
| 35 * @param {boolean} returnByValue |
| 36 * @param {boolean} generatePreview |
| 37 * @param {function(?WebInspector.RemoteObject, boolean, ?RuntimeAgent.Remot
eObject=, ?DebuggerAgent.ExceptionDetails=)} callback |
| 38 */ |
| 39 evaluate: function(expression, objectGroup, includeCommandLineAPI, doNotPaus
eOnExceptionsAndMuteConsole, returnByValue, generatePreview, callback) |
| 40 { |
| 41 var mime = WebInspector.ResourceType.fromActivePanel(); |
| 42 if (WebInspector.languageService.handles.transpile(mime)) { |
| 43 var location = this._locationResolver(this.pauseLocation
()); |
| 44 WebInspector.languageService.transpile(mime, expression,
location).then(function(result) { |
| 45 WebInspector.ExecutionContext.prototype.evaluate
.call(this, result, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAn
dMuteConsole, returnByValue, generatePreview, callback); |
| 46 }) |
| 47 .catch(function(err) { |
| 48 //TODO: decide how to handle errors? |
| 49 throw err; |
| 50 }); |
| 51 } else { |
| 52 WebInspector.ExecutionContext.prototype.evaluate.call(th
is, expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMut
eConsole, returnByValue, generatePreview, callback); |
| 53 } |
| 54 }, |
| 55 |
| 56 /** |
| 57 * @override |
| 58 * @param {string} expressionString |
| 59 * @param {string} text |
| 60 * @param {number} cursorOffset |
| 61 * @param {string} prefix |
| 62 * @param {boolean} force |
| 63 * @param {function(!Array.<string>, number=)} completionsReadyCallback |
| 64 */ |
| 65 completionsForExpression: function(expressionString, text, cursorOffset, pre
fix, force, completionsReadyCallback) |
| 66 { |
| 67 function handleDebuggerCompletionsComplete(vals) { |
| 68 if (!vals) { |
| 69 completionsReadyCallback([]); |
| 70 } |
| 71 completionsReadyCallback(vals.map(function(v) { return v.text; })); |
| 72 } |
| 73 |
| 74 var location = this._locationResolver(this.pauseLocation()); |
| 75 |
| 76 //If possible, ceede to the language service |
| 77 if (location) { //paused - get active mime from pause location |
| 78 var mime = WebInspector.ResourceType.mimeFromURL(location.source); |
| 79 |
| 80 if (WebInspector.languageService.handles.debuggerCompletions(mime))
{ |
| 81 WebInspector.languageService.debuggerCompletions(mime, text, cur
sorOffset, prefix, location).then(handleDebuggerCompletionsComplete); |
| 82 return; |
| 83 } |
| 84 } else { //not paused - get active mime from source pane |
| 85 var activeDocMime = WebInspector.ResourceType.fromActivePanel(); |
| 86 |
| 87 if (WebInspector.languageService.handles.debuggerCompletions(activeD
ocMime)) { |
| 88 WebInspector.languageService.debuggerCompletions(activeDocMime,
text, cursorOffset, prefix, undefined).then(handleDebuggerCompletionsComplete); |
| 89 return; |
| 90 } |
| 91 } |
| 92 |
| 93 //Fallback to the underlying context |
| 94 WebInspector.ExecutionContext.prototype.completionsForExpression.call(th
is, expressionString, text, cursorOffset, prefix, force, completionsReadyCallbac
k); |
| 95 }, |
| 96 |
| 97 __proto__: WebInspector.ExecutionContext.prototype |
| 98 } |
OLD | NEW |