Skip to content

Commit 9046485

Browse files
osa1Commit Queue
authored and
Commit Queue
committed
[dart2wasm] Add function names to source maps
Annotate code with the enclosing Dart function names. Fixes #56718. Change-Id: I1d53fc3752580514aa92b3d62ec717c93ad58d66 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386780 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Ömer Ağacan <[email protected]>
1 parent 574a6b3 commit 9046485

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

pkg/dart2wasm/lib/code_generator.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ abstract class AstCodeGenerator
187187
final location = source.getLocation(fileUri, fileOffset);
188188
final old = _sourceMapFileOffset;
189189
_sourceMapFileOffset = fileOffset;
190-
b.startSourceMapping(fileUri, location.line - 1, location.column - 1, null);
190+
b.startSourceMapping(fileUri, location.line - 1, location.column - 1,
191+
enclosingMember.name.text);
191192
return old;
192193
}
193194

tests/web/wasm/source_map_simple_lib.dart

+9-6
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ void g() {
1818

1919
runtimeFalse() => int.parse('1') == 0;
2020

21-
// `expectedFrames` is (String, line, column) of the frames we check.
21+
// `expectedFrames` is (file, line, column, name) of the frames we check.
2222
//
2323
// Information we don't check are "null": we don't want to check line/column
2424
// of standard library functions to avoid breaking the test with unrelated
2525
// changes to the standard library.
26-
void testMain(String testName, List<(String?, int?, int?)?> expectedFrames) {
26+
void testMain(
27+
String testName, List<(String?, int?, int?, String?)?> expectedFrames) {
2728
// Use `f` and `g` in a few places to make sure wasm-opt won't inline them
2829
// in the test.
2930
final fTearOff = f;
@@ -69,7 +70,8 @@ void testMain(String testName, List<(String?, int?, int?)?> expectedFrames) {
6970
}
7071
if ((expected.$1 != null && actual.$1 != expected.$1) ||
7172
(expected.$2 != null && actual.$2 != expected.$2) ||
72-
(expected.$3 != null && actual.$3 != expected.$3)) {
73+
(expected.$3 != null && actual.$3 != expected.$3) ||
74+
(expected.$4 != null && actual.$4 != expected.$4)) {
7375
throw 'Mismatch:\n Expected: $expected\n Actual: $actual';
7476
}
7577
}
@@ -112,9 +114,9 @@ Mapping getSourceMapping(String testName) {
112114
return allMappings;
113115
}
114116

115-
List<(String?, int?, int?)?> parseStack(
117+
List<(String?, int?, int?, String?)?> parseStack(
116118
String testName, Mapping mapping, String stackTraceString) {
117-
final parsed = <(String?, int?, int?)?>[];
119+
final parsed = <(String?, int?, int?, String?)?>[];
118120
for (final line in stackTraceString.split('\n')) {
119121
if (line.contains('.mjs') || line.contains('.js')) {
120122
parsed.add(null);
@@ -145,7 +147,8 @@ List<(String?, int?, int?)?> parseStack(
145147
final filename = span.sourceUrl!.pathSegments.last;
146148
final lineNumber = span.start.line;
147149
final columnNumber = span.start.column;
148-
parsed.add((filename, 1 + lineNumber, 1 + columnNumber));
150+
final symbolName = span.text;
151+
parsed.add((filename, 1 + lineNumber, 1 + columnNumber, symbolName));
149152
}
150153
return parsed;
151154
}

tests/web/wasm/source_map_simple_optimized_test.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ void main() {
1010
Lib.testMain('source_map_simple_optimized', frameDetails);
1111
}
1212

13-
const List<(String?, int?, int?)?> frameDetails = [
14-
('errors_patch.dart', null, null), // _throwWithCurrentStackTrace
15-
('source_map_simple_lib.dart', 16, 3), // g
16-
('source_map_simple_lib.dart', 12, 3), // f
17-
('source_map_simple_lib.dart', 38, 5), // testMain, inlined in main
13+
const List<(String?, int?, int?, String?)?> frameDetails = [
14+
('errors_patch.dart', null, null, '_throwWithCurrentStackTrace'),
15+
('source_map_simple_lib.dart', 16, 3, 'g'),
16+
('source_map_simple_lib.dart', 12, 3, 'f'),
17+
('source_map_simple_lib.dart', 39, 5, 'testMain'),
1818
];
1919

2020
/*

tests/web/wasm/source_map_simple_test.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ void main() {
1010
Lib.testMain('source_map_simple', frameDetails);
1111
}
1212

13-
const List<(String?, int?, int?)?> frameDetails = [
14-
('errors_patch.dart', null, null), // _throwWithCurrentStackTrace
15-
('source_map_simple_lib.dart', 16, 3), // g
16-
('source_map_simple_lib.dart', 12, 3), // f
17-
('source_map_simple_lib.dart', 38, 5), // testMain
18-
('source_map_simple_test.dart', 10, 7), // main
13+
const List<(String?, int?, int?, String?)?> frameDetails = [
14+
('errors_patch.dart', null, null, '_throwWithCurrentStackTrace'),
15+
('source_map_simple_lib.dart', 16, 3, 'g'),
16+
('source_map_simple_lib.dart', 12, 3, 'f'),
17+
('source_map_simple_lib.dart', 39, 5, 'testMain'),
18+
('source_map_simple_test.dart', 10, 7, 'main'),
1919
null, // main tear-off, compiler generated, not mapped
2020
// The rest of the stack is dependent on the compiler mode.
2121
];

0 commit comments

Comments
 (0)