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 /// The Dart TypedData library. | 5 /// The Dart TypedData library. |
6 library dart.typed_data; | 6 library dart.typed_data; |
7 | 7 |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:_collection-dev'; | 9 import 'dart:_collection-dev'; |
10 import 'dart:_js_helper' show Creates, JavaScriptIndexingBehavior, JSName, Null, Returns; | 10 import 'dart:_js_helper' show Creates, JavaScriptIndexingBehavior, JSName, Null, Returns; |
11 import 'dart:_foreign_helper' show JS; | 11 import 'dart:_foreign_helper' show JS; |
12 | 12 |
13 // TODO(10691): migrate to ListMixin. | |
14 class _Lists { | |
15 | |
16 /** | |
17 * Returns the index in the array [a] of the given [element], starting | |
18 * the search at index [startIndex] to [endIndex] (exclusive). | |
19 * Returns -1 if [element] is not found. | |
20 */ | |
21 static int indexOf(List a, | |
22 Object element, | |
23 int startIndex, | |
24 int endIndex) { | |
25 if (startIndex >= a.length) { | |
26 return -1; | |
27 } | |
28 if (startIndex < 0) { | |
29 startIndex = 0; | |
30 } | |
31 for (int i = startIndex; i < endIndex; i++) { | |
32 if (a[i] == element) { | |
33 return i; | |
34 } | |
35 } | |
36 return -1; | |
37 } | |
38 | |
39 /** | |
40 * Returns the last index in the array [a] of the given [element], starting | |
41 * the search at index [startIndex] to 0. | |
42 * Returns -1 if [element] is not found. | |
43 */ | |
44 static int lastIndexOf(List a, Object element, int startIndex) { | |
45 if (startIndex < 0) { | |
46 return -1; | |
47 } | |
48 if (startIndex >= a.length) { | |
49 startIndex = a.length - 1; | |
50 } | |
51 for (int i = startIndex; i >= 0; i--) { | |
52 if (a[i] == element) { | |
53 return i; | |
54 } | |
55 } | |
56 return -1; | |
57 } | |
58 | |
59 /** | |
60 * Returns a sub list copy of this list, from [start] to | |
61 * [end] ([end] not inclusive). | |
62 * Returns an empty list if [length] is 0. | |
63 * It is an error if indices are not valid for the list, or | |
64 * if [end] is before [start]. | |
65 */ | |
66 static List getRange(List a, int start, int end, List accumulator) { | |
67 if (start < 0) throw new RangeError.value(start); | |
68 if (end < start) throw new RangeError.value(end); | |
69 if (end > a.length) throw new RangeError.value(end); | |
70 for (int i = start; i < end; i++) { | |
71 accumulator.add(a[i]); | |
72 } | |
73 return accumulator; | |
74 } | |
75 } | |
76 /** | 13 /** |
77 * Describes endianness to be used when accessing a sequence of bytes. | 14 * Describes endianness to be used when accessing a sequence of bytes. |
78 */ | 15 */ |
79 class Endianness { | 16 class Endianness { |
80 const Endianness(this._littleEndian); | 17 const Endianness(this._littleEndian); |
81 | 18 |
82 static const Endianness BIG_ENDIAN = const Endianness(false); | 19 static const Endianness BIG_ENDIAN = const Endianness(false); |
83 static const Endianness LITTLE_ENDIAN = const Endianness(true); | 20 static const Endianness LITTLE_ENDIAN = const Endianness(true); |
84 static final Endianness HOST_ENDIAN = | 21 static final Endianness HOST_ENDIAN = |
85 (new ByteData.view(new Int16List.fromList([1]).buffer)).getInt8(0) == 1 ? | 22 (new ByteData.view(new Int16List.fromList([1]).buffer)).getInt8(0) == 1 ? |
86 LITTLE_ENDIAN : BIG_ENDIAN; | 23 LITTLE_ENDIAN : BIG_ENDIAN; |
87 | 24 |
88 final bool _littleEndian; | 25 final bool _littleEndian; |
89 } | 26 } |
90 | 27 |
28 | |
91 class ByteBuffer native "ArrayBuffer" { | 29 class ByteBuffer native "ArrayBuffer" { |
92 @JSName('byteLength') | 30 @JSName('byteLength') |
93 final int lengthInBytes; | 31 final int lengthInBytes; |
94 } | 32 } |
95 | 33 |
34 | |
96 class TypedData native "ArrayBufferView" { | 35 class TypedData native "ArrayBufferView" { |
97 @Creates('ByteBuffer') | 36 @Creates('ByteBuffer') |
98 @Returns('ByteBuffer|Null') | 37 @Returns('ByteBuffer|Null') |
99 final ByteBuffer buffer; | 38 final ByteBuffer buffer; |
100 | 39 |
101 @JSName('byteLength') | 40 @JSName('byteLength') |
102 final int lengthInBytes; | 41 final int lengthInBytes; |
103 | 42 |
104 @JSName('byteOffset') | 43 @JSName('byteOffset') |
105 final int offsetInBytes; | 44 final int offsetInBytes; |
106 | 45 |
107 @JSName('BYTES_PER_ELEMENT') | 46 @JSName('BYTES_PER_ELEMENT') |
108 final int elementSizeInBytes; | 47 final int elementSizeInBytes; |
109 | 48 |
110 void _invalidIndex(int index, int length) { | 49 void _invalidIndex(int index, int length) { |
111 if (index < 0 || index >= length) { | 50 if (index < 0 || index >= length) { |
112 throw new RangeError.range(index, 0, length); | 51 throw new RangeError.range(index, 0, length); |
113 } else { | 52 } else { |
114 throw new ArgumentError('Invalid list index $index'); | 53 throw new ArgumentError('Invalid list index $index'); |
115 } | 54 } |
116 } | 55 } |
117 | 56 |
118 void _checkBounds(int index, int length) { | 57 void _checkIndex(int index, int length) { |
119 if (JS('bool', '(# >>> 0 != #)', index, index) || index >= length) { | 58 if (JS('bool', '(# >>> 0 != #)', index, index) || index >= length) { |
120 _invalidIndex(index, length); | 59 _invalidIndex(index, length); |
121 } | 60 } |
122 } | 61 } |
62 | |
63 int _checkSublistArguments(int start, int end, int length) { | |
64 _checkIndex(start, length); | |
65 if (end == null) return length; | |
66 _checkIndex(end, length); | |
67 if (start > end) throw new RangeError.value(end); | |
68 return end; | |
69 } | |
123 } | 70 } |
124 | 71 |
72 | |
73 // Ensures that [list] is a JavaScript Array or a typed array. If necessary, | |
74 // returns a copy of the list. | |
75 List _ensureNativeList(List list) { | |
76 return list; // TODO: make sure. | |
floitsch
2013/07/02 18:52:15
TODOs should either have an issue number or an own
| |
77 } | |
78 | |
79 | |
125 class ByteData extends TypedData native "DataView" { | 80 class ByteData extends TypedData native "DataView" { |
126 factory ByteData(int length) => | 81 factory ByteData(int length) => _create(length); |
floitsch
2013/07/02 18:52:15
_create1 ?
| |
127 _TypedArrayFactoryProvider.createByteData(length); | |
128 | 82 |
129 factory ByteData.view(ByteBuffer buffer, [int byteOffset, int byteLength]) => | 83 factory ByteData.view(ByteBuffer buffer, |
130 _TypedArrayFactoryProvider.createByteData_fromBuffer( | 84 [int byteOffset = 0, int byteLength]) => |
131 buffer, byteOffset, byteLength); | 85 byteLength == null |
86 ? _create2(buffer, byteOffset) | |
87 : _create3(buffer, byteOffset, byteLength); | |
132 | 88 |
133 num getFloat32(int byteOffset, [Endianness endian=Endianness.BIG_ENDIAN]) => | 89 num getFloat32(int byteOffset, [Endianness endian=Endianness.BIG_ENDIAN]) => |
134 _getFloat32(byteOffset, endian._littleEndian); | 90 _getFloat32(byteOffset, endian._littleEndian); |
135 | 91 |
136 @JSName('getFloat32') | 92 @JSName('getFloat32') |
137 @Returns('num') | 93 @Returns('num') |
138 num _getFloat32(int byteOffset, [bool littleEndian]) native; | 94 num _getFloat32(int byteOffset, [bool littleEndian]) native; |
139 | 95 |
140 num getFloat64(int byteOffset, [Endianness endian=Endianness.BIG_ENDIAN]) => | 96 num getFloat64(int byteOffset, [Endianness endian=Endianness.BIG_ENDIAN]) => |
141 _getFloat64(byteOffset, endian._littleEndian); | 97 _getFloat64(byteOffset, endian._littleEndian); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 _setUint32(byteOffset, value, endian._littleEndian); | 180 _setUint32(byteOffset, value, endian._littleEndian); |
225 | 181 |
226 @JSName('setUint32') | 182 @JSName('setUint32') |
227 void _setUint32(int byteOffset, int value, [bool littleEndian]) native; | 183 void _setUint32(int byteOffset, int value, [bool littleEndian]) native; |
228 | 184 |
229 void setUint64(int byteOffset, int value, [Endianness endian=Endianness.BIG_EN DIAN]) { | 185 void setUint64(int byteOffset, int value, [Endianness endian=Endianness.BIG_EN DIAN]) { |
230 throw new UnsupportedError("Uint64 accessor not supported by dart2js."); | 186 throw new UnsupportedError("Uint64 accessor not supported by dart2js."); |
231 } | 187 } |
232 | 188 |
233 void setUint8(int byteOffset, int value) native; | 189 void setUint8(int byteOffset, int value) native; |
234 } | 190 |
235 | 191 static ByteData _create1(arg) => |
236 class Float32List extends TypedData implements JavaScriptIndexingBehavior, List< double> native "Float32Array" { | 192 JS('ByteData', 'new DataView(#)', arg); |
237 factory Float32List(int length) => | 193 |
238 _TypedArrayFactoryProvider.createFloat32List(length); | 194 static ByteData _create2(arg1, arg2) => |
195 JS('ByteData', 'new DataView(#, #)', arg1, arg2); | |
196 | |
197 static ByteData _create3(arg1, arg2, arg3) => | |
198 JS('ByteData', 'new DataView(#, #, #)', arg1, arg2, arg3); | |
199 } | |
200 | |
201 | |
202 class Float32List | |
203 extends TypedData with ListMixin<double>, FixedLengthListMixin<double> | |
204 implements JavaScriptIndexingBehavior, List<double> | |
205 native "Float32Array" { | |
206 factory Float32List(int length) => _create1(length); | |
239 | 207 |
240 factory Float32List.fromList(List<num> list) => | 208 factory Float32List.fromList(List<num> list) => |
241 _TypedArrayFactoryProvider.createFloat32List_fromList(list); | 209 _create1(_ensureNativeList(list)); |
242 | 210 |
243 factory Float32List.view(ByteBuffer buffer, [int byteOffset, int length]) => | 211 factory Float32List.view(ByteBuffer buffer, |
244 _TypedArrayFactoryProvider.createFloat32List_fromBuffer(buffer, byteOffset, length); | 212 [int byteOffset = 0, int length]) => |
213 length == null | |
214 ? _create2(buffer, byteOffset) | |
215 : _create3(buffer, byteOffset, length); | |
245 | 216 |
246 static const int BYTES_PER_ELEMENT = 4; | 217 static const int BYTES_PER_ELEMENT = 4; |
247 | 218 |
248 int get length => JS("int", "#.length", this); | 219 int get length => JS("int", "#.length", this); |
249 | 220 |
250 num operator[](int index) { | 221 num operator[](int index) { |
251 _checkBounds(index, length); | 222 _checkIndex(index, length); |
252 return JS("num", "#[#]", this, index); | 223 return JS("num", "#[#]", this, index); |
253 } | 224 } |
254 | 225 |
255 void operator[]=(int index, num value) { | 226 void operator[]=(int index, num value) { |
256 _checkBounds(index, length); | 227 _checkIndex(index, length); |
257 JS("void", "#[#] = #", this, index, value); | 228 JS("void", "#[#] = #", this, index, value); |
258 } | 229 } |
259 // -- start List<num> mixins. | 230 |
260 // num is the element type. | 231 List<double> sublist(int start, [int end]) { |
261 | 232 end = _checkSublistArguments(start, end, length); |
262 // From Iterable<num>: | 233 var source = JS('Float32List', '#.subarray(#, #)', this, start, end); |
263 | 234 return _create1(source); |
264 Iterator<num> get iterator { | 235 } |
265 // Note: NodeLists are not fixed size. And most probably length shouldn't | 236 |
266 // be cached in both iterator _and_ forEach method. For now caching it | 237 static Float32List _create1(arg) => |
267 // for consistency. | 238 JS('Float32List', 'new Float32Array(#)', arg); |
268 return new ListIterator<num>(this); | 239 |
269 } | 240 static Float32List _create2(arg1, arg2) => |
270 | 241 JS('Float32List', 'new Float32Array(#, #)', arg1, arg2); |
271 num reduce(num combine(num value, num element)) { | 242 |
272 return IterableMixinWorkaround.reduce(this, combine); | 243 static Float32List _create3(arg1, arg2, arg3) => |
273 } | 244 JS('Float32List', 'new Float32Array(#, #, #)', arg1, arg2, arg3); |
274 | 245 } |
275 dynamic fold(dynamic initialValue, | 246 |
276 dynamic combine(dynamic previousValue, num element)) { | 247 |
277 return IterableMixinWorkaround.fold(this, initialValue, combine); | 248 class Float64List |
278 } | 249 extends TypedData with ListMixin<double>, FixedLengthListMixin<double> |
279 | 250 implements JavaScriptIndexingBehavior, List<double> |
280 bool contains(num element) => IterableMixinWorkaround.contains(this, element); | 251 native "Float64Array" { |
281 | 252 factory Float64List(int length) => _create1(length); |
282 void forEach(void f(num element)) => IterableMixinWorkaround.forEach(this, f); | |
283 | |
284 String join([String separator = ""]) => | |
285 IterableMixinWorkaround.joinList(this, separator); | |
286 | |
287 Iterable map(f(num element)) => | |
288 IterableMixinWorkaround.mapList(this, f); | |
289 | |
290 Iterable<num> where(bool f(num element)) => | |
291 IterableMixinWorkaround.where(this, f); | |
292 | |
293 Iterable expand(Iterable f(num element)) => | |
294 IterableMixinWorkaround.expand(this, f); | |
295 | |
296 bool every(bool f(num element)) => IterableMixinWorkaround.every(this, f); | |
297 | |
298 bool any(bool f(num element)) => IterableMixinWorkaround.any(this, f); | |
299 | |
300 List<num> toList({ bool growable: true }) => | |
301 new List<num>.from(this, growable: growable); | |
302 | |
303 Set<num> toSet() => new Set<num>.from(this); | |
304 | |
305 bool get isEmpty => this.length == 0; | |
306 | |
307 bool get isNotEmpty => !isEmpty; | |
308 | |
309 Iterable<num> take(int n) => IterableMixinWorkaround.takeList(this, n); | |
310 | |
311 Iterable<num> takeWhile(bool test(num value)) { | |
312 return IterableMixinWorkaround.takeWhile(this, test); | |
313 } | |
314 | |
315 Iterable<num> skip(int n) => IterableMixinWorkaround.skipList(this, n); | |
316 | |
317 Iterable<num> skipWhile(bool test(num value)) { | |
318 return IterableMixinWorkaround.skipWhile(this, test); | |
319 } | |
320 | |
321 dynamic firstWhere(bool test(num value), { Object orElse() }) { | |
322 return IterableMixinWorkaround.firstWhere(this, test, orElse); | |
323 } | |
324 | |
325 dynamic lastWhere(bool test(num value), { Object orElse() }) { | |
326 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | |
327 } | |
328 | |
329 num singleWhere(bool test(num value)) { | |
330 return IterableMixinWorkaround.singleWhere(this, test); | |
331 } | |
332 | |
333 num elementAt(int index) { | |
334 return this[index]; | |
335 } | |
336 | |
337 // From Collection<num>: | |
338 | |
339 void add(num value) { | |
340 throw new UnsupportedError("Cannot add to immutable List."); | |
341 } | |
342 | |
343 void addAll(Iterable<num> iterable) { | |
344 throw new UnsupportedError("Cannot add to immutable List."); | |
345 } | |
346 | |
347 // From List<num>: | |
348 void set length(int value) { | |
349 throw new UnsupportedError("Cannot resize immutable List."); | |
350 } | |
351 | |
352 void clear() { | |
353 throw new UnsupportedError("Cannot clear immutable List."); | |
354 } | |
355 | |
356 Iterable<num> get reversed { | |
357 return IterableMixinWorkaround.reversedList(this); | |
358 } | |
359 | |
360 void sort([int compare(num a, num b)]) { | |
361 throw new UnsupportedError("Cannot sort immutable List."); | |
362 } | |
363 | |
364 int indexOf(num element, [int start = 0]) => | |
365 _Lists.indexOf(this, element, start, this.length); | |
366 | |
367 int lastIndexOf(num element, [int start]) { | |
368 if (start == null) start = length - 1; | |
369 return _Lists.lastIndexOf(this, element, start); | |
370 } | |
371 | |
372 num get first { | |
373 if (this.length > 0) return this[0]; | |
374 throw new StateError("No elements"); | |
375 } | |
376 | |
377 num get last { | |
378 if (this.length > 0) return this[this.length - 1]; | |
379 throw new StateError("No elements"); | |
380 } | |
381 | |
382 num get single { | |
383 if (length == 1) return this[0]; | |
384 if (length == 0) throw new StateError("No elements"); | |
385 throw new StateError("More than one element"); | |
386 } | |
387 | |
388 void insert(int index, num element) { | |
389 throw new UnsupportedError("Cannot add to immutable List."); | |
390 } | |
391 | |
392 void insertAll(int index, Iterable<num> iterable) { | |
393 throw new UnsupportedError("Cannot add to immutable List."); | |
394 } | |
395 | |
396 void setAll(int index, Iterable<num> iterable) { | |
397 throw new UnsupportedError("Cannot modify an immutable List."); | |
398 } | |
399 | |
400 num removeAt(int pos) { | |
401 throw new UnsupportedError("Cannot remove from immutable List."); | |
402 } | |
403 | |
404 num removeLast() { | |
405 throw new UnsupportedError("Cannot remove from immutable List."); | |
406 } | |
407 | |
408 void remove(Object object) { | |
409 throw new UnsupportedError("Cannot remove from immutable List."); | |
410 } | |
411 | |
412 void removeWhere(bool test(num element)) { | |
413 throw new UnsupportedError("Cannot remove from immutable List."); | |
414 } | |
415 | |
416 void retainWhere(bool test(num element)) { | |
417 throw new UnsupportedError("Cannot remove from immutable List."); | |
418 } | |
419 | |
420 void setRange(int start, int end, Iterable<num> iterable, [int skipCount=0]) { | |
421 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); | |
422 } | |
423 | |
424 void removeRange(int start, int end) { | |
425 throw new UnsupportedError("Cannot removeRange on immutable List."); | |
426 } | |
427 | |
428 void replaceRange(int start, int end, Iterable<num> iterable) { | |
429 throw new UnsupportedError("Cannot modify an immutable List."); | |
430 } | |
431 | |
432 void fillRange(int start, int end, [num fillValue]) { | |
433 throw new UnsupportedError("Cannot modify an immutable List."); | |
434 } | |
435 | |
436 Iterable<num> getRange(int start, int end) => | |
437 IterableMixinWorkaround.getRangeList(this, start, end); | |
438 | |
439 List<num> sublist(int start, [int end]) { | |
440 if (end == null) end = length; | |
441 return _Lists.getRange(this, start, end, <num>[]); | |
442 } | |
443 | |
444 Map<int, num> asMap() => | |
445 IterableMixinWorkaround.asMapList(this); | |
446 | |
447 String toString() { | |
448 StringBuffer buffer = new StringBuffer('['); | |
449 buffer.writeAll(this, ', '); | |
450 buffer.write(']'); | |
451 return buffer.toString(); | |
452 } | |
453 | |
454 // -- end List<num> mixins. | |
455 } | |
456 | |
457 class Float64List extends TypedData implements JavaScriptIndexingBehavior, List< double> native "Float64Array" { | |
458 | |
459 factory Float64List(int length) => | |
460 _TypedArrayFactoryProvider.createFloat64List(length); | |
461 | 253 |
462 factory Float64List.fromList(List<num> list) => | 254 factory Float64List.fromList(List<num> list) => |
463 _TypedArrayFactoryProvider.createFloat64List_fromList(list); | 255 _create1(_ensureNativeList(list)); |
464 | 256 |
465 factory Float64List.view(ByteBuffer buffer, [int byteOffset, int length]) => | 257 factory Float64List.view(ByteBuffer buffer, |
466 _TypedArrayFactoryProvider.createFloat64List_fromBuffer(buffer, byteOffset, length); | 258 [int byteOffset = 0, int length]) => |
259 length == null | |
260 ? _create2(buffer, byteOffset) | |
261 : _create3(buffer, byteOffset, length); | |
467 | 262 |
468 static const int BYTES_PER_ELEMENT = 8; | 263 static const int BYTES_PER_ELEMENT = 8; |
469 | 264 |
470 int get length => JS("int", "#.length", this); | 265 int get length => JS("int", "#.length", this); |
471 | 266 |
472 num operator[](int index) { | 267 num operator[](int index) { |
473 _checkBounds(index, length); | 268 _checkIndex(index, length); |
474 return JS("num", "#[#]", this, index); | 269 return JS("num", "#[#]", this, index); |
475 } | 270 } |
476 | 271 |
477 void operator[]=(int index, num value) { | 272 void operator[]=(int index, num value) { |
478 _checkBounds(index, length); | 273 _checkIndex(index, length); |
479 JS("void", "#[#] = #", this, index, value); | 274 JS("void", "#[#] = #", this, index, value); |
480 } | 275 } |
481 // -- start List<num> mixins. | 276 |
482 // num is the element type. | 277 List<double> sublist(int start, [int end]) { |
483 | 278 end = _checkSublistArguments(start, end, length); |
484 // From Iterable<num>: | 279 var source = JS('Float64List', '#.subarray(#, #)', this, start, end); |
485 | 280 return _create1(source); |
486 Iterator<num> get iterator { | 281 } |
487 // Note: NodeLists are not fixed size. And most probably length shouldn't | 282 |
488 // be cached in both iterator _and_ forEach method. For now caching it | 283 static Float64List _create1(arg) => |
489 // for consistency. | 284 JS('Float64List', 'new Float64Array(#)', arg); |
490 return new ListIterator<num>(this); | 285 |
491 } | 286 static Float64List _create2(arg1, arg2) => |
492 | 287 JS('Float64List', 'new Float64Array(#, #)', arg1, arg2); |
493 num reduce(num combine(num value, num element)) { | 288 |
494 return IterableMixinWorkaround.reduce(this, combine); | 289 static Float64List _create3(arg1, arg2, arg3) => |
495 } | 290 JS('Float64List', 'new Float64Array(#, #, #)', arg1, arg2, arg3); |
496 | 291 } |
497 dynamic fold(dynamic initialValue, | 292 |
498 dynamic combine(dynamic previousValue, num element)) { | 293 |
499 return IterableMixinWorkaround.fold(this, initialValue, combine); | 294 class Int16List |
500 } | 295 extends TypedData with ListMixin<int>, FixedLengthListMixin<int> |
501 | 296 implements JavaScriptIndexingBehavior, List<int> |
502 bool contains(num element) => IterableMixinWorkaround.contains(this, element); | 297 native "Int16Array" { |
503 | 298 factory Int16List(int length) => _create1(length); |
504 void forEach(void f(num element)) => IterableMixinWorkaround.forEach(this, f); | 299 |
505 | 300 factory Int16List.fromList(List<num> list) => |
506 String join([String separator = ""]) => | 301 _create1(_ensureNativeList(list)); |
507 IterableMixinWorkaround.joinList(this, separator); | 302 |
508 | 303 factory Int16List.view(ByteBuffer buffer, [int byteOffset = 0, int length]) => |
509 Iterable map(f(num element)) => | 304 length == null |
510 IterableMixinWorkaround.mapList(this, f); | 305 ? _create2(buffer, byteOffset) |
511 | 306 : _create3(buffer, byteOffset, length); |
512 Iterable<num> where(bool f(num element)) => | |
513 IterableMixinWorkaround.where(this, f); | |
514 | |
515 Iterable expand(Iterable f(num element)) => | |
516 IterableMixinWorkaround.expand(this, f); | |
517 | |
518 bool every(bool f(num element)) => IterableMixinWorkaround.every(this, f); | |
519 | |
520 bool any(bool f(num element)) => IterableMixinWorkaround.any(this, f); | |
521 | |
522 List<num> toList({ bool growable: true }) => | |
523 new List<num>.from(this, growable: growable); | |
524 | |
525 Set<num> toSet() => new Set<num>.from(this); | |
526 | |
527 bool get isEmpty => this.length == 0; | |
528 | |
529 bool get isNotEmpty => !isEmpty; | |
530 | |
531 Iterable<num> take(int n) => IterableMixinWorkaround.takeList(this, n); | |
532 | |
533 Iterable<num> takeWhile(bool test(num value)) { | |
534 return IterableMixinWorkaround.takeWhile(this, test); | |
535 } | |
536 | |
537 Iterable<num> skip(int n) => IterableMixinWorkaround.skipList(this, n); | |
538 | |
539 Iterable<num> skipWhile(bool test(num value)) { | |
540 return IterableMixinWorkaround.skipWhile(this, test); | |
541 } | |
542 | |
543 dynamic firstWhere(bool test(num value), { Object orElse() }) { | |
544 return IterableMixinWorkaround.firstWhere(this, test, orElse); | |
545 } | |
546 | |
547 dynamic lastWhere(bool test(num value), { Object orElse() }) { | |
548 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | |
549 } | |
550 | |
551 num singleWhere(bool test(num value)) { | |
552 return IterableMixinWorkaround.singleWhere(this, test); | |
553 } | |
554 | |
555 num elementAt(int index) { | |
556 return this[index]; | |
557 } | |
558 | |
559 // From Collection<num>: | |
560 | |
561 void add(num value) { | |
562 throw new UnsupportedError("Cannot add to immutable List."); | |
563 } | |
564 | |
565 void addAll(Iterable<num> iterable) { | |
566 throw new UnsupportedError("Cannot add to immutable List."); | |
567 } | |
568 | |
569 // From List<num>: | |
570 void set length(int value) { | |
571 throw new UnsupportedError("Cannot resize immutable List."); | |
572 } | |
573 | |
574 void clear() { | |
575 throw new UnsupportedError("Cannot clear immutable List."); | |
576 } | |
577 | |
578 Iterable<num> get reversed { | |
579 return IterableMixinWorkaround.reversedList(this); | |
580 } | |
581 | |
582 void sort([int compare(num a, num b)]) { | |
583 throw new UnsupportedError("Cannot sort immutable List."); | |
584 } | |
585 | |
586 int indexOf(num element, [int start = 0]) => | |
587 _Lists.indexOf(this, element, start, this.length); | |
588 | |
589 int lastIndexOf(num element, [int start]) { | |
590 if (start == null) start = length - 1; | |
591 return _Lists.lastIndexOf(this, element, start); | |
592 } | |
593 | |
594 num get first { | |
595 if (this.length > 0) return this[0]; | |
596 throw new StateError("No elements"); | |
597 } | |
598 | |
599 num get last { | |
600 if (this.length > 0) return this[this.length - 1]; | |
601 throw new StateError("No elements"); | |
602 } | |
603 | |
604 num get single { | |
605 if (length == 1) return this[0]; | |
606 if (length == 0) throw new StateError("No elements"); | |
607 throw new StateError("More than one element"); | |
608 } | |
609 | |
610 void insert(int index, num element) { | |
611 throw new UnsupportedError("Cannot add to immutable List."); | |
612 } | |
613 | |
614 void insertAll(int index, Iterable<num> iterable) { | |
615 throw new UnsupportedError("Cannot add to immutable List."); | |
616 } | |
617 | |
618 void setAll(int index, Iterable<num> iterable) { | |
619 throw new UnsupportedError("Cannot modify an immutable List."); | |
620 } | |
621 | |
622 num removeAt(int pos) { | |
623 throw new UnsupportedError("Cannot remove from immutable List."); | |
624 } | |
625 | |
626 num removeLast() { | |
627 throw new UnsupportedError("Cannot remove from immutable List."); | |
628 } | |
629 | |
630 void remove(Object object) { | |
631 throw new UnsupportedError("Cannot remove from immutable List."); | |
632 } | |
633 | |
634 void removeWhere(bool test(num element)) { | |
635 throw new UnsupportedError("Cannot remove from immutable List."); | |
636 } | |
637 | |
638 void retainWhere(bool test(num element)) { | |
639 throw new UnsupportedError("Cannot remove from immutable List."); | |
640 } | |
641 | |
642 void setRange(int start, int end, Iterable<num> iterable, [int skipCount=0]) { | |
643 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); | |
644 } | |
645 | |
646 void removeRange(int start, int end) { | |
647 throw new UnsupportedError("Cannot removeRange on immutable List."); | |
648 } | |
649 | |
650 void replaceRange(int start, int end, Iterable<num> iterable) { | |
651 throw new UnsupportedError("Cannot modify an immutable List."); | |
652 } | |
653 | |
654 void fillRange(int start, int end, [num fillValue]) { | |
655 throw new UnsupportedError("Cannot modify an immutable List."); | |
656 } | |
657 | |
658 Iterable<num> getRange(int start, int end) => | |
659 IterableMixinWorkaround.getRangeList(this, start, end); | |
660 | |
661 List<num> sublist(int start, [int end]) { | |
662 if (end == null) end = length; | |
663 return _Lists.getRange(this, start, end, <num>[]); | |
664 } | |
665 | |
666 Map<int, num> asMap() => | |
667 IterableMixinWorkaround.asMapList(this); | |
668 | |
669 String toString() { | |
670 StringBuffer buffer = new StringBuffer('['); | |
671 buffer.writeAll(this, ', '); | |
672 buffer.write(']'); | |
673 return buffer.toString(); | |
674 } | |
675 | |
676 // -- end List<num> mixins. | |
677 } | |
678 | |
679 class Int16List extends TypedData implements JavaScriptIndexingBehavior, List<in t> native "Int16Array" { | |
680 | |
681 factory Int16List(int length) => | |
682 _TypedArrayFactoryProvider.createInt16List(length); | |
683 | |
684 factory Int16List.fromList(List<int> list) => | |
685 _TypedArrayFactoryProvider.createInt16List_fromList(list); | |
686 | |
687 factory Int16List.view(ByteBuffer buffer, [int byteOffset, int length]) => | |
688 _TypedArrayFactoryProvider.createInt16List_fromBuffer(buffer, byteOffset, le ngth); | |
689 | 307 |
690 static const int BYTES_PER_ELEMENT = 2; | 308 static const int BYTES_PER_ELEMENT = 2; |
691 | 309 |
692 int get length => JS("int", "#.length", this); | 310 int get length => JS("int", "#.length", this); |
693 | 311 |
694 int operator[](int index) { | 312 num operator[](int index) { |
695 _checkBounds(index, length); | 313 _checkIndex(index, length); |
696 return JS("int", "#[#]", this, index); | 314 return JS("num", "#[#]", this, index); |
697 } | 315 } |
698 | 316 |
699 void operator[]=(int index, int value) { | 317 void operator[]=(int index, num value) { |
700 _checkBounds(index, length); | 318 _checkIndex(index, length); |
701 JS("void", "#[#] = #", this, index, value); | 319 JS("void", "#[#] = #", this, index, value); |
702 } | 320 } |
703 // -- start List<int> mixins. | 321 |
704 // int is the element type. | 322 List<int> sublist(int start, [int end]) { |
705 | 323 end = _checkSublistArguments(start, end, length); |
706 // From Iterable<int>: | 324 var source = JS('Int16List', '#.subarray(#, #)', this, start, end); |
707 | 325 return _create1(source); |
708 Iterator<int> get iterator { | 326 } |
709 // Note: NodeLists are not fixed size. And most probably length shouldn't | 327 |
710 // be cached in both iterator _and_ forEach method. For now caching it | 328 static Int16List _create1(arg) => |
711 // for consistency. | 329 JS('Int16List', 'new Int16Array(#)', arg); |
712 return new ListIterator<int>(this); | 330 |
713 } | 331 static Int16List _create2(arg1, arg2) => |
714 | 332 JS('Int16List', 'new Int16Array(#, #)', arg1, arg2); |
715 int reduce(int combine(int value, int element)) { | 333 |
716 return IterableMixinWorkaround.reduce(this, combine); | 334 static Int16List _create3(arg1, arg2, arg3) => |
717 } | 335 JS('Int16List', 'new Int16Array(#, #, #)', arg1, arg2, arg3); |
718 | 336 } |
719 dynamic fold(dynamic initialValue, | 337 |
720 dynamic combine(dynamic previousValue, int element)) { | 338 |
721 return IterableMixinWorkaround.fold(this, initialValue, combine); | 339 class Int32List |
722 } | 340 extends TypedData with ListMixin<int>, FixedLengthListMixin<int> |
723 | 341 implements JavaScriptIndexingBehavior, List<int> |
724 bool contains(int element) => IterableMixinWorkaround.contains(this, element); | 342 native "Int32Array" { |
725 | 343 factory Int32List(int length) => _create1(length); |
726 void forEach(void f(int element)) => IterableMixinWorkaround.forEach(this, f); | 344 |
727 | 345 factory Int32List.fromList(List<num> list) => |
728 String join([String separator = ""]) => | 346 _create1(_ensureNativeList(list)); |
729 IterableMixinWorkaround.joinList(this, separator); | 347 |
730 | 348 factory Int32List.view(ByteBuffer buffer, [int byteOffset = 0, int length]) => |
731 Iterable map(f(int element)) => | 349 length == null |
732 IterableMixinWorkaround.mapList(this, f); | 350 ? _create2(buffer, byteOffset) |
733 | 351 : _create3(buffer, byteOffset, length); |
734 Iterable<int> where(bool f(int element)) => | |
735 IterableMixinWorkaround.where(this, f); | |
736 | |
737 Iterable expand(Iterable f(int element)) => | |
738 IterableMixinWorkaround.expand(this, f); | |
739 | |
740 bool every(bool f(int element)) => IterableMixinWorkaround.every(this, f); | |
741 | |
742 bool any(bool f(int element)) => IterableMixinWorkaround.any(this, f); | |
743 | |
744 List<int> toList({ bool growable: true }) => | |
745 new List<int>.from(this, growable: growable); | |
746 | |
747 Set<int> toSet() => new Set<int>.from(this); | |
748 | |
749 bool get isEmpty => this.length == 0; | |
750 | |
751 bool get isNotEmpty => !isEmpty; | |
752 | |
753 Iterable<int> take(int n) => IterableMixinWorkaround.takeList(this, n); | |
754 | |
755 Iterable<int> takeWhile(bool test(int value)) { | |
756 return IterableMixinWorkaround.takeWhile(this, test); | |
757 } | |
758 | |
759 Iterable<int> skip(int n) => IterableMixinWorkaround.skipList(this, n); | |
760 | |
761 Iterable<int> skipWhile(bool test(int value)) { | |
762 return IterableMixinWorkaround.skipWhile(this, test); | |
763 } | |
764 | |
765 dynamic firstWhere(bool test(int value), { Object orElse() }) { | |
766 return IterableMixinWorkaround.firstWhere(this, test, orElse); | |
767 } | |
768 | |
769 dynamic lastWhere(bool test(int value), { Object orElse() }) { | |
770 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | |
771 } | |
772 | |
773 int singleWhere(bool test(int value)) { | |
774 return IterableMixinWorkaround.singleWhere(this, test); | |
775 } | |
776 | |
777 int elementAt(int index) { | |
778 return this[index]; | |
779 } | |
780 | |
781 // From Collection<int>: | |
782 | |
783 void add(int value) { | |
784 throw new UnsupportedError("Cannot add to immutable List."); | |
785 } | |
786 | |
787 void addAll(Iterable<int> iterable) { | |
788 throw new UnsupportedError("Cannot add to immutable List."); | |
789 } | |
790 | |
791 // From List<int>: | |
792 void set length(int value) { | |
793 throw new UnsupportedError("Cannot resize immutable List."); | |
794 } | |
795 | |
796 void clear() { | |
797 throw new UnsupportedError("Cannot clear immutable List."); | |
798 } | |
799 | |
800 Iterable<int> get reversed { | |
801 return IterableMixinWorkaround.reversedList(this); | |
802 } | |
803 | |
804 void sort([int compare(int a, int b)]) { | |
805 throw new UnsupportedError("Cannot sort immutable List."); | |
806 } | |
807 | |
808 int indexOf(int element, [int start = 0]) => | |
809 _Lists.indexOf(this, element, start, this.length); | |
810 | |
811 int lastIndexOf(int element, [int start]) { | |
812 if (start == null) start = length - 1; | |
813 return _Lists.lastIndexOf(this, element, start); | |
814 } | |
815 | |
816 int get first { | |
817 if (this.length > 0) return this[0]; | |
818 throw new StateError("No elements"); | |
819 } | |
820 | |
821 int get last { | |
822 if (this.length > 0) return this[this.length - 1]; | |
823 throw new StateError("No elements"); | |
824 } | |
825 | |
826 int get single { | |
827 if (length == 1) return this[0]; | |
828 if (length == 0) throw new StateError("No elements"); | |
829 throw new StateError("More than one element"); | |
830 } | |
831 | |
832 void insert(int index, int element) { | |
833 throw new UnsupportedError("Cannot add to immutable List."); | |
834 } | |
835 | |
836 void insertAll(int index, Iterable<int> iterable) { | |
837 throw new UnsupportedError("Cannot add to immutable List."); | |
838 } | |
839 | |
840 void setAll(int index, Iterable<int> iterable) { | |
841 throw new UnsupportedError("Cannot modify an immutable List."); | |
842 } | |
843 | |
844 int removeAt(int pos) { | |
845 throw new UnsupportedError("Cannot remove from immutable List."); | |
846 } | |
847 | |
848 int removeLast() { | |
849 throw new UnsupportedError("Cannot remove from immutable List."); | |
850 } | |
851 | |
852 void remove(Object object) { | |
853 throw new UnsupportedError("Cannot remove from immutable List."); | |
854 } | |
855 | |
856 void removeWhere(bool test(int element)) { | |
857 throw new UnsupportedError("Cannot remove from immutable List."); | |
858 } | |
859 | |
860 void retainWhere(bool test(int element)) { | |
861 throw new UnsupportedError("Cannot remove from immutable List."); | |
862 } | |
863 | |
864 void setRange(int start, int end, Iterable<int> iterable, [int skipCount=0]) { | |
865 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); | |
866 } | |
867 | |
868 void removeRange(int start, int end) { | |
869 throw new UnsupportedError("Cannot removeRange on immutable List."); | |
870 } | |
871 | |
872 void replaceRange(int start, int end, Iterable<int> iterable) { | |
873 throw new UnsupportedError("Cannot modify an immutable List."); | |
874 } | |
875 | |
876 void fillRange(int start, int end, [int fillValue]) { | |
877 throw new UnsupportedError("Cannot modify an immutable List."); | |
878 } | |
879 | |
880 Iterable<int> getRange(int start, int end) => | |
881 IterableMixinWorkaround.getRangeList(this, start, end); | |
882 | |
883 List<int> sublist(int start, [int end]) { | |
884 if (end == null) end = length; | |
885 return _Lists.getRange(this, start, end, <int>[]); | |
886 } | |
887 | |
888 Map<int, int> asMap() => | |
889 IterableMixinWorkaround.asMapList(this); | |
890 | |
891 String toString() { | |
892 StringBuffer buffer = new StringBuffer('['); | |
893 buffer.writeAll(this, ', '); | |
894 buffer.write(']'); | |
895 return buffer.toString(); | |
896 } | |
897 | |
898 // -- end List<int> mixins. | |
899 } | |
900 | |
901 class Int32List extends TypedData implements JavaScriptIndexingBehavior, List<in t> native "Int32Array" { | |
902 | |
903 factory Int32List(int length) => | |
904 _TypedArrayFactoryProvider.createInt32List(length); | |
905 | |
906 factory Int32List.fromList(List<int> list) => | |
907 _TypedArrayFactoryProvider.createInt32List_fromList(list); | |
908 | |
909 factory Int32List.view(ByteBuffer buffer, [int byteOffset, int length]) => | |
910 _TypedArrayFactoryProvider.createInt32List_fromBuffer(buffer, byteOffset, le ngth); | |
911 | 352 |
912 static const int BYTES_PER_ELEMENT = 4; | 353 static const int BYTES_PER_ELEMENT = 4; |
913 | 354 |
914 int get length => JS("int", "#.length", this); | 355 int get length => JS("int", "#.length", this); |
915 | 356 |
916 int operator[](int index) { | 357 num operator[](int index) { |
917 _checkBounds(index, length); | 358 _checkIndex(index, length); |
918 return JS("int", "#[#]", this, index); | 359 return JS("num", "#[#]", this, index); |
919 } | 360 } |
920 | 361 |
921 void operator[]=(int index, int value) { | 362 void operator[]=(int index, num value) { |
922 _checkBounds(index, length); | 363 _checkIndex(index, length); |
923 JS("void", "#[#] = #", this, index, value); | 364 JS("void", "#[#] = #", this, index, value); |
924 } | 365 } |
925 // -- start List<int> mixins. | 366 |
926 // int is the element type. | 367 List<int> sublist(int start, [int end]) { |
927 | 368 end = _checkSublistArguments(start, end, length); |
928 // From Iterable<int>: | 369 var source = JS('Int32List', '#.subarray(#, #)', this, start, end); |
929 | 370 return _create1(source); |
930 Iterator<int> get iterator { | 371 } |
931 // Note: NodeLists are not fixed size. And most probably length shouldn't | 372 |
932 // be cached in both iterator _and_ forEach method. For now caching it | 373 static Int32List _create1(arg) => |
933 // for consistency. | 374 JS('Int32List', 'new Int32Array(#)', arg); |
934 return new ListIterator<int>(this); | 375 |
935 } | 376 static Int32List _create2(arg1, arg2) => |
936 | 377 JS('Int32List', 'new Int32Array(#, #)', arg1, arg2); |
937 int reduce(int combine(int value, int element)) { | 378 |
938 return IterableMixinWorkaround.reduce(this, combine); | 379 static Int32List _create3(arg1, arg2, arg3) => |
939 } | 380 JS('Int32List', 'new Int32Array(#, #, #)', arg1, arg2, arg3); |
940 | 381 } |
941 dynamic fold(dynamic initialValue, | 382 |
942 dynamic combine(dynamic previousValue, int element)) { | 383 |
943 return IterableMixinWorkaround.fold(this, initialValue, combine); | 384 class Int8List |
944 } | 385 extends TypedData with ListMixin<int>, FixedLengthListMixin<int> |
945 | 386 implements JavaScriptIndexingBehavior, List<int> |
946 bool contains(int element) => IterableMixinWorkaround.contains(this, element); | 387 native "Int8Array" { |
947 | 388 factory Int8List(int length) => _create1(length); |
948 void forEach(void f(int element)) => IterableMixinWorkaround.forEach(this, f); | 389 |
949 | 390 factory Int8List.fromList(List<num> list) => |
950 String join([String separator = ""]) => | 391 _create1(_ensureNativeList(list)); |
951 IterableMixinWorkaround.joinList(this, separator); | 392 |
952 | 393 factory Int8List.view(ByteBuffer buffer, [int byteOffset = 0, int length]) => |
953 Iterable map(f(int element)) => | 394 length == null |
954 IterableMixinWorkaround.mapList(this, f); | 395 ? _create2(buffer, byteOffset) |
955 | 396 : _create3(buffer, byteOffset, length); |
956 Iterable<int> where(bool f(int element)) => | |
957 IterableMixinWorkaround.where(this, f); | |
958 | |
959 Iterable expand(Iterable f(int element)) => | |
960 IterableMixinWorkaround.expand(this, f); | |
961 | |
962 bool every(bool f(int element)) => IterableMixinWorkaround.every(this, f); | |
963 | |
964 bool any(bool f(int element)) => IterableMixinWorkaround.any(this, f); | |
965 | |
966 List<int> toList({ bool growable: true }) => | |
967 new List<int>.from(this, growable: growable); | |
968 | |
969 Set<int> toSet() => new Set<int>.from(this); | |
970 | |
971 bool get isEmpty => this.length == 0; | |
972 | |
973 bool get isNotEmpty => !isEmpty; | |
974 | |
975 Iterable<int> take(int n) => IterableMixinWorkaround.takeList(this, n); | |
976 | |
977 Iterable<int> takeWhile(bool test(int value)) { | |
978 return IterableMixinWorkaround.takeWhile(this, test); | |
979 } | |
980 | |
981 Iterable<int> skip(int n) => IterableMixinWorkaround.skipList(this, n); | |
982 | |
983 Iterable<int> skipWhile(bool test(int value)) { | |
984 return IterableMixinWorkaround.skipWhile(this, test); | |
985 } | |
986 | |
987 dynamic firstWhere(bool test(int value), { Object orElse() }) { | |
988 return IterableMixinWorkaround.firstWhere(this, test, orElse); | |
989 } | |
990 | |
991 dynamic lastWhere(bool test(int value), { Object orElse() }) { | |
992 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | |
993 } | |
994 | |
995 int singleWhere(bool test(int value)) { | |
996 return IterableMixinWorkaround.singleWhere(this, test); | |
997 } | |
998 | |
999 int elementAt(int index) { | |
1000 return this[index]; | |
1001 } | |
1002 | |
1003 // From Collection<int>: | |
1004 | |
1005 void add(int value) { | |
1006 throw new UnsupportedError("Cannot add to immutable List."); | |
1007 } | |
1008 | |
1009 void addAll(Iterable<int> iterable) { | |
1010 throw new UnsupportedError("Cannot add to immutable List."); | |
1011 } | |
1012 | |
1013 // From List<int>: | |
1014 void set length(int value) { | |
1015 throw new UnsupportedError("Cannot resize immutable List."); | |
1016 } | |
1017 | |
1018 void clear() { | |
1019 throw new UnsupportedError("Cannot clear immutable List."); | |
1020 } | |
1021 | |
1022 Iterable<int> get reversed { | |
1023 return IterableMixinWorkaround.reversedList(this); | |
1024 } | |
1025 | |
1026 void sort([int compare(int a, int b)]) { | |
1027 throw new UnsupportedError("Cannot sort immutable List."); | |
1028 } | |
1029 | |
1030 int indexOf(int element, [int start = 0]) => | |
1031 _Lists.indexOf(this, element, start, this.length); | |
1032 | |
1033 int lastIndexOf(int element, [int start]) { | |
1034 if (start == null) start = length - 1; | |
1035 return _Lists.lastIndexOf(this, element, start); | |
1036 } | |
1037 | |
1038 int get first { | |
1039 if (this.length > 0) return this[0]; | |
1040 throw new StateError("No elements"); | |
1041 } | |
1042 | |
1043 int get last { | |
1044 if (this.length > 0) return this[this.length - 1]; | |
1045 throw new StateError("No elements"); | |
1046 } | |
1047 | |
1048 int get single { | |
1049 if (length == 1) return this[0]; | |
1050 if (length == 0) throw new StateError("No elements"); | |
1051 throw new StateError("More than one element"); | |
1052 } | |
1053 | |
1054 void insert(int index, int element) { | |
1055 throw new UnsupportedError("Cannot add to immutable List."); | |
1056 } | |
1057 | |
1058 void insertAll(int index, Iterable<int> iterable) { | |
1059 throw new UnsupportedError("Cannot add to immutable List."); | |
1060 } | |
1061 | |
1062 void setAll(int index, Iterable<int> iterable) { | |
1063 throw new UnsupportedError("Cannot modify an immutable List."); | |
1064 } | |
1065 | |
1066 int removeAt(int pos) { | |
1067 throw new UnsupportedError("Cannot remove from immutable List."); | |
1068 } | |
1069 | |
1070 int removeLast() { | |
1071 throw new UnsupportedError("Cannot remove from immutable List."); | |
1072 } | |
1073 | |
1074 void remove(Object object) { | |
1075 throw new UnsupportedError("Cannot remove from immutable List."); | |
1076 } | |
1077 | |
1078 void removeWhere(bool test(int element)) { | |
1079 throw new UnsupportedError("Cannot remove from immutable List."); | |
1080 } | |
1081 | |
1082 void retainWhere(bool test(int element)) { | |
1083 throw new UnsupportedError("Cannot remove from immutable List."); | |
1084 } | |
1085 | |
1086 void setRange(int start, int end, Iterable<int> iterable, [int skipCount=0]) { | |
1087 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); | |
1088 } | |
1089 | |
1090 void removeRange(int start, int end) { | |
1091 throw new UnsupportedError("Cannot removeRange on immutable List."); | |
1092 } | |
1093 | |
1094 void replaceRange(int start, int end, Iterable<int> iterable) { | |
1095 throw new UnsupportedError("Cannot modify an immutable List."); | |
1096 } | |
1097 | |
1098 void fillRange(int start, int end, [int fillValue]) { | |
1099 throw new UnsupportedError("Cannot modify an immutable List."); | |
1100 } | |
1101 | |
1102 Iterable<int> getRange(int start, int end) => | |
1103 IterableMixinWorkaround.getRangeList(this, start, end); | |
1104 | |
1105 List<int> sublist(int start, [int end]) { | |
1106 if (end == null) end = length; | |
1107 return _Lists.getRange(this, start, end, <int>[]); | |
1108 } | |
1109 | |
1110 Map<int, int> asMap() => | |
1111 IterableMixinWorkaround.asMapList(this); | |
1112 | |
1113 String toString() { | |
1114 StringBuffer buffer = new StringBuffer('['); | |
1115 buffer.writeAll(this, ', '); | |
1116 buffer.write(']'); | |
1117 return buffer.toString(); | |
1118 } | |
1119 | |
1120 // -- end List<int> mixins. | |
1121 } | |
1122 | |
1123 class Int8List extends TypedData implements JavaScriptIndexingBehavior, List<int > native "Int8Array" { | |
1124 | |
1125 factory Int8List(int length) => | |
1126 _TypedArrayFactoryProvider.createInt8List(length); | |
1127 | |
1128 factory Int8List.fromList(List<int> list) => | |
1129 _TypedArrayFactoryProvider.createInt8List_fromList(list); | |
1130 | |
1131 factory Int8List.view(ByteBuffer buffer, [int byteOffset, int length]) => | |
1132 _TypedArrayFactoryProvider.createInt8List_fromBuffer(buffer, byteOffset, len gth); | |
1133 | 397 |
1134 static const int BYTES_PER_ELEMENT = 1; | 398 static const int BYTES_PER_ELEMENT = 1; |
1135 | 399 |
1136 int get length => JS("int", "#.length", this); | 400 int get length => JS("int", "#.length", this); |
1137 | 401 |
1138 int operator[](int index) { | 402 num operator[](int index) { |
1139 _checkBounds(index, length); | 403 _checkIndex(index, length); |
1140 return JS("int", "#[#]", this, index); | 404 return JS("num", "#[#]", this, index); |
1141 } | 405 } |
1142 | 406 |
1143 void operator[]=(int index, int value) { | 407 void operator[]=(int index, num value) { |
1144 _checkBounds(index, length); | 408 _checkIndex(index, length); |
1145 JS("void", "#[#] = #", this, index, value); | 409 JS("void", "#[#] = #", this, index, value); |
1146 } | 410 } |
1147 // -- start List<int> mixins. | 411 |
1148 // int is the element type. | 412 List<int> sublist(int start, [int end]) { |
1149 | 413 end = _checkSublistArguments(start, end, length); |
1150 // From Iterable<int>: | 414 var source = JS('Int8List', '#.subarray(#, #)', this, start, end); |
1151 | 415 return _create1(source); |
1152 Iterator<int> get iterator { | 416 } |
1153 // Note: NodeLists are not fixed size. And most probably length shouldn't | 417 |
1154 // be cached in both iterator _and_ forEach method. For now caching it | 418 static Int8List _create1(arg) => |
1155 // for consistency. | 419 JS('Int8List', 'new Int8Array(#)', arg); |
1156 return new ListIterator<int>(this); | 420 |
1157 } | 421 static Int8List _create2(arg1, arg2) => |
1158 | 422 JS('Int8List', 'new Int8Array(#, #)', arg1, arg2); |
1159 int reduce(int combine(int value, int element)) { | 423 |
1160 return IterableMixinWorkaround.reduce(this, combine); | 424 static Int8List _create3(arg1, arg2, arg3) => |
1161 } | 425 JS('Int8List', 'new Int8Array(#, #, #)', arg1, arg2, arg3); |
1162 | 426 } |
1163 dynamic fold(dynamic initialValue, | 427 |
1164 dynamic combine(dynamic previousValue, int element)) { | 428 |
1165 return IterableMixinWorkaround.fold(this, initialValue, combine); | 429 class Uint16List |
1166 } | 430 extends TypedData with ListMixin<int>, FixedLengthListMixin<int> |
1167 | 431 implements JavaScriptIndexingBehavior, List<int> |
1168 bool contains(int element) => IterableMixinWorkaround.contains(this, element); | 432 native "Uint16Array" { |
1169 | 433 factory Uint16List(int length) => _create1(length); |
1170 void forEach(void f(int element)) => IterableMixinWorkaround.forEach(this, f); | 434 |
1171 | 435 factory Uint16List.fromList(List<num> list) => |
1172 String join([String separator = ""]) => | 436 _create1(_ensureNativeList(list)); |
1173 IterableMixinWorkaround.joinList(this, separator); | 437 |
1174 | 438 factory Uint16List.view(ByteBuffer buffer, |
1175 Iterable map(f(int element)) => | 439 [int byteOffset = 0, int length]) => |
1176 IterableMixinWorkaround.mapList(this, f); | 440 length == null |
1177 | 441 ? _create2(buffer, byteOffset) |
1178 Iterable<int> where(bool f(int element)) => | 442 : _create3(buffer, byteOffset, length); |
1179 IterableMixinWorkaround.where(this, f); | |
1180 | |
1181 Iterable expand(Iterable f(int element)) => | |
1182 IterableMixinWorkaround.expand(this, f); | |
1183 | |
1184 bool every(bool f(int element)) => IterableMixinWorkaround.every(this, f); | |
1185 | |
1186 bool any(bool f(int element)) => IterableMixinWorkaround.any(this, f); | |
1187 | |
1188 List<int> toList({ bool growable: true }) => | |
1189 new List<int>.from(this, growable: growable); | |
1190 | |
1191 Set<int> toSet() => new Set<int>.from(this); | |
1192 | |
1193 bool get isEmpty => this.length == 0; | |
1194 | |
1195 bool get isNotEmpty => !isEmpty; | |
1196 | |
1197 Iterable<int> take(int n) => IterableMixinWorkaround.takeList(this, n); | |
1198 | |
1199 Iterable<int> takeWhile(bool test(int value)) { | |
1200 return IterableMixinWorkaround.takeWhile(this, test); | |
1201 } | |
1202 | |
1203 Iterable<int> skip(int n) => IterableMixinWorkaround.skipList(this, n); | |
1204 | |
1205 Iterable<int> skipWhile(bool test(int value)) { | |
1206 return IterableMixinWorkaround.skipWhile(this, test); | |
1207 } | |
1208 | |
1209 dynamic firstWhere(bool test(int value), { Object orElse() }) { | |
1210 return IterableMixinWorkaround.firstWhere(this, test, orElse); | |
1211 } | |
1212 | |
1213 dynamic lastWhere(bool test(int value), { Object orElse() }) { | |
1214 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | |
1215 } | |
1216 | |
1217 int singleWhere(bool test(int value)) { | |
1218 return IterableMixinWorkaround.singleWhere(this, test); | |
1219 } | |
1220 | |
1221 int elementAt(int index) { | |
1222 return this[index]; | |
1223 } | |
1224 | |
1225 // From Collection<int>: | |
1226 | |
1227 void add(int value) { | |
1228 throw new UnsupportedError("Cannot add to immutable List."); | |
1229 } | |
1230 | |
1231 void addAll(Iterable<int> iterable) { | |
1232 throw new UnsupportedError("Cannot add to immutable List."); | |
1233 } | |
1234 | |
1235 // From List<int>: | |
1236 void set length(int value) { | |
1237 throw new UnsupportedError("Cannot resize immutable List."); | |
1238 } | |
1239 | |
1240 void clear() { | |
1241 throw new UnsupportedError("Cannot clear immutable List."); | |
1242 } | |
1243 | |
1244 Iterable<int> get reversed { | |
1245 return IterableMixinWorkaround.reversedList(this); | |
1246 } | |
1247 | |
1248 void sort([int compare(int a, int b)]) { | |
1249 throw new UnsupportedError("Cannot sort immutable List."); | |
1250 } | |
1251 | |
1252 int indexOf(int element, [int start = 0]) => | |
1253 _Lists.indexOf(this, element, start, this.length); | |
1254 | |
1255 int lastIndexOf(int element, [int start]) { | |
1256 if (start == null) start = length - 1; | |
1257 return _Lists.lastIndexOf(this, element, start); | |
1258 } | |
1259 | |
1260 int get first { | |
1261 if (this.length > 0) return this[0]; | |
1262 throw new StateError("No elements"); | |
1263 } | |
1264 | |
1265 int get last { | |
1266 if (this.length > 0) return this[this.length - 1]; | |
1267 throw new StateError("No elements"); | |
1268 } | |
1269 | |
1270 int get single { | |
1271 if (length == 1) return this[0]; | |
1272 if (length == 0) throw new StateError("No elements"); | |
1273 throw new StateError("More than one element"); | |
1274 } | |
1275 | |
1276 void insert(int index, int element) { | |
1277 throw new UnsupportedError("Cannot add to immutable List."); | |
1278 } | |
1279 | |
1280 void insertAll(int index, Iterable<int> iterable) { | |
1281 throw new UnsupportedError("Cannot add to immutable List."); | |
1282 } | |
1283 | |
1284 void setAll(int index, Iterable<int> iterable) { | |
1285 throw new UnsupportedError("Cannot modify an immutable List."); | |
1286 } | |
1287 | |
1288 int removeAt(int pos) { | |
1289 throw new UnsupportedError("Cannot remove from immutable List."); | |
1290 } | |
1291 | |
1292 int removeLast() { | |
1293 throw new UnsupportedError("Cannot remove from immutable List."); | |
1294 } | |
1295 | |
1296 void remove(Object object) { | |
1297 throw new UnsupportedError("Cannot remove from immutable List."); | |
1298 } | |
1299 | |
1300 void removeWhere(bool test(int element)) { | |
1301 throw new UnsupportedError("Cannot remove from immutable List."); | |
1302 } | |
1303 | |
1304 void retainWhere(bool test(int element)) { | |
1305 throw new UnsupportedError("Cannot remove from immutable List."); | |
1306 } | |
1307 | |
1308 void setRange(int start, int end, Iterable<int> iterable, [int skipCount=0]) { | |
1309 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); | |
1310 } | |
1311 | |
1312 void removeRange(int start, int end) { | |
1313 throw new UnsupportedError("Cannot removeRange on immutable List."); | |
1314 } | |
1315 | |
1316 void replaceRange(int start, int end, Iterable<int> iterable) { | |
1317 throw new UnsupportedError("Cannot modify an immutable List."); | |
1318 } | |
1319 | |
1320 void fillRange(int start, int end, [int fillValue]) { | |
1321 throw new UnsupportedError("Cannot modify an immutable List."); | |
1322 } | |
1323 | |
1324 Iterable<int> getRange(int start, int end) => | |
1325 IterableMixinWorkaround.getRangeList(this, start, end); | |
1326 | |
1327 List<int> sublist(int start, [int end]) { | |
1328 if (end == null) end = length; | |
1329 return _Lists.getRange(this, start, end, <int>[]); | |
1330 } | |
1331 | |
1332 Map<int, int> asMap() => | |
1333 IterableMixinWorkaround.asMapList(this); | |
1334 | |
1335 String toString() { | |
1336 StringBuffer buffer = new StringBuffer('['); | |
1337 buffer.writeAll(this, ', '); | |
1338 buffer.write(']'); | |
1339 return buffer.toString(); | |
1340 } | |
1341 | |
1342 // -- end List<int> mixins. | |
1343 } | |
1344 | |
1345 class Uint16List extends TypedData implements JavaScriptIndexingBehavior, List<i nt> native "Uint16Array" { | |
1346 | |
1347 factory Uint16List(int length) => | |
1348 _TypedArrayFactoryProvider.createUint16List(length); | |
1349 | |
1350 factory Uint16List.fromList(List<int> list) => | |
1351 _TypedArrayFactoryProvider.createUint16List_fromList(list); | |
1352 | |
1353 factory Uint16List.view(ByteBuffer buffer, [int byteOffset, int length]) => | |
1354 _TypedArrayFactoryProvider.createUint16List_fromBuffer(buffer, byteOffset, l ength); | |
1355 | 443 |
1356 static const int BYTES_PER_ELEMENT = 2; | 444 static const int BYTES_PER_ELEMENT = 2; |
1357 | 445 |
1358 int get length => JS("int", "#.length", this); | 446 int get length => JS("int", "#.length", this); |
1359 | 447 |
1360 int operator[](int index) { | 448 num operator[](int index) { |
1361 _checkBounds(index, length); | 449 _checkIndex(index, length); |
1362 return JS("int", "#[#]", this, index); | 450 return JS("num", "#[#]", this, index); |
1363 } | 451 } |
1364 | 452 |
1365 void operator[]=(int index, int value) { | 453 void operator[]=(int index, num value) { |
1366 _checkBounds(index, length); | 454 _checkIndex(index, length); |
1367 JS("void", "#[#] = #", this, index, value); | 455 JS("void", "#[#] = #", this, index, value); |
1368 } | 456 } |
1369 // -- start List<int> mixins. | 457 |
1370 // int is the element type. | 458 List<int> sublist(int start, [int end]) { |
1371 | 459 end = _checkSublistArguments(start, end, length); |
1372 // From Iterable<int>: | 460 var source = JS('Uint16List', '#.subarray(#, #)', this, start, end); |
1373 | 461 return _create1(source); |
1374 Iterator<int> get iterator { | 462 } |
1375 // Note: NodeLists are not fixed size. And most probably length shouldn't | 463 |
1376 // be cached in both iterator _and_ forEach method. For now caching it | 464 static Uint16List _create1(arg) => |
1377 // for consistency. | 465 JS('Uint16List', 'new Uint16Array(#)', arg); |
1378 return new ListIterator<int>(this); | 466 |
1379 } | 467 static Uint16List _create2(arg1, arg2) => |
1380 | 468 JS('Uint16List', 'new Uint16Array(#, #)', arg1, arg2); |
1381 int reduce(int combine(int value, int element)) { | 469 |
1382 return IterableMixinWorkaround.reduce(this, combine); | 470 static Uint16List _create3(arg1, arg2, arg3) => |
1383 } | 471 JS('Uint16List', 'new Uint16Array(#, #, #)', arg1, arg2, arg3); |
1384 | 472 } |
1385 dynamic fold(dynamic initialValue, | 473 |
1386 dynamic combine(dynamic previousValue, int element)) { | 474 |
1387 return IterableMixinWorkaround.fold(this, initialValue, combine); | 475 class Uint32List |
1388 } | 476 extends TypedData with ListMixin<int>, FixedLengthListMixin<int> |
1389 | 477 implements JavaScriptIndexingBehavior, List<int> |
1390 bool contains(int element) => IterableMixinWorkaround.contains(this, element); | 478 native "Uint32Array" { |
1391 | 479 factory Uint32List(int length) => _create1(length); |
1392 void forEach(void f(int element)) => IterableMixinWorkaround.forEach(this, f); | 480 |
1393 | 481 factory Uint32List.fromList(List<num> list) => |
1394 String join([String separator = ""]) => | 482 _create1(_ensureNativeList(list)); |
1395 IterableMixinWorkaround.joinList(this, separator); | 483 |
1396 | 484 factory Uint32List.view(ByteBuffer buffer, |
1397 Iterable map(f(int element)) => | 485 [int byteOffset = 0, int length]) => |
1398 IterableMixinWorkaround.mapList(this, f); | 486 length == null |
1399 | 487 ? _create2(buffer, byteOffset) |
1400 Iterable<int> where(bool f(int element)) => | 488 : _create3(buffer, byteOffset, length); |
1401 IterableMixinWorkaround.where(this, f); | |
1402 | |
1403 Iterable expand(Iterable f(int element)) => | |
1404 IterableMixinWorkaround.expand(this, f); | |
1405 | |
1406 bool every(bool f(int element)) => IterableMixinWorkaround.every(this, f); | |
1407 | |
1408 bool any(bool f(int element)) => IterableMixinWorkaround.any(this, f); | |
1409 | |
1410 List<int> toList({ bool growable: true }) => | |
1411 new List<int>.from(this, growable: growable); | |
1412 | |
1413 Set<int> toSet() => new Set<int>.from(this); | |
1414 | |
1415 bool get isEmpty => this.length == 0; | |
1416 | |
1417 bool get isNotEmpty => !isEmpty; | |
1418 | |
1419 Iterable<int> take(int n) => IterableMixinWorkaround.takeList(this, n); | |
1420 | |
1421 Iterable<int> takeWhile(bool test(int value)) { | |
1422 return IterableMixinWorkaround.takeWhile(this, test); | |
1423 } | |
1424 | |
1425 Iterable<int> skip(int n) => IterableMixinWorkaround.skipList(this, n); | |
1426 | |
1427 Iterable<int> skipWhile(bool test(int value)) { | |
1428 return IterableMixinWorkaround.skipWhile(this, test); | |
1429 } | |
1430 | |
1431 dynamic firstWhere(bool test(int value), { Object orElse() }) { | |
1432 return IterableMixinWorkaround.firstWhere(this, test, orElse); | |
1433 } | |
1434 | |
1435 dynamic lastWhere(bool test(int value), { Object orElse() }) { | |
1436 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | |
1437 } | |
1438 | |
1439 int singleWhere(bool test(int value)) { | |
1440 return IterableMixinWorkaround.singleWhere(this, test); | |
1441 } | |
1442 | |
1443 int elementAt(int index) { | |
1444 return this[index]; | |
1445 } | |
1446 | |
1447 // From Collection<int>: | |
1448 | |
1449 void add(int value) { | |
1450 throw new UnsupportedError("Cannot add to immutable List."); | |
1451 } | |
1452 | |
1453 void addAll(Iterable<int> iterable) { | |
1454 throw new UnsupportedError("Cannot add to immutable List."); | |
1455 } | |
1456 | |
1457 // From List<int>: | |
1458 void set length(int value) { | |
1459 throw new UnsupportedError("Cannot resize immutable List."); | |
1460 } | |
1461 | |
1462 void clear() { | |
1463 throw new UnsupportedError("Cannot clear immutable List."); | |
1464 } | |
1465 | |
1466 Iterable<int> get reversed { | |
1467 return IterableMixinWorkaround.reversedList(this); | |
1468 } | |
1469 | |
1470 void sort([int compare(int a, int b)]) { | |
1471 throw new UnsupportedError("Cannot sort immutable List."); | |
1472 } | |
1473 | |
1474 int indexOf(int element, [int start = 0]) => | |
1475 _Lists.indexOf(this, element, start, this.length); | |
1476 | |
1477 int lastIndexOf(int element, [int start]) { | |
1478 if (start == null) start = length - 1; | |
1479 return _Lists.lastIndexOf(this, element, start); | |
1480 } | |
1481 | |
1482 int get first { | |
1483 if (this.length > 0) return this[0]; | |
1484 throw new StateError("No elements"); | |
1485 } | |
1486 | |
1487 int get last { | |
1488 if (this.length > 0) return this[this.length - 1]; | |
1489 throw new StateError("No elements"); | |
1490 } | |
1491 | |
1492 int get single { | |
1493 if (length == 1) return this[0]; | |
1494 if (length == 0) throw new StateError("No elements"); | |
1495 throw new StateError("More than one element"); | |
1496 } | |
1497 | |
1498 void insert(int index, int element) { | |
1499 throw new UnsupportedError("Cannot add to immutable List."); | |
1500 } | |
1501 | |
1502 void insertAll(int index, Iterable<int> iterable) { | |
1503 throw new UnsupportedError("Cannot add to immutable List."); | |
1504 } | |
1505 | |
1506 void setAll(int index, Iterable<int> iterable) { | |
1507 throw new UnsupportedError("Cannot modify an immutable List."); | |
1508 } | |
1509 | |
1510 int removeAt(int pos) { | |
1511 throw new UnsupportedError("Cannot remove from immutable List."); | |
1512 } | |
1513 | |
1514 int removeLast() { | |
1515 throw new UnsupportedError("Cannot remove from immutable List."); | |
1516 } | |
1517 | |
1518 void remove(Object object) { | |
1519 throw new UnsupportedError("Cannot remove from immutable List."); | |
1520 } | |
1521 | |
1522 void removeWhere(bool test(int element)) { | |
1523 throw new UnsupportedError("Cannot remove from immutable List."); | |
1524 } | |
1525 | |
1526 void retainWhere(bool test(int element)) { | |
1527 throw new UnsupportedError("Cannot remove from immutable List."); | |
1528 } | |
1529 | |
1530 void setRange(int start, int end, Iterable<int> iterable, [int skipCount=0]) { | |
1531 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); | |
1532 } | |
1533 | |
1534 void removeRange(int start, int end) { | |
1535 throw new UnsupportedError("Cannot removeRange on immutable List."); | |
1536 } | |
1537 | |
1538 void replaceRange(int start, int end, Iterable<int> iterable) { | |
1539 throw new UnsupportedError("Cannot modify an immutable List."); | |
1540 } | |
1541 | |
1542 void fillRange(int start, int end, [int fillValue]) { | |
1543 throw new UnsupportedError("Cannot modify an immutable List."); | |
1544 } | |
1545 | |
1546 Iterable<int> getRange(int start, int end) => | |
1547 IterableMixinWorkaround.getRangeList(this, start, end); | |
1548 | |
1549 List<int> sublist(int start, [int end]) { | |
1550 if (end == null) end = length; | |
1551 return _Lists.getRange(this, start, end, <int>[]); | |
1552 } | |
1553 | |
1554 Map<int, int> asMap() => | |
1555 IterableMixinWorkaround.asMapList(this); | |
1556 | |
1557 String toString() { | |
1558 StringBuffer buffer = new StringBuffer('['); | |
1559 buffer.writeAll(this, ', '); | |
1560 buffer.write(']'); | |
1561 return buffer.toString(); | |
1562 } | |
1563 | |
1564 // -- end List<int> mixins. | |
1565 } | |
1566 | |
1567 class Uint32List extends TypedData implements JavaScriptIndexingBehavior, List<i nt> native "Uint32Array" { | |
1568 | |
1569 factory Uint32List(int length) => | |
1570 _TypedArrayFactoryProvider.createUint32List(length); | |
1571 | |
1572 factory Uint32List.fromList(List<int> list) => | |
1573 _TypedArrayFactoryProvider.createUint32List_fromList(list); | |
1574 | |
1575 factory Uint32List.view(ByteBuffer buffer, [int byteOffset, int length]) => | |
1576 _TypedArrayFactoryProvider.createUint32List_fromBuffer(buffer, byteOffset, l ength); | |
1577 | 489 |
1578 static const int BYTES_PER_ELEMENT = 4; | 490 static const int BYTES_PER_ELEMENT = 4; |
1579 | 491 |
1580 int get length => JS("int", "#.length", this); | 492 int get length => JS("int", "#.length", this); |
1581 | 493 |
1582 int operator[](int index) { | 494 num operator[](int index) { |
1583 _checkBounds(index, length); | 495 _checkIndex(index, length); |
1584 return JS("int", "#[#]", this, index); | 496 return JS("num", "#[#]", this, index); |
1585 } | 497 } |
1586 | 498 |
1587 void operator[]=(int index, int value) { | 499 void operator[]=(int index, num value) { |
1588 _checkBounds(index, length); | 500 _checkIndex(index, length); |
1589 JS("void", "#[#] = #", this, index, value); | 501 JS("void", "#[#] = #", this, index, value); |
1590 } | 502 } |
1591 // -- start List<int> mixins. | 503 |
1592 // int is the element type. | 504 List<int> sublist(int start, [int end]) { |
1593 | 505 end = _checkSublistArguments(start, end, length); |
1594 // From Iterable<int>: | 506 var source = JS('Uint32List', '#.subarray(#, #)', this, start, end); |
1595 | 507 return _create1(source); |
1596 Iterator<int> get iterator { | 508 } |
1597 // Note: NodeLists are not fixed size. And most probably length shouldn't | 509 |
1598 // be cached in both iterator _and_ forEach method. For now caching it | 510 static Uint32List _create1(arg) => |
1599 // for consistency. | 511 JS('Uint32List', 'new Uint32Array(#)', arg); |
1600 return new ListIterator<int>(this); | 512 |
1601 } | 513 static Uint32List _create2(arg1, arg2) => |
1602 | 514 JS('Uint32List', 'new Uint32Array(#, #)', arg1, arg2); |
1603 int reduce(int combine(int value, int element)) { | 515 |
1604 return IterableMixinWorkaround.reduce(this, combine); | 516 static Uint32List _create3(arg1, arg2, arg3) => |
1605 } | 517 JS('Uint32List', 'new Uint32Array(#, #, #)', arg1, arg2, arg3); |
1606 | 518 } |
1607 dynamic fold(dynamic initialValue, | 519 |
1608 dynamic combine(dynamic previousValue, int element)) { | 520 |
1609 return IterableMixinWorkaround.fold(this, initialValue, combine); | 521 class Uint8ClampedList extends Uint8List |
1610 } | 522 native "Uint8ClampedArray,CanvasPixelArray" { |
1611 | 523 factory Uint8ClampedList(int length) => _create1(length); |
1612 bool contains(int element) => IterableMixinWorkaround.contains(this, element); | 524 |
1613 | 525 factory Uint8ClampedList.fromList(List<num> list) => |
1614 void forEach(void f(int element)) => IterableMixinWorkaround.forEach(this, f); | 526 _create1(_ensureNativeList(list)); |
1615 | 527 |
1616 String join([String separator = ""]) => | 528 factory Uint8ClampedList.view(ByteBuffer buffer, |
1617 IterableMixinWorkaround.joinList(this, separator); | 529 [int byteOffset = 0, int length]) => |
1618 | 530 length == null |
1619 Iterable map(f(int element)) => | 531 ? _create2(buffer, byteOffset) |
1620 IterableMixinWorkaround.mapList(this, f); | 532 : _create3(buffer, byteOffset, length); |
1621 | 533 |
1622 Iterable<int> where(bool f(int element)) => | 534 static const int BYTES_PER_ELEMENT = 1; |
1623 IterableMixinWorkaround.where(this, f); | 535 |
1624 | 536 // Use implementation from Uint8List |
1625 Iterable expand(Iterable f(int element)) => | |
1626 IterableMixinWorkaround.expand(this, f); | |
1627 | |
1628 bool every(bool f(int element)) => IterableMixinWorkaround.every(this, f); | |
1629 | |
1630 bool any(bool f(int element)) => IterableMixinWorkaround.any(this, f); | |
1631 | |
1632 List<int> toList({ bool growable: true }) => | |
1633 new List<int>.from(this, growable: growable); | |
1634 | |
1635 Set<int> toSet() => new Set<int>.from(this); | |
1636 | |
1637 bool get isEmpty => this.length == 0; | |
1638 | |
1639 bool get isNotEmpty => !isEmpty; | |
1640 | |
1641 Iterable<int> take(int n) => IterableMixinWorkaround.takeList(this, n); | |
1642 | |
1643 Iterable<int> takeWhile(bool test(int value)) { | |
1644 return IterableMixinWorkaround.takeWhile(this, test); | |
1645 } | |
1646 | |
1647 Iterable<int> skip(int n) => IterableMixinWorkaround.skipList(this, n); | |
1648 | |
1649 Iterable<int> skipWhile(bool test(int value)) { | |
1650 return IterableMixinWorkaround.skipWhile(this, test); | |
1651 } | |
1652 | |
1653 dynamic firstWhere(bool test(int value), { Object orElse() }) { | |
1654 return IterableMixinWorkaround.firstWhere(this, test, orElse); | |
1655 } | |
1656 | |
1657 dynamic lastWhere(bool test(int value), { Object orElse() }) { | |
1658 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | |
1659 } | |
1660 | |
1661 int singleWhere(bool test(int value)) { | |
1662 return IterableMixinWorkaround.singleWhere(this, test); | |
1663 } | |
1664 | |
1665 int elementAt(int index) { | |
1666 return this[index]; | |
1667 } | |
1668 | |
1669 // From Collection<int>: | |
1670 | |
1671 void add(int value) { | |
1672 throw new UnsupportedError("Cannot add to immutable List."); | |
1673 } | |
1674 | |
1675 void addAll(Iterable<int> iterable) { | |
1676 throw new UnsupportedError("Cannot add to immutable List."); | |
1677 } | |
1678 | |
1679 // From List<int>: | |
1680 void set length(int value) { | |
1681 throw new UnsupportedError("Cannot resize immutable List."); | |
1682 } | |
1683 | |
1684 void clear() { | |
1685 throw new UnsupportedError("Cannot clear immutable List."); | |
1686 } | |
1687 | |
1688 Iterable<int> get reversed { | |
1689 return IterableMixinWorkaround.reversedList(this); | |
1690 } | |
1691 | |
1692 void sort([int compare(int a, int b)]) { | |
1693 throw new UnsupportedError("Cannot sort immutable List."); | |
1694 } | |
1695 | |
1696 int indexOf(int element, [int start = 0]) => | |
1697 _Lists.indexOf(this, element, start, this.length); | |
1698 | |
1699 int lastIndexOf(int element, [int start]) { | |
1700 if (start == null) start = length - 1; | |
1701 return _Lists.lastIndexOf(this, element, start); | |
1702 } | |
1703 | |
1704 int get first { | |
1705 if (this.length > 0) return this[0]; | |
1706 throw new StateError("No elements"); | |
1707 } | |
1708 | |
1709 int get last { | |
1710 if (this.length > 0) return this[this.length - 1]; | |
1711 throw new StateError("No elements"); | |
1712 } | |
1713 | |
1714 int get single { | |
1715 if (length == 1) return this[0]; | |
1716 if (length == 0) throw new StateError("No elements"); | |
1717 throw new StateError("More than one element"); | |
1718 } | |
1719 | |
1720 void insert(int index, int element) { | |
1721 throw new UnsupportedError("Cannot add to immutable List."); | |
1722 } | |
1723 | |
1724 void insertAll(int index, Iterable<int> iterable) { | |
1725 throw new UnsupportedError("Cannot add to immutable List."); | |
1726 } | |
1727 | |
1728 void setAll(int index, Iterable<int> iterable) { | |
1729 throw new UnsupportedError("Cannot modify an immutable List."); | |
1730 } | |
1731 | |
1732 int removeAt(int pos) { | |
1733 throw new UnsupportedError("Cannot remove from immutable List."); | |
1734 } | |
1735 | |
1736 int removeLast() { | |
1737 throw new UnsupportedError("Cannot remove from immutable List."); | |
1738 } | |
1739 | |
1740 void remove(Object object) { | |
1741 throw new UnsupportedError("Cannot remove from immutable List."); | |
1742 } | |
1743 | |
1744 void removeWhere(bool test(int element)) { | |
1745 throw new UnsupportedError("Cannot remove from immutable List."); | |
1746 } | |
1747 | |
1748 void retainWhere(bool test(int element)) { | |
1749 throw new UnsupportedError("Cannot remove from immutable List."); | |
1750 } | |
1751 | |
1752 void setRange(int start, int end, Iterable<int> iterable, [int skipCount=0]) { | |
1753 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); | |
1754 } | |
1755 | |
1756 void removeRange(int start, int end) { | |
1757 throw new UnsupportedError("Cannot removeRange on immutable List."); | |
1758 } | |
1759 | |
1760 void replaceRange(int start, int end, Iterable<int> iterable) { | |
1761 throw new UnsupportedError("Cannot modify an immutable List."); | |
1762 } | |
1763 | |
1764 void fillRange(int start, int end, [int fillValue]) { | |
1765 throw new UnsupportedError("Cannot modify an immutable List."); | |
1766 } | |
1767 | |
1768 Iterable<int> getRange(int start, int end) => | |
1769 IterableMixinWorkaround.getRangeList(this, start, end); | |
1770 | |
1771 List<int> sublist(int start, [int end]) { | |
1772 if (end == null) end = length; | |
1773 return _Lists.getRange(this, start, end, <int>[]); | |
1774 } | |
1775 | |
1776 Map<int, int> asMap() => | |
1777 IterableMixinWorkaround.asMapList(this); | |
1778 | |
1779 String toString() { | |
1780 StringBuffer buffer = new StringBuffer('['); | |
1781 buffer.writeAll(this, ', '); | |
1782 buffer.write(']'); | |
1783 return buffer.toString(); | |
1784 } | |
1785 | |
1786 // -- end List<int> mixins. | |
1787 } | |
1788 | |
1789 class Uint8ClampedList extends Uint8List implements JavaScriptIndexingBehavior, List<int> native "Uint8ClampedArray,CanvasPixelArray" { | |
1790 | |
1791 factory Uint8ClampedList(int length) => | |
1792 _TypedArrayFactoryProvider.createUint8ClampedList(length); | |
1793 | |
1794 factory Uint8ClampedList.fromList(List<int> list) => | |
1795 _TypedArrayFactoryProvider.createUint8ClampedList_fromList(list); | |
1796 | |
1797 factory Uint8ClampedList.view(ByteBuffer buffer, [int byteOffset, int length]) => | |
1798 _TypedArrayFactoryProvider.createUint8ClampedList_fromBuffer(buffer, byteOff set, length); | |
1799 | |
1800 // Use implementation from Uint8Array. | |
1801 // final int length; | 537 // final int length; |
1802 | 538 |
1803 int operator[](int index) { | 539 num operator[](int index) { |
1804 _checkBounds(index, length); | 540 _checkIndex(index, length); |
1805 return JS("int", "#[#]", this, index); | 541 return JS("num", "#[#]", this, index); |
1806 } | 542 } |
1807 | 543 |
1808 void operator[]=(int index, int value) { | 544 void operator[]=(int index, num value) { |
1809 _checkBounds(index, length); | 545 _checkIndex(index, length); |
1810 JS("void", "#[#] = #", this, index, value); | 546 JS("void", "#[#] = #", this, index, value); |
1811 } | 547 } |
1812 // -- start List<int> mixins. | 548 |
1813 // int is the element type. | 549 List<int> sublist(int start, [int end]) { |
1814 | 550 end = _checkSublistArguments(start, end, length); |
1815 // From Iterable<int>: | 551 var source = JS('Uint8ClampedList', '#.subarray(#, #)', this, start, end); |
1816 | 552 return _create1(source); |
1817 Iterator<int> get iterator { | 553 } |
1818 // Note: NodeLists are not fixed size. And most probably length shouldn't | 554 |
1819 // be cached in both iterator _and_ forEach method. For now caching it | 555 static Uint8ClampedList _create1(arg) => |
1820 // for consistency. | 556 JS('Uint8ClampedList', 'new Uint8ClampedArray(#)', arg); |
1821 return new ListIterator<int>(this); | 557 |
1822 } | 558 static Uint8ClampedList _create2(arg1, arg2) => |
1823 | 559 JS('Uint8ClampedList', 'new Uint8ClampedArray(#, #)', arg1, arg2); |
1824 int reduce(int combine(int value, int element)) { | 560 |
1825 return IterableMixinWorkaround.reduce(this, combine); | 561 static Uint8ClampedList _create3(arg1, arg2, arg3) => |
1826 } | 562 JS('Uint8ClampedList', 'new Uint8ClampedArray(#, #, #)', arg1, arg2, arg3) ; |
floitsch
2013/07/02 18:52:15
long line.
| |
1827 | 563 } |
1828 dynamic fold(dynamic initialValue, | 564 |
1829 dynamic combine(dynamic previousValue, int element)) { | 565 |
1830 return IterableMixinWorkaround.fold(this, initialValue, combine); | 566 class Uint8List |
1831 } | 567 extends TypedData with ListMixin<int>, FixedLengthListMixin<int> |
1832 | 568 implements JavaScriptIndexingBehavior, List<int> |
1833 bool contains(int element) => IterableMixinWorkaround.contains(this, element); | 569 native "Uint8Array" { |
1834 | 570 factory Uint8List(int length) => _create1(length); |
1835 void forEach(void f(int element)) => IterableMixinWorkaround.forEach(this, f); | 571 |
1836 | 572 factory Uint8List.fromList(List<num> list) => |
1837 String join([String separator = ""]) => | 573 _create1(_ensureNativeList(list)); |
1838 IterableMixinWorkaround.joinList(this, separator); | 574 |
1839 | 575 factory Uint8List.view(ByteBuffer buffer, |
1840 Iterable map(f(int element)) => | 576 [int byteOffset = 0, int length]) => |
1841 IterableMixinWorkaround.mapList(this, f); | 577 length == null |
1842 | 578 ? _create2(buffer, byteOffset) |
1843 Iterable<int> where(bool f(int element)) => | 579 : _create3(buffer, byteOffset, length); |
1844 IterableMixinWorkaround.where(this, f); | |
1845 | |
1846 Iterable expand(Iterable f(int element)) => | |
1847 IterableMixinWorkaround.expand(this, f); | |
1848 | |
1849 bool every(bool f(int element)) => IterableMixinWorkaround.every(this, f); | |
1850 | |
1851 bool any(bool f(int element)) => IterableMixinWorkaround.any(this, f); | |
1852 | |
1853 List<int> toList({ bool growable: true }) => | |
1854 new List<int>.from(this, growable: growable); | |
1855 | |
1856 Set<int> toSet() => new Set<int>.from(this); | |
1857 | |
1858 bool get isEmpty => this.length == 0; | |
1859 | |
1860 bool get isNotEmpty => !isEmpty; | |
1861 | |
1862 Iterable<int> take(int n) => IterableMixinWorkaround.takeList(this, n); | |
1863 | |
1864 Iterable<int> takeWhile(bool test(int value)) { | |
1865 return IterableMixinWorkaround.takeWhile(this, test); | |
1866 } | |
1867 | |
1868 Iterable<int> skip(int n) => IterableMixinWorkaround.skipList(this, n); | |
1869 | |
1870 Iterable<int> skipWhile(bool test(int value)) { | |
1871 return IterableMixinWorkaround.skipWhile(this, test); | |
1872 } | |
1873 | |
1874 dynamic firstWhere(bool test(int value), { Object orElse() }) { | |
1875 return IterableMixinWorkaround.firstWhere(this, test, orElse); | |
1876 } | |
1877 | |
1878 dynamic lastWhere(bool test(int value), { Object orElse() }) { | |
1879 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | |
1880 } | |
1881 | |
1882 int singleWhere(bool test(int value)) { | |
1883 return IterableMixinWorkaround.singleWhere(this, test); | |
1884 } | |
1885 | |
1886 int elementAt(int index) { | |
1887 return this[index]; | |
1888 } | |
1889 | |
1890 // From Collection<int>: | |
1891 | |
1892 void add(int value) { | |
1893 throw new UnsupportedError("Cannot add to immutable List."); | |
1894 } | |
1895 | |
1896 void addAll(Iterable<int> iterable) { | |
1897 throw new UnsupportedError("Cannot add to immutable List."); | |
1898 } | |
1899 | |
1900 // From List<int>: | |
1901 void set length(int value) { | |
1902 throw new UnsupportedError("Cannot resize immutable List."); | |
1903 } | |
1904 | |
1905 void clear() { | |
1906 throw new UnsupportedError("Cannot clear immutable List."); | |
1907 } | |
1908 | |
1909 Iterable<int> get reversed { | |
1910 return IterableMixinWorkaround.reversedList(this); | |
1911 } | |
1912 | |
1913 void sort([int compare(int a, int b)]) { | |
1914 throw new UnsupportedError("Cannot sort immutable List."); | |
1915 } | |
1916 | |
1917 int indexOf(int element, [int start = 0]) => | |
1918 _Lists.indexOf(this, element, start, this.length); | |
1919 | |
1920 int lastIndexOf(int element, [int start]) { | |
1921 if (start == null) start = length - 1; | |
1922 return _Lists.lastIndexOf(this, element, start); | |
1923 } | |
1924 | |
1925 int get first { | |
1926 if (this.length > 0) return this[0]; | |
1927 throw new StateError("No elements"); | |
1928 } | |
1929 | |
1930 int get last { | |
1931 if (this.length > 0) return this[this.length - 1]; | |
1932 throw new StateError("No elements"); | |
1933 } | |
1934 | |
1935 int get single { | |
1936 if (length == 1) return this[0]; | |
1937 if (length == 0) throw new StateError("No elements"); | |
1938 throw new StateError("More than one element"); | |
1939 } | |
1940 | |
1941 void insert(int index, int element) { | |
1942 throw new UnsupportedError("Cannot add to immutable List."); | |
1943 } | |
1944 | |
1945 void insertAll(int index, Iterable<int> iterable) { | |
1946 throw new UnsupportedError("Cannot add to immutable List."); | |
1947 } | |
1948 | |
1949 void setAll(int index, Iterable<int> iterable) { | |
1950 throw new UnsupportedError("Cannot modify an immutable List."); | |
1951 } | |
1952 | |
1953 int removeAt(int pos) { | |
1954 throw new UnsupportedError("Cannot remove from immutable List."); | |
1955 } | |
1956 | |
1957 int removeLast() { | |
1958 throw new UnsupportedError("Cannot remove from immutable List."); | |
1959 } | |
1960 | |
1961 void remove(Object object) { | |
1962 throw new UnsupportedError("Cannot remove from immutable List."); | |
1963 } | |
1964 | |
1965 void removeWhere(bool test(int element)) { | |
1966 throw new UnsupportedError("Cannot remove from immutable List."); | |
1967 } | |
1968 | |
1969 void retainWhere(bool test(int element)) { | |
1970 throw new UnsupportedError("Cannot remove from immutable List."); | |
1971 } | |
1972 | |
1973 void setRange(int start, int end, Iterable<int> iterable, [int skipCount=0]) { | |
1974 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); | |
1975 } | |
1976 | |
1977 void removeRange(int start, int end) { | |
1978 throw new UnsupportedError("Cannot removeRange on immutable List."); | |
1979 } | |
1980 | |
1981 void replaceRange(int start, int end, Iterable<int> iterable) { | |
1982 throw new UnsupportedError("Cannot modify an immutable List."); | |
1983 } | |
1984 | |
1985 void fillRange(int start, int end, [int fillValue]) { | |
1986 throw new UnsupportedError("Cannot modify an immutable List."); | |
1987 } | |
1988 | |
1989 Iterable<int> getRange(int start, int end) => | |
1990 IterableMixinWorkaround.getRangeList(this, start, end); | |
1991 | |
1992 List<int> sublist(int start, [int end]) { | |
1993 if (end == null) end = length; | |
1994 return _Lists.getRange(this, start, end, <int>[]); | |
1995 } | |
1996 | |
1997 Map<int, int> asMap() => | |
1998 IterableMixinWorkaround.asMapList(this); | |
1999 | |
2000 String toString() { | |
2001 StringBuffer buffer = new StringBuffer('['); | |
2002 buffer.writeAll(this, ', '); | |
2003 buffer.write(']'); | |
2004 return buffer.toString(); | |
2005 } | |
2006 | |
2007 // -- end List<int> mixins. | |
2008 } | |
2009 | |
2010 class Uint8List extends TypedData implements JavaScriptIndexingBehavior, List<in t> native "Uint8Array" { | |
2011 | |
2012 factory Uint8List(int length) => | |
2013 _TypedArrayFactoryProvider.createUint8List(length); | |
2014 | |
2015 factory Uint8List.fromList(List<int> list) => | |
2016 _TypedArrayFactoryProvider.createUint8List_fromList(list); | |
2017 | |
2018 factory Uint8List.view(ByteBuffer buffer, [int byteOffset, int length]) => | |
2019 _TypedArrayFactoryProvider.createUint8List_fromBuffer(buffer, byteOffset, le ngth); | |
2020 | 580 |
2021 static const int BYTES_PER_ELEMENT = 1; | 581 static const int BYTES_PER_ELEMENT = 1; |
2022 | 582 |
2023 int get length => JS("int", "#.length", this); | 583 int get length => JS("int", "#.length", this); |
2024 | 584 |
2025 int operator[](int index) { | 585 num operator[](int index) { |
2026 _checkBounds(index, length); | 586 _checkIndex(index, length); |
2027 return JS("int", "#[#]", this, index); | 587 return JS("num", "#[#]", this, index); |
2028 } | 588 } |
2029 | 589 |
2030 void operator[]=(int index, int value) { | 590 void operator[]=(int index, num value) { |
2031 _checkBounds(index, length); | 591 _checkIndex(index, length); |
2032 JS("void", "#[#] = #", this, index, value); | 592 JS("void", "#[#] = #", this, index, value); |
2033 } | 593 } |
2034 // -- start List<int> mixins. | 594 |
2035 // int is the element type. | 595 List<int> sublist(int start, [int end]) { |
2036 | 596 end = _checkSublistArguments(start, end, length); |
2037 // From Iterable<int>: | 597 var source = JS('Uint8List', '#.subarray(#, #)', this, start, end); |
2038 | 598 return _create1(source); |
2039 Iterator<int> get iterator { | 599 } |
2040 // Note: NodeLists are not fixed size. And most probably length shouldn't | 600 |
2041 // be cached in both iterator _and_ forEach method. For now caching it | 601 static Uint8List _create1(arg) => |
2042 // for consistency. | 602 JS('Uint8List', 'new Uint8Array(#)', arg); |
2043 return new ListIterator<int>(this); | 603 |
2044 } | 604 static Uint8List _create2(arg1, arg2) => |
2045 | 605 JS('Uint8List', 'new Uint8Array(#, #)', arg1, arg2); |
2046 int reduce(int combine(int value, int element)) { | 606 |
2047 return IterableMixinWorkaround.reduce(this, combine); | 607 static Uint8List _create3(arg1, arg2, arg3) => |
2048 } | 608 JS('Uint8List', 'new Uint8Array(#, #, #)', arg1, arg2, arg3); |
2049 | |
2050 dynamic fold(dynamic initialValue, | |
2051 dynamic combine(dynamic previousValue, int element)) { | |
2052 return IterableMixinWorkaround.fold(this, initialValue, combine); | |
2053 } | |
2054 | |
2055 bool contains(int element) => IterableMixinWorkaround.contains(this, element); | |
2056 | |
2057 void forEach(void f(int element)) => IterableMixinWorkaround.forEach(this, f); | |
2058 | |
2059 String join([String separator = ""]) => | |
2060 IterableMixinWorkaround.joinList(this, separator); | |
2061 | |
2062 Iterable map(f(int element)) => | |
2063 IterableMixinWorkaround.mapList(this, f); | |
2064 | |
2065 Iterable<int> where(bool f(int element)) => | |
2066 IterableMixinWorkaround.where(this, f); | |
2067 | |
2068 Iterable expand(Iterable f(int element)) => | |
2069 IterableMixinWorkaround.expand(this, f); | |
2070 | |
2071 bool every(bool f(int element)) => IterableMixinWorkaround.every(this, f); | |
2072 | |
2073 bool any(bool f(int element)) => IterableMixinWorkaround.any(this, f); | |
2074 | |
2075 List<int> toList({ bool growable: true }) => | |
2076 new List<int>.from(this, growable: growable); | |
2077 | |
2078 Set<int> toSet() => new Set<int>.from(this); | |
2079 | |
2080 bool get isEmpty => this.length == 0; | |
2081 | |
2082 bool get isNotEmpty => !isEmpty; | |
2083 | |
2084 Iterable<int> take(int n) => IterableMixinWorkaround.takeList(this, n); | |
2085 | |
2086 Iterable<int> takeWhile(bool test(int value)) { | |
2087 return IterableMixinWorkaround.takeWhile(this, test); | |
2088 } | |
2089 | |
2090 Iterable<int> skip(int n) => IterableMixinWorkaround.skipList(this, n); | |
2091 | |
2092 Iterable<int> skipWhile(bool test(int value)) { | |
2093 return IterableMixinWorkaround.skipWhile(this, test); | |
2094 } | |
2095 | |
2096 dynamic firstWhere(bool test(int value), { Object orElse() }) { | |
2097 return IterableMixinWorkaround.firstWhere(this, test, orElse); | |
2098 } | |
2099 | |
2100 dynamic lastWhere(bool test(int value), { Object orElse() }) { | |
2101 return IterableMixinWorkaround.lastWhereList(this, test, orElse); | |
2102 } | |
2103 | |
2104 int singleWhere(bool test(int value)) { | |
2105 return IterableMixinWorkaround.singleWhere(this, test); | |
2106 } | |
2107 | |
2108 int elementAt(int index) { | |
2109 return this[index]; | |
2110 } | |
2111 | |
2112 // From Collection<int>: | |
2113 | |
2114 void add(int value) { | |
2115 throw new UnsupportedError("Cannot add to immutable List."); | |
2116 } | |
2117 | |
2118 void addAll(Iterable<int> iterable) { | |
2119 throw new UnsupportedError("Cannot add to immutable List."); | |
2120 } | |
2121 | |
2122 // From List<int>: | |
2123 void set length(int value) { | |
2124 throw new UnsupportedError("Cannot resize immutable List."); | |
2125 } | |
2126 | |
2127 void clear() { | |
2128 throw new UnsupportedError("Cannot clear immutable List."); | |
2129 } | |
2130 | |
2131 Iterable<int> get reversed { | |
2132 return IterableMixinWorkaround.reversedList(this); | |
2133 } | |
2134 | |
2135 void sort([int compare(int a, int b)]) { | |
2136 throw new UnsupportedError("Cannot sort immutable List."); | |
2137 } | |
2138 | |
2139 int indexOf(int element, [int start = 0]) => | |
2140 _Lists.indexOf(this, element, start, this.length); | |
2141 | |
2142 int lastIndexOf(int element, [int start]) { | |
2143 if (start == null) start = length - 1; | |
2144 return _Lists.lastIndexOf(this, element, start); | |
2145 } | |
2146 | |
2147 int get first { | |
2148 if (this.length > 0) return this[0]; | |
2149 throw new StateError("No elements"); | |
2150 } | |
2151 | |
2152 int get last { | |
2153 if (this.length > 0) return this[this.length - 1]; | |
2154 throw new StateError("No elements"); | |
2155 } | |
2156 | |
2157 int get single { | |
2158 if (length == 1) return this[0]; | |
2159 if (length == 0) throw new StateError("No elements"); | |
2160 throw new StateError("More than one element"); | |
2161 } | |
2162 | |
2163 void insert(int index, int element) { | |
2164 throw new UnsupportedError("Cannot add to immutable List."); | |
2165 } | |
2166 | |
2167 void insertAll(int index, Iterable<int> iterable) { | |
2168 throw new UnsupportedError("Cannot add to immutable List."); | |
2169 } | |
2170 | |
2171 void setAll(int index, Iterable<int> iterable) { | |
2172 throw new UnsupportedError("Cannot modify an immutable List."); | |
2173 } | |
2174 | |
2175 int removeAt(int pos) { | |
2176 throw new UnsupportedError("Cannot remove from immutable List."); | |
2177 } | |
2178 | |
2179 int removeLast() { | |
2180 throw new UnsupportedError("Cannot remove from immutable List."); | |
2181 } | |
2182 | |
2183 void remove(Object object) { | |
2184 throw new UnsupportedError("Cannot remove from immutable List."); | |
2185 } | |
2186 | |
2187 void removeWhere(bool test(int element)) { | |
2188 throw new UnsupportedError("Cannot remove from immutable List."); | |
2189 } | |
2190 | |
2191 void retainWhere(bool test(int element)) { | |
2192 throw new UnsupportedError("Cannot remove from immutable List."); | |
2193 } | |
2194 | |
2195 void setRange(int start, int end, Iterable<int> iterable, [int skipCount=0]) { | |
2196 IterableMixinWorkaround.setRangeList(this, start, end, iterable, skipCount); | |
2197 } | |
2198 | |
2199 void removeRange(int start, int end) { | |
2200 throw new UnsupportedError("Cannot removeRange on immutable List."); | |
2201 } | |
2202 | |
2203 void replaceRange(int start, int end, Iterable<int> iterable) { | |
2204 throw new UnsupportedError("Cannot modify an immutable List."); | |
2205 } | |
2206 | |
2207 void fillRange(int start, int end, [int fillValue]) { | |
2208 throw new UnsupportedError("Cannot modify an immutable List."); | |
2209 } | |
2210 | |
2211 Iterable<int> getRange(int start, int end) => | |
2212 IterableMixinWorkaround.getRangeList(this, start, end); | |
2213 | |
2214 List<int> sublist(int start, [int end]) { | |
2215 if (end == null) end = length; | |
2216 return _Lists.getRange(this, start, end, <int>[]); | |
2217 } | |
2218 | |
2219 Map<int, int> asMap() => | |
2220 IterableMixinWorkaround.asMapList(this); | |
2221 | |
2222 String toString() { | |
2223 StringBuffer buffer = new StringBuffer('['); | |
2224 buffer.writeAll(this, ', '); | |
2225 buffer.write(']'); | |
2226 return buffer.toString(); | |
2227 } | |
2228 | |
2229 // -- end List<int> mixins. | |
2230 } | 609 } |
2231 | 610 |
2232 | 611 |
2233 class Int64List extends TypedData implements JavaScriptIndexingBehavior, List<in t> { | 612 class Int64List extends TypedData implements JavaScriptIndexingBehavior, List<in t> { |
2234 factory Int64List(int length) { | 613 factory Int64List(int length) { |
2235 throw new UnsupportedError("Int64List not supported by dart2js."); | 614 throw new UnsupportedError("Int64List not supported by dart2js."); |
2236 } | 615 } |
2237 | 616 |
2238 factory Int64List.fromList(List<int> list) { | 617 factory Int64List.fromList(List<int> list) { |
2239 throw new UnsupportedError("Int64List not supported by dart2js."); | 618 throw new UnsupportedError("Int64List not supported by dart2js."); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2292 | 671 |
2293 | 672 |
2294 abstract class Uint32x4 { | 673 abstract class Uint32x4 { |
2295 factory Uint32x4(int x, int y, int z, int w) { | 674 factory Uint32x4(int x, int y, int z, int w) { |
2296 throw new UnsupportedError("Uint32x4 not supported by dart2js."); | 675 throw new UnsupportedError("Uint32x4 not supported by dart2js."); |
2297 } | 676 } |
2298 factory Uint32x4.bool(bool x, bool y, bool z, bool w) { | 677 factory Uint32x4.bool(bool x, bool y, bool z, bool w) { |
2299 throw new UnsupportedError("Uint32x4 not supported by dart2js."); | 678 throw new UnsupportedError("Uint32x4 not supported by dart2js."); |
2300 } | 679 } |
2301 } | 680 } |
2302 | |
2303 | |
2304 // TODO(vsm): Eliminate this class and just inline into above. | |
2305 class _TypedArrayFactoryProvider { | |
2306 static ByteData createByteData(int length) => _B8(length); | |
2307 static ByteData createByteData_fromBuffer(ByteBuffer buffer, | |
2308 [int byteOffset = 0, int length]) { | |
2309 if (length == null) return _B8_2(buffer, byteOffset); | |
2310 return _B8_3(buffer, byteOffset, length); | |
2311 } | |
2312 | |
2313 static Float32List createFloat32List(int length) => _F32(length); | |
2314 static Float32List createFloat32List_fromList(List<num> list) => | |
2315 _F32(ensureNative(list)); | |
2316 static Float32List createFloat32List_fromBuffer(ByteBuffer buffer, | |
2317 [int byteOffset = 0, int length]) { | |
2318 if (length == null) return _F32_2(buffer, byteOffset); | |
2319 return _F32_3(buffer, byteOffset, length); | |
2320 } | |
2321 | |
2322 static Float64List createFloat64List(int length) => _F64(length); | |
2323 static Float64List createFloat64List_fromList(List<num> list) => | |
2324 _F64(ensureNative(list)); | |
2325 static Float64List createFloat64List_fromBuffer(ByteBuffer buffer, | |
2326 [int byteOffset = 0, int length]) { | |
2327 if (length == null) return _F64_2(buffer, byteOffset); | |
2328 return _F64_3(buffer, byteOffset, length); | |
2329 } | |
2330 | |
2331 static Int8List createInt8List(int length) => _I8(length); | |
2332 static Int8List createInt8List_fromList(List<num> list) => | |
2333 _I8(ensureNative(list)); | |
2334 static Int8List createInt8List_fromBuffer(ByteBuffer buffer, | |
2335 [int byteOffset = 0, int length]) { | |
2336 if (length == null) return _I8_2(buffer, byteOffset); | |
2337 return _I8_3(buffer, byteOffset, length); | |
2338 } | |
2339 | |
2340 static Int16List createInt16List(int length) => _I16(length); | |
2341 static Int16List createInt16List_fromList(List<num> list) => | |
2342 _I16(ensureNative(list)); | |
2343 static Int16List createInt16List_fromBuffer(ByteBuffer buffer, | |
2344 [int byteOffset = 0, int length]) { | |
2345 if (length == null) return _I16_2(buffer, byteOffset); | |
2346 return _I16_3(buffer, byteOffset, length); | |
2347 } | |
2348 | |
2349 static Int32List createInt32List(int length) => _I32(length); | |
2350 static Int32List createInt32List_fromList(List<num> list) => | |
2351 _I32(ensureNative(list)); | |
2352 static Int32List createInt32List_fromBuffer(ByteBuffer buffer, | |
2353 [int byteOffset = 0, int length]) { | |
2354 if (length == null) return _I32_2(buffer, byteOffset); | |
2355 return _I32_3(buffer, byteOffset, length); | |
2356 } | |
2357 | |
2358 static Uint8List createUint8List(int length) => _U8(length); | |
2359 static Uint8List createUint8List_fromList(List<num> list) => | |
2360 _U8(ensureNative(list)); | |
2361 static Uint8List createUint8List_fromBuffer(ByteBuffer buffer, | |
2362 [int byteOffset = 0, int length]) { | |
2363 if (length == null) return _U8_2(buffer, byteOffset); | |
2364 return _U8_3(buffer, byteOffset, length); | |
2365 } | |
2366 | |
2367 static Uint16List createUint16List(int length) => _U16(length); | |
2368 static Uint16List createUint16List_fromList(List<num> list) => | |
2369 _U16(ensureNative(list)); | |
2370 static Uint16List createUint16List_fromBuffer(ByteBuffer buffer, | |
2371 [int byteOffset = 0, int length]) { | |
2372 if (length == null) return _U16_2(buffer, byteOffset); | |
2373 return _U16_3(buffer, byteOffset, length); | |
2374 } | |
2375 | |
2376 static Uint32List createUint32List(int length) => _U32(length); | |
2377 static Uint32List createUint32List_fromList(List<num> list) => | |
2378 _U32(ensureNative(list)); | |
2379 static Uint32List createUint32List_fromBuffer(ByteBuffer buffer, | |
2380 [int byteOffset = 0, int length]) { | |
2381 if (length == null) return _U32_2(buffer, byteOffset); | |
2382 return _U32_3(buffer, byteOffset, length); | |
2383 } | |
2384 | |
2385 static Uint8ClampedList createUint8ClampedList(int length) => _U8C(length); | |
2386 static Uint8ClampedList createUint8ClampedList_fromList(List<num> list) => | |
2387 _U8C(ensureNative(list)); | |
2388 static Uint8ClampedList createUint8ClampedList_fromBuffer( | |
2389 ByteBuffer buffer, [int byteOffset = 0, int length]) { | |
2390 if (length == null) return _U8C_2(buffer, byteOffset); | |
2391 return _U8C_3(buffer, byteOffset, length); | |
2392 } | |
2393 | |
2394 static ByteData _B8(arg) => | |
2395 JS('ByteData', 'new DataView(new ArrayBuffer(#))', arg); | |
2396 static Float32List _F32(arg) => | |
2397 JS('Float32List', 'new Float32Array(#)', arg); | |
2398 static Float64List _F64(arg) => | |
2399 JS('Float64List', 'new Float64Array(#)', arg); | |
2400 static Int8List _I8(arg) => | |
2401 JS('Int8List', 'new Int8Array(#)', arg); | |
2402 static Int16List _I16(arg) => | |
2403 JS('Int16List', 'new Int16Array(#)', arg); | |
2404 static Int32List _I32(arg) => | |
2405 JS('Int32List', 'new Int32Array(#)', arg); | |
2406 static Uint8List _U8(arg) => | |
2407 JS('Uint8List', 'new Uint8Array(#)', arg); | |
2408 static Uint16List _U16(arg) => | |
2409 JS('Uint16List', 'new Uint16Array(#)', arg); | |
2410 static Uint32List _U32(arg) => | |
2411 JS('Uint32List', 'new Uint32Array(#)', arg); | |
2412 static Uint8ClampedList _U8C(arg) => | |
2413 JS('Uint8ClampedList', 'new Uint8ClampedArray(#)', arg); | |
2414 | |
2415 static ByteData _B8_2(arg1, arg2) => | |
2416 JS('ByteData', 'new DataView(#, #)', arg1, arg2); | |
2417 static Float32List _F32_2(arg1, arg2) => | |
2418 JS('Float32List', 'new Float32Array(#, #)', arg1, arg2); | |
2419 static Float64List _F64_2(arg1, arg2) => | |
2420 JS('Float64List', 'new Float64Array(#, #)', arg1, arg2); | |
2421 static Int8List _I8_2(arg1, arg2) => | |
2422 JS('Int8List', 'new Int8Array(#, #)', arg1, arg2); | |
2423 static Int16List _I16_2(arg1, arg2) => | |
2424 JS('Int16List', 'new Int16Array(#, #)', arg1, arg2); | |
2425 static Int32List _I32_2(arg1, arg2) => | |
2426 JS('Int32List', 'new Int32Array(#, #)', arg1, arg2); | |
2427 static Uint8List _U8_2(arg1, arg2) => | |
2428 JS('Uint8List', 'new Uint8Array(#, #)', arg1, arg2); | |
2429 static Uint16List _U16_2(arg1, arg2) => | |
2430 JS('Uint16List', 'new Uint16Array(#, #)', arg1, arg2); | |
2431 static Uint32List _U32_2(arg1, arg2) => | |
2432 JS('Uint32List', 'new Uint32Array(#, #)', arg1, arg2); | |
2433 static Uint8ClampedList _U8C_2(arg1, arg2) => | |
2434 JS('Uint8ClampedList', 'new Uint8ClampedArray(#, #)', arg1, arg2); | |
2435 | |
2436 static ByteData _B8_3(arg1, arg2, arg3) => | |
2437 JS('ByteData', 'new DataView(#, #, #)', arg1, arg2, arg3); | |
2438 static Float32List _F32_3(arg1, arg2, arg3) => | |
2439 JS('Float32List', 'new Float32Array(#, #, #)', arg1, arg2, arg3); | |
2440 static Float64List _F64_3(arg1, arg2, arg3) => | |
2441 JS('Float64List', 'new Float64Array(#, #, #)', arg1, arg2, arg3); | |
2442 static Int8List _I8_3(arg1, arg2, arg3) => | |
2443 JS('Int8List', 'new Int8Array(#, #, #)', arg1, arg2, arg3); | |
2444 static Int16List _I16_3(arg1, arg2, arg3) => | |
2445 JS('Int16List', 'new Int16Array(#, #, #)', arg1, arg2, arg3); | |
2446 static Int32List _I32_3(arg1, arg2, arg3) => | |
2447 JS('Int32List', 'new Int32Array(#, #, #)', arg1, arg2, arg3); | |
2448 static Uint8List _U8_3(arg1, arg2, arg3) => | |
2449 JS('Uint8List', 'new Uint8Array(#, #, #)', arg1, arg2, arg3); | |
2450 static Uint16List _U16_3(arg1, arg2, arg3) => | |
2451 JS('Uint16List', 'new Uint16Array(#, #, #)', arg1, arg2, arg3); | |
2452 static Uint32List _U32_3(arg1, arg2, arg3) => | |
2453 JS('Uint32List', 'new Uint32Array(#, #, #)', arg1, arg2, arg3); | |
2454 static Uint8ClampedList _U8C_3(arg1, arg2, arg3) => | |
2455 JS('Uint8ClampedList', 'new Uint8ClampedArray(#, #, #)', arg1, arg2, arg3) ; | |
2456 | |
2457 | |
2458 // Ensures that [list] is a JavaScript Array or a typed array. If necessary, | |
2459 // copies the list. | |
2460 static ensureNative(List list) => list; // TODO: make sure. | |
2461 } | |
OLD | NEW |