Chromium Code Reviews| Index: Source/devtools/front_end/SourcesPanel.js |
| diff --git a/Source/devtools/front_end/SourcesPanel.js b/Source/devtools/front_end/SourcesPanel.js |
| index fba5ba6ace557ea3e3e42ff271ded6f986f5b501..bba87914f2c0e820cba4c38cd77645e67afd17d1 100644 |
| --- a/Source/devtools/front_end/SourcesPanel.js |
| +++ b/Source/devtools/front_end/SourcesPanel.js |
| @@ -1273,7 +1273,7 @@ WebInspector.SourcesPanel.prototype = { |
| appendApplicableItems: function(event, contextMenu, target) |
| { |
| this._appendUISourceCodeItems(event, contextMenu, target); |
| - this._appendFunctionItems(contextMenu, target); |
| + this._appendRemoteObjectItems(contextMenu, target); |
| }, |
| _suggestReload: function() |
| @@ -1391,20 +1391,86 @@ WebInspector.SourcesPanel.prototype = { |
| * @param {!WebInspector.ContextMenu} contextMenu |
| * @param {!Object} target |
| */ |
| - _appendFunctionItems: function(contextMenu, target) |
| + _appendRemoteObjectItems: function(contextMenu, target) |
| { |
| if (!(target instanceof WebInspector.RemoteObject)) |
| return; |
| var remoteObject = /** @type {!WebInspector.RemoteObject} */ (target); |
| - if (remoteObject.type !== "function") |
| - return; |
| + contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Save to temp variable" : "Save to Temp Variable"), this._saveToTempVariable.bind(this, remoteObject)); |
|
pfeldman
2014/03/19 18:08:03
"Store as global variable"
aandrey
2014/03/20 09:21:22
Done.
|
| + if (remoteObject.type === "function") |
| + contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Show function definition" : "Show Function Definition"), this._showFunctionDefinition.bind(this, remoteObject)); |
| + }, |
| + |
| + /** |
| + * @param {!WebInspector.RemoteObject} remoteObject |
| + */ |
| + _saveToTempVariable: function(remoteObject) |
| + { |
| + WebInspector.runtimeModel.evaluate("window", "", false, true, false, false, didGetGlobalObject); |
| /** |
| + * @param {?WebInspector.RemoteObject} global |
| + * @param {boolean=} wasThrown |
| + */ |
| + function didGetGlobalObject(global, wasThrown) |
| + { |
| + /** @this {Window} */ |
| + function remoteFunction(value) |
| + { |
| + var prefix = "temp"; |
| + var index = 1; |
| + while ((prefix + index) in this) |
| + ++index; |
| + var name = prefix + index; |
| + this[name] = value; |
| + return name; |
| + } |
| + |
| + if (wasThrown || !global) |
| + failedToSave(global); |
| + else |
| + global.callFunction(remoteFunction, [WebInspector.RemoteObject.toCallArgument(remoteObject)], didSave.bind(null, global)); |
| + } |
| + |
| + /** |
| + * @param {!WebInspector.RemoteObject} global |
| + * @param {?WebInspector.RemoteObject} result |
| + * @param {boolean=} wasThrown |
| + */ |
| + function didSave(global, result, wasThrown) |
| + { |
| + global.release(); |
| + if (wasThrown || !result || result.type !== "string") |
| + failedToSave(result); |
| + else |
| + WebInspector.console.evaluate(result.value); |
| + } |
| + |
| + /** |
| + * @param {?WebInspector.RemoteObject} result |
| + */ |
| + function failedToSave(result) |
| + { |
| + var message = WebInspector.UIString("Failed to save to temp variable."); |
| + if (result) { |
| + message += " " + result.description; |
| + result.release(); |
| + } |
| + WebInspector.console.showErrorMessage(message) |
| + } |
| + }, |
| + |
| + /** |
| + * @param {!WebInspector.RemoteObject} remoteObject |
| + */ |
| + _showFunctionDefinition: function(remoteObject) |
| + { |
| + /** |
| * @param {?Protocol.Error} error |
| * @param {!DebuggerAgent.FunctionDetails} response |
| * @this {WebInspector.SourcesPanel} |
| */ |
| - function didGetDetails(error, response) |
| + function didGetFunctionDetails(error, response) |
| { |
| if (error) { |
| console.error(error); |
| @@ -1417,16 +1483,7 @@ WebInspector.SourcesPanel.prototype = { |
| this.showUILocation(uiLocation, true); |
| } |
| - |
| - /** |
| - * @this {WebInspector.SourcesPanel} |
| - */ |
| - function revealFunction() |
| - { |
| - DebuggerAgent.getFunctionDetails(remoteObject.objectId, didGetDetails.bind(this)); |
| - } |
| - |
| - contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Show function definition" : "Show Function Definition"), revealFunction.bind(this)); |
| + DebuggerAgent.getFunctionDetails(remoteObject.objectId, didGetFunctionDetails.bind(this)); |
| }, |
| /** |