Skip to content

Commit

Permalink
improving default checkpoint behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
dannycoates committed Mar 13, 2011
1 parent f16501a commit 55c0e53
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 132 deletions.
13 changes: 13 additions & 0 deletions lib/backtrace.js
@@ -0,0 +1,13 @@
function Backtrace(obj) {
var keys = Object.keys(obj)
for (var i = keys.length - 1; i >= 0; i--) {
var key = keys[i]
this[key] = obj[key]
}
}

exports.Backtrace = Backtrace

Backtrace.prototype.pp = function() {

}
17 changes: 17 additions & 0 deletions lib/bind-actor.js
@@ -0,0 +1,17 @@
module.exports = bindActor
function bindActor () {
var args =
Array.prototype.slice.call
(arguments) // jswtf.
, obj = null
, fn
if (typeof args[0] === "object") {
obj = args.shift()
fn = args.shift()
if (typeof fn === "string")
fn = obj[ fn ]
} else fn = args.shift()
return function (cb) {
fn.apply(obj, args.concat(cb)) }
}

69 changes: 51 additions & 18 deletions lib/breakpoint.js
@@ -1,42 +1,75 @@
var asyncMap = require('./async_map')
var asyncMap = require('./async_map'),
chain = require('./chain'),
inspect = require('util').inspect

function Breakpoint(obj, manager, client) {
this.manager = manager;
this.client = client;
var keys = Object.keys(obj);
this.manager = manager
this.client = client
var keys = Object.keys(obj)
for (var i = keys.length - 1; i >= 0; i--) {
var key = keys[i];
this[key] = obj[key];
var key = keys[i]
this[key] = obj[key]
}
}

exports.Breakpoint = Breakpoint;
exports.Breakpoint = Breakpoint

function evaluateWatch(expression, callback) {
this.client.evaluate(expression, 0, function(err, result) {
callback(err, result.value)
})
}

function print(foo, cb) {
console.log(inspect(foo, false, 5, true))
cb(null, foo)
}

function defaultAction(cp, cb) {
var watchKeys = Object.keys(cp.watch),
client = this.client,
res = []

if (watchKeys.length > 0) {
watchKeys.forEach(function(key) {
console.log(key + ' = ' + cp.watch[key])
})
cb()
}
else {
//TODO: get first 2 scopes of variables
chain(
[[client, 'scope', 0, 0]
,[print, chain.last]
]
,res
,cb)
}
}

Breakpoint.prototype.clear = function() {
this.manager.clearBreakpoint(this.number);
this.manager.clearBreakpoint(this.number)
}

Breakpoint.prototype.change = function(enabled, condition) {
this.manager.changeBreakpoint(this.number, enabled, condition);
this.manager.changeBreakpoint(this.number, enabled, condition)
}

Breakpoint.prototype.handleBreak = function() {
var cp = {},
self = this

asyncMap(this.watch, evaluateWatch.bind(this),
function(err, results) {
// TODO: check err
cp.watch = results;
self.action(cp, function(err) {
if(err) console.log(err)
self.client.continue(null, null, function(){})
});
})
asyncMap(
this.watch || [],
evaluateWatch.bind(this),
function(err, results) {
// TODO: check err
cp.watch = results
var action = self.action || defaultAction.bind(self)
action(cp, function(err) {
if (err) console.log(err)
self.client.continue(null, null, function(){})
})
}
)
}
9 changes: 6 additions & 3 deletions lib/breakpoint_manager.js
Expand Up @@ -38,14 +38,17 @@ BreakpointManager.prototype.setBreakpoint = function(options, callback) {
true,
options.condition,
function(err, obj) {
self.breakpoints[obj.breakpoint] = new Breakpoint({
var bp =
new Breakpoint({
number: obj.breakpoint,
script_id: options.scriptId,
scriptId: options.scriptId,
type: 'scriptId',
actual_locations: obj.actual_locations,
actualLocations: obj.actual_locations,
watch: options.watch,
action: options.action
}, self, self.client)
self.breakpoints[obj.breakpoint] = bp
if (typeof(callback) === 'function') callback(err, bp)
})
}

Expand Down
21 changes: 21 additions & 0 deletions lib/chain.js
@@ -0,0 +1,21 @@
module.exports = chain
var bindActor = require("./bind-actor.js")
chain.first = {} ; chain.last = {}
function chain (things, res, cb) {
if (!cb) cb = res , res = []
;(function LOOP (i, len) {
if (i >= len) return cb(null,res)
if (Array.isArray(things[i]))
things[i] = bindActor.apply(null,
things[i].map(function(i){
return (i===chain.first) ? res[0]
: (i===chain.last)
? res[res.length - 1] : i }))
if (!things[i]) return LOOP(i + 1, len)
things[i](function (er, data) {
res.push(er || data)
if (er) return cb(er, res)
LOOP(i + 1, len)
})
})(0, things.length) }

0 comments on commit 55c0e53

Please sign in to comment.