Chromium Code Reviews| Index: sdk/lib/_internal/compiler/js_lib/js_helper.dart |
| diff --git a/sdk/lib/_internal/compiler/js_lib/js_helper.dart b/sdk/lib/_internal/compiler/js_lib/js_helper.dart |
| index 1c6183d4f32f67fa48e559fe73df982f09ffb73f..82d66d0c9fe35359b4f06222ec2536a173fb9331 100644 |
| --- a/sdk/lib/_internal/compiler/js_lib/js_helper.dart |
| +++ b/sdk/lib/_internal/compiler/js_lib/js_helper.dart |
| @@ -1388,23 +1388,41 @@ class JsCache { |
| * for example, if a non-integer index is given to an optimized |
| * indexed access. |
| */ |
| +@NoInline() |
| iae(argument) { |
| throw _argumentError(argument); |
| } |
| /** |
| - * Called by generated code to throw an index-out-of-range exception, |
| - * for example, if a bounds check fails in an optimized indexed |
| - * access. This may also be called when the index is not an integer, in |
| - * which case it throws an illegal-argument exception instead, like |
| - * [iae], or when the receiver is null. |
| + * Called by generated code to throw an index-out-of-range exception, for |
| + * example, if a bounds check fails in an optimized indexed access. This may |
| + * also be called when the index is not an integer, in which case it throws an |
| + * illegal-argument exception instead, like [iae], or when the receiver is null. |
| */ |
| +@NoInline() |
| ioore(receiver, index) { |
| if (receiver == null) receiver.length; // Force a NoSuchMethodError. |
| - if (index is !int) iae(index); |
| - throw new RangeError.value(index); |
| + throw diagnoseIndexError(receiver, index); |
| } |
| +/** |
| + * Diagnoses an indexing error. Returns the ArgumentError or RangeError that |
| + * describes the problem. |
| + */ |
| +@NoInline() |
| +Error diagnoseIndexError(indexable, 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 |
| + // [RangeError.checkValidIndex] with no optional arguments. |
|
Lasse Reichstein Nielsen
2015/06/12 14:24:37
no optional parameters omitted?
no optional parame
sra1
2015/06/12 22:29:05
Done.
|
| + if (index < 0 || index >= length) { |
| + return new RangeError.index(index, indexable, 'index', null, length); |
| + } |
| + // The above should always match, but if it does not, use the following. |
| + return new RangeError.value(index, 'index'); |
| +} |
| + |
| + |
| stringLastIndexOfUnchecked(receiver, element, start) |
| => JS('int', r'#.lastIndexOf(#, #)', receiver, element, start); |