dart-sdk/tests/language/stacktrace_demangle_ctors_test.dart
Mike Fairhurst a48e0ef493 Fix #28740 demangle constructors in stack traces (A.A becomes new A) REDO
Regular constructors and unnamed factory constructors:
- Were A.A, now are new A
Named constructors (including factory constructors):
- Were A.A.name, now are new A.name

Previous attempt (a84b6b7f) didn't update vm/cc tests, which broke the
build, was reverted, and also revealed an important case:

Functions within constructors:
- Were A.A.x, now are new A.x

Doing this was cleanest by switching the loop out for recursion, which
provides a nice guarantee that any anonymous function within some other
function will always have the correct prefix, and the class name (which
may or may not be prepended at the end) is only applied once, and its
existence is only checked in one place.

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2823253005 .
2017-04-28 10:19:20 -07:00

60 lines
1.4 KiB
Dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// 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.
// Test that stack traces are properly demangled in constructors (#28740).
import "package:expect/expect.dart";
class SomeClass {
SomeClass.namedConstructor() {
throw new Exception();
}
SomeClass() {
throw new Exception();
}
factory SomeClass.useFactory() {
throw new Exception();
}
}
class OnlyHasFactory {
factory OnlyHasFactory() {
throw new Exception();
}
}
void main() {
try {
new SomeClass();
} on Exception catch (e, st) {
final stString = st.toString();
Expect.isTrue(stString.contains("new SomeClass"));
Expect.isFalse(stString.contains("SomeClass."));
}
try {
new SomeClass.namedConstructor();
} on Exception catch (e, st) {
final stString = st.toString();
Expect.isTrue(stString.contains("new SomeClass.namedConstructor"));
}
try {
new OnlyHasFactory();
} on Exception catch (e, st) {
final stString = st.toString();
Expect.isTrue(stString.contains("new OnlyHasFactory"));
Expect.isFalse(stString.contains("OnlyHasFactory."));
}
try {
new SomeClass.useFactory();
} on Exception catch (e, st) {
final stString = st.toString();
Expect.isTrue(stString.contains("new SomeClass.useFactory"));
}
}