Line data Source code
1 : // Copyright (c) 2013, 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 'frame.dart'; 6 : import 'trace.dart'; 7 : 8 : /// A thunk for lazily constructing a [Trace]. 9 : typedef TraceThunk = Trace Function(); 10 : 11 : /// A wrapper around a [TraceThunk]. This works around issue 9579 by avoiding 12 : /// the conversion of native [StackTrace]s to strings until it's absolutely 13 : /// necessary. 14 : class LazyTrace implements Trace { 15 : final TraceThunk _thunk; 16 22 : late final Trace _trace = _thunk(); 17 : 18 11 : LazyTrace(this._thunk); 19 : 20 11 : @override 21 22 : List<Frame> get frames => _trace.frames; 22 11 : @override 23 22 : StackTrace get original => _trace.original; 24 0 : @override 25 0 : StackTrace get vmTrace => _trace.vmTrace; 26 0 : @override 27 0 : Trace get terse => LazyTrace(() => _trace.terse); 28 11 : @override 29 : Trace foldFrames(bool Function(Frame) predicate, {bool terse = false}) => 30 44 : LazyTrace(() => _trace.foldFrames(predicate, terse: terse)); 31 0 : @override 32 0 : String toString() => _trace.toString(); 33 : }