/**
 * Helper class for capturing stack traces.
 *
 * Copyright (C) 2015 Martin Poelstra
 * License: MIT
 */ import Stack from "./Stack" ; /**
 * Stack trace container with optional source traces.
 *
 * Typically used for capturing traces across asynchronous calls (e.g.
 * with Promises or Events).
 */ export default class Trace { public stack : Stack ; public sources ? : Stack [ ] ; public static traceLimit : number = 10 ; constructor ( ignoreUntil = Trace ) { this . stack = new Stack ( ignoreUntil ) ; } param source public setSource ( source ) { if ( ! source . sources ) { this . sources = [ source . stack ] ; } else { this . sources = source . sources . concat ( source . stack ) ; if ( this . sources . length > Trace . traceLimit ) { this . sources = this . sources . slice ( 0 , Trace . traceLimit ) ; } } } public inspect ( ) { let result = this . stack . inspect ( ) ; if ( this . sources ) { for ( let i = this . sources . length - 1 ; i >= 0 ; i -- ) { result += "\n  from previous:\n" + this . sources [ i ] . inspect ( ) ; } } return result ; } }