Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(428)

Unified Diff: sdk/lib/_internal/js_runtime/lib/js_helper.dart

Issue 1318943005: Update range errors to agree on the numbers. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: More tests Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/js_runtime/lib/js_helper.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/js_helper.dart b/sdk/lib/_internal/js_runtime/lib/js_helper.dart
index 91049cda0fe66872d542cdc2d79fdb2ac2b06f45..b4ab91c192b236631901ea56dfd63960692ea18a 100644
--- a/sdk/lib/_internal/js_runtime/lib/js_helper.dart
+++ b/sdk/lib/_internal/js_runtime/lib/js_helper.dart
@@ -1566,7 +1566,7 @@ ioore(receiver, index) {
*/
@NoInline()
Error diagnoseIndexError(indexable, index) {
- if (index is !int) return new ArgumentError.value(index, 'index');
+ if (index is! int) return new ArgumentError.value(index, 'index');
int length = indexable.length;
// The following returns the same error that would be thrown by calling
// [RangeError.checkValidIndex] with no optional parameters provided.
@@ -1577,6 +1577,29 @@ Error diagnoseIndexError(indexable, index) {
return new RangeError.value(index, 'index');
}
+/**
+ * Diagnoses a range error. Returns the ArgumentError or RangeError that
+ * describes the problem.
+ */
+@NoInline()
+Error diagnoseRangeError(start, end, length) {
+ if (start is! int) {
+ return new ArgumentError.value(start, 'start');
+ }
+ if (start < 0 || start > length) {
+ return new RangeError.range(start, 0, length, 'start');
+ }
+ if (end != null) {
+ if (end is! int) {
+ return new ArgumentError.value(end, 'end');
+ }
+ if (end < start || end > length) {
+ return new RangeError.range(end, start, length, 'end');
+ }
+ }
+ // The above should always match, but if it does not, use the following.
+ return new ArgumentError.value(end, "end");
+}
stringLastIndexOfUnchecked(receiver, element, start)
=> JS('int', r'#.lastIndexOf(#, #)', receiver, element, start);

Powered by Google App Engine
This is Rietveld 408576698