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 /** | 5 /** |
6 * Specialized integers and floating point numbers, | 6 * Specialized integers and floating point numbers, |
7 * with SIMD support and efficient lists. | 7 * with SIMD support and efficient lists. |
8 */ | 8 */ |
9 library dart.typed_data.implementation; | 9 library dart.typed_data.implementation; |
10 | 10 |
(...skipping 1860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 } | 1871 } |
1872 | 1872 |
1873 /// Checks that the value is a Uint32. If not, it's not valid as an array | 1873 /// Checks that the value is a Uint32. If not, it's not valid as an array |
1874 /// index or offset. Also ensures that the value is non-negative. | 1874 /// index or offset. Also ensures that the value is non-negative. |
1875 bool _isInvalidArrayIndex(int index) { | 1875 bool _isInvalidArrayIndex(int index) { |
1876 return (JS('bool', '(# >>> 0 !== #)', index, index)); | 1876 return (JS('bool', '(# >>> 0 !== #)', index, index)); |
1877 } | 1877 } |
1878 | 1878 |
1879 /// Checks that [index] is a valid index into [list] which has length [length]. | 1879 /// Checks that [index] is a valid index into [list] which has length [length]. |
1880 /// | 1880 /// |
1881 /// That is, [index] is an insteger in the range `0..length - 1`. | 1881 /// That is, [index] is an integer in the range `0..length - 1`. |
1882 void _checkValidIndex(int index, List list, int length) { | 1882 void _checkValidIndex(int index, List list, int length) { |
1883 if (_isInvalidArrayIndex(index) || JS('int', '#', index) >= length) { | 1883 if (_isInvalidArrayIndex(index) || JS('int', '#', index) >= length) { |
1884 throw diagnoseIndexError(list, index); | 1884 throw diagnoseIndexError(list, index); |
1885 } | 1885 } |
1886 } | 1886 } |
1887 | 1887 |
1888 /// Checks that [start] and [end] form a range of a list of length [length]. | 1888 /// Checks that [start] and [end] form a range of a list of length [length]. |
1889 /// | 1889 /// |
1890 /// That is: `start` and `end` are integers with `0 <= start <= end <= length`. | 1890 /// That is: `start` and `end` are integers with `0 <= start <= end <= length`. |
1891 /// If `end` is `null` in which case it is considered to be `length` | 1891 /// If `end` is `null` in which case it is considered to be `length` |
1892 /// | 1892 /// |
1893 /// Returns the actual value of `end`, which is `length` if `end` is `null`, and | 1893 /// Returns the actual value of `end`, which is `length` if `end` is `null`, and |
1894 /// the original value of `end` otherwise. | 1894 /// the original value of `end` otherwise. |
1895 int _checkValidRange(int start, int end, int length) { | 1895 int _checkValidRange(int start, int end, int length) { |
1896 if (_isInvalidArrayIndex(start) || // Ensures start is non-negative int. | 1896 if (_isInvalidArrayIndex(start) || // Ensures start is non-negative int. |
1897 ((end == null) | 1897 ((end == null) |
1898 ? start > length | 1898 ? start > length |
1899 : (_isInvalidArrayIndex(end) || start > end || end > length))) { | 1899 : (_isInvalidArrayIndex(end) || start > end || end > length))) { |
1900 throw diagnoseRangeError(start, end, length); | 1900 throw diagnoseRangeError(start, end, length); |
1901 } | 1901 } |
1902 if (end == null) return length; | 1902 if (end == null) return length; |
1903 return end; | 1903 return end; |
1904 } | 1904 } |
OLD | NEW |