Line data Source code
1 : // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 : // for details. All rights reserved. Use of this source code is governed by a
3 : // BSD-style license that can be found in the LICENSE file.
4 :
5 : import 'chain.dart';
6 : import 'frame.dart';
7 : import 'lazy_trace.dart';
8 : import 'trace.dart';
9 :
10 : /// A thunk for lazily constructing a [Chain].
11 : typedef Chain ChainThunk();
12 :
13 : /// A wrapper around a [ChainThunk]. This works around issue 9579 by avoiding
14 : /// the conversion of native [StackTrace]s to strings until it's absolutely
15 : /// necessary.
16 : class LazyChain implements Chain {
17 : final ChainThunk _thunk;
18 : Chain _inner;
19 :
20 0 : LazyChain(this._thunk);
21 :
22 : Chain get _chain {
23 0 : if (_inner == null) _inner = _thunk();
24 0 : return _inner;
25 : }
26 :
27 0 : List<Trace> get traces => _chain.traces;
28 0 : Chain get terse => _chain.terse;
29 : Chain foldFrames(bool predicate(Frame frame), {bool terse: false}) =>
30 0 : new LazyChain(() => _chain.foldFrames(predicate, terse: terse));
31 0 : Trace toTrace() => new LazyTrace(() => _chain.toTrace());
32 0 : String toString() => _chain.toString();
33 : }
|