Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improving default checkpoint behavior
- Loading branch information
1 parent
f16501a
commit 55c0e53
Showing
9 changed files
with
234 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(){}) | ||
}) | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) } | ||
|
Oops, something went wrong.