OLD | NEW |
---|---|
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart2js.helpers; | 5 part of dart2js.helpers; |
6 | 6 |
7 /// Function signature for [trace]. | 7 /// Function signature for [trace]. |
8 typedef void Trace(String message, | 8 typedef void Trace(String message, |
9 {bool condition(String stackTrace), | 9 {bool condition(String stackTrace), |
10 int limit, | 10 int limit, |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 int maxFileLength = 0; | 124 int maxFileLength = 0; |
125 int maxLineNoLength = 0; | 125 int maxLineNoLength = 0; |
126 int maxColumnNoLength = 0; | 126 int maxColumnNoLength = 0; |
127 | 127 |
128 String stackTrace = '$s'; | 128 String stackTrace = '$s'; |
129 List<StackTraceLine> lines = <StackTraceLine>[]; | 129 List<StackTraceLine> lines = <StackTraceLine>[]; |
130 // Parse each line in the stack trace. The supported line formats from the | 130 // Parse each line in the stack trace. The supported line formats from the |
131 // Dart VM are: | 131 // Dart VM are: |
132 // #n <method-name> (<uri>:<line-no>:<column-no>) | 132 // #n <method-name> (<uri>:<line-no>:<column-no>) |
133 // #n <method-name> (<uri>:<line-no>) | 133 // #n <method-name> (<uri>:<line-no>) |
134 // #n <method-name> (<uri>) | |
Johnni Winther
2015/09/09 13:43:07
Needed to support async bodies.
sigurdm
2015/09/10 06:37:51
Perhaps write that in a comment
Johnni Winther
2015/09/11 10:42:06
Done.
| |
134 // in which '<anonymous closure>' is the name used for an (unnamed) function | 135 // in which '<anonymous closure>' is the name used for an (unnamed) function |
135 // expression. | 136 // expression. |
136 for (String line in stackTrace.split('\n')) { | 137 for (String line in stackTrace.split('\n')) { |
137 try { | 138 try { |
138 index++; | 139 index++; |
139 if (rangeStart != null && index < rangeStart) continue; | 140 if (rangeStart != null && index < rangeStart) continue; |
140 if (rangeEnd != null && index > rangeEnd) break; | 141 if (rangeEnd != null && index > rangeEnd) break; |
141 if (line.isEmpty) continue; | 142 if (line.isEmpty) continue; |
142 | 143 |
143 // Strip index. | 144 // Strip index. |
144 line = line.replaceFirst(indexPattern, ''); | 145 line = line.replaceFirst(indexPattern, ''); |
145 | 146 |
146 int leftParenPos = line.indexOf('('); | 147 int leftParenPos = line.indexOf('('); |
147 int rightParenPos = line.indexOf(')', leftParenPos); | 148 int rightParenPos = line.indexOf(')', leftParenPos); |
148 int lastColon = line.lastIndexOf(':', rightParenPos); | 149 int lastColon = line.lastIndexOf(':', rightParenPos); |
149 int nextToLastColon = line.lastIndexOf(':', lastColon-1); | 150 int nextToLastColon = line.lastIndexOf(':', lastColon-1); |
150 | 151 |
151 String lineNo; | 152 String lineNo; |
152 String columnNo; | 153 String columnNo; |
153 if (nextToLastColon != -1) { | 154 if (nextToLastColon != -1) { |
154 lineNo = line.substring(nextToLastColon+1, lastColon); | 155 lineNo = line.substring(nextToLastColon+1, lastColon); |
155 columnNo = line.substring(lastColon+1, rightParenPos); | 156 columnNo = line.substring(lastColon+1, rightParenPos); |
156 try { | 157 try { |
157 int.parse(lineNo); | 158 int.parse(columnNo); |
159 try { | |
160 int.parse(lineNo); | |
161 } on FormatException { | |
162 // Only line number. | |
163 lineNo = columnNo; | |
164 columnNo = ''; | |
165 nextToLastColon = lastColon; | |
166 } | |
158 } on FormatException { | 167 } on FormatException { |
159 lineNo = columnNo; | 168 // No column number nor line number. |
169 lineNo = ''; | |
160 columnNo = ''; | 170 columnNo = ''; |
161 nextToLastColon = lastColon; | 171 nextToLastColon = rightParenPos; |
162 } | 172 } |
163 } else { | 173 } else { |
164 lineNo = line.substring(lastColon+1, rightParenPos); | 174 lineNo = line.substring(lastColon+1, rightParenPos); |
165 columnNo = ''; | 175 columnNo = ''; |
166 nextToLastColon = lastColon; | 176 try { |
177 int.parse(lineNo); | |
178 nextToLastColon = lastColon; | |
179 } on FormatException { | |
180 // No column number nor line number. | |
181 lineNo = columnNo; | |
182 columnNo = ''; | |
183 nextToLastColon = rightParenPos; | |
184 } | |
167 } | 185 } |
168 | 186 |
169 if (lineNo.length > maxLineNoLength) { | 187 if (lineNo.length > maxLineNoLength) { |
170 maxLineNoLength = lineNo.length; | 188 maxLineNoLength = lineNo.length; |
171 } | 189 } |
172 if (columnNo.length > maxColumnNoLength) { | 190 if (columnNo.length > maxColumnNoLength) { |
173 maxColumnNoLength = columnNo.length; | 191 maxColumnNoLength = columnNo.length; |
174 } | 192 } |
175 | 193 |
176 String file = line.substring(leftParenPos+1, nextToLastColon); | 194 String file = line.substring(leftParenPos+1, nextToLastColon); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 } | 348 } |
331 for (int index = text.length ; index < intendedLength ; index ++) { | 349 for (int index = text.length ; index < intendedLength ; index ++) { |
332 int dotsIndex = index % dotsLength; | 350 int dotsIndex = index % dotsLength; |
333 sb.write(dots.substring(dotsIndex, dotsIndex + 1)); | 351 sb.write(dots.substring(dotsIndex, dotsIndex + 1)); |
334 } | 352 } |
335 if (padLeft) { | 353 if (padLeft) { |
336 sb.write(text); | 354 sb.write(text); |
337 } | 355 } |
338 return sb.toString(); | 356 return sb.toString(); |
339 } | 357 } |
OLD | NEW |