| Index: Source/devtools/front_end/languages/MultiLingualExecutionContext.js
|
| diff --git a/Source/devtools/front_end/languages/MultiLingualExecutionContext.js b/Source/devtools/front_end/languages/MultiLingualExecutionContext.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3def58e726d24f27a3c4e5947c9d2b694091e79a
|
| --- /dev/null
|
| +++ b/Source/devtools/front_end/languages/MultiLingualExecutionContext.js
|
| @@ -0,0 +1,98 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +/**
|
| + * @constructor
|
| + * @extends {WebInspector.ExecutionContext}
|
| + * @param {!WebInspector.ExecutionContext} executionContext
|
| + */
|
| +WebInspector.MultiLingualExecutionContext = function(executionContext)
|
| +{
|
| + WebInspector.ExecutionContext.call(this, executionContext.runtimeModel.target(), executionContext.id, executionContext.name, executionContext.origin, executionContext.isMainWorldContext, executionContext.frameId);
|
| +}
|
| +
|
| +WebInspector.MultiLingualExecutionContext.prototype = {
|
| + /**
|
| + * @param {!WebInspector.DebuggerModel.Location=} raw
|
| + */
|
| + _locationResolver: function(raw) {
|
| + if (!raw) return;
|
| + var loc = WebInspector.debuggerWorkspaceBinding.rawLocationToUILocation(raw);
|
| + return {
|
| + source: loc.uiSourceCode.uri(),
|
| + line: loc.lineNumber,
|
| + column: loc.columnNumber
|
| + };
|
| + },
|
| +
|
| + /**
|
| + * @override
|
| + * @param {string} expression
|
| + * @param {string} objectGroup
|
| + * @param {boolean} includeCommandLineAPI
|
| + * @param {boolean} doNotPauseOnExceptionsAndMuteConsole
|
| + * @param {boolean} returnByValue
|
| + * @param {boolean} generatePreview
|
| + * @param {function(?WebInspector.RemoteObject, boolean, ?RuntimeAgent.RemoteObject=, ?DebuggerAgent.ExceptionDetails=)} callback
|
| + */
|
| + evaluate: function(expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, callback)
|
| + {
|
| + var mime = WebInspector.ResourceType.fromActivePanel();
|
| + if (WebInspector.languageService.handles.transpile(mime)) {
|
| + var location = this._locationResolver(this.pauseLocation());
|
| + WebInspector.languageService.transpile(mime, expression, location).then(function(result) {
|
| + WebInspector.ExecutionContext.prototype.evaluate.call(this, result, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, callback);
|
| + })
|
| + .catch(function(err) {
|
| + //TODO: decide how to handle errors?
|
| + throw err;
|
| + });
|
| + } else {
|
| + WebInspector.ExecutionContext.prototype.evaluate.call(this, expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, callback);
|
| + }
|
| + },
|
| +
|
| + /**
|
| + * @override
|
| + * @param {string} expressionString
|
| + * @param {string} text
|
| + * @param {number} cursorOffset
|
| + * @param {string} prefix
|
| + * @param {boolean} force
|
| + * @param {function(!Array.<string>, number=)} completionsReadyCallback
|
| + */
|
| + completionsForExpression: function(expressionString, text, cursorOffset, prefix, force, completionsReadyCallback)
|
| + {
|
| + function handleDebuggerCompletionsComplete(vals) {
|
| + if (!vals) {
|
| + completionsReadyCallback([]);
|
| + }
|
| + completionsReadyCallback(vals.map(function(v) { return v.text; }));
|
| + }
|
| +
|
| + var location = this._locationResolver(this.pauseLocation());
|
| +
|
| + //If possible, ceede to the language service
|
| + if (location) { //paused - get active mime from pause location
|
| + var mime = WebInspector.ResourceType.mimeFromURL(location.source);
|
| +
|
| + if (WebInspector.languageService.handles.debuggerCompletions(mime)) {
|
| + WebInspector.languageService.debuggerCompletions(mime, text, cursorOffset, prefix, location).then(handleDebuggerCompletionsComplete);
|
| + return;
|
| + }
|
| + } else { //not paused - get active mime from source pane
|
| + var activeDocMime = WebInspector.ResourceType.fromActivePanel();
|
| +
|
| + if (WebInspector.languageService.handles.debuggerCompletions(activeDocMime)) {
|
| + WebInspector.languageService.debuggerCompletions(activeDocMime, text, cursorOffset, prefix, undefined).then(handleDebuggerCompletionsComplete);
|
| + return;
|
| + }
|
| + }
|
| +
|
| + //Fallback to the underlying context
|
| + WebInspector.ExecutionContext.prototype.completionsForExpression.call(this, expressionString, text, cursorOffset, prefix, force, completionsReadyCallback);
|
| + },
|
| +
|
| + __proto__: WebInspector.ExecutionContext.prototype
|
| +}
|
|
|