// Inspired by https://github.com/tlrobinson/long-stack-traces
var EventEmitter = require('events').EventEmitter;
var util = require('util');

function extendTrace(object, property) {
    var old = object[property];
    object[property] = function(x) {
        var error = new Error();
        var name = object.constructor.name + '#' + property + '(' + 
            Array.prototype.slice.call(arguments).map(function(el) {
                return util.inspect(el, false, 0);
            }).join(', ') + ')';

        var last = arguments.length - 1;
        var cb = arguments[last];
        if (typeof arguments[last] === 'function') {
            arguments[last] = function replacement() {
                try {
                    return cb.apply(this, arguments);
                } catch (err) {
                    if (err && err.stack && !err.__augmented) {
                        err.stack = filter(err).join('\n');
                        err.stack += '\n--> in ' + name;
                        err.stack += '\n' + filter(error).slice(1).join('\n');
                        err.__augmented = true;
                    }
                    throw err;
                }
            };
        }
        return old.apply(this, arguments);
    };
}
exports.extendTrace = extendTrace;


function filter(error) {
    return error.stack.split('\n').filter(function(line) {
        return line.indexOf(__filename) < 0;
    });
}

@@ -173,20 +173,25 @@
 property
+, pos
 ) %7B%0A
-
     var 
@@ -246,17 +246,16 @@
 unction(
-x
 ) %7B%0A    
@@ -518,17 +518,76 @@
     
-var last 
+if (typeof pos === 'undefined') pos = -1;%0A        if (pos %3C 0) pos +
 = ar
@@ -604,12 +604,8 @@
 ngth
- - 1
 ;%0A  
@@ -629,20 +629,19 @@
 guments%5B
-last
+pos
 %5D;%0A     
@@ -664,20 +664,19 @@
 guments%5B
-last
+pos
 %5D === 'f
@@ -713,12 +713,11 @@
 nts%5B
-last
+pos
 %5D = 

allow replacing particular parameters