Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1134)

Unified Diff: Source/devtools/front_end/SourcesPanel.js

Issue 201613004: DevTools: Add context menu option for objects to save to temp variable. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/front_end/RemoteObject.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/SourcesPanel.js
diff --git a/Source/devtools/front_end/SourcesPanel.js b/Source/devtools/front_end/SourcesPanel.js
index 8a1d4dd913f4c42fce88d6f859095178e4bcd141..53ebff0d8c5b42c971d2c09a3c8fda91a64545a7 100644
--- a/Source/devtools/front_end/SourcesPanel.js
+++ b/Source/devtools/front_end/SourcesPanel.js
@@ -1352,7 +1352,7 @@ WebInspector.SourcesPanel.prototype = {
appendApplicableItems: function(event, contextMenu, target)
{
this._appendUISourceCodeItems(contextMenu, target);
- this._appendFunctionItems(contextMenu, target);
+ this._appendRemoteObjectItems(contextMenu, target);
},
_suggestReload: function()
@@ -1455,42 +1455,128 @@ 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));
+ 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)
+ {
/**
+ * @param {?WebInspector.RemoteObject} result
+ * @param {?string=} error
+ * @this {WebInspector.SourcesPanel}
+ */
+ function failedToSave(result, error)
+ {
+ --this._pendingSavesToTemp;
+ if (result) {
+ error = error || result.description;
+ result.release();
+ }
+ var message = "Failed to save to temp variable" + (error ? ": " + error : "");
pfeldman 2014/03/17 15:36:43 UIString()
+ WebInspector.console.showErrorMessage(message)
+ }
+
+ /**
+ * @param {!WebInspector.RemoteObject} global
+ * @param {string} name
* @param {?Protocol.Error} error
- * @param {!DebuggerAgent.FunctionDetails} response
* @this {WebInspector.SourcesPanel}
*/
- function didGetDetails(error, response)
+ function didSave(global, name, error)
{
+ global.release();
if (error) {
- console.error(error);
- return;
+ failedToSave.call(this, null, error);
+ } else {
+ --this._pendingSavesToTemp;
+ WebInspector.console.evaluate(name);
}
+ }
- var uiLocation = WebInspector.debuggerModel.rawLocationToUILocation(response.location);
- if (!uiLocation)
+ /**
+ * @param {!WebInspector.RemoteObject} global
+ * @param {?WebInspector.RemoteObject} result
+ * @param {boolean=} wasThrown
+ * @this {WebInspector.SourcesPanel}
+ */
+ function didGetTempVarName(global, result, wasThrown)
+ {
+ if (wasThrown || !result || result.type !== "string") {
+ global.release();
+ failedToSave.call(this, result);
return;
+ }
- this.showUILocation(uiLocation, true);
+ var name = /** @type {string} */ (result.value);
+ global.setObjectPropertyValue(name, remoteObject, didSave.bind(this, global, name));
}
/**
+ * @param {?WebInspector.RemoteObject} global
+ * @param {boolean=} wasThrown
* @this {WebInspector.SourcesPanel}
*/
- function revealFunction()
+ function didGetGlobalObject(global, wasThrown)
{
- DebuggerAgent.getFunctionDetails(remoteObject.objectId, didGetDetails.bind(this));
+ /** @this {Window} */
+ function tempVarName(skip)
+ {
+ var prefix = "temp";
+ var index = 1;
+ while (skip-- >= 0) {
+ while ((prefix + index) in this)
+ ++index;
+ }
+ return prefix + index;
+ }
+
+ var skip = this._pendingSavesToTemp || 0;
+ this._pendingSavesToTemp = skip + 1;
+
+ if (wasThrown || !global) {
+ failedToSave.call(this, global);
+ return;
+ }
+ global.callFunction(tempVarName, [{ value: skip }], didGetTempVarName.bind(this, global));
}
- contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Show function definition" : "Show Function Definition"), revealFunction.bind(this));
+ WebInspector.runtimeModel.evaluate("window", "", false, true, false, false, didGetGlobalObject.bind(this));
pfeldman 2014/03/17 15:36:43 Please implement it top-bottom for better readabil
+ },
+
+ /**
+ * @param {!WebInspector.RemoteObject} remoteObject
+ */
+ _showFunctionDefinition: function(remoteObject)
+ {
+ /**
+ * @param {?Protocol.Error} error
+ * @param {!DebuggerAgent.FunctionDetails} response
+ * @this {WebInspector.SourcesPanel}
+ */
+ function didGetFunctionDetails(error, response)
+ {
+ if (error) {
+ console.error(error);
+ return;
+ }
+
+ var uiLocation = WebInspector.debuggerModel.rawLocationToUILocation(response.location);
+ if (!uiLocation)
+ return;
+
+ this.showUILocation(uiLocation, true);
+ }
+ DebuggerAgent.getFunctionDetails(remoteObject.objectId, didGetFunctionDetails.bind(this));
},
showGoToSourceDialog: function()
« no previous file with comments | « Source/devtools/front_end/RemoteObject.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698