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 ChainThunk = Chain Function(); 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 : late final Chain _chain = _thunk(); 19 : 20 0 : LazyChain(this._thunk); 21 : 22 0 : @override 23 0 : List<Trace> get traces => _chain.traces; 24 0 : @override 25 0 : Chain get terse => _chain.terse; 26 0 : @override 27 : Chain foldFrames(bool Function(Frame) predicate, {bool terse = false}) => 28 0 : LazyChain(() => _chain.foldFrames(predicate, terse: terse)); 29 0 : @override 30 0 : Trace toTrace() => LazyTrace(() => _chain.toTrace()); 31 0 : @override 32 0 : String toString() => _chain.toString(); 33 : }