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

Unified Diff: sdk/lib/_internal/compiler/js_lib/native_typed_data.dart

Issue 1187553005: Revert "Better messages for optimized index errors." (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/js_string.dart ('k') | sdk/lib/core/errors.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/js_lib/native_typed_data.dart
diff --git a/sdk/lib/_internal/compiler/js_lib/native_typed_data.dart b/sdk/lib/_internal/compiler/js_lib/native_typed_data.dart
index d134c6db81766fb4a62ebd0f0d3d10207c0f48b9..b09537d11f25cc5755d130e70817189a28fb66aa 100644
--- a/sdk/lib/_internal/compiler/js_lib/native_typed_data.dart
+++ b/sdk/lib/_internal/compiler/js_lib/native_typed_data.dart
@@ -11,9 +11,8 @@ library dart.typed_data.implementation;
import 'dart:collection';
import 'dart:_internal';
import 'dart:_interceptors' show JSIndexable, JSUInt32, JSUInt31;
-import 'dart:_js_helper' show
- Creates, JavaScriptIndexingBehavior, JSName, Native, Null, Returns,
- diagnoseIndexError;
+import 'dart:_js_helper'
+show Creates, JavaScriptIndexingBehavior, JSName, Native, Null, Returns;
import 'dart:_foreign_helper' show JS;
import 'dart:math' as Math;
@@ -446,34 +445,35 @@ class NativeTypedData implements TypedData {
@JSName('BYTES_PER_ELEMENT')
final int elementSizeInBytes;
- void _checkIndex(int index, int length) {
- if (JS('bool', '(# >>> 0) !== #', index, index) ||
- JS('int', '#', index) >= length) { // 'int' guaranteed by above test.
- throw diagnoseIndexError(this, index);
- }
- }
-
- void _invalidPosition(int position, int length) {
- if (position is !int) {
- throw new ArgumentError.value(position, null, 'Invalid list position');
+ void _invalidIndex(int index, int length) {
+ if (index < 0 || index >= length) {
+ if (this is List) {
+ var list = this; // Typed as dynamic to avoid warning.
+ if (length == list.length) {
+ throw new RangeError.index(index, this);
+ }
+ }
+ throw new RangeError.range(index, 0, length - 1);
} else {
- throw new RangeError.range(position, 0, length);
+ throw new ArgumentError('Invalid list index $index');
}
}
- void _checkPosition(int position, int length) {
- if (JS('bool', '(# >>> 0) !== #', position, position) ||
- JS('int', '#', position) > length) { // 'int' guaranteed by above test.
- _invalidPosition(position, length);
+ void _checkIndex(int index, int length) {
+ if (JS('bool', '(# >>> 0) !== #', index, index) ||
+ JS('int', '#', index) >= length) { // 'int' guaranteed by above test.
+ _invalidIndex(index, length);
}
}
int _checkSublistArguments(int start, int end, int length) {
// For `sublist` the [start] and [end] indices are allowed to be equal to
- // [length].
- _checkPosition(start, length);
+ // [length]. However, [_checkIndex] only allows indices in the range
+ // 0 .. length - 1. We therefore increment the [length] argument by one
+ // for the [_checkIndex] checks.
+ _checkIndex(start, length + 1);
if (end == null) return length;
- _checkPosition(end, length);
+ _checkIndex(end, length + 1);
if (start > end) throw new RangeError.range(start, 0, end);
return end;
}
@@ -862,8 +862,8 @@ abstract class NativeTypedArray extends NativeTypedData
void _setRangeFast(int start, int end,
NativeTypedArray source, int skipCount) {
int targetLength = this.length;
- _checkPosition(start, targetLength);
- _checkPosition(end, targetLength);
+ _checkIndex(start, targetLength + 1);
+ _checkIndex(end, targetLength + 1);
if (start > end) throw new RangeError.range(start, 0, end);
int count = end - start;
« no previous file with comments | « sdk/lib/_internal/compiler/js_lib/js_string.dart ('k') | sdk/lib/core/errors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698