Chromium Code Reviews| Index: runtime/lib/typed_data.dart |
| diff --git a/runtime/lib/typed_data.dart b/runtime/lib/typed_data.dart |
| index e60c1459d560d8fa0179812755741de54faaae5a..c0b523b648f5cc37af5d3b801b0826afaec3437c 100644 |
| --- a/runtime/lib/typed_data.dart |
| +++ b/runtime/lib/typed_data.dart |
| @@ -2181,6 +2181,7 @@ class _Int8ArrayView extends _TypedListView implements Int8List { |
| _rangeCheck(buffer.lengthInBytes, |
| _offsetInBytes, |
| length * Int8List.BYTES_PER_ELEMENT); |
| + _offsetAlignmentCheck(_offsetInBytes, Int8List.BYTES_PER_ELEMENT); |
|
siva
2013/08/29 16:30:16
int8, uint8 and uint8 clamped do not need any alig
Cutch
2013/09/08 13:16:36
Done.
|
| } |
| @@ -2232,6 +2233,7 @@ class _Uint8ArrayView extends _TypedListView implements Uint8List { |
| _rangeCheck(buffer.lengthInBytes, |
| _offsetInBytes, |
| length * Uint8List.BYTES_PER_ELEMENT); |
| + _offsetAlignmentCheck(_offsetInBytes, Uint8List.BYTES_PER_ELEMENT); |
|
siva
2013/08/29 16:30:16
see comment above.
Cutch
2013/09/08 13:16:36
Done.
|
| } |
| @@ -2284,6 +2286,7 @@ class _Uint8ClampedArrayView extends _TypedListView implements Uint8ClampedList |
| _rangeCheck(buffer.lengthInBytes, |
| offsetInBytes, |
| length * Uint8List.BYTES_PER_ELEMENT); |
| + _offsetAlignmentCheck(_offsetInBytes, Uint8List.BYTES_PER_ELEMENT); |
|
siva
2013/08/29 16:30:16
Ditto.
Cutch
2013/09/08 13:16:36
Done.
|
| } |
| @@ -2335,6 +2338,7 @@ class _Int16ArrayView extends _TypedListView implements Int16List { |
| _rangeCheck(buffer.lengthInBytes, |
| offsetInBytes, |
| length * Int16List.BYTES_PER_ELEMENT); |
| + _offsetAlignmentCheck(_offsetInBytes, Int16List.BYTES_PER_ELEMENT); |
| } |
| @@ -2386,6 +2390,7 @@ class _Uint16ArrayView extends _TypedListView implements Uint16List { |
| _rangeCheck(buffer.lengthInBytes, |
| offsetInBytes, |
| length * Uint16List.BYTES_PER_ELEMENT); |
| + _offsetAlignmentCheck(_offsetInBytes, Uint16List.BYTES_PER_ELEMENT); |
| } |
| @@ -2437,6 +2442,7 @@ class _Int32ArrayView extends _TypedListView implements Int32List { |
| _rangeCheck(buffer.lengthInBytes, |
| offsetInBytes, |
| length * Int32List.BYTES_PER_ELEMENT); |
| + _offsetAlignmentCheck(_offsetInBytes, Int32List.BYTES_PER_ELEMENT); |
| } |
| @@ -2488,6 +2494,7 @@ class _Uint32ArrayView extends _TypedListView implements Uint32List { |
| _rangeCheck(buffer.lengthInBytes, |
| offsetInBytes, |
| length * Uint32List.BYTES_PER_ELEMENT); |
| + _offsetAlignmentCheck(_offsetInBytes, Uint32List.BYTES_PER_ELEMENT); |
| } |
| @@ -2539,6 +2546,7 @@ class _Int64ArrayView extends _TypedListView implements Int64List { |
| _rangeCheck(buffer.lengthInBytes, |
| offsetInBytes, |
| length * Int64List.BYTES_PER_ELEMENT); |
| + _offsetAlignmentCheck(_offsetInBytes, Int64List.BYTES_PER_ELEMENT); |
| } |
| @@ -2590,6 +2598,7 @@ class _Uint64ArrayView extends _TypedListView implements Uint64List { |
| _rangeCheck(buffer.lengthInBytes, |
| offsetInBytes, |
| length * Uint64List.BYTES_PER_ELEMENT); |
| + _offsetAlignmentCheck(_offsetInBytes, Uint64List.BYTES_PER_ELEMENT); |
| } |
| @@ -2641,6 +2650,7 @@ class _Float32ArrayView extends _TypedListView implements Float32List { |
| _rangeCheck(buffer.lengthInBytes, |
| offsetInBytes, |
| length * Float32List.BYTES_PER_ELEMENT); |
| + _offsetAlignmentCheck(_offsetInBytes, Float32List.BYTES_PER_ELEMENT); |
| } |
| @@ -2692,6 +2702,7 @@ class _Float64ArrayView extends _TypedListView implements Float64List { |
| _rangeCheck(buffer.lengthInBytes, |
| offsetInBytes, |
| length * Float64List.BYTES_PER_ELEMENT); |
| + _offsetAlignmentCheck(_offsetInBytes, Float64List.BYTES_PER_ELEMENT); |
| } |
| @@ -2743,6 +2754,7 @@ class _Float32x4ArrayView extends _TypedListView implements Float32x4List { |
| _rangeCheck(buffer.lengthInBytes, |
| offsetInBytes, |
| length * Float32x4List.BYTES_PER_ELEMENT); |
| + _offsetAlignmentCheck(_offsetInBytes, Float32x4List.BYTES_PER_ELEMENT); |
| } |
| @@ -3135,6 +3147,14 @@ void _rangeCheck(int listLength, int start, int length) { |
| } |
| +void _offsetAlignmentCheck(int offset, int alignment) { |
| + if ((offset % alignment) != 0) { |
| + throw new RangeError('Offset ($offset) must be a multiple of ' |
| + 'BYTES_PER_ELEMENT ($alignment)'); |
| + } |
| +} |
| + |
| + |
| int _defaultIfNull(object, value) { |
| if (object == null) { |
| return value; |