stacktrace.js
function StackTrace$$instrument(fn, callback, errback, thisArg) {
            if (typeof fn !== 'function') {
                throw new Error('Cannot instrument non-function object');
            } else if (typeof fn.__stacktraceOriginalFn === 'function') {
                // Already instrumented, return given Function
                return fn;
            }

            var instrumented = function StackTrace$$instrumented() {
                try {
                    this.get().then(callback, errback)['catch'](errback);
                    return fn.apply(thisArg || this, arguments);
                } catch (e) {
                    if (_isShapedLikeParsableError(e)) {
                        this.fromError(e).then(callback, errback)['catch'](errback);
                    }
                    throw e;
                }
            }.bind(this);
            instrumented.__stacktraceOriginalFn = fn;

            return instrumented;
        }
function StackTrace$$instrument(fn, callback, errback, thisArg) {
            if (typeof fn !== 'function') {
                throw new Error('Cannot instrument non-function object');
            } else if (typeof fn.__stacktraceOriginalFn === 'function') {
                // Already instrumented, return given Function
                return fn;
            }

            var instrumented = function StackTrace$$instrumented() {
                try {
                    this.get().then(callback, errback)['catch'](errback);
                    return fn.apply(thisArg || this, arguments);
                } catch (e) {
                    if (_isShapedLikeParsableError(e)) {
                        this.fromError(e).then(callback, errback)['catch'](errback);
                    }
                    throw e;
                }
            }.bind(this);
            instrumented.__stacktraceOriginalFn = fn;

            return instrumented;
        }
function StackTrace$$instrument ( fn , callback , errback , thisArg ) { if ( typeof fn !== 'function' ) { throw new Error ( 'Cannot instrument non-function object' ) ; } else if ( typeof fn . __stacktraceOriginalFn === 'function' ) { // Already instrumented, return given Function return fn ; } var instrumented = function StackTrace$$instrumented ( ) { try { this . get ( ) . then ( callback , errback ) [ 'catch' ] ( errback ) ; return fn . apply ( thisArg || this , arguments ) ; } catch ( e ) { if ( _isShapedLikeParsableError ( e ) ) { this . fromError ( e ) . then ( callback , errback ) [ 'catch' ] ( errback ) ; } throw e ; } } . bind ( this ) ; instrumented . __stacktraceOriginalFn = fn ; return instrumented ; }
Given a function, wrap it such that invocations trigger a callback that
is called with a stack trace.

@param {Function} fn to be instrumented
@param {Function} callback function to call with a stack trace on invocation
@param {Function} errback optional function to call with error if unable to get stack trace.
@param {Object} thisArg optional context object (e.g. window)
Given a function wrap it such that invocations trigger a callback that is called with a stack trace .