summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-04 09:24:00 +0000
committeryurys@google.com <yurys@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-04 09:24:00 +0000
commitde21492cdd9d039bfb91742f2b33301df516e179 (patch)
tree0f47aad126755bace2db2ee9740762133571e8f8
parentd2d9e014bf8ed05216b11eb032e0dbf2cf24a778 (diff)
downloadchromium_src-de21492cdd9d039bfb91742f2b33301df516e179.zip
chromium_src-de21492cdd9d039bfb91742f2b33301df516e179.tar.gz
chromium_src-de21492cdd9d039bfb91742f2b33301df516e179.tar.bz2
Now it's possible to evaluate expressions in the debugger console.
Review URL: http://codereview.chromium.org/99340 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15200 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/glue/devtools/js/debugger_agent.js114
-rw-r--r--webkit/glue/devtools/js/devtools.js22
-rw-r--r--webkit/glue/webdevtoolsagent_impl.cc6
3 files changed, 105 insertions, 37 deletions
diff --git a/webkit/glue/devtools/js/debugger_agent.js b/webkit/glue/devtools/js/debugger_agent.js
index 2f3ff7c..3e58e80 100644
--- a/webkit/glue/devtools/js/debugger_agent.js
+++ b/webkit/glue/devtools/js/debugger_agent.js
@@ -34,7 +34,7 @@ devtools.DebuggerAgent = function() {
/**
* Information on current stack top frame.
* See JavaScriptCallFrame.idl.
- * @type {?Object}
+ * @type {?devtools.CallFrame}
*/
this.currentCallFrame_ = null;
@@ -199,7 +199,7 @@ devtools.DebuggerAgent.prototype.setPauseOnExceptions = function(value) {
/**
* Current stack top frame.
- * @return {Object}
+ * @return {devtools.CallFrame}
*/
devtools.DebuggerAgent.prototype.getCurrentCallFrame = function() {
return this.currentCallFrame_;
@@ -208,17 +208,14 @@ devtools.DebuggerAgent.prototype.getCurrentCallFrame = function() {
/**
* Sends 'evaluate' request to the debugger.
- * @param {string} expr Expression to evaluate.
+ * @param {Object} arguments Request arguments map.
* @param {function(devtools.DebuggerMessage)} callback Callback to be called
* when response is received.
*/
-devtools.DebuggerAgent.prototype.requestEvaluate = function(expr, callback) {
- var cmd = new devtools.DebugCommand('evaluate', {
- 'expression': expr,
- 'global':true
- });
+devtools.DebuggerAgent.prototype.requestEvaluate = function(
+ arguments, callback) {
+ var cmd = new devtools.DebugCommand('evaluate', arguments);
devtools.DebuggerAgent.sendCommand_(cmd);
-
this.requestSeqToCallback_[cmd.getSequenceNumber()] = callback;
};
@@ -363,14 +360,10 @@ devtools.DebuggerAgent.prototype.handleBreakEvent_ = function(msg) {
var body = msg.getBody();
var line = devtools.DebuggerAgent.v8ToWwebkitLineNumber_(body.sourceLine);
- this.currentCallFrame_ = {
- 'sourceID': body.script.id,
- 'line': line,
- 'script': body.script,
- 'scopeChain': [],
- 'thisObject': {}
- };
-
+ this.currentCallFrame_ = new devtools.CallFrame();
+ this.currentCallFrame_.sourceID = body.script.id;
+ this.currentCallFrame_.line = line;
+ this.currentCallFrame_.script = body.script;
this.requestBacktrace_();
};
@@ -393,13 +386,10 @@ devtools.DebuggerAgent.prototype.handleExceptionEvent_ = function(msg) {
var line = devtools.DebuggerAgent.v8ToWwebkitLineNumber_(body.sourceLine);
- this.currentCallFrame_ = {
- 'sourceID': sourceId,
- 'line': line,
- 'script': body.script,
- 'scopeChain': [],
- 'thisObject': {}
- };
+ this.currentCallFrame_ = new devtools.CallFrame();
+ this.currentCallFrame_.sourceID = sourceId;
+ this.currentCallFrame_.line = line;
+ this.currentCallFrame_.script = body.script;
this.requestBacktrace_();
} else {
this.resumeExecution();
@@ -496,6 +486,7 @@ devtools.DebuggerAgent.prototype.handleBacktraceResponse_ = function(msg) {
for (var i = frames.length - 1; i>=0; i--) {
var nextFrame = frames[i];
var f = devtools.DebuggerAgent.formatCallFrame_(nextFrame, script, msg);
+ f.frameNumber = i;
f.caller = callerFrame;
callerFrame = f;
}
@@ -521,12 +512,16 @@ devtools.DebuggerAgent.prototype.invokeCallbackForResponse_ = function(msg) {
};
+devtools.DebuggerAgent.prototype.evaluateInCallFrame_ = function(expression) {
+};
+
+
/**
* @param {Object} stackFrame Frame json object from 'backtrace' response.
* @param {Object} script Script json object from 'break' event.
* @param {devtools.DebuggerMessage} msg Parsed 'backtrace' response.
- * @return {!Object} Object containing information related to the call frame in
- * the format expected by ScriptsPanel and its panes.
+ * @return {!devtools.CallFrame} Object containing information related to the
+ * call frame in the format expected by ScriptsPanel and its panes.
*/
devtools.DebuggerAgent.formatCallFrame_ = function(stackFrame, script, msg) {
var sourceId = script.id;
@@ -551,16 +546,15 @@ devtools.DebuggerAgent.formatCallFrame_ = function(stackFrame, script, msg) {
scope['this'] = devtools.DebuggerAgent.formatObject_(thisObject, msg);
var line = devtools.DebuggerAgent.v8ToWwebkitLineNumber_(stackFrame.line);
- return {
- 'sourceID': sourceId,
- 'line': line,
- 'type': 'function',
- 'functionName': funcName, //stackFrame.text,
- 'caller': null,
- 'localScope': scope,
- 'scopeChain': [scope],
- 'thisObject': thisObject,
- };
+ var result = new devtools.CallFrame();
+ result.sourceID = sourceId;
+ result.line = line;
+ result.type = 'function';
+ result.functionName = funcName;
+ result.localScope = scope;
+ result.scopeChain = [scope];
+ result.thisObject = thisObject;
+ return result;
};
@@ -890,6 +884,54 @@ devtools.BreakpointInfo.prototype.isRemoved = function() {
};
+/**
+ * Call stack frame data.
+ * @construnctor
+ */
+devtools.CallFrame = function() {
+ this.sourceID = null;
+ this.line = null;
+ this.type = 'function';
+ this.functionName = null;
+ this.caller = null;
+ this.localScope = null;
+ this.scopeChain = [];
+ this.thisObject = {};
+ this.frameNumber = null;
+};
+
+
+/**
+ * This method is called by
+ * WebInspector.ScriptsPanel.evaluateInSelectedCallFrame. This method issues
+ * asynchronous evaluate request.
+ * @param {string} expression An expression to be evaluated in the context of
+ * this call frame.
+ * @return {string} User message that the expression is being evaluated.
+ */
+devtools.CallFrame.prototype.evaluate = function(expression) {
+ devtools.tools.getDebuggerAgent().requestEvaluate({
+ 'expression': expression,
+ 'frame': this.frameNumber,
+ 'global': false,
+ 'disable_break': false
+ },
+ devtools.CallFrame.handleEvaluateResponse_);
+ return 'evaluating...';
+};
+
+
+/**
+ * Handles 'evaluate' response for a call frame
+ * @param {devtools.DebuggerMessage} response
+ */
+devtools.CallFrame.handleEvaluateResponse_ = function(response) {
+ var body = response.getBody();
+ var value = devtools.DebuggerAgent.formatValue_(body);
+ WebInspector.addMessageToConsole(new WebInspector.ConsoleCommandResult(
+ value, false /* exception */, null /* commandMessage */));
+};
+
/**
* JSON based commands sent to v8 debugger.
diff --git a/webkit/glue/devtools/js/devtools.js b/webkit/glue/devtools/js/devtools.js
index 2d387e4..1432a08 100644
--- a/webkit/glue/devtools/js/devtools.js
+++ b/webkit/glue/devtools/js/devtools.js
@@ -559,7 +559,7 @@ WebInspector.ScopeChainSidebarPane.TreeElement.prototype.didResolveChildren_ =
};
-/**
+/**
* @override
*/
WebInspector.StylePropertyTreeElement.prototype.toggleEnabled =
@@ -590,3 +590,23 @@ WebInspector.StylePropertyTreeElement.prototype.applyStyleText = function(
}
});
};
+
+
+/**
+ * @override
+ */
+WebInspector.Console.prototype._evalInInspectedWindow = function(expression) {
+ if (WebInspector.panels.scripts.paused)
+ return WebInspector.panels.scripts.evaluateInSelectedCallFrame(expression);
+
+ var console = this;
+ devtools.tools.evaluateJavaScript(expression, function(response) {
+ // TODO(yurys): send exception information along with the response
+ var exception = false;
+ console.addMessage(new WebInspector.ConsoleCommandResult(
+ response, exception, null /* commandMessage */));
+ });
+ // TODO(yurys): refactor WebInspector.Console so that the result is added into
+ // the command log message.
+ return 'evaluating...';
+};
diff --git a/webkit/glue/webdevtoolsagent_impl.cc b/webkit/glue/webdevtoolsagent_impl.cc
index 6de1ec5..a4c1745 100644
--- a/webkit/glue/webdevtoolsagent_impl.cc
+++ b/webkit/glue/webdevtoolsagent_impl.cc
@@ -13,6 +13,7 @@
#include "Page.h"
#include "PlatformString.h"
#include "ScriptValue.h"
+#include "v8_proxy.h"
#include <wtf/OwnPtr.h>
#undef LOG
@@ -189,6 +190,11 @@ void WebDevToolsAgentImpl::EvaluateJavaScript(int call_id, const String& js) {
ScriptValue result = page->mainFrame()->loader()->executeScript(js);
String result_string;
if (!result.hasNoValue()) {
+ // toString() may need global context.
+ v8::HandleScope scope;
+ v8::Handle<v8::Context> context = WebCore::V8Proxy::GetContext(
+ page->mainFrame());
+ v8::Context::Scope context_scope(context);
result_string = result.toString(NULL);
}
tools_agent_delegate_stub_->DidEvaluateJavaScript(call_id, result_string);