Browse files

factor out filterStack

  • Loading branch information...
1 parent 4ace329 commit 1f7e70714a968c321afb98df8ee36388ccf455ce @substack committed May 15, 2012
Showing with 26 additions and 17 deletions.
  1. +26 −17 index.js
View
43 index.js
@@ -113,24 +113,13 @@ Fritter.prototype.defineContext = function () {
if (caught.indexOf(err) < 0) {
caught.push(err);
+
+ var stack_ = self.options.longStacks
+ ? filterStack(self.stack)
+ : self.stack
+ ;
self.emit('error', err, {
- stack : self.stack.filter(function (s, ix) {
- var before = self.stack[ix + 1];
- if (!before) return true;
- if (!s) return true;
-
- var bn = before.callee && (
- before.callee.name
- || (before.callee.id && before.callee.id.name)
- );
- var sn = s.id && s.id.name;
-
- if (before.type === 'CallExpression'
- && bn && sn && bn === sn) {
- return false;
- }
- return true;
- }),
+ stack : stack_,
current : self.current
});
}
@@ -237,3 +226,23 @@ function copyAttributes (fn, fn_) {
for (var i = 0; i < keys.length; i++) fn_[key] = fn[key];
return fn_;
}
+
+function filterStack (stack) {
+ return stack.filter(function (s, ix) {
+ var before = stack[ix + 1];
+ if (!before) return true;
+ if (!s) return true;
+
+ var bn = before.callee && (
+ before.callee.name
+ || (before.callee.id && before.callee.id.name)
+ );
+ var sn = s.id && s.id.name;
+
+ if (before.type === 'CallExpression'
+ && bn && sn && bn === sn) {
+ return false;
+ }
+ return true;
+ });
+}

0 comments on commit 1f7e707

Please sign in to comment.