Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(330)

Side by Side Diff: lib/src/trace.dart

Issue 1653603002: pkg/stack_trace: Use StackTrace.current (Closed) Base URL: https://github.com/dart-lang/stack_trace.git@master
Patch Set: nits Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:collection'; 5 import 'dart:collection';
6 import 'dart:math' as math; 6 import 'dart:math' as math;
7 7
8 import 'chain.dart'; 8 import 'chain.dart';
9 import 'frame.dart'; 9 import 'frame.dart';
10 import 'lazy_trace.dart'; 10 import 'lazy_trace.dart';
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 /// 74 ///
75 /// By default, the first frame of this trace will be the line where 75 /// By default, the first frame of this trace will be the line where
76 /// [Trace.current] is called. If [level] is passed, the trace will start that 76 /// [Trace.current] is called. If [level] is passed, the trace will start that
77 /// many frames up instead. 77 /// many frames up instead.
78 factory Trace.current([int level=0]) { 78 factory Trace.current([int level=0]) {
79 if (level < 0) { 79 if (level < 0) {
80 throw new ArgumentError("Argument [level] must be greater than or equal " 80 throw new ArgumentError("Argument [level] must be greater than or equal "
81 "to 0."); 81 "to 0.");
82 } 82 }
83 83
84 try { 84 var trace = new Trace.from(StackTrace.current);
85 throw ''; 85 return new LazyTrace(() => new Trace(trace.frames.skip(level + 1)));
86 } catch (_, nativeTrace) {
87 var trace = new Trace.from(nativeTrace);
88 return new LazyTrace(() => new Trace(trace.frames.skip(level + 1)));
89 }
90 } 86 }
91 87
92 /// Returns a new stack trace containing the same data as [trace]. 88 /// Returns a new stack trace containing the same data as [trace].
93 /// 89 ///
94 /// If [trace] is a native [StackTrace], its data will be parsed out; if it's 90 /// If [trace] is a native [StackTrace], its data will be parsed out; if it's
95 /// a [Trace], it will be returned as-is. 91 /// a [Trace], it will be returned as-is.
96 factory Trace.from(StackTrace trace) { 92 factory Trace.from(StackTrace trace) {
97 // Normally explicitly validating null arguments is bad Dart style, but here 93 // Normally explicitly validating null arguments is bad Dart style, but here
98 // the natural failure will only occur when the LazyTrace is materialized, 94 // the natural failure will only occur when the LazyTrace is materialized,
99 // and we want to provide an error that's more local to the actual problem. 95 // and we want to provide an error that's more local to the actual problem.
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 var longest = frames.map((frame) => frame.location.length) 285 var longest = frames.map((frame) => frame.location.length)
290 .fold(0, math.max); 286 .fold(0, math.max);
291 287
292 // Print out the stack trace nicely formatted. 288 // Print out the stack trace nicely formatted.
293 return frames.map((frame) { 289 return frames.map((frame) {
294 if (frame is UnparsedFrame) return "$frame\n"; 290 if (frame is UnparsedFrame) return "$frame\n";
295 return '${padRight(frame.location, longest)} ${frame.member}\n'; 291 return '${padRight(frame.location, longest)} ${frame.member}\n';
296 }).join(); 292 }).join();
297 } 293 }
298 } 294 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698