Skip to content

Commit

Permalink
Trace.current skips an extra frame in JS.
Browse files Browse the repository at this point in the history
JS traces include a frame for StackTrace.current while VM traces do not.

R=rnystrom@google.com

Review URL: https://codereview.chromium.org//2067063002 .
  • Loading branch information
nex3 committed Jun 14, 2016
1 parent 9f8a17f commit 9da0910
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.6.6

* `new Trace.current()` and `new Chain.current()` now skip an extra frame when
run in a JS context. This makes their return values match the VM context.

## 1.6.5

* Really fix strong mode warnings.
Expand Down
6 changes: 5 additions & 1 deletion lib/src/trace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ class Trace implements StackTrace {
}

var trace = new Trace.from(StackTrace.current);
return new LazyTrace(() => new Trace(trace.frames.skip(level + 1)));
return new LazyTrace(() {
// 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.
return new Trace(trace.frames.skip(level + (inJS ? 2 : 1)));
});
}

/// Returns a new stack trace containing the same data as [trace].
Expand Down
6 changes: 6 additions & 0 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:path/path.dart' as p;

/// The line used in the string representation of stack chains to represent
/// the gap between traces.
const chainGap = '===== asynchronous gap ===========================\n';

// TODO(nweiz): When cross-platform imports work, use them to set this.
/// Whether we're running in a JS context.
final bool inJS = p.style == p.Style.url;

/// Returns [string] with enough spaces added to the end to make it [length]
/// characters long.
String padRight(String string, int length) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name: stack_trace
#
# When the major version is upgraded, you *must* update that version constraint
# in pub to stay in sync with this.
version: 1.6.6-dev
version: 1.6.6
author: "Dart Team <misc@dartlang.org>"
homepage: https://github.com/dart-lang/stack_trace
description: >
Expand Down

0 comments on commit 9da0910

Please sign in to comment.