Chain.current constructor
Returns the current stack chain.
By default, the first frame of the first trace will be the line where
Chain.current is called. If level
is passed, the first trace will
start that many frames up instead.
If this is called outside of a capture zone, it just returns a single-trace chain.
Implementation
factory Chain.current([int level = 0]) {
if (_currentSpec != null) return _currentSpec.currentChain(level + 1);
var chain = new Chain.forTrace(StackTrace.current);
return new LazyChain(() {
// JS includes a frame for the call to StackTrace.current, but the VM
// doesn't, so we skip an extra frame in a JS context.
var first = new Trace(
chain.traces.first.frames.skip(level + (inJS ? 2 : 1)),
original: chain.traces.first.original.toString());
return new Chain([first]..addAll(chain.traces.skip(1)));
});
}