Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 9da0910

Browse files
committed
Trace.current skips an extra frame in JS.
JS traces include a frame for StackTrace.current while VM traces do not. [email protected] Review URL: https://codereview.chromium.org//2067063002 .
1 parent 9f8a17f commit 9da0910

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.6.6
2+
3+
* `new Trace.current()` and `new Chain.current()` now skip an extra frame when
4+
run in a JS context. This makes their return values match the VM context.
5+
16
## 1.6.5
27

38
* Really fix strong mode warnings.

lib/src/trace.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ class Trace implements StackTrace {
8181
}
8282

8383
var trace = new Trace.from(StackTrace.current);
84-
return new LazyTrace(() => new Trace(trace.frames.skip(level + 1)));
84+
return new LazyTrace(() {
85+
// JS includes a frame for the call to StackTrace.current, but the VM
86+
// doesn't, so we skip an extra frame in a JS context.
87+
return new Trace(trace.frames.skip(level + (inJS ? 2 : 1)));
88+
});
8589
}
8690

8791
/// Returns a new stack trace containing the same data as [trace].

lib/src/utils.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:path/path.dart' as p;
6+
57
/// The line used in the string representation of stack chains to represent
68
/// the gap between traces.
79
const chainGap = '===== asynchronous gap ===========================\n';
810

11+
// TODO(nweiz): When cross-platform imports work, use them to set this.
12+
/// Whether we're running in a JS context.
13+
final bool inJS = p.style == p.Style.url;
14+
915
/// Returns [string] with enough spaces added to the end to make it [length]
1016
/// characters long.
1117
String padRight(String string, int length) {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name: stack_trace
77
#
88
# When the major version is upgraded, you *must* update that version constraint
99
# in pub to stay in sync with this.
10-
version: 1.6.6-dev
10+
version: 1.6.6
1111
author: "Dart Team <[email protected]>"
1212
homepage: https://github.com/dart-lang/stack_trace
1313
description: >

0 commit comments

Comments
 (0)