Permalink
Browse files

wip

  • Loading branch information...
1 parent fd97199 commit b01ee132dbff4ceaeb7a8eaa3b45847ce55f52fc @c4milo committed May 14, 2012
Showing with 379 additions and 2,340 deletions.
  1. +0 −2,273 Inspector.json
  2. +70 −0 index.js
  3. +0 −6 instructions.txt
  4. +2 −1 lib/console.js
  5. +145 −16 lib/debugger.js
  6. +69 −0 lib/debugger/index.js
  7. +3 −4 lib/index.js
  8. +3 −5 lib/runtime.js
  9. +57 −0 lib/timeline.js
  10. +30 −35 webkit-devtools-agent.js
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,70 @@
+var agents = require('./lib');
+var fork = require('child_process').fork;
+
+var child = fork('./webkit-devtools-agent.js', process.argv);
+
+child.on('message', function(message) {
+ var data = message.data;
+ switch(message.event) {
+ case 'connection':
+ initializeAgents();
+ break;
+ case 'method':
+ var id = data.id;
+ var command = data.method.split('.');
+ var domain = agents[command[0]];
+ var method = command[1];
+ var params = data.params;
+
+ if (!domain || !domain[method]) {
+ console.warn('%s is not implemented', data.method);
+ return;
+ }
+
+ domain[method](params, function(result) {
+ child.send({
+ event: 'result',
+ data: {
+ id: id,
+ result: result
+ }
+ });
+ });
+ break;
+ }
+});
+
+function initializeAgents() {
+ var sendEvent = function(data) {
+ child.send({
+ event: 'event',
+ data: data
+ });
+ };
+
+ var runtimeAgent = new agents.Runtime(sendEvent);
+
+ for (var agent in agents) {
+ if (typeof agents[agent] == 'function' &&
+ agent != 'Runtime') {
+ agents[agent] = new agents[agent](sendEvent, runtimeAgent);
+ }
+ }
+ agents['Runtime'] = runtimeAgent;
+}
+
+if (!module.parent) {
+ child.kill('SIGUSR2');
+} else {
+ process.on('SIGUSR2', function() {
+ child.kill('SIGUSR2');
+ });
+}
+
+child.on('exit', function(code, signal) {
+ console.log(code);
+ console.log(signal);
+ //TODO: re-spawn it
+});
+
+
View
@@ -1,6 +0,0 @@
-1. /Applications/Google\ Chrome\ Canary.app/Contents/MacOS/Google\ Chrome\ Canary --remote-debugging-port=9222
-
-2. Start nodejs agent
-
-3. Go to http://localhost:9222/devtools/devtools.html?host=localhost:8080&page=0 using another chrome browser.
-
View
@@ -1,8 +1,9 @@
var util = require('util');
-function ConsoleAgent(sendEvent) {
+function ConsoleAgent(sendEvent, runtimeAgent) {
var self = this;
this.sendEvent = sendEvent;
+ this.runtimeAgent = runtimeAgent;
this.enabled = false;
this.messages = [];
View
@@ -1,11 +1,9 @@
-var RuntimeAgent = require('./runtime');
-
-function DebuggerAgent(sendEvent) {
+function DebuggerAgent(sendEvent, runtimeAgent) {
this.sendEvent = sendEvent;
this.enabled = false;
- this.runtimeAgent = new RuntimeAgent(sendEvent);
+ this.runtimeAgent = runtimeAgent;
- if (typeof v8debugger != 'function') {
+ if (typeof v8debugger != 'object') {
var msg = 'DebuggerAgent: you need to run ' +
'your nodejs app using --expose_debug_as=v8debugger to be able ' +
'to use the debugger.';
@@ -15,6 +13,7 @@ function DebuggerAgent(sendEvent) {
this.executionState = null;
this.pauseOnExceptions = 'none';
this.Debug = v8debugger.Debug;
+ this.paused = false;
}
var formatScript = function(script) {
@@ -40,7 +39,7 @@ var formatScript = function(script) {
startColumn: script.column_offset,
endLine: endLine,
endColumn: endColumn,
- isContentScript: !!script.context_data && script.context_data.indexOf("injected") == 0
+ isContentScript: !!script.context_data && script.context_data.indexOf("injected") === 0
};
};
@@ -121,6 +120,67 @@ var frameMirrorToJSCallFrame = function(frameMirror, callerFrame) {
};
};
+var wrapCallFrames = function(callFrame, runtimeAgent) {
+ if (!callFrame) {
+ return false;
+ }
+
+ var result = [];
+ var depth = 0;
+ do {
+ result.push(new CallFrameProxy(depth++, callFrame, runtimeAgent));
+ callFrame = callFrame.caller;
+ } while (callFrame);
+
+ return result;
+};
+
+var CallFrameProxy = function(ordinal, callFrame, runtimeAgent) {
+ this.callFrameId = "{\"ordinal\":" + ordinal + ",\"injectedScriptId\":" + callFrame.scriptId + "}";
+
+ this.functionName =
+ (callFrame.type === "function" ?
+ callFrame.functionName : "");
+
+ this.location = {
+ scriptId: String(callFrame.scriptId),
+ lineNumber: callFrame.line,
+ columnNumber: callFrame.column
+ };
+
+ this.scopeChain = this._wrapScopeChain(callFrame, runtimeAgent);
+ this.this = runtimeAgent.wrapObject(callFrame.thisObject, "backtrace");
+}
+
+CallFrameProxy.prototype = {
+ _wrapScopeChain: function(callFrame, runtimeAgent) {
+ const GLOBAL_SCOPE = 0;
+ const LOCAL_SCOPE = 1;
+ const WITH_SCOPE = 2;
+ const CLOSURE_SCOPE = 3;
+ const CATCH_SCOPE = 4;
+
+ var scopeTypeNames = {};
+ scopeTypeNames[GLOBAL_SCOPE] = "global";
+ scopeTypeNames[LOCAL_SCOPE] = "local";
+ scopeTypeNames[WITH_SCOPE] = "with";
+ scopeTypeNames[CLOSURE_SCOPE] = "closure";
+ scopeTypeNames[CATCH_SCOPE] = "catch";
+
+ var scopeChain = callFrame.scopeChain;
+ var scopeChainProxy = [];
+ var foundLocalScope = false;
+ for (var i = 0; i < scopeChain.length; i++) {
+ var scope = {};
+ scope.object = runtimeAgent.wrapObject(scopeChain[i], "backtrace");
+
+ var scopeType = callFrame.scopeType[i];
+ scope.type = scopeTypeNames[scopeType];
+ scopeChainProxy.push(scope);
+ }
+ return scopeChainProxy;
+ }
+};
(function() {
@@ -137,6 +197,7 @@ var frameMirrorToJSCallFrame = function(frameMirror, callerFrame) {
};
this.enable = function(params, sendResult) {
+ var self = this;
this.enabled = true;
var scripts = this.Debug.scripts();
@@ -155,23 +216,62 @@ var frameMirrorToJSCallFrame = function(frameMirror, callerFrame) {
sendResult({result: this.enabled});
this.Debug.setListener(function(eventType, executionState, eventData, data) {
- var DebugEvent = this.Debug.DebugEvent;
+ var DebugEvent = self.Debug.DebugEvent;
+ if (self.paused) { return; }
+ self.executionState = eventData.executionState();
switch(eventType) {
case DebugEvent.AfterCompile:
case DebugEvent.BeforeCompile:
case DebugEvent.NewFunction:
case DebugEvent.ScriptCollected:
break;
case DebugEvent.Break:
- this.sendEvent({
- method: 'Debugger.paused'
+ try {
+ console.log('por aqui 1');
+ console.log(self.currentCallFrame());
+ console.log('por aqui 2');
+ self.sendEvent({
+ method: 'Debugger.paused',
+ params: {
+ callFrames: wrapCallFrames(self.currentCallFrame(), self.runtimeAgent),
+ reason: 'other'
+ }
+ });
+
+ self.sendEvent({
+ method: 'Debugger.breakpointResolved',
+ params: {
+ breakpointId: eventData.breakPointsHit()[0].script_break_point().number().toString(),
+ location: {
+ columnNumber: eventData.sourceColumn(),
+ lineNumber: eventData.sourceLine(),
+ scriptId: eventData.func().script().id().toString()
+ }
+ }
});
+ } catch(e) {
+ console.log('exceptionnnnnnnnn');
+ console.log(e);
+ console.log(e.stack);
+ }
+
break;
case DebugEvent.Exception:
- //Get current stack trace
- //
+ self.sendEvent({
+ method: 'Debugger.paused',
+ params: {
+ callFrames: wrapCallFrames(self.currentCallFrame(), self.runtimeAgent),
+ reason: 'exception'
+ }
+ });
break;
}
+ console.log('Is break on execution? ' + self.Debug.isBreakOnException());
+ if (!self.paused) {
+ process.nextTick(self.pause());
+ }
+ console.log('Is break on execution? ' + self.Debug.isBreakOnException());
+
});
};
@@ -243,6 +343,10 @@ var frameMirrorToJSCallFrame = function(frameMirror, callerFrame) {
};
this.stepOver = function(params, sendResult) {
+ if (!this.paused || !this.executionState) {
+ return;
+ }
+ console.log(this.executionState);
this.executionState.prepareStep(this.Debug.StepAction.StepNext, 1);
sendResult({});
};
@@ -257,14 +361,30 @@ var frameMirrorToJSCallFrame = function(frameMirror, callerFrame) {
sendResult({});
};
+ this.pauseOnNextStatement = function(pause) {
+ //this.paused = true;
+ //this.Debug.breakExecution();
+ };
+
this.pause = function(params, sendResult) {
- this.Debug.breakExecution();
- sendResult({});
+ var self = this;
+ return function() {
+ self.paused = true;
+ if (typeof sendResult == 'function') {
+ sendResult({});
+ }
+ self.Debug.breakExecution();
+ };
};
this.resume = function(params, sendResult) {
- this.Debug.clearAllBreakPoints();
+ //releaseObjectGroup "backtrace"
+ this.executionState = null;
+ this.paused = false;
sendResult({});
+ this.sendEvent({
+ method: 'Debugger.resumed'
+ });
};
@@ -285,10 +405,13 @@ var frameMirrorToJSCallFrame = function(frameMirror, callerFrame) {
}
var changeLog = [];
- return this.Debug.LiveEdit.SetScriptSource( scriptToEdit,
+ var result = this.Debug.LiveEdit.SetScriptSource( scriptToEdit,
params.scriptSource,
params.preview, changeLog);
-
+ sendResult({
+ result: result,
+ callFrames: wrapCallFrames(this.currentCallFrame(), this.runtimeAgent),
+ });
};
this.getScriptSource = function(params, sendResult) {
@@ -322,6 +445,10 @@ var frameMirrorToJSCallFrame = function(frameMirror, callerFrame) {
};
this.evaluateOnCallFrame = function(params, sendResult) {
+
+ };
+
+ this.currentCallFrame = function() {
var frameCount = this.executionState.frameCount();
if (frameCount === 0) {
console.warn('DebuggerAgent.evaluateOnCallFrame: ' +
@@ -334,6 +461,8 @@ var frameMirrorToJSCallFrame = function(frameMirror, callerFrame) {
var frameMirror = this.executionState.frame(i);
topFrame = frameMirrorToJSCallFrame(frameMirror, topFrame);
}
+
+ return topFrame;
};
}).call(DebuggerAgent.prototype);
Oops, something went wrong.

0 comments on commit b01ee13

Please sign in to comment.