OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library _js_helper; | 5 library _js_helper; |
6 | 6 |
7 import 'dart:_async_await_error_codes' as async_error_codes; | 7 import 'dart:_async_await_error_codes' as async_error_codes; |
8 | 8 |
9 import 'dart:_js_embedded_names' show | 9 import 'dart:_js_embedded_names' show |
10 DEFERRED_LIBRARY_URIS, | 10 DEFERRED_LIBRARY_URIS, |
(...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1381 static void update(cache, String key, value) { | 1381 static void update(cache, String key, value) { |
1382 JS('void', '#[#] = #', cache, key, value); | 1382 JS('void', '#[#] = #', cache, key, value); |
1383 } | 1383 } |
1384 } | 1384 } |
1385 | 1385 |
1386 /** | 1386 /** |
1387 * Called by generated code to throw an illegal-argument exception, | 1387 * Called by generated code to throw an illegal-argument exception, |
1388 * for example, if a non-integer index is given to an optimized | 1388 * for example, if a non-integer index is given to an optimized |
1389 * indexed access. | 1389 * indexed access. |
1390 */ | 1390 */ |
1391 @NoInline() | |
1391 iae(argument) { | 1392 iae(argument) { |
1392 throw _argumentError(argument); | 1393 throw _argumentError(argument); |
1393 } | 1394 } |
1394 | 1395 |
1395 /** | 1396 /** |
1396 * Called by generated code to throw an index-out-of-range exception, | 1397 * Called by generated code to throw an index-out-of-range exception, for |
1397 * for example, if a bounds check fails in an optimized indexed | 1398 * example, if a bounds check fails in an optimized indexed access. This may |
1398 * access. This may also be called when the index is not an integer, in | 1399 * also be called when the index is not an integer, in which case it throws an |
1399 * which case it throws an illegal-argument exception instead, like | 1400 * illegal-argument exception instead, like [iae], or when the receiver is null. |
1400 * [iae], or when the receiver is null. | |
1401 */ | 1401 */ |
1402 @NoInline() | |
1402 ioore(receiver, index) { | 1403 ioore(receiver, index) { |
1403 if (receiver == null) receiver.length; // Force a NoSuchMethodError. | 1404 if (receiver == null) receiver.length; // Force a NoSuchMethodError. |
1404 if (index is !int) iae(index); | 1405 throw diagnoseIndexError(receiver, index); |
1405 throw new RangeError.value(index); | |
1406 } | 1406 } |
1407 | 1407 |
1408 /** | |
1409 * Diagnoses an indexing error. Returns the ArgumentError or RangeError that | |
1410 * describes the problem. | |
1411 */ | |
1412 @NoInline() | |
1413 Error diagnoseIndexError(indexable, index) { | |
1414 if (index is !int) return new ArgumentError.value(index, 'index'); | |
1415 int length = indexable.length; | |
1416 // The following returns the same error that would be thrown by | |
1417 // [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.
| |
1418 if (index < 0 || index >= length) { | |
1419 return new RangeError.index(index, indexable, 'index', null, length); | |
1420 } | |
1421 // The above should always match, but if it does not, use the following. | |
1422 return new RangeError.value(index, 'index'); | |
1423 } | |
1424 | |
1425 | |
1408 stringLastIndexOfUnchecked(receiver, element, start) | 1426 stringLastIndexOfUnchecked(receiver, element, start) |
1409 => JS('int', r'#.lastIndexOf(#, #)', receiver, element, start); | 1427 => JS('int', r'#.lastIndexOf(#, #)', receiver, element, start); |
1410 | 1428 |
1411 | 1429 |
1412 /// 'factory' for constructing ArgumentError.value to keep the call sites small. | 1430 /// 'factory' for constructing ArgumentError.value to keep the call sites small. |
1413 @NoInline() | 1431 @NoInline() |
1414 ArgumentError _argumentError(object) { | 1432 ArgumentError _argumentError(object) { |
1415 return new ArgumentError.value(object); | 1433 return new ArgumentError.value(object); |
1416 } | 1434 } |
1417 | 1435 |
(...skipping 2674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4092 // This is a function that will return a helper function that does the | 4110 // This is a function that will return a helper function that does the |
4093 // iteration of the sync*. | 4111 // iteration of the sync*. |
4094 // | 4112 // |
4095 // Each invocation should give a body with fresh state. | 4113 // Each invocation should give a body with fresh state. |
4096 final dynamic /* js function */ _outerHelper; | 4114 final dynamic /* js function */ _outerHelper; |
4097 | 4115 |
4098 SyncStarIterable(this._outerHelper); | 4116 SyncStarIterable(this._outerHelper); |
4099 | 4117 |
4100 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper)); | 4118 Iterator get iterator => new SyncStarIterator(JS('', '#()', _outerHelper)); |
4101 } | 4119 } |
OLD | NEW |