OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 dart.core; | 5 part of dart.core; |
6 | 6 |
7 /** | 7 /** |
8 * Error objects thrown in the case of a program failure. | 8 * Error objects thrown in the case of a program failure. |
9 * | 9 * |
10 * An `Error` object represents a program failure that the programmer | 10 * An `Error` object represents a program failure that the programmer |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 * | 293 * |
294 * Throws if the range is not valid for an indexable object with | 294 * Throws if the range is not valid for an indexable object with |
295 * the given [length]. | 295 * the given [length]. |
296 * A range is valid for an indexable object with a given [length] | 296 * A range is valid for an indexable object with a given [length] |
297 * | 297 * |
298 * if `0 <= [start] <= [end] <= [length]`. | 298 * if `0 <= [start] <= [end] <= [length]`. |
299 * An `end` of `null` is considered equivalent to `length`. | 299 * An `end` of `null` is considered equivalent to `length`. |
300 * | 300 * |
301 * The [startName] and [endName] defaults to `"start"` and `"end"`, | 301 * The [startName] and [endName] defaults to `"start"` and `"end"`, |
302 * respectively. | 302 * respectively. |
| 303 * |
| 304 * Returns the actual `end` value, which is `length` if `end` is `null`, |
| 305 * and `end` otherwise. |
303 */ | 306 */ |
304 static void checkValidRange(int start, int end, int length, | 307 static int checkValidRange(int start, int end, int length, |
305 [String startName, String endName, | 308 [String startName, String endName, |
306 String message]) { | 309 String message]) { |
307 if (start < 0 || start > length) { | 310 if (start < 0 || start > length) { |
308 if (startName == null) startName = "start"; | 311 if (startName == null) startName = "start"; |
309 throw new RangeError.range(start, 0, length, startName, message); | 312 throw new RangeError.range(start, 0, length, startName, message); |
310 } | 313 } |
311 if (end != null && (end < start || end > length)) { | 314 if (end != null) { |
312 if (endName == null) endName = "end"; | 315 if (end < start || end > length) { |
313 throw new RangeError.range(end, start, length, endName, message); | 316 if (endName == null) endName = "end"; |
| 317 throw new RangeError.range(end, start, length, endName, message); |
| 318 } |
| 319 return end; |
314 } | 320 } |
| 321 return length; |
315 } | 322 } |
316 | 323 |
317 /** | 324 /** |
318 * Check that an integer value isn't negative. | 325 * Check that an integer value isn't negative. |
319 * | 326 * |
320 * Throws if the value is negative. | 327 * Throws if the value is negative. |
321 */ | 328 */ |
322 static void checkNotNegative(int value, [String name, String message]) { | 329 static void checkNotNegative(int value, [String name, String message]) { |
323 if (value < 0) throw new RangeError.range(value, 0, null, name, message); | 330 if (value < 0) throw new RangeError.range(value, 0, null, name, message); |
324 } | 331 } |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 * the first time it is read. If evaluating the initializer expression causes | 559 * the first time it is read. If evaluating the initializer expression causes |
553 * another read of the variable, this error is thrown. | 560 * another read of the variable, this error is thrown. |
554 */ | 561 */ |
555 class CyclicInitializationError extends Error { | 562 class CyclicInitializationError extends Error { |
556 final String variableName; | 563 final String variableName; |
557 CyclicInitializationError([this.variableName]); | 564 CyclicInitializationError([this.variableName]); |
558 String toString() => variableName == null | 565 String toString() => variableName == null |
559 ? "Reading static variable during its initialization" | 566 ? "Reading static variable during its initialization" |
560 : "Reading static variable '$variableName' during its initialization"; | 567 : "Reading static variable '$variableName' during its initialization"; |
561 } | 568 } |
OLD | NEW |