Chromium Code Reviews| Index: runtime/lib/byte_array.dart |
| =================================================================== |
| --- runtime/lib/byte_array.dart (revision 15751) |
| +++ runtime/lib/byte_array.dart (working copy) |
| @@ -34,6 +34,22 @@ |
| } |
| +patch class Uint8ClampedList { |
| + /* patch */ factory Uint8ClampedList(int length) { |
| + return new _Uint8ClampedArray(length); |
| + } |
| + |
| + /* patch */ factory Uint8ClampedList.transferable(int length) { |
| + return new _Uint8ClampedArray.transferable(length); |
| + } |
| + |
| + /* patch */ factory Uint8ClampedList.view(ByteArray array, |
| + [int start = 0, int length]) { |
|
cshapiro
2012/12/05 23:01:49
Is this indented correctly? I would assume the op
srdjan
2012/12/06 19:23:14
Done.
|
| + return new _Uint8ClampedArrayView(array, start, length); |
| + } |
| +} |
| + |
| + |
| patch class Int16List { |
| /* patch */ factory Int16List(int length) { |
| return new _Int16Array(length); |
| @@ -445,7 +461,6 @@ |
| static _Int8Array _new(int length) native "Int8Array_new"; |
| static _Int8Array _newTransferable(int length) |
| native "Int8Array_newTransferable"; |
| - |
| int _getIndexed(int index) native "Int8Array_getIndexed"; |
| int _setIndexed(int index, int value) native "Int8Array_setIndexed"; |
| @@ -513,14 +528,90 @@ |
| static const int _BYTES_PER_ELEMENT = 1; |
| static _Uint8Array _new(int length) native "Uint8Array_new"; |
| - static _Uint8Array _newTransferable(int length) |
| + static _Uint8Array _newTransferable(int length) |
| native "Uint8Array_newTransferable"; |
| - |
| + |
| int _getIndexed(int index) native "Uint8Array_getIndexed"; |
| int _setIndexed(int index, int value) native "Uint8Array_setIndexed"; |
| } |
| + |
|
cshapiro
2012/12/05 23:01:49
extra vertical space?
srdjan
2012/12/06 19:23:14
Done.
|
| +class _Uint8ClampedArray extends _ByteArrayBase implements Uint8ClampedList { |
| + factory _Uint8ClampedArray(int length) { |
| + return _new(length); |
| + } |
| + |
| + factory _Uint8ClampedArray.transferable(int length) { |
| + return _newTransferable(length); |
| + } |
| + |
| + factory _Uint8ClampedArray.view(ByteArray array, |
| + [int start = 0, int length]) { |
| + if (length == null) { |
| + length = array.lengthInBytes(); |
| + } |
| + return new _Uint8ClampedArrayView(array, start, length); |
| + } |
| + |
| + int operator[](int index) { |
| + return _getIndexed(index); |
| + } |
| + |
| + int operator[]=(int index, int value) { |
| + if (value < 0) { |
| + value = 0; |
| + } else if (value > 0xFF) { |
| + value = 0xFF; |
| + } |
| + _setIndexed(index, _toUint8(value)); |
|
cshapiro
2012/12/05 23:01:49
Why not replace lines 562-566 with a new function
srdjan
2012/12/06 19:23:14
Done.
|
| + } |
| + |
| + Iterator<int> iterator() { |
| + return new _ByteArrayIterator<int>(this); |
| + } |
| + |
| + List<int> getRange(int start, int length) { |
| + _rangeCheck(this.length, start, length); |
| + List<int> result = _new(length); |
| + result.setRange(0, length, this, start); |
| + return result; |
| + } |
| + |
| + void setRange(int start, int length, List<int> from, [int startFrom = 0]) { |
| + if (from is _Uint8ClampedArray || from is _ExternalUint8ClampedArray) { |
|
cshapiro
2012/12/05 23:01:49
I think _Uint8Array and _ExternalUint8Array are va
srdjan
2012/12/06 19:23:14
We need to talk more about that.
|
| + _setRange(start * _BYTES_PER_ELEMENT, |
| + length * _BYTES_PER_ELEMENT, |
| + from, |
| + startFrom * _BYTES_PER_ELEMENT); |
| + } else { |
| + Arrays.copy(from, startFrom, this, start, length); |
| + } |
| + } |
| + |
| + String toString() { |
| + return Collections.collectionToString(this); |
| + } |
| + |
| + int bytesPerElement() { |
| + return _BYTES_PER_ELEMENT; |
| + } |
| + |
| + int lengthInBytes() { |
| + return _length() * _BYTES_PER_ELEMENT; |
| + } |
| + |
| + static const int _BYTES_PER_ELEMENT = 1; |
| + |
| + static _Uint8ClampedArray _new(int length) native "Uint8ClampedArray_new"; |
| + static _Uint8ClampedArray _newTransferable(int length) |
| + native "Uint8ClampedArray_newTransferable"; |
| + |
| + int _getIndexed(int index) native "Uint8ClampedArray_getIndexed"; |
| + int _setIndexed(int index, int value) native "Uint8ClampedArray_setIndexed"; |
| +} |
| + |
| + |
| class _Int16Array extends _ByteArrayBase implements Int16List { |
| factory _Int16Array(int length) { |
| return _new(length); |
| @@ -722,8 +813,8 @@ |
| static _Int32Array _new(int length) native "Int32Array_new"; |
| static _Int32Array _newTransferable(int length) |
| native "Int32Array_newTransferable"; |
| - |
| + |
| int _getIndexed(int index) native "Int32Array_getIndexed"; |
| int _setIndexed(int index, int value) native "Int32Array_setIndexed"; |
| } |