Trace.current skips an extra frame in JS. JS traces include a frame for StackTrace.current while VM traces do not. R=rnystrom@google.com Review URL: https://codereview.chromium.org//2067063002 .
diff --git a/pkgs/stack_trace/CHANGELOG.md b/pkgs/stack_trace/CHANGELOG.md index 174754c..21fd734 100644 --- a/pkgs/stack_trace/CHANGELOG.md +++ b/pkgs/stack_trace/CHANGELOG.md
@@ -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.
diff --git a/pkgs/stack_trace/lib/src/trace.dart b/pkgs/stack_trace/lib/src/trace.dart index 8537b62..20343ad 100644 --- a/pkgs/stack_trace/lib/src/trace.dart +++ b/pkgs/stack_trace/lib/src/trace.dart
@@ -81,7 +81,11 @@ } 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].
diff --git a/pkgs/stack_trace/lib/src/utils.dart b/pkgs/stack_trace/lib/src/utils.dart index 710abdc..b06d462 100644 --- a/pkgs/stack_trace/lib/src/utils.dart +++ b/pkgs/stack_trace/lib/src/utils.dart
@@ -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) {
diff --git a/pkgs/stack_trace/pubspec.yaml b/pkgs/stack_trace/pubspec.yaml index ac3c311..06c9d3c 100644 --- a/pkgs/stack_trace/pubspec.yaml +++ b/pkgs/stack_trace/pubspec.yaml
@@ -7,7 +7,7 @@ # # 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: >