Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: pkg/dev_compiler/tool/input_sdk/private/native_typed_data.dart

Issue 2752163002: Format all dart dev compiler files (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Specialized integers and floating point numbers, 6 * Specialized integers and floating point numbers,
7 * with SIMD support and efficient lists. 7 * with SIMD support and efficient lists.
8 */ 8 */
9 library dart.typed_data.implementation; 9 library dart.typed_data.implementation;
10 10
11 import 'dart:collection'; 11 import 'dart:collection';
12 import 'dart:_internal'; 12 import 'dart:_internal';
13 import 'dart:_interceptors' show JSIndexable; 13 import 'dart:_interceptors' show JSIndexable;
14 import 'dart:_js_helper' 14 import 'dart:_js_helper'
15 show Creates, JavaScriptIndexingBehavior, JSName, Native, Null, Returns, 15 show
16 diagnoseIndexError, diagnoseRangeError; 16 Creates,
17 JavaScriptIndexingBehavior,
18 JSName,
19 Native,
20 Null,
21 Returns,
22 diagnoseIndexError,
23 diagnoseRangeError;
17 import 'dart:_foreign_helper' show JS; 24 import 'dart:_foreign_helper' show JS;
18 import 'dart:math' as Math; 25 import 'dart:math' as Math;
19 26
20 import 'dart:typed_data'; 27 import 'dart:typed_data';
21 28
22 @Native("ArrayBuffer") 29 @Native("ArrayBuffer")
23 class NativeByteBuffer implements ByteBuffer { 30 class NativeByteBuffer implements ByteBuffer {
24 @JSName('byteLength') 31 @JSName('byteLength')
25 external int get lengthInBytes; 32 external int get lengthInBytes;
26 33
27 Type get runtimeType => ByteBuffer; 34 Type get runtimeType => ByteBuffer;
28 35
29 Uint8List asUint8List([int offsetInBytes = 0, int length]) { 36 Uint8List asUint8List([int offsetInBytes = 0, int length]) {
30 return new NativeUint8List.view(this, offsetInBytes, length); 37 return new NativeUint8List.view(this, offsetInBytes, length);
31 } 38 }
32 39
33 Int8List asInt8List([int offsetInBytes = 0, int length]) { 40 Int8List asInt8List([int offsetInBytes = 0, int length]) {
34 return new NativeInt8List.view(this, offsetInBytes, length); 41 return new NativeInt8List.view(this, offsetInBytes, length);
35 } 42 }
36 43
37 Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int length]) { 44 Uint8ClampedList asUint8ClampedList([int offsetInBytes = 0, int length]) {
38 return new NativeUint8ClampedList.view(this, offsetInBytes, length); 45 return new NativeUint8ClampedList.view(this, offsetInBytes, length);
39 } 46 }
40 47
41 Uint16List asUint16List([int offsetInBytes = 0, int length]) { 48 Uint16List asUint16List([int offsetInBytes = 0, int length]) {
42 return new NativeUint16List.view(this, offsetInBytes, length); 49 return new NativeUint16List.view(this, offsetInBytes, length);
43 } 50 }
51
44 Int16List asInt16List([int offsetInBytes = 0, int length]) { 52 Int16List asInt16List([int offsetInBytes = 0, int length]) {
45 return new NativeInt16List.view(this, offsetInBytes, length); 53 return new NativeInt16List.view(this, offsetInBytes, length);
46 } 54 }
47 55
48 Uint32List asUint32List([int offsetInBytes = 0, int length]) { 56 Uint32List asUint32List([int offsetInBytes = 0, int length]) {
49 return new NativeUint32List.view(this, offsetInBytes, length); 57 return new NativeUint32List.view(this, offsetInBytes, length);
50 } 58 }
51 59
52 Int32List asInt32List([int offsetInBytes = 0, int length]) { 60 Int32List asInt32List([int offsetInBytes = 0, int length]) {
53 return new NativeInt32List.view(this, offsetInBytes, length); 61 return new NativeInt32List.view(this, offsetInBytes, length);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 NativeFloat64List storage = 93 NativeFloat64List storage =
86 this.asFloat64List(offsetInBytes, length != null ? length * 2 : null); 94 this.asFloat64List(offsetInBytes, length != null ? length * 2 : null);
87 return new NativeFloat64x2List._externalStorage(storage); 95 return new NativeFloat64x2List._externalStorage(storage);
88 } 96 }
89 97
90 ByteData asByteData([int offsetInBytes = 0, int length]) { 98 ByteData asByteData([int offsetInBytes = 0, int length]) {
91 return new NativeByteData.view(this, offsetInBytes, length); 99 return new NativeByteData.view(this, offsetInBytes, length);
92 } 100 }
93 } 101 }
94 102
95
96
97 /** 103 /**
98 * A fixed-length list of Float32x4 numbers that is viewable as a 104 * A fixed-length list of Float32x4 numbers that is viewable as a
99 * [TypedData]. For long lists, this implementation will be considerably more 105 * [TypedData]. For long lists, this implementation will be considerably more
100 * space- and time-efficient than the default [List] implementation. 106 * space- and time-efficient than the default [List] implementation.
101 */ 107 */
102 class NativeFloat32x4List 108 class NativeFloat32x4List extends Object
103 extends Object with ListMixin<Float32x4>, FixedLengthListMixin<Float32x4> 109 with ListMixin<Float32x4>, FixedLengthListMixin<Float32x4>
104 implements Float32x4List { 110 implements Float32x4List {
105
106 final NativeFloat32List _storage; 111 final NativeFloat32List _storage;
107 112
108 /** 113 /**
109 * Creates a [Float32x4List] of the specified length (in elements), 114 * Creates a [Float32x4List] of the specified length (in elements),
110 * all of whose elements are initially zero. 115 * all of whose elements are initially zero.
111 */ 116 */
112 NativeFloat32x4List(int length) 117 NativeFloat32x4List(int length)
113 : _storage = new NativeFloat32List(length * 4); 118 : _storage = new NativeFloat32List(length * 4);
114 119
115 NativeFloat32x4List._externalStorage(this._storage); 120 NativeFloat32x4List._externalStorage(this._storage);
(...skipping 27 matching lines...) Expand all
143 ByteBuffer get buffer => _storage.buffer; 148 ByteBuffer get buffer => _storage.buffer;
144 149
145 int get lengthInBytes => _storage.lengthInBytes; 150 int get lengthInBytes => _storage.lengthInBytes;
146 151
147 int get offsetInBytes => _storage.offsetInBytes; 152 int get offsetInBytes => _storage.offsetInBytes;
148 153
149 int get elementSizeInBytes => Float32x4List.BYTES_PER_ELEMENT; 154 int get elementSizeInBytes => Float32x4List.BYTES_PER_ELEMENT;
150 155
151 int get length => _storage.length ~/ 4; 156 int get length => _storage.length ~/ 4;
152 157
153 Float32x4 operator[](int index) { 158 Float32x4 operator [](int index) {
154 _checkValidIndex(index, this, this.length); 159 _checkValidIndex(index, this, this.length);
155 double _x = _storage[(index * 4) + 0]; 160 double _x = _storage[(index * 4) + 0];
156 double _y = _storage[(index * 4) + 1]; 161 double _y = _storage[(index * 4) + 1];
157 double _z = _storage[(index * 4) + 2]; 162 double _z = _storage[(index * 4) + 2];
158 double _w = _storage[(index * 4) + 3]; 163 double _w = _storage[(index * 4) + 3];
159 return new NativeFloat32x4._truncated(_x, _y, _z, _w); 164 return new NativeFloat32x4._truncated(_x, _y, _z, _w);
160 } 165 }
161 166
162 void operator[]=(int index, Float32x4 value) { 167 void operator []=(int index, Float32x4 value) {
163 _checkValidIndex(index, this, this.length); 168 _checkValidIndex(index, this, this.length);
164 _storage[(index * 4) + 0] = value.x; 169 _storage[(index * 4) + 0] = value.x;
165 _storage[(index * 4) + 1] = value.y; 170 _storage[(index * 4) + 1] = value.y;
166 _storage[(index * 4) + 2] = value.z; 171 _storage[(index * 4) + 2] = value.z;
167 _storage[(index * 4) + 3] = value.w; 172 _storage[(index * 4) + 3] = value.w;
168 } 173 }
169 174
170 List<Float32x4> sublist(int start, [int end]) { 175 List<Float32x4> sublist(int start, [int end]) {
171 end = _checkValidRange(start, end, this.length); 176 end = _checkValidRange(start, end, this.length);
172 return new NativeFloat32x4List._externalStorage( 177 return new NativeFloat32x4List._externalStorage(
173 _storage.sublist(start * 4, end * 4)); 178 _storage.sublist(start * 4, end * 4));
174 } 179 }
175 } 180 }
176 181
177
178 /** 182 /**
179 * A fixed-length list of Int32x4 numbers that is viewable as a 183 * A fixed-length list of Int32x4 numbers that is viewable as a
180 * [TypedData]. For long lists, this implementation will be considerably more 184 * [TypedData]. For long lists, this implementation will be considerably more
181 * space- and time-efficient than the default [List] implementation. 185 * space- and time-efficient than the default [List] implementation.
182 */ 186 */
183 class NativeInt32x4List 187 class NativeInt32x4List extends Object
184 extends Object with ListMixin<Int32x4>, FixedLengthListMixin<Int32x4> 188 with ListMixin<Int32x4>, FixedLengthListMixin<Int32x4>
185 implements Int32x4List { 189 implements Int32x4List {
186
187 final Int32List _storage; 190 final Int32List _storage;
188 191
189 /** 192 /**
190 * Creates a [Int32x4List] of the specified length (in elements), 193 * Creates a [Int32x4List] of the specified length (in elements),
191 * all of whose elements are initially zero. 194 * all of whose elements are initially zero.
192 */ 195 */
193 NativeInt32x4List(int length) : _storage = new NativeInt32List(length * 4); 196 NativeInt32x4List(int length) : _storage = new NativeInt32List(length * 4);
194 197
195 NativeInt32x4List._externalStorage(Int32List storage) : _storage = storage; 198 NativeInt32x4List._externalStorage(Int32List storage) : _storage = storage;
196 199
(...skipping 26 matching lines...) Expand all
223 ByteBuffer get buffer => _storage.buffer; 226 ByteBuffer get buffer => _storage.buffer;
224 227
225 int get lengthInBytes => _storage.lengthInBytes; 228 int get lengthInBytes => _storage.lengthInBytes;
226 229
227 int get offsetInBytes => _storage.offsetInBytes; 230 int get offsetInBytes => _storage.offsetInBytes;
228 231
229 int get elementSizeInBytes => Int32x4List.BYTES_PER_ELEMENT; 232 int get elementSizeInBytes => Int32x4List.BYTES_PER_ELEMENT;
230 233
231 int get length => _storage.length ~/ 4; 234 int get length => _storage.length ~/ 4;
232 235
233 Int32x4 operator[](int index) { 236 Int32x4 operator [](int index) {
234 _checkValidIndex(index, this, this.length); 237 _checkValidIndex(index, this, this.length);
235 int _x = _storage[(index * 4) + 0]; 238 int _x = _storage[(index * 4) + 0];
236 int _y = _storage[(index * 4) + 1]; 239 int _y = _storage[(index * 4) + 1];
237 int _z = _storage[(index * 4) + 2]; 240 int _z = _storage[(index * 4) + 2];
238 int _w = _storage[(index * 4) + 3]; 241 int _w = _storage[(index * 4) + 3];
239 return new NativeInt32x4._truncated(_x, _y, _z, _w); 242 return new NativeInt32x4._truncated(_x, _y, _z, _w);
240 } 243 }
241 244
242 void operator[]=(int index, Int32x4 value) { 245 void operator []=(int index, Int32x4 value) {
243 _checkValidIndex(index, this, this.length); 246 _checkValidIndex(index, this, this.length);
244 _storage[(index * 4) + 0] = value.x; 247 _storage[(index * 4) + 0] = value.x;
245 _storage[(index * 4) + 1] = value.y; 248 _storage[(index * 4) + 1] = value.y;
246 _storage[(index * 4) + 2] = value.z; 249 _storage[(index * 4) + 2] = value.z;
247 _storage[(index * 4) + 3] = value.w; 250 _storage[(index * 4) + 3] = value.w;
248 } 251 }
249 252
250 List<Int32x4> sublist(int start, [int end]) { 253 List<Int32x4> sublist(int start, [int end]) {
251 end = _checkValidRange(start, end, this.length); 254 end = _checkValidRange(start, end, this.length);
252 return new NativeInt32x4List._externalStorage( 255 return new NativeInt32x4List._externalStorage(
253 _storage.sublist(start * 4, end * 4)); 256 _storage.sublist(start * 4, end * 4));
254 } 257 }
255 } 258 }
256 259
257
258 /** 260 /**
259 * A fixed-length list of Float64x2 numbers that is viewable as a 261 * A fixed-length list of Float64x2 numbers that is viewable as a
260 * [TypedData]. For long lists, this implementation will be considerably more 262 * [TypedData]. For long lists, this implementation will be considerably more
261 * space- and time-efficient than the default [List] implementation. 263 * space- and time-efficient than the default [List] implementation.
262 */ 264 */
263 class NativeFloat64x2List 265 class NativeFloat64x2List extends Object
264 extends Object with ListMixin<Float64x2>, FixedLengthListMixin<Float64x2> 266 with ListMixin<Float64x2>, FixedLengthListMixin<Float64x2>
265 implements Float64x2List { 267 implements Float64x2List {
266
267 final NativeFloat64List _storage; 268 final NativeFloat64List _storage;
268 269
269 /** 270 /**
270 * Creates a [Float64x2List] of the specified length (in elements), 271 * Creates a [Float64x2List] of the specified length (in elements),
271 * all of whose elements are initially zero. 272 * all of whose elements are initially zero.
272 */ 273 */
273 NativeFloat64x2List(int length) 274 NativeFloat64x2List(int length)
274 : _storage = new NativeFloat64List(length * 2); 275 : _storage = new NativeFloat64List(length * 2);
275 276
276 NativeFloat64x2List._externalStorage(this._storage); 277 NativeFloat64x2List._externalStorage(this._storage);
(...skipping 25 matching lines...) Expand all
302 ByteBuffer get buffer => _storage.buffer; 303 ByteBuffer get buffer => _storage.buffer;
303 304
304 int get lengthInBytes => _storage.lengthInBytes; 305 int get lengthInBytes => _storage.lengthInBytes;
305 306
306 int get offsetInBytes => _storage.offsetInBytes; 307 int get offsetInBytes => _storage.offsetInBytes;
307 308
308 int get elementSizeInBytes => Float64x2List.BYTES_PER_ELEMENT; 309 int get elementSizeInBytes => Float64x2List.BYTES_PER_ELEMENT;
309 310
310 int get length => _storage.length ~/ 2; 311 int get length => _storage.length ~/ 2;
311 312
312 Float64x2 operator[](int index) { 313 Float64x2 operator [](int index) {
313 _checkValidIndex(index, this, this.length); 314 _checkValidIndex(index, this, this.length);
314 double _x = _storage[(index * 2) + 0]; 315 double _x = _storage[(index * 2) + 0];
315 double _y = _storage[(index * 2) + 1]; 316 double _y = _storage[(index * 2) + 1];
316 return new Float64x2(_x, _y); 317 return new Float64x2(_x, _y);
317 } 318 }
318 319
319 void operator[]=(int index, Float64x2 value) { 320 void operator []=(int index, Float64x2 value) {
320 _checkValidIndex(index, this, this.length); 321 _checkValidIndex(index, this, this.length);
321 _storage[(index * 2) + 0] = value.x; 322 _storage[(index * 2) + 0] = value.x;
322 _storage[(index * 2) + 1] = value.y; 323 _storage[(index * 2) + 1] = value.y;
323 } 324 }
324 325
325 List<Float64x2> sublist(int start, [int end]) { 326 List<Float64x2> sublist(int start, [int end]) {
326 end = _checkValidRange(start, end, this.length); 327 end = _checkValidRange(start, end, this.length);
327 return new NativeFloat64x2List._externalStorage( 328 return new NativeFloat64x2List._externalStorage(
328 _storage.sublist(start * 2, end * 2)); 329 _storage.sublist(start * 2, end * 2));
329 } 330 }
(...skipping 22 matching lines...) Expand all
352 external int get offsetInBytes; 353 external int get offsetInBytes;
353 354
354 /** 355 /**
355 * Returns the number of bytes in the representation of each element in this 356 * Returns the number of bytes in the representation of each element in this
356 * list. 357 * list.
357 */ 358 */
358 @JSName('BYTES_PER_ELEMENT') 359 @JSName('BYTES_PER_ELEMENT')
359 external int get elementSizeInBytes; 360 external int get elementSizeInBytes;
360 361
361 void _invalidPosition(int position, int length, String name) { 362 void _invalidPosition(int position, int length, String name) {
362 if (position is !int) { 363 if (position is! int) {
363 throw new ArgumentError.value(position, name, 'Invalid list position'); 364 throw new ArgumentError.value(position, name, 'Invalid list position');
364 } else { 365 } else {
365 throw new RangeError.range(position, 0, length, name); 366 throw new RangeError.range(position, 0, length, name);
366 } 367 }
367 } 368 }
368 369
369 void _checkPosition(int position, int length, String name) { 370 void _checkPosition(int position, int length, String name) {
370 if (JS('bool', '(# >>> 0) !== #', position, position) || 371 if (JS('bool', '(# >>> 0) !== #', position, position) ||
371 JS('int', '#', position) > length) { // 'int' guaranteed by above test. 372 JS('int', '#', position) > length) {
373 // 'int' guaranteed by above test.
372 _invalidPosition(position, length, name); 374 _invalidPosition(position, length, name);
373 } 375 }
374 } 376 }
375 } 377 }
376 378
377
378 // Validates the unnamed constructor length argument. Checking is necessary 379 // Validates the unnamed constructor length argument. Checking is necessary
379 // because passing unvalidated values to the native constructors can cause 380 // because passing unvalidated values to the native constructors can cause
380 // conversions or create views. 381 // conversions or create views.
381 int _checkLength(length) { 382 int _checkLength(length) {
382 if (length is! int) throw new ArgumentError('Invalid length $length'); 383 if (length is! int) throw new ArgumentError('Invalid length $length');
383 return length; 384 return length;
384 } 385 }
385 386
386 // Validates `.view` constructor arguments. Checking is necessary because 387 // Validates `.view` constructor arguments. Checking is necessary because
387 // passing unvalidated values to the native constructors can cause conversions 388 // passing unvalidated values to the native constructors can cause conversions
(...skipping 15 matching lines...) Expand all
403 // returns a copy of the list. 404 // returns a copy of the list.
404 List _ensureNativeList(List list) { 405 List _ensureNativeList(List list) {
405 if (list is JSIndexable) return list; 406 if (list is JSIndexable) return list;
406 List result = new List(list.length); 407 List result = new List(list.length);
407 for (int i = 0; i < list.length; i++) { 408 for (int i = 0; i < list.length; i++) {
408 result[i] = list[i]; 409 result[i] = list[i];
409 } 410 }
410 return result; 411 return result;
411 } 412 }
412 413
413
414 @Native("DataView") 414 @Native("DataView")
415 class NativeByteData extends NativeTypedData implements ByteData { 415 class NativeByteData extends NativeTypedData implements ByteData {
416 /** 416 /**
417 * Creates a [ByteData] of the specified length (in elements), all of 417 * Creates a [ByteData] of the specified length (in elements), all of
418 * whose elements are initially zero. 418 * whose elements are initially zero.
419 */ 419 */
420 factory NativeByteData(int length) => _create1(_checkLength(length)); 420 factory NativeByteData(int length) => _create1(_checkLength(length));
421 421
422 /** 422 /**
423 * Creates an [ByteData] _view_ of the specified region in the specified 423 * Creates an [ByteData] _view_ of the specified region in the specified
424 * byte buffer. Changes in the [ByteData] will be visible in the byte 424 * byte buffer. Changes in the [ByteData] will be visible in the byte
425 * buffer and vice versa. If the [offsetInBytes] index of the region is not 425 * buffer and vice versa. If the [offsetInBytes] index of the region is not
426 * specified, it defaults to zero (the first byte in the byte buffer). 426 * specified, it defaults to zero (the first byte in the byte buffer).
427 * If the length is not specified, it defaults to null, which indicates 427 * If the length is not specified, it defaults to null, which indicates
428 * that the view extends to the end of the byte buffer. 428 * that the view extends to the end of the byte buffer.
429 * 429 *
430 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or 430 * Throws [RangeError] if [offsetInBytes] or [length] are negative, or
431 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than 431 * if [offsetInBytes] + ([length] * elementSizeInBytes) is greater than
432 * the length of [buffer]. 432 * the length of [buffer].
433 */ 433 */
434 factory NativeByteData.view(ByteBuffer buffer, 434 factory NativeByteData.view(
435 int offsetInBytes, int length) { 435 ByteBuffer buffer, int offsetInBytes, int length) {
436 _checkViewArguments(buffer, offsetInBytes, length); 436 _checkViewArguments(buffer, offsetInBytes, length);
437 return length == null 437 return length == null
438 ? _create2(buffer, offsetInBytes) 438 ? _create2(buffer, offsetInBytes)
439 : _create3(buffer, offsetInBytes, length); 439 : _create3(buffer, offsetInBytes, length);
440 } 440 }
441 441
442 Type get runtimeType => ByteData; 442 Type get runtimeType => ByteData;
443 443
444 int get elementSizeInBytes => 1; 444 int get elementSizeInBytes => 1;
445 445
446 /** 446 /**
447 * Returns the floating point number represented by the four bytes at 447 * Returns the floating point number represented by the four bytes at
448 * the specified [byteOffset] in this object, in IEEE 754 448 * the specified [byteOffset] in this object, in IEEE 754
449 * single-precision binary floating-point format (binary32). 449 * single-precision binary floating-point format (binary32).
450 * 450 *
451 * Throws [RangeError] if [byteOffset] is negative, or 451 * Throws [RangeError] if [byteOffset] is negative, or
452 * `byteOffset + 4` is greater than the length of this object. 452 * `byteOffset + 4` is greater than the length of this object.
453 */ 453 */
454 double getFloat32(int byteOffset, [Endianness endian=Endianness.BIG_ENDIAN]) = > 454 double getFloat32(int byteOffset,
455 [Endianness endian = Endianness.BIG_ENDIAN]) =>
455 _getFloat32(byteOffset, Endianness.LITTLE_ENDIAN == endian); 456 _getFloat32(byteOffset, Endianness.LITTLE_ENDIAN == endian);
456 457
457 @JSName('getFloat32') 458 @JSName('getFloat32')
458 @Returns('double') 459 @Returns('double')
459 double _getFloat32(int byteOffset, [bool littleEndian]) native; 460 double _getFloat32(int byteOffset, [bool littleEndian]) native ;
460 461
461 /** 462 /**
462 * Returns the floating point number represented by the eight bytes at 463 * Returns the floating point number represented by the eight bytes at
463 * the specified [byteOffset] in this object, in IEEE 754 464 * the specified [byteOffset] in this object, in IEEE 754
464 * double-precision binary floating-point format (binary64). 465 * double-precision binary floating-point format (binary64).
465 * 466 *
466 * Throws [RangeError] if [byteOffset] is negative, or 467 * Throws [RangeError] if [byteOffset] is negative, or
467 * `byteOffset + 8` is greater than the length of this object. 468 * `byteOffset + 8` is greater than the length of this object.
468 */ 469 */
469 double getFloat64(int byteOffset, [Endianness endian=Endianness.BIG_ENDIAN]) = > 470 double getFloat64(int byteOffset,
471 [Endianness endian = Endianness.BIG_ENDIAN]) =>
470 _getFloat64(byteOffset, Endianness.LITTLE_ENDIAN == endian); 472 _getFloat64(byteOffset, Endianness.LITTLE_ENDIAN == endian);
471 473
472 @JSName('getFloat64') 474 @JSName('getFloat64')
473 @Returns('double') 475 @Returns('double')
474 double _getFloat64(int byteOffset, [bool littleEndian]) native; 476 double _getFloat64(int byteOffset, [bool littleEndian]) native ;
475 477
476 /** 478 /**
477 * Returns the (possibly negative) integer represented by the two bytes at 479 * Returns the (possibly negative) integer represented by the two bytes at
478 * the specified [byteOffset] in this object, in two's complement binary 480 * the specified [byteOffset] in this object, in two's complement binary
479 * form. 481 * form.
480 * The return value will be between 2<sup>15</sup> and 2<sup>15</sup> - 1, 482 * The return value will be between 2<sup>15</sup> and 2<sup>15</sup> - 1,
481 * inclusive. 483 * inclusive.
482 * 484 *
483 * Throws [RangeError] if [byteOffset] is negative, or 485 * Throws [RangeError] if [byteOffset] is negative, or
484 * `byteOffset + 2` is greater than the length of this object. 486 * `byteOffset + 2` is greater than the length of this object.
485 */ 487 */
486 int getInt16(int byteOffset, [Endianness endian=Endianness.BIG_ENDIAN]) => 488 int getInt16(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) =>
487 _getInt16(byteOffset, Endianness.LITTLE_ENDIAN == endian); 489 _getInt16(byteOffset, Endianness.LITTLE_ENDIAN == endian);
488 490
489 @JSName('getInt16') 491 @JSName('getInt16')
490 @Returns('int') 492 @Returns('int')
491 int _getInt16(int byteOffset, [bool littleEndian]) native; 493 int _getInt16(int byteOffset, [bool littleEndian]) native ;
492 494
493 /** 495 /**
494 * Returns the (possibly negative) integer represented by the four bytes at 496 * Returns the (possibly negative) integer represented by the four bytes at
495 * the specified [byteOffset] in this object, in two's complement binary 497 * the specified [byteOffset] in this object, in two's complement binary
496 * form. 498 * form.
497 * The return value will be between 2<sup>31</sup> and 2<sup>31</sup> - 1, 499 * The return value will be between 2<sup>31</sup> and 2<sup>31</sup> - 1,
498 * inclusive. 500 * inclusive.
499 * 501 *
500 * Throws [RangeError] if [byteOffset] is negative, or 502 * Throws [RangeError] if [byteOffset] is negative, or
501 * `byteOffset + 4` is greater than the length of this object. 503 * `byteOffset + 4` is greater than the length of this object.
502 */ 504 */
503 int getInt32(int byteOffset, [Endianness endian=Endianness.BIG_ENDIAN]) => 505 int getInt32(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) =>
504 _getInt32(byteOffset, Endianness.LITTLE_ENDIAN == endian); 506 _getInt32(byteOffset, Endianness.LITTLE_ENDIAN == endian);
505 507
506 @JSName('getInt32') 508 @JSName('getInt32')
507 @Returns('int') 509 @Returns('int')
508 int _getInt32(int byteOffset, [bool littleEndian]) native; 510 int _getInt32(int byteOffset, [bool littleEndian]) native ;
509 511
510 /** 512 /**
511 * Returns the (possibly negative) integer represented by the eight bytes at 513 * Returns the (possibly negative) integer represented by the eight bytes at
512 * the specified [byteOffset] in this object, in two's complement binary 514 * the specified [byteOffset] in this object, in two's complement binary
513 * form. 515 * form.
514 * The return value will be between 2<sup>63</sup> and 2<sup>63</sup> - 1, 516 * The return value will be between 2<sup>63</sup> and 2<sup>63</sup> - 1,
515 * inclusive. 517 * inclusive.
516 * 518 *
517 * Throws [RangeError] if [byteOffset] is negative, or 519 * Throws [RangeError] if [byteOffset] is negative, or
518 * `byteOffset + 8` is greater than the length of this object. 520 * `byteOffset + 8` is greater than the length of this object.
519 */ 521 */
520 int getInt64(int byteOffset, [Endianness endian=Endianness.BIG_ENDIAN]) { 522 int getInt64(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
521 throw new UnsupportedError('Int64 accessor not supported by dart2js.'); 523 throw new UnsupportedError('Int64 accessor not supported by dart2js.');
522 } 524 }
523 525
524 /** 526 /**
525 * Returns the (possibly negative) integer represented by the byte at the 527 * Returns the (possibly negative) integer represented by the byte at the
526 * specified [byteOffset] in this object, in two's complement binary 528 * specified [byteOffset] in this object, in two's complement binary
527 * representation. The return value will be between -128 and 127, inclusive. 529 * representation. The return value will be between -128 and 127, inclusive.
528 * 530 *
529 * Throws [RangeError] if [byteOffset] is negative, or 531 * Throws [RangeError] if [byteOffset] is negative, or
530 * greater than or equal to the length of this object. 532 * greater than or equal to the length of this object.
531 */ 533 */
532 int getInt8(int byteOffset) native; 534 int getInt8(int byteOffset) native ;
533 535
534 /** 536 /**
535 * Returns the positive integer represented by the two bytes starting 537 * Returns the positive integer represented by the two bytes starting
536 * at the specified [byteOffset] in this object, in unsigned binary 538 * at the specified [byteOffset] in this object, in unsigned binary
537 * form. 539 * form.
538 * The return value will be between 0 and 2<sup>16</sup> - 1, inclusive. 540 * The return value will be between 0 and 2<sup>16</sup> - 1, inclusive.
539 * 541 *
540 * Throws [RangeError] if [byteOffset] is negative, or 542 * Throws [RangeError] if [byteOffset] is negative, or
541 * `byteOffset + 2` is greater than the length of this object. 543 * `byteOffset + 2` is greater than the length of this object.
542 */ 544 */
543 int getUint16(int byteOffset, [Endianness endian=Endianness.BIG_ENDIAN]) => 545 int getUint16(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) =>
544 _getUint16(byteOffset, Endianness.LITTLE_ENDIAN == endian); 546 _getUint16(byteOffset, Endianness.LITTLE_ENDIAN == endian);
545 547
546 @JSName('getUint16') 548 @JSName('getUint16')
547 @Returns('int') 549 @Returns('int')
548 int _getUint16(int byteOffset, [bool littleEndian]) native; 550 int _getUint16(int byteOffset, [bool littleEndian]) native ;
549 551
550 /** 552 /**
551 * Returns the positive integer represented by the four bytes starting 553 * Returns the positive integer represented by the four bytes starting
552 * at the specified [byteOffset] in this object, in unsigned binary 554 * at the specified [byteOffset] in this object, in unsigned binary
553 * form. 555 * form.
554 * The return value will be between 0 and 2<sup>32</sup> - 1, inclusive. 556 * The return value will be between 0 and 2<sup>32</sup> - 1, inclusive.
555 * 557 *
556 * Throws [RangeError] if [byteOffset] is negative, or 558 * Throws [RangeError] if [byteOffset] is negative, or
557 * `byteOffset + 4` is greater than the length of this object. 559 * `byteOffset + 4` is greater than the length of this object.
558 */ 560 */
559 int getUint32(int byteOffset, [Endianness endian=Endianness.BIG_ENDIAN]) => 561 int getUint32(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) =>
560 _getUint32(byteOffset, Endianness.LITTLE_ENDIAN == endian); 562 _getUint32(byteOffset, Endianness.LITTLE_ENDIAN == endian);
561 563
562 @JSName('getUint32') 564 @JSName('getUint32')
563 @Returns('int') 565 @Returns('int')
564 int _getUint32(int byteOffset, [bool littleEndian]) native; 566 int _getUint32(int byteOffset, [bool littleEndian]) native ;
565 567
566 /** 568 /**
567 * Returns the positive integer represented by the eight bytes starting 569 * Returns the positive integer represented by the eight bytes starting
568 * at the specified [byteOffset] in this object, in unsigned binary 570 * at the specified [byteOffset] in this object, in unsigned binary
569 * form. 571 * form.
570 * The return value will be between 0 and 2<sup>64</sup> - 1, inclusive. 572 * The return value will be between 0 and 2<sup>64</sup> - 1, inclusive.
571 * 573 *
572 * Throws [RangeError] if [byteOffset] is negative, or 574 * Throws [RangeError] if [byteOffset] is negative, or
573 * `byteOffset + 8` is greater than the length of this object. 575 * `byteOffset + 8` is greater than the length of this object.
574 */ 576 */
575 int getUint64(int byteOffset, [Endianness endian=Endianness.BIG_ENDIAN]) { 577 int getUint64(int byteOffset, [Endianness endian = Endianness.BIG_ENDIAN]) {
576 throw new UnsupportedError('Uint64 accessor not supported by dart2js.'); 578 throw new UnsupportedError('Uint64 accessor not supported by dart2js.');
577 } 579 }
578 580
579 /** 581 /**
580 * Returns the positive integer represented by the byte at the specified 582 * Returns the positive integer represented by the byte at the specified
581 * [byteOffset] in this object, in unsigned binary form. The 583 * [byteOffset] in this object, in unsigned binary form. The
582 * return value will be between 0 and 255, inclusive. 584 * return value will be between 0 and 255, inclusive.
583 * 585 *
584 * Throws [RangeError] if [byteOffset] is negative, or 586 * Throws [RangeError] if [byteOffset] is negative, or
585 * greater than or equal to the length of this object. 587 * greater than or equal to the length of this object.
586 */ 588 */
587 int getUint8(int byteOffset) native; 589 int getUint8(int byteOffset) native ;
588 590
589 /** 591 /**
590 * Sets the four bytes starting at the specified [byteOffset] in this 592 * Sets the four bytes starting at the specified [byteOffset] in this
591 * object to the IEEE 754 single-precision binary floating-point 593 * object to the IEEE 754 single-precision binary floating-point
592 * (binary32) representation of the specified [value]. 594 * (binary32) representation of the specified [value].
593 * 595 *
594 * **Note that this method can lose precision.** The input [value] is 596 * **Note that this method can lose precision.** The input [value] is
595 * a 64-bit floating point value, which will be converted to 32-bit 597 * a 64-bit floating point value, which will be converted to 32-bit
596 * floating point value by IEEE 754 rounding rules before it is stored. 598 * floating point value by IEEE 754 rounding rules before it is stored.
597 * If [value] cannot be represented exactly as a binary32, it will be 599 * If [value] cannot be represented exactly as a binary32, it will be
598 * converted to the nearest binary32 value. If two binary32 values are 600 * converted to the nearest binary32 value. If two binary32 values are
599 * equally close, the one whose least significant bit is zero will be used. 601 * equally close, the one whose least significant bit is zero will be used.
600 * Note that finite (but large) values can be converted to infinity, and 602 * Note that finite (but large) values can be converted to infinity, and
601 * small non-zero values can be converted to zero. 603 * small non-zero values can be converted to zero.
602 * 604 *
603 * Throws [RangeError] if [byteOffset] is negative, or 605 * Throws [RangeError] if [byteOffset] is negative, or
604 * `byteOffset + 4` is greater than the length of this object. 606 * `byteOffset + 4` is greater than the length of this object.
605 */ 607 */
606 void setFloat32(int byteOffset, num value, 608 void setFloat32(int byteOffset, num value,
607 [Endianness endian=Endianness.BIG_ENDIAN]) => 609 [Endianness endian = Endianness.BIG_ENDIAN]) =>
608 _setFloat32(byteOffset, value, Endianness.LITTLE_ENDIAN == endian); 610 _setFloat32(byteOffset, value, Endianness.LITTLE_ENDIAN == endian);
609 611
610 @JSName('setFloat32') 612 @JSName('setFloat32')
611 void _setFloat32(int byteOffset, num value, [bool littleEndian]) native; 613 void _setFloat32(int byteOffset, num value, [bool littleEndian]) native ;
612 614
613 /** 615 /**
614 * Sets the eight bytes starting at the specified [byteOffset] in this 616 * Sets the eight bytes starting at the specified [byteOffset] in this
615 * object to the IEEE 754 double-precision binary floating-point 617 * object to the IEEE 754 double-precision binary floating-point
616 * (binary64) representation of the specified [value]. 618 * (binary64) representation of the specified [value].
617 * 619 *
618 * Throws [RangeError] if [byteOffset] is negative, or 620 * Throws [RangeError] if [byteOffset] is negative, or
619 * `byteOffset + 8` is greater than the length of this object. 621 * `byteOffset + 8` is greater than the length of this object.
620 */ 622 */
621 void setFloat64(int byteOffset, num value, 623 void setFloat64(int byteOffset, num value,
622 [Endianness endian=Endianness.BIG_ENDIAN]) => 624 [Endianness endian = Endianness.BIG_ENDIAN]) =>
623 _setFloat64(byteOffset, value, Endianness.LITTLE_ENDIAN == endian); 625 _setFloat64(byteOffset, value, Endianness.LITTLE_ENDIAN == endian);
624 626
625 @JSName('setFloat64') 627 @JSName('setFloat64')
626 void _setFloat64(int byteOffset, num value, [bool littleEndian]) native; 628 void _setFloat64(int byteOffset, num value, [bool littleEndian]) native ;
627 629
628 /** 630 /**
629 * Sets the two bytes starting at the specified [byteOffset] in this 631 * Sets the two bytes starting at the specified [byteOffset] in this
630 * object to the two's complement binary representation of the specified 632 * object to the two's complement binary representation of the specified
631 * [value], which must fit in two bytes. In other words, [value] must lie 633 * [value], which must fit in two bytes. In other words, [value] must lie
632 * between 2<sup>15</sup> and 2<sup>15</sup> - 1, inclusive. 634 * between 2<sup>15</sup> and 2<sup>15</sup> - 1, inclusive.
633 * 635 *
634 * Throws [RangeError] if [byteOffset] is negative, or 636 * Throws [RangeError] if [byteOffset] is negative, or
635 * `byteOffset + 2` is greater than the length of this object. 637 * `byteOffset + 2` is greater than the length of this object.
636 */ 638 */
637 void setInt16(int byteOffset, int value, 639 void setInt16(int byteOffset, int value,
638 [Endianness endian=Endianness.BIG_ENDIAN]) => 640 [Endianness endian = Endianness.BIG_ENDIAN]) =>
639 _setInt16(byteOffset, value, Endianness.LITTLE_ENDIAN == endian); 641 _setInt16(byteOffset, value, Endianness.LITTLE_ENDIAN == endian);
640 642
641 @JSName('setInt16') 643 @JSName('setInt16')
642 void _setInt16(int byteOffset, int value, [bool littleEndian]) native; 644 void _setInt16(int byteOffset, int value, [bool littleEndian]) native ;
643 645
644 /** 646 /**
645 * Sets the four bytes starting at the specified [byteOffset] in this 647 * Sets the four bytes starting at the specified [byteOffset] in this
646 * object to the two's complement binary representation of the specified 648 * object to the two's complement binary representation of the specified
647 * [value], which must fit in four bytes. In other words, [value] must lie 649 * [value], which must fit in four bytes. In other words, [value] must lie
648 * between 2<sup>31</sup> and 2<sup>31</sup> - 1, inclusive. 650 * between 2<sup>31</sup> and 2<sup>31</sup> - 1, inclusive.
649 * 651 *
650 * Throws [RangeError] if [byteOffset] is negative, or 652 * Throws [RangeError] if [byteOffset] is negative, or
651 * `byteOffset + 4` is greater than the length of this object. 653 * `byteOffset + 4` is greater than the length of this object.
652 */ 654 */
653 void setInt32(int byteOffset, int value, 655 void setInt32(int byteOffset, int value,
654 [Endianness endian=Endianness.BIG_ENDIAN]) => 656 [Endianness endian = Endianness.BIG_ENDIAN]) =>
655 _setInt32(byteOffset, value, Endianness.LITTLE_ENDIAN == endian); 657 _setInt32(byteOffset, value, Endianness.LITTLE_ENDIAN == endian);
656 658
657 @JSName('setInt32') 659 @JSName('setInt32')
658 void _setInt32(int byteOffset, int value, [bool littleEndian]) native; 660 void _setInt32(int byteOffset, int value, [bool littleEndian]) native ;
659 661
660 /** 662 /**
661 * Sets the eight bytes starting at the specified [byteOffset] in this 663 * Sets the eight bytes starting at the specified [byteOffset] in this
662 * object to the two's complement binary representation of the specified 664 * object to the two's complement binary representation of the specified
663 * [value], which must fit in eight bytes. In other words, [value] must lie 665 * [value], which must fit in eight bytes. In other words, [value] must lie
664 * between 2<sup>63</sup> and 2<sup>63</sup> - 1, inclusive. 666 * between 2<sup>63</sup> and 2<sup>63</sup> - 1, inclusive.
665 * 667 *
666 * Throws [RangeError] if [byteOffset] is negative, or 668 * Throws [RangeError] if [byteOffset] is negative, or
667 * `byteOffset + 8` is greater than the length of this object. 669 * `byteOffset + 8` is greater than the length of this object.
668 */ 670 */
669 void setInt64(int byteOffset, int value, 671 void setInt64(int byteOffset, int value,
670 [Endianness endian=Endianness.BIG_ENDIAN]) { 672 [Endianness endian = Endianness.BIG_ENDIAN]) {
671 throw new UnsupportedError('Int64 accessor not supported by dart2js.'); 673 throw new UnsupportedError('Int64 accessor not supported by dart2js.');
672 } 674 }
673 675
674 /** 676 /**
675 * Sets the byte at the specified [byteOffset] in this object to the 677 * Sets the byte at the specified [byteOffset] in this object to the
676 * two's complement binary representation of the specified [value], which 678 * two's complement binary representation of the specified [value], which
677 * must fit in a single byte. In other words, [value] must be between 679 * must fit in a single byte. In other words, [value] must be between
678 * -128 and 127, inclusive. 680 * -128 and 127, inclusive.
679 * 681 *
680 * Throws [RangeError] if [byteOffset] is negative, or 682 * Throws [RangeError] if [byteOffset] is negative, or
681 * greater than or equal to the length of this object. 683 * greater than or equal to the length of this object.
682 */ 684 */
683 void setInt8(int byteOffset, int value) native; 685 void setInt8(int byteOffset, int value) native ;
684 686
685 /** 687 /**
686 * Sets the two bytes starting at the specified [byteOffset] in this object 688 * Sets the two bytes starting at the specified [byteOffset] in this object
687 * to the unsigned binary representation of the specified [value], 689 * to the unsigned binary representation of the specified [value],
688 * which must fit in two bytes. in other words, [value] must be between 690 * which must fit in two bytes. in other words, [value] must be between
689 * 0 and 2<sup>16</sup> - 1, inclusive. 691 * 0 and 2<sup>16</sup> - 1, inclusive.
690 * 692 *
691 * Throws [RangeError] if [byteOffset] is negative, or 693 * Throws [RangeError] if [byteOffset] is negative, or
692 * `byteOffset + 2` is greater than the length of this object. 694 * `byteOffset + 2` is greater than the length of this object.
693 */ 695 */
694 void setUint16(int byteOffset, int value, 696 void setUint16(int byteOffset, int value,
695 [Endianness endian=Endianness.BIG_ENDIAN]) => 697 [Endianness endian = Endianness.BIG_ENDIAN]) =>
696 _setUint16(byteOffset, value, Endianness.LITTLE_ENDIAN == endian); 698 _setUint16(byteOffset, value, Endianness.LITTLE_ENDIAN == endian);
697 699
698 @JSName('setUint16') 700 @JSName('setUint16')
699 void _setUint16(int byteOffset, int value, [bool littleEndian]) native; 701 void _setUint16(int byteOffset, int value, [bool littleEndian]) native ;
700 702
701 /** 703 /**
702 * Sets the four bytes starting at the specified [byteOffset] in this object 704 * Sets the four bytes starting at the specified [byteOffset] in this object
703 * to the unsigned binary representation of the specified [value], 705 * to the unsigned binary representation of the specified [value],
704 * which must fit in four bytes. in other words, [value] must be between 706 * which must fit in four bytes. in other words, [value] must be between
705 * 0 and 2<sup>32</sup> - 1, inclusive. 707 * 0 and 2<sup>32</sup> - 1, inclusive.
706 * 708 *
707 * Throws [RangeError] if [byteOffset] is negative, or 709 * Throws [RangeError] if [byteOffset] is negative, or
708 * `byteOffset + 4` is greater than the length of this object. 710 * `byteOffset + 4` is greater than the length of this object.
709 */ 711 */
710 void setUint32(int byteOffset, int value, 712 void setUint32(int byteOffset, int value,
711 [Endianness endian=Endianness.BIG_ENDIAN]) => 713 [Endianness endian = Endianness.BIG_ENDIAN]) =>
712 _setUint32(byteOffset, value, Endianness.LITTLE_ENDIAN == endian); 714 _setUint32(byteOffset, value, Endianness.LITTLE_ENDIAN == endian);
713 715
714 @JSName('setUint32') 716 @JSName('setUint32')
715 void _setUint32(int byteOffset, int value, [bool littleEndian]) native; 717 void _setUint32(int byteOffset, int value, [bool littleEndian]) native ;
716 718
717 /** 719 /**
718 * Sets the eight bytes starting at the specified [byteOffset] in this object 720 * Sets the eight bytes starting at the specified [byteOffset] in this object
719 * to the unsigned binary representation of the specified [value], 721 * to the unsigned binary representation of the specified [value],
720 * which must fit in eight bytes. in other words, [value] must be between 722 * which must fit in eight bytes. in other words, [value] must be between
721 * 0 and 2<sup>64</sup> - 1, inclusive. 723 * 0 and 2<sup>64</sup> - 1, inclusive.
722 * 724 *
723 * Throws [RangeError] if [byteOffset] is negative, or 725 * Throws [RangeError] if [byteOffset] is negative, or
724 * `byteOffset + 8` is greater than the length of this object. 726 * `byteOffset + 8` is greater than the length of this object.
725 */ 727 */
726 void setUint64(int byteOffset, int value, 728 void setUint64(int byteOffset, int value,
727 [Endianness endian=Endianness.BIG_ENDIAN]) { 729 [Endianness endian = Endianness.BIG_ENDIAN]) {
728 throw new UnsupportedError('Uint64 accessor not supported by dart2js.'); 730 throw new UnsupportedError('Uint64 accessor not supported by dart2js.');
729 } 731 }
730 732
731 /** 733 /**
732 * Sets the byte at the specified [byteOffset] in this object to the 734 * Sets the byte at the specified [byteOffset] in this object to the
733 * unsigned binary representation of the specified [value], which must fit 735 * unsigned binary representation of the specified [value], which must fit
734 * in a single byte. in other words, [value] must be between 0 and 255, 736 * in a single byte. in other words, [value] must be between 0 and 255,
735 * inclusive. 737 * inclusive.
736 * 738 *
737 * Throws [RangeError] if [byteOffset] is negative, 739 * Throws [RangeError] if [byteOffset] is negative,
738 * or greater than or equal to the length of this object. 740 * or greater than or equal to the length of this object.
739 */ 741 */
740 void setUint8(int byteOffset, int value) native; 742 void setUint8(int byteOffset, int value) native ;
741 743
742 static NativeByteData _create1(arg) => 744 static NativeByteData _create1(arg) =>
743 JS('NativeByteData', 'new DataView(new ArrayBuffer(#))', arg); 745 JS('NativeByteData', 'new DataView(new ArrayBuffer(#))', arg);
744 746
745 static NativeByteData _create2(arg1, arg2) => 747 static NativeByteData _create2(arg1, arg2) =>
746 JS('NativeByteData', 'new DataView(#, #)', arg1, arg2); 748 JS('NativeByteData', 'new DataView(#, #)', arg1, arg2);
747 749
748 static NativeByteData _create3(arg1, arg2, arg3) => 750 static NativeByteData _create3(arg1, arg2, arg3) =>
749 JS('NativeByteData', 'new DataView(#, #, #)', arg1, arg2, arg3); 751 JS('NativeByteData', 'new DataView(#, #, #)', arg1, arg2, arg3);
750 } 752 }
751 753
752
753 abstract class NativeTypedArray extends NativeTypedData 754 abstract class NativeTypedArray extends NativeTypedData
754 implements JavaScriptIndexingBehavior { 755 implements JavaScriptIndexingBehavior {
755 int get length; 756 int get length;
756 757
757 void _setRangeFast(int start, int end, 758 void _setRangeFast(
758 NativeTypedArray source, int skipCount) { 759 int start, int end, NativeTypedArray source, int skipCount) {
759 int targetLength = this.length; 760 int targetLength = this.length;
760 _checkPosition(start, targetLength, "start"); 761 _checkPosition(start, targetLength, "start");
761 _checkPosition(end, targetLength, "end"); 762 _checkPosition(end, targetLength, "end");
762 if (start > end) throw new RangeError.range(start, 0, end); 763 if (start > end) throw new RangeError.range(start, 0, end);
763 int count = end - start; 764 int count = end - start;
764 765
765 if (skipCount < 0) throw new ArgumentError(skipCount); 766 if (skipCount < 0) throw new ArgumentError(skipCount);
766 767
767 int sourceLength = source.length; 768 int sourceLength = source.length;
768 if (sourceLength - skipCount < count) { 769 if (sourceLength - skipCount < count) {
769 throw new StateError('Not enough elements'); 770 throw new StateError('Not enough elements');
770 } 771 }
771 772
772 if (skipCount != 0 || sourceLength != count) { 773 if (skipCount != 0 || sourceLength != count) {
773 // Create a view of the exact subrange that is copied from the source. 774 // Create a view of the exact subrange that is copied from the source.
774 source = JS('', '#.subarray(#, #)', 775 source = JS('', '#.subarray(#, #)', source, skipCount, skipCount + count);
775 source, skipCount, skipCount + count);
776 } 776 }
777 JS('void', '#.set(#, #)', this, source, start); 777 JS('void', '#.set(#, #)', this, source, start);
778 } 778 }
779 } 779 }
780 780
781 abstract class NativeTypedArrayOfDouble 781 abstract class NativeTypedArrayOfDouble extends NativeTypedArray
782 extends NativeTypedArray 782 with ListMixin<double>, FixedLengthListMixin<double> {
783 with ListMixin<double>, FixedLengthListMixin<double> {
784
785 int get length => JS('int', '#.length', this); 783 int get length => JS('int', '#.length', this);
786 784
787 double operator[](int index) { 785 double operator [](int index) {
788 _checkValidIndex(index, this, this.length); 786 _checkValidIndex(index, this, this.length);
789 return JS('double', '#[#]', this, index); 787 return JS('double', '#[#]', this, index);
790 } 788 }
791 789
792 void operator[]=(int index, num value) { 790 void operator []=(int index, num value) {
793 _checkValidIndex(index, this, this.length); 791 _checkValidIndex(index, this, this.length);
794 JS('void', '#[#] = #', this, index, value); 792 JS('void', '#[#] = #', this, index, value);
795 } 793 }
796 794
797 void setRange(int start, int end, Iterable<double> iterable, 795 void setRange(int start, int end, Iterable<double> iterable,
798 [int skipCount = 0]) { 796 [int skipCount = 0]) {
799 if (iterable is NativeTypedArrayOfDouble) { 797 if (iterable is NativeTypedArrayOfDouble) {
800 _setRangeFast(start, end, iterable, skipCount); 798 _setRangeFast(start, end, iterable, skipCount);
801 return; 799 return;
802 } 800 }
803 super.setRange(start, end, iterable, skipCount); 801 super.setRange(start, end, iterable, skipCount);
804 } 802 }
805 } 803 }
806 804
807 abstract class NativeTypedArrayOfInt 805 abstract class NativeTypedArrayOfInt extends NativeTypedArray
808 extends NativeTypedArray 806 with ListMixin<int>, FixedLengthListMixin<int>
809 with ListMixin<int>, FixedLengthListMixin<int>
810 implements List<int> { 807 implements List<int> {
811
812 int get length => JS('int', '#.length', this); 808 int get length => JS('int', '#.length', this);
813 809
814 // operator[]() is not here since different versions have different return 810 // operator[]() is not here since different versions have different return
815 // types 811 // types
816 812
817 void operator[]=(int index, int value) { 813 void operator []=(int index, int value) {
818 _checkValidIndex(index, this, this.length); 814 _checkValidIndex(index, this, this.length);
819 JS('void', '#[#] = #', this, index, value); 815 JS('void', '#[#] = #', this, index, value);
820 } 816 }
821 817
822 void setRange(int start, int end, Iterable<int> iterable, 818 void setRange(int start, int end, Iterable<int> iterable,
823 [int skipCount = 0]) { 819 [int skipCount = 0]) {
824 if (iterable is NativeTypedArrayOfInt) { 820 if (iterable is NativeTypedArrayOfInt) {
825 _setRangeFast(start, end, iterable, skipCount); 821 _setRangeFast(start, end, iterable, skipCount);
826 return; 822 return;
827 } 823 }
828 super.setRange(start, end, iterable, skipCount); 824 super.setRange(start, end, iterable, skipCount);
829 } 825 }
830 } 826 }
831 827
832
833 @Native("Float32Array") 828 @Native("Float32Array")
834 class NativeFloat32List 829 class NativeFloat32List extends NativeTypedArrayOfDouble
835 extends NativeTypedArrayOfDouble
836 implements Float32List { 830 implements Float32List {
837
838 factory NativeFloat32List(int length) => _create1(_checkLength(length)); 831 factory NativeFloat32List(int length) => _create1(_checkLength(length));
839 832
840 factory NativeFloat32List.fromList(List<double> elements) => 833 factory NativeFloat32List.fromList(List<double> elements) =>
841 _create1(_ensureNativeList(elements)); 834 _create1(_ensureNativeList(elements));
842 835
843 factory NativeFloat32List.view(ByteBuffer buffer, 836 factory NativeFloat32List.view(
844 int offsetInBytes, int length) { 837 ByteBuffer buffer, int offsetInBytes, int length) {
845 _checkViewArguments(buffer, offsetInBytes, length); 838 _checkViewArguments(buffer, offsetInBytes, length);
846 return length == null 839 return length == null
847 ? _create2(buffer, offsetInBytes) 840 ? _create2(buffer, offsetInBytes)
848 : _create3(buffer, offsetInBytes, length); 841 : _create3(buffer, offsetInBytes, length);
849 } 842 }
850 843
851 Type get runtimeType => Float32List; 844 Type get runtimeType => Float32List;
852 845
853 List<double> sublist(int start, [int end]) { 846 List<double> sublist(int start, [int end]) {
854 end = _checkValidRange(start, end, this.length); 847 end = _checkValidRange(start, end, this.length);
855 var source = JS('NativeFloat32List', '#.subarray(#, #)', this, start, end); 848 var source = JS('NativeFloat32List', '#.subarray(#, #)', this, start, end);
856 return _create1(source); 849 return _create1(source);
857 } 850 }
858 851
859 static NativeFloat32List _create1(arg) => 852 static NativeFloat32List _create1(arg) =>
860 JS('NativeFloat32List', 'new Float32Array(#)', arg); 853 JS('NativeFloat32List', 'new Float32Array(#)', arg);
861 854
862 static NativeFloat32List _create2(arg1, arg2) => 855 static NativeFloat32List _create2(arg1, arg2) =>
863 JS('NativeFloat32List', 'new Float32Array(#, #)', arg1, arg2); 856 JS('NativeFloat32List', 'new Float32Array(#, #)', arg1, arg2);
864 857
865 static NativeFloat32List _create3(arg1, arg2, arg3) => 858 static NativeFloat32List _create3(arg1, arg2, arg3) =>
866 JS('NativeFloat32List', 'new Float32Array(#, #, #)', arg1, arg2, arg3); 859 JS('NativeFloat32List', 'new Float32Array(#, #, #)', arg1, arg2, arg3);
867 } 860 }
868 861
869
870 @Native("Float64Array") 862 @Native("Float64Array")
871 class NativeFloat64List 863 class NativeFloat64List extends NativeTypedArrayOfDouble
872 extends NativeTypedArrayOfDouble
873 implements Float64List { 864 implements Float64List {
874
875 factory NativeFloat64List(int length) => _create1(_checkLength(length)); 865 factory NativeFloat64List(int length) => _create1(_checkLength(length));
876 866
877 factory NativeFloat64List.fromList(List<double> elements) => 867 factory NativeFloat64List.fromList(List<double> elements) =>
878 _create1(_ensureNativeList(elements)); 868 _create1(_ensureNativeList(elements));
879 869
880 factory NativeFloat64List.view(ByteBuffer buffer, 870 factory NativeFloat64List.view(
881 int offsetInBytes, int length) { 871 ByteBuffer buffer, int offsetInBytes, int length) {
882 _checkViewArguments(buffer, offsetInBytes, length); 872 _checkViewArguments(buffer, offsetInBytes, length);
883 return length == null 873 return length == null
884 ? _create2(buffer, offsetInBytes) 874 ? _create2(buffer, offsetInBytes)
885 : _create3(buffer, offsetInBytes, length); 875 : _create3(buffer, offsetInBytes, length);
886 } 876 }
887 877
888 Type get runtimeType => Float64List; 878 Type get runtimeType => Float64List;
889 879
890 List<double> sublist(int start, [int end]) { 880 List<double> sublist(int start, [int end]) {
891 end = _checkValidRange(start, end, this.length); 881 end = _checkValidRange(start, end, this.length);
892 var source = JS('NativeFloat64List', '#.subarray(#, #)', this, start, end); 882 var source = JS('NativeFloat64List', '#.subarray(#, #)', this, start, end);
893 return _create1(source); 883 return _create1(source);
894 } 884 }
895 885
896 static NativeFloat64List _create1(arg) => 886 static NativeFloat64List _create1(arg) =>
897 JS('NativeFloat64List', 'new Float64Array(#)', arg); 887 JS('NativeFloat64List', 'new Float64Array(#)', arg);
898 888
899 static NativeFloat64List _create2(arg1, arg2) => 889 static NativeFloat64List _create2(arg1, arg2) =>
900 JS('NativeFloat64List', 'new Float64Array(#, #)', arg1, arg2); 890 JS('NativeFloat64List', 'new Float64Array(#, #)', arg1, arg2);
901 891
902 static NativeFloat64List _create3(arg1, arg2, arg3) => 892 static NativeFloat64List _create3(arg1, arg2, arg3) =>
903 JS('NativeFloat64List', 'new Float64Array(#, #, #)', arg1, arg2, arg3); 893 JS('NativeFloat64List', 'new Float64Array(#, #, #)', arg1, arg2, arg3);
904 } 894 }
905 895
906
907 @Native("Int16Array") 896 @Native("Int16Array")
908 class NativeInt16List 897 class NativeInt16List extends NativeTypedArrayOfInt implements Int16List {
909 extends NativeTypedArrayOfInt
910 implements Int16List {
911
912 factory NativeInt16List(int length) => _create1(_checkLength(length)); 898 factory NativeInt16List(int length) => _create1(_checkLength(length));
913 899
914 factory NativeInt16List.fromList(List<int> elements) => 900 factory NativeInt16List.fromList(List<int> elements) =>
915 _create1(_ensureNativeList(elements)); 901 _create1(_ensureNativeList(elements));
916 902
917 factory NativeInt16List.view(NativeByteBuffer buffer, 903 factory NativeInt16List.view(
918 int offsetInBytes, int length) { 904 NativeByteBuffer buffer, int offsetInBytes, int length) {
919 _checkViewArguments(buffer, offsetInBytes, length); 905 _checkViewArguments(buffer, offsetInBytes, length);
920 return length == null 906 return length == null
921 ? _create2(buffer, offsetInBytes) 907 ? _create2(buffer, offsetInBytes)
922 : _create3(buffer, offsetInBytes, length); 908 : _create3(buffer, offsetInBytes, length);
923 } 909 }
924 910
925 Type get runtimeType => Int16List; 911 Type get runtimeType => Int16List;
926 912
927 int operator[](int index) { 913 int operator [](int index) {
928 _checkValidIndex(index, this, this.length); 914 _checkValidIndex(index, this, this.length);
929 return JS('int', '#[#]', this, index); 915 return JS('int', '#[#]', this, index);
930 } 916 }
931 917
932 List<int> sublist(int start, [int end]) { 918 List<int> sublist(int start, [int end]) {
933 end = _checkValidRange(start, end, this.length); 919 end = _checkValidRange(start, end, this.length);
934 var source = JS('NativeInt16List', '#.subarray(#, #)', this, start, end); 920 var source = JS('NativeInt16List', '#.subarray(#, #)', this, start, end);
935 return _create1(source); 921 return _create1(source);
936 } 922 }
937 923
938 static NativeInt16List _create1(arg) => 924 static NativeInt16List _create1(arg) =>
939 JS('NativeInt16List', 'new Int16Array(#)', arg); 925 JS('NativeInt16List', 'new Int16Array(#)', arg);
940 926
941 static NativeInt16List _create2(arg1, arg2) => 927 static NativeInt16List _create2(arg1, arg2) =>
942 JS('NativeInt16List', 'new Int16Array(#, #)', arg1, arg2); 928 JS('NativeInt16List', 'new Int16Array(#, #)', arg1, arg2);
943 929
944 static NativeInt16List _create3(arg1, arg2, arg3) => 930 static NativeInt16List _create3(arg1, arg2, arg3) =>
945 JS('NativeInt16List', 'new Int16Array(#, #, #)', arg1, arg2, arg3); 931 JS('NativeInt16List', 'new Int16Array(#, #, #)', arg1, arg2, arg3);
946 } 932 }
947 933
948
949 @Native("Int32Array") 934 @Native("Int32Array")
950 class NativeInt32List extends NativeTypedArrayOfInt implements Int32List { 935 class NativeInt32List extends NativeTypedArrayOfInt implements Int32List {
951
952 factory NativeInt32List(int length) => _create1(_checkLength(length)); 936 factory NativeInt32List(int length) => _create1(_checkLength(length));
953 937
954 factory NativeInt32List.fromList(List<int> elements) => 938 factory NativeInt32List.fromList(List<int> elements) =>
955 _create1(_ensureNativeList(elements)); 939 _create1(_ensureNativeList(elements));
956 940
957 factory NativeInt32List.view(ByteBuffer buffer, 941 factory NativeInt32List.view(
958 int offsetInBytes, int length) { 942 ByteBuffer buffer, int offsetInBytes, int length) {
959 _checkViewArguments(buffer, offsetInBytes, length); 943 _checkViewArguments(buffer, offsetInBytes, length);
960 return length == null 944 return length == null
961 ? _create2(buffer, offsetInBytes) 945 ? _create2(buffer, offsetInBytes)
962 : _create3(buffer, offsetInBytes, length); 946 : _create3(buffer, offsetInBytes, length);
963 } 947 }
964 948
965 Type get runtimeType => Int32List; 949 Type get runtimeType => Int32List;
966 950
967 int operator[](int index) { 951 int operator [](int index) {
968 _checkValidIndex(index, this, this.length); 952 _checkValidIndex(index, this, this.length);
969 return JS('int', '#[#]', this, index); 953 return JS('int', '#[#]', this, index);
970 } 954 }
971 955
972 List<int> sublist(int start, [int end]) { 956 List<int> sublist(int start, [int end]) {
973 end = _checkValidRange(start, end, this.length); 957 end = _checkValidRange(start, end, this.length);
974 var source = JS('NativeInt32List', '#.subarray(#, #)', this, start, end); 958 var source = JS('NativeInt32List', '#.subarray(#, #)', this, start, end);
975 return _create1(source); 959 return _create1(source);
976 } 960 }
977 961
978 static NativeInt32List _create1(arg) => 962 static NativeInt32List _create1(arg) =>
979 JS('NativeInt32List', 'new Int32Array(#)', arg); 963 JS('NativeInt32List', 'new Int32Array(#)', arg);
980 964
981 static NativeInt32List _create2(arg1, arg2) => 965 static NativeInt32List _create2(arg1, arg2) =>
982 JS('NativeInt32List', 'new Int32Array(#, #)', arg1, arg2); 966 JS('NativeInt32List', 'new Int32Array(#, #)', arg1, arg2);
983 967
984 static NativeInt32List _create3(arg1, arg2, arg3) => 968 static NativeInt32List _create3(arg1, arg2, arg3) =>
985 JS('NativeInt32List', 'new Int32Array(#, #, #)', arg1, arg2, arg3); 969 JS('NativeInt32List', 'new Int32Array(#, #, #)', arg1, arg2, arg3);
986 } 970 }
987 971
988
989 @Native("Int8Array") 972 @Native("Int8Array")
990 class NativeInt8List extends NativeTypedArrayOfInt implements Int8List { 973 class NativeInt8List extends NativeTypedArrayOfInt implements Int8List {
991
992 factory NativeInt8List(int length) => _create1(_checkLength(length)); 974 factory NativeInt8List(int length) => _create1(_checkLength(length));
993 975
994 factory NativeInt8List.fromList(List<int> elements) => 976 factory NativeInt8List.fromList(List<int> elements) =>
995 _create1(_ensureNativeList(elements)); 977 _create1(_ensureNativeList(elements));
996 978
997 factory NativeInt8List.view(ByteBuffer buffer, 979 factory NativeInt8List.view(
998 int offsetInBytes, int length) { 980 ByteBuffer buffer, int offsetInBytes, int length) {
999 _checkViewArguments(buffer, offsetInBytes, length); 981 _checkViewArguments(buffer, offsetInBytes, length);
1000 return length == null 982 return length == null
1001 ? _create2(buffer, offsetInBytes) 983 ? _create2(buffer, offsetInBytes)
1002 : _create3(buffer, offsetInBytes, length); 984 : _create3(buffer, offsetInBytes, length);
1003 } 985 }
1004 986
1005 Type get runtimeType => Int8List; 987 Type get runtimeType => Int8List;
1006 988
1007 int operator[](int index) { 989 int operator [](int index) {
1008 _checkValidIndex(index, this, this.length); 990 _checkValidIndex(index, this, this.length);
1009 return JS('int', '#[#]', this, index); 991 return JS('int', '#[#]', this, index);
1010 } 992 }
1011 993
1012 List<int> sublist(int start, [int end]) { 994 List<int> sublist(int start, [int end]) {
1013 end = _checkValidRange(start, end, this.length); 995 end = _checkValidRange(start, end, this.length);
1014 var source = JS('NativeInt8List', '#.subarray(#, #)', this, start, end); 996 var source = JS('NativeInt8List', '#.subarray(#, #)', this, start, end);
1015 return _create1(source); 997 return _create1(source);
1016 } 998 }
1017 999
1018 static NativeInt8List _create1(arg) => 1000 static NativeInt8List _create1(arg) =>
1019 JS('NativeInt8List', 'new Int8Array(#)', arg); 1001 JS('NativeInt8List', 'new Int8Array(#)', arg);
1020 1002
1021 static NativeInt8List _create2(arg1, arg2) => 1003 static NativeInt8List _create2(arg1, arg2) =>
1022 JS('NativeInt8List', 'new Int8Array(#, #)', arg1, arg2); 1004 JS('NativeInt8List', 'new Int8Array(#, #)', arg1, arg2);
1023 1005
1024 static Int8List _create3(arg1, arg2, arg3) => 1006 static Int8List _create3(arg1, arg2, arg3) =>
1025 JS('NativeInt8List', 'new Int8Array(#, #, #)', arg1, arg2, arg3); 1007 JS('NativeInt8List', 'new Int8Array(#, #, #)', arg1, arg2, arg3);
1026 } 1008 }
1027 1009
1028
1029 @Native("Uint16Array") 1010 @Native("Uint16Array")
1030 class NativeUint16List extends NativeTypedArrayOfInt implements Uint16List { 1011 class NativeUint16List extends NativeTypedArrayOfInt implements Uint16List {
1031
1032 factory NativeUint16List(int length) => _create1(_checkLength(length)); 1012 factory NativeUint16List(int length) => _create1(_checkLength(length));
1033 1013
1034 factory NativeUint16List.fromList(List<int> list) => 1014 factory NativeUint16List.fromList(List<int> list) =>
1035 _create1(_ensureNativeList(list)); 1015 _create1(_ensureNativeList(list));
1036 1016
1037 factory NativeUint16List.view(ByteBuffer buffer, 1017 factory NativeUint16List.view(
1038 int offsetInBytes, int length) { 1018 ByteBuffer buffer, int offsetInBytes, int length) {
1039 _checkViewArguments(buffer, offsetInBytes, length); 1019 _checkViewArguments(buffer, offsetInBytes, length);
1040 return length == null 1020 return length == null
1041 ? _create2(buffer, offsetInBytes) 1021 ? _create2(buffer, offsetInBytes)
1042 : _create3(buffer, offsetInBytes, length); 1022 : _create3(buffer, offsetInBytes, length);
1043 } 1023 }
1044 1024
1045 Type get runtimeType => Uint16List; 1025 Type get runtimeType => Uint16List;
1046 1026
1047 int operator[](int index) { 1027 int operator [](int index) {
1048 _checkValidIndex(index, this, this.length); 1028 _checkValidIndex(index, this, this.length);
1049 return JS('int', '#[#]', this, index); 1029 return JS('int', '#[#]', this, index);
1050 } 1030 }
1051 1031
1052 List<int> sublist(int start, [int end]) { 1032 List<int> sublist(int start, [int end]) {
1053 end = _checkValidRange(start, end, this.length); 1033 end = _checkValidRange(start, end, this.length);
1054 var source = JS('NativeUint16List', '#.subarray(#, #)', this, start, end); 1034 var source = JS('NativeUint16List', '#.subarray(#, #)', this, start, end);
1055 return _create1(source); 1035 return _create1(source);
1056 } 1036 }
1057 1037
1058 static NativeUint16List _create1(arg) => 1038 static NativeUint16List _create1(arg) =>
1059 JS('NativeUint16List', 'new Uint16Array(#)', arg); 1039 JS('NativeUint16List', 'new Uint16Array(#)', arg);
1060 1040
1061 static NativeUint16List _create2(arg1, arg2) => 1041 static NativeUint16List _create2(arg1, arg2) =>
1062 JS('NativeUint16List', 'new Uint16Array(#, #)', arg1, arg2); 1042 JS('NativeUint16List', 'new Uint16Array(#, #)', arg1, arg2);
1063 1043
1064 static NativeUint16List _create3(arg1, arg2, arg3) => 1044 static NativeUint16List _create3(arg1, arg2, arg3) =>
1065 JS('NativeUint16List', 'new Uint16Array(#, #, #)', arg1, arg2, arg3); 1045 JS('NativeUint16List', 'new Uint16Array(#, #, #)', arg1, arg2, arg3);
1066 } 1046 }
1067 1047
1068
1069 @Native("Uint32Array") 1048 @Native("Uint32Array")
1070 class NativeUint32List extends NativeTypedArrayOfInt implements Uint32List { 1049 class NativeUint32List extends NativeTypedArrayOfInt implements Uint32List {
1071
1072 factory NativeUint32List(int length) => _create1(_checkLength(length)); 1050 factory NativeUint32List(int length) => _create1(_checkLength(length));
1073 1051
1074 factory NativeUint32List.fromList(List<int> elements) => 1052 factory NativeUint32List.fromList(List<int> elements) =>
1075 _create1(_ensureNativeList(elements)); 1053 _create1(_ensureNativeList(elements));
1076 1054
1077 factory NativeUint32List.view(ByteBuffer buffer, 1055 factory NativeUint32List.view(
1078 int offsetInBytes, int length) { 1056 ByteBuffer buffer, int offsetInBytes, int length) {
1079 _checkViewArguments(buffer, offsetInBytes, length); 1057 _checkViewArguments(buffer, offsetInBytes, length);
1080 return length == null 1058 return length == null
1081 ? _create2(buffer, offsetInBytes) 1059 ? _create2(buffer, offsetInBytes)
1082 : _create3(buffer, offsetInBytes, length); 1060 : _create3(buffer, offsetInBytes, length);
1083 } 1061 }
1084 1062
1085 Type get runtimeType => Uint32List; 1063 Type get runtimeType => Uint32List;
1086 1064
1087 int operator[](int index) { 1065 int operator [](int index) {
1088 _checkValidIndex(index, this, this.length); 1066 _checkValidIndex(index, this, this.length);
1089 return JS('int', '#[#]', this, index); 1067 return JS('int', '#[#]', this, index);
1090 } 1068 }
1091 1069
1092 List<int> sublist(int start, [int end]) { 1070 List<int> sublist(int start, [int end]) {
1093 end = _checkValidRange(start, end, this.length); 1071 end = _checkValidRange(start, end, this.length);
1094 var source = JS('NativeUint32List', '#.subarray(#, #)', this, start, end); 1072 var source = JS('NativeUint32List', '#.subarray(#, #)', this, start, end);
1095 return _create1(source); 1073 return _create1(source);
1096 } 1074 }
1097 1075
1098 static NativeUint32List _create1(arg) => 1076 static NativeUint32List _create1(arg) =>
1099 JS('NativeUint32List', 'new Uint32Array(#)', arg); 1077 JS('NativeUint32List', 'new Uint32Array(#)', arg);
1100 1078
1101 static NativeUint32List _create2(arg1, arg2) => 1079 static NativeUint32List _create2(arg1, arg2) =>
1102 JS('NativeUint32List', 'new Uint32Array(#, #)', arg1, arg2); 1080 JS('NativeUint32List', 'new Uint32Array(#, #)', arg1, arg2);
1103 1081
1104 static NativeUint32List _create3(arg1, arg2, arg3) => 1082 static NativeUint32List _create3(arg1, arg2, arg3) =>
1105 JS('NativeUint32List', 'new Uint32Array(#, #, #)', arg1, arg2, arg3); 1083 JS('NativeUint32List', 'new Uint32Array(#, #, #)', arg1, arg2, arg3);
1106 } 1084 }
1107 1085
1108
1109 @Native("Uint8ClampedArray,CanvasPixelArray") 1086 @Native("Uint8ClampedArray,CanvasPixelArray")
1110 class NativeUint8ClampedList 1087 class NativeUint8ClampedList extends NativeTypedArrayOfInt
1111 extends NativeTypedArrayOfInt
1112 implements Uint8ClampedList { 1088 implements Uint8ClampedList {
1113
1114 factory NativeUint8ClampedList(int length) => _create1(_checkLength(length)); 1089 factory NativeUint8ClampedList(int length) => _create1(_checkLength(length));
1115 1090
1116 factory NativeUint8ClampedList.fromList(List<int> elements) => 1091 factory NativeUint8ClampedList.fromList(List<int> elements) =>
1117 _create1(_ensureNativeList(elements)); 1092 _create1(_ensureNativeList(elements));
1118 1093
1119 factory NativeUint8ClampedList.view(ByteBuffer buffer, 1094 factory NativeUint8ClampedList.view(
1120 int offsetInBytes, int length) { 1095 ByteBuffer buffer, int offsetInBytes, int length) {
1121 _checkViewArguments(buffer, offsetInBytes, length); 1096 _checkViewArguments(buffer, offsetInBytes, length);
1122 return length == null 1097 return length == null
1123 ? _create2(buffer, offsetInBytes) 1098 ? _create2(buffer, offsetInBytes)
1124 : _create3(buffer, offsetInBytes, length); 1099 : _create3(buffer, offsetInBytes, length);
1125 } 1100 }
1126 1101
1127 Type get runtimeType => Uint8ClampedList; 1102 Type get runtimeType => Uint8ClampedList;
1128 1103
1129 int get length => JS('int', '#.length', this); 1104 int get length => JS('int', '#.length', this);
1130 1105
1131 int operator[](int index) { 1106 int operator [](int index) {
1132 _checkValidIndex(index, this, this.length); 1107 _checkValidIndex(index, this, this.length);
1133 return JS('int', '#[#]', this, index); 1108 return JS('int', '#[#]', this, index);
1134 } 1109 }
1135 1110
1136 List<int> sublist(int start, [int end]) { 1111 List<int> sublist(int start, [int end]) {
1137 end = _checkValidRange(start, end, this.length); 1112 end = _checkValidRange(start, end, this.length);
1138 var source = JS('NativeUint8ClampedList', '#.subarray(#, #)', 1113 var source =
1139 this, start, end); 1114 JS('NativeUint8ClampedList', '#.subarray(#, #)', this, start, end);
1140 return _create1(source); 1115 return _create1(source);
1141 } 1116 }
1142 1117
1143 static NativeUint8ClampedList _create1(arg) => 1118 static NativeUint8ClampedList _create1(arg) =>
1144 JS('NativeUint8ClampedList', 'new Uint8ClampedArray(#)', arg); 1119 JS('NativeUint8ClampedList', 'new Uint8ClampedArray(#)', arg);
1145 1120
1146 static NativeUint8ClampedList _create2(arg1, arg2) => 1121 static NativeUint8ClampedList _create2(arg1, arg2) =>
1147 JS('NativeUint8ClampedList', 'new Uint8ClampedArray(#, #)', arg1, arg2); 1122 JS('NativeUint8ClampedList', 'new Uint8ClampedArray(#, #)', arg1, arg2);
1148 1123
1149 static NativeUint8ClampedList _create3(arg1, arg2, arg3) => 1124 static NativeUint8ClampedList _create3(arg1, arg2, arg3) => JS(
1150 JS('NativeUint8ClampedList', 'new Uint8ClampedArray(#, #, #)', 1125 'NativeUint8ClampedList',
1151 arg1, arg2, arg3); 1126 'new Uint8ClampedArray(#, #, #)',
1127 arg1,
1128 arg2,
1129 arg3);
1152 } 1130 }
1153 1131
1154
1155 // On some browsers Uint8ClampedArray is a subtype of Uint8Array. Marking 1132 // On some browsers Uint8ClampedArray is a subtype of Uint8Array. Marking
1156 // Uint8List as !nonleaf ensures that the native dispatch correctly handles 1133 // Uint8List as !nonleaf ensures that the native dispatch correctly handles
1157 // the potential for Uint8ClampedArray to 'accidentally' pick up the 1134 // the potential for Uint8ClampedArray to 'accidentally' pick up the
1158 // dispatch record for Uint8List. 1135 // dispatch record for Uint8List.
1159 @Native("Uint8Array,!nonleaf") 1136 @Native("Uint8Array,!nonleaf")
1160 class NativeUint8List extends NativeTypedArrayOfInt implements Uint8List { 1137 class NativeUint8List extends NativeTypedArrayOfInt implements Uint8List {
1161
1162 factory NativeUint8List(int length) => _create1(_checkLength(length)); 1138 factory NativeUint8List(int length) => _create1(_checkLength(length));
1163 1139
1164 factory NativeUint8List.fromList(List<int> elements) => 1140 factory NativeUint8List.fromList(List<int> elements) =>
1165 _create1(_ensureNativeList(elements)); 1141 _create1(_ensureNativeList(elements));
1166 1142
1167 factory NativeUint8List.view(ByteBuffer buffer, 1143 factory NativeUint8List.view(
1168 int offsetInBytes, int length) { 1144 ByteBuffer buffer, int offsetInBytes, int length) {
1169 _checkViewArguments(buffer, offsetInBytes, length); 1145 _checkViewArguments(buffer, offsetInBytes, length);
1170 return length == null 1146 return length == null
1171 ? _create2(buffer, offsetInBytes) 1147 ? _create2(buffer, offsetInBytes)
1172 : _create3(buffer, offsetInBytes, length); 1148 : _create3(buffer, offsetInBytes, length);
1173 } 1149 }
1174 1150
1175 Type get runtimeType => Uint8List; 1151 Type get runtimeType => Uint8List;
1176 1152
1177 int get length => JS('int', '#.length', this); 1153 int get length => JS('int', '#.length', this);
1178 1154
1179 int operator[](int index) { 1155 int operator [](int index) {
1180 _checkValidIndex(index, this, this.length); 1156 _checkValidIndex(index, this, this.length);
1181 return JS('int', '#[#]', this, index); 1157 return JS('int', '#[#]', this, index);
1182 } 1158 }
1183 1159
1184 List<int> sublist(int start, [int end]) { 1160 List<int> sublist(int start, [int end]) {
1185 end = _checkValidRange(start, end, this.length); 1161 end = _checkValidRange(start, end, this.length);
1186 var source = JS('NativeUint8List', '#.subarray(#, #)', this, start, end); 1162 var source = JS('NativeUint8List', '#.subarray(#, #)', this, start, end);
1187 return _create1(source); 1163 return _create1(source);
1188 } 1164 }
1189 1165
1190 static NativeUint8List _create1(arg) => 1166 static NativeUint8List _create1(arg) =>
1191 JS('NativeUint8List', 'new Uint8Array(#)', arg); 1167 JS('NativeUint8List', 'new Uint8Array(#)', arg);
1192 1168
1193 static NativeUint8List _create2(arg1, arg2) => 1169 static NativeUint8List _create2(arg1, arg2) =>
1194 JS('NativeUint8List', 'new Uint8Array(#, #)', arg1, arg2); 1170 JS('NativeUint8List', 'new Uint8Array(#, #)', arg1, arg2);
1195 1171
1196 static NativeUint8List _create3(arg1, arg2, arg3) => 1172 static NativeUint8List _create3(arg1, arg2, arg3) =>
1197 JS('NativeUint8List', 'new Uint8Array(#, #, #)', arg1, arg2, arg3); 1173 JS('NativeUint8List', 'new Uint8Array(#, #, #)', arg1, arg2, arg3);
1198 } 1174 }
1199 1175
1200
1201 /** 1176 /**
1202 * Implementation of Dart Float32x4 immutable value type and operations. 1177 * Implementation of Dart Float32x4 immutable value type and operations.
1203 * Float32x4 stores 4 32-bit floating point values in "lanes". 1178 * Float32x4 stores 4 32-bit floating point values in "lanes".
1204 * The lanes are "x", "y", "z", and "w" respectively. 1179 * The lanes are "x", "y", "z", and "w" respectively.
1205 */ 1180 */
1206 class NativeFloat32x4 implements Float32x4 { 1181 class NativeFloat32x4 implements Float32x4 {
1207 final double x; 1182 final double x;
1208 final double y; 1183 final double y;
1209 final double z; 1184 final double z;
1210 final double w; 1185 final double w;
1211 1186
1212 static final NativeFloat32List _list = new NativeFloat32List(4); 1187 static final NativeFloat32List _list = new NativeFloat32List(4);
1213 static final Uint32List _uint32view = _list.buffer.asUint32List(); 1188 static final Uint32List _uint32view = _list.buffer.asUint32List();
1214 1189
1215 static _truncate(x) { 1190 static _truncate(x) {
1216 _list[0] = x; 1191 _list[0] = x;
1217 return _list[0]; 1192 return _list[0];
1218 } 1193 }
1219 1194
1220 NativeFloat32x4(double x, double y, double z, double w) 1195 NativeFloat32x4(double x, double y, double z, double w)
1221 : this.x = _truncate(x), 1196 : this.x = _truncate(x),
1222 this.y = _truncate(y), 1197 this.y = _truncate(y),
1223 this.z = _truncate(z), 1198 this.z = _truncate(z),
1224 this.w = _truncate(w) { 1199 this.w = _truncate(w) {
1225 // We would prefer to check for `double` but in dart2js we can't see the 1200 // We would prefer to check for `double` but in dart2js we can't see the
1226 // difference anyway. 1201 // difference anyway.
1227 if (x is! num) throw new ArgumentError(x); 1202 if (x is! num) throw new ArgumentError(x);
1228 if (y is! num) throw new ArgumentError(y); 1203 if (y is! num) throw new ArgumentError(y);
1229 if (z is! num) throw new ArgumentError(z); 1204 if (z is! num) throw new ArgumentError(z);
1230 if (w is! num) throw new ArgumentError(w); 1205 if (w is! num) throw new ArgumentError(w);
1231 } 1206 }
1232 1207
1233 NativeFloat32x4.splat(double v) : this(v, v, v, v); 1208 NativeFloat32x4.splat(double v) : this(v, v, v, v);
1234 NativeFloat32x4.zero() : this._truncated(0.0, 0.0, 0.0, 0.0); 1209 NativeFloat32x4.zero() : this._truncated(0.0, 0.0, 0.0, 0.0);
1235 1210
1236 /// Returns a bit-wise copy of [i] as a Float32x4. 1211 /// Returns a bit-wise copy of [i] as a Float32x4.
1237 factory NativeFloat32x4.fromInt32x4Bits(Int32x4 i) { 1212 factory NativeFloat32x4.fromInt32x4Bits(Int32x4 i) {
1238 _uint32view[0] = i.x; 1213 _uint32view[0] = i.x;
1239 _uint32view[1] = i.y; 1214 _uint32view[1] = i.y;
1240 _uint32view[2] = i.z; 1215 _uint32view[2] = i.z;
1241 _uint32view[3] = i.w; 1216 _uint32view[3] = i.w;
1242 return new NativeFloat32x4._truncated(_list[0], _list[1], _list[2], _list[3] ); 1217 return new NativeFloat32x4._truncated(
1218 _list[0], _list[1], _list[2], _list[3]);
1243 } 1219 }
1244 1220
1245 NativeFloat32x4.fromFloat64x2(Float64x2 v) 1221 NativeFloat32x4.fromFloat64x2(Float64x2 v)
1246 : this._truncated(_truncate(v.x), _truncate(v.y), 0.0, 0.0); 1222 : this._truncated(_truncate(v.x), _truncate(v.y), 0.0, 0.0);
1247 1223
1248 /// Creates a new NativeFloat32x4. 1224 /// Creates a new NativeFloat32x4.
1249 /// 1225 ///
1250 /// Does not verify if the given arguments are non-null. 1226 /// Does not verify if the given arguments are non-null.
1251 NativeFloat32x4._doubles(double x, double y, double z, double w) 1227 NativeFloat32x4._doubles(double x, double y, double z, double w)
1252 : this.x = _truncate(x), 1228 : this.x = _truncate(x),
1253 this.y = _truncate(y), 1229 this.y = _truncate(y),
1254 this.z = _truncate(z), 1230 this.z = _truncate(z),
1255 this.w = _truncate(w); 1231 this.w = _truncate(w);
1256 1232
1257 /// Creates a new NativeFloat32x4. 1233 /// Creates a new NativeFloat32x4.
1258 /// 1234 ///
1259 /// The constructor does not truncate the arguments. They must already be in 1235 /// The constructor does not truncate the arguments. They must already be in
1260 /// the correct range. It does not verify the type of the given arguments, 1236 /// the correct range. It does not verify the type of the given arguments,
1261 /// either. 1237 /// either.
1262 NativeFloat32x4._truncated(this.x, this.y, this.z, this.w); 1238 NativeFloat32x4._truncated(this.x, this.y, this.z, this.w);
1263 1239
1264 String toString() { 1240 String toString() {
1265 return '[$x, $y, $z, $w]'; 1241 return '[$x, $y, $z, $w]';
1266 } 1242 }
1267 1243
1268 /// Addition operator. 1244 /// Addition operator.
1269 Float32x4 operator+(Float32x4 other) { 1245 Float32x4 operator +(Float32x4 other) {
1270 double _x = x + other.x; 1246 double _x = x + other.x;
1271 double _y = y + other.y; 1247 double _y = y + other.y;
1272 double _z = z + other.z; 1248 double _z = z + other.z;
1273 double _w = w + other.w; 1249 double _w = w + other.w;
1274 return new NativeFloat32x4._doubles(_x, _y, _z, _w); 1250 return new NativeFloat32x4._doubles(_x, _y, _z, _w);
1275 } 1251 }
1276 1252
1277 /// Negate operator. 1253 /// Negate operator.
1278 Float32x4 operator-() { 1254 Float32x4 operator -() {
1279 return new NativeFloat32x4._truncated(-x, -y, -z, -w); 1255 return new NativeFloat32x4._truncated(-x, -y, -z, -w);
1280 } 1256 }
1281 1257
1282 /// Subtraction operator. 1258 /// Subtraction operator.
1283 Float32x4 operator-(Float32x4 other) { 1259 Float32x4 operator -(Float32x4 other) {
1284 double _x = x - other.x; 1260 double _x = x - other.x;
1285 double _y = y - other.y; 1261 double _y = y - other.y;
1286 double _z = z - other.z; 1262 double _z = z - other.z;
1287 double _w = w - other.w; 1263 double _w = w - other.w;
1288 return new NativeFloat32x4._doubles(_x, _y, _z, _w); 1264 return new NativeFloat32x4._doubles(_x, _y, _z, _w);
1289 } 1265 }
1290 1266
1291 /// Multiplication operator. 1267 /// Multiplication operator.
1292 Float32x4 operator*(Float32x4 other) { 1268 Float32x4 operator *(Float32x4 other) {
1293 double _x = x * other.x; 1269 double _x = x * other.x;
1294 double _y = y * other.y; 1270 double _y = y * other.y;
1295 double _z = z * other.z; 1271 double _z = z * other.z;
1296 double _w = w * other.w; 1272 double _w = w * other.w;
1297 return new NativeFloat32x4._doubles(_x, _y, _z, _w); 1273 return new NativeFloat32x4._doubles(_x, _y, _z, _w);
1298 } 1274 }
1299 1275
1300 /// Division operator. 1276 /// Division operator.
1301 Float32x4 operator/(Float32x4 other) { 1277 Float32x4 operator /(Float32x4 other) {
1302 double _x = x / other.x; 1278 double _x = x / other.x;
1303 double _y = y / other.y; 1279 double _y = y / other.y;
1304 double _z = z / other.z; 1280 double _z = z / other.z;
1305 double _w = w / other.w; 1281 double _w = w / other.w;
1306 return new NativeFloat32x4._doubles(_x, _y, _z, _w); 1282 return new NativeFloat32x4._doubles(_x, _y, _z, _w);
1307 } 1283 }
1308 1284
1309 /// Relational less than. 1285 /// Relational less than.
1310 Int32x4 lessThan(Float32x4 other) { 1286 Int32x4 lessThan(Float32x4 other) {
1311 bool _cx = x < other.x; 1287 bool _cx = x < other.x;
1312 bool _cy = y < other.y; 1288 bool _cy = y < other.y;
1313 bool _cz = z < other.z; 1289 bool _cz = z < other.z;
1314 bool _cw = w < other.w; 1290 bool _cw = w < other.w;
1315 return new NativeInt32x4._truncated(_cx ? -1 : 0, 1291 return new NativeInt32x4._truncated(
1316 _cy ? -1 : 0, 1292 _cx ? -1 : 0, _cy ? -1 : 0, _cz ? -1 : 0, _cw ? -1 : 0);
1317 _cz ? -1 : 0,
1318 _cw ? -1 : 0);
1319 } 1293 }
1320 1294
1321 /// Relational less than or equal. 1295 /// Relational less than or equal.
1322 Int32x4 lessThanOrEqual(Float32x4 other) { 1296 Int32x4 lessThanOrEqual(Float32x4 other) {
1323 bool _cx = x <= other.x; 1297 bool _cx = x <= other.x;
1324 bool _cy = y <= other.y; 1298 bool _cy = y <= other.y;
1325 bool _cz = z <= other.z; 1299 bool _cz = z <= other.z;
1326 bool _cw = w <= other.w; 1300 bool _cw = w <= other.w;
1327 return new NativeInt32x4._truncated(_cx ? -1 : 0, 1301 return new NativeInt32x4._truncated(
1328 _cy ? -1 : 0, 1302 _cx ? -1 : 0, _cy ? -1 : 0, _cz ? -1 : 0, _cw ? -1 : 0);
1329 _cz ? -1 : 0,
1330 _cw ? -1 : 0);
1331 } 1303 }
1332 1304
1333 /// Relational greater than. 1305 /// Relational greater than.
1334 Int32x4 greaterThan(Float32x4 other) { 1306 Int32x4 greaterThan(Float32x4 other) {
1335 bool _cx = x > other.x; 1307 bool _cx = x > other.x;
1336 bool _cy = y > other.y; 1308 bool _cy = y > other.y;
1337 bool _cz = z > other.z; 1309 bool _cz = z > other.z;
1338 bool _cw = w > other.w; 1310 bool _cw = w > other.w;
1339 return new NativeInt32x4._truncated(_cx ? -1 : 0, 1311 return new NativeInt32x4._truncated(
1340 _cy ? -1 : 0, 1312 _cx ? -1 : 0, _cy ? -1 : 0, _cz ? -1 : 0, _cw ? -1 : 0);
1341 _cz ? -1 : 0,
1342 _cw ? -1 : 0);
1343 } 1313 }
1344 1314
1345 /// Relational greater than or equal. 1315 /// Relational greater than or equal.
1346 Int32x4 greaterThanOrEqual(Float32x4 other) { 1316 Int32x4 greaterThanOrEqual(Float32x4 other) {
1347 bool _cx = x >= other.x; 1317 bool _cx = x >= other.x;
1348 bool _cy = y >= other.y; 1318 bool _cy = y >= other.y;
1349 bool _cz = z >= other.z; 1319 bool _cz = z >= other.z;
1350 bool _cw = w >= other.w; 1320 bool _cw = w >= other.w;
1351 return new NativeInt32x4._truncated(_cx ? -1 : 0, 1321 return new NativeInt32x4._truncated(
1352 _cy ? -1 : 0, 1322 _cx ? -1 : 0, _cy ? -1 : 0, _cz ? -1 : 0, _cw ? -1 : 0);
1353 _cz ? -1 : 0,
1354 _cw ? -1 : 0);
1355 } 1323 }
1356 1324
1357 /// Relational equal. 1325 /// Relational equal.
1358 Int32x4 equal(Float32x4 other) { 1326 Int32x4 equal(Float32x4 other) {
1359 bool _cx = x == other.x; 1327 bool _cx = x == other.x;
1360 bool _cy = y == other.y; 1328 bool _cy = y == other.y;
1361 bool _cz = z == other.z; 1329 bool _cz = z == other.z;
1362 bool _cw = w == other.w; 1330 bool _cw = w == other.w;
1363 return new NativeInt32x4._truncated(_cx ? -1 : 0, 1331 return new NativeInt32x4._truncated(
1364 _cy ? -1 : 0, 1332 _cx ? -1 : 0, _cy ? -1 : 0, _cz ? -1 : 0, _cw ? -1 : 0);
1365 _cz ? -1 : 0,
1366 _cw ? -1 : 0);
1367 } 1333 }
1368 1334
1369 /// Relational not-equal. 1335 /// Relational not-equal.
1370 Int32x4 notEqual(Float32x4 other) { 1336 Int32x4 notEqual(Float32x4 other) {
1371 bool _cx = x != other.x; 1337 bool _cx = x != other.x;
1372 bool _cy = y != other.y; 1338 bool _cy = y != other.y;
1373 bool _cz = z != other.z; 1339 bool _cz = z != other.z;
1374 bool _cw = w != other.w; 1340 bool _cw = w != other.w;
1375 return new NativeInt32x4._truncated(_cx ? -1 : 0, 1341 return new NativeInt32x4._truncated(
1376 _cy ? -1 : 0, 1342 _cx ? -1 : 0, _cy ? -1 : 0, _cz ? -1 : 0, _cw ? -1 : 0);
1377 _cz ? -1 : 0,
1378 _cw ? -1 : 0);
1379 } 1343 }
1380 1344
1381 /// Returns a copy of [this] each lane being scaled by [s]. 1345 /// Returns a copy of [this] each lane being scaled by [s].
1382 Float32x4 scale(double s) { 1346 Float32x4 scale(double s) {
1383 double _x = s * x; 1347 double _x = s * x;
1384 double _y = s * y; 1348 double _y = s * y;
1385 double _z = s * z; 1349 double _z = s * z;
1386 double _w = s * w; 1350 double _w = s * w;
1387 return new NativeFloat32x4._doubles(_x, _y, _z, _w); 1351 return new NativeFloat32x4._doubles(_x, _y, _z, _w);
1388 } 1352 }
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 /// Returns the square root of the reciprocal of [this]. 1501 /// Returns the square root of the reciprocal of [this].
1538 Float32x4 reciprocalSqrt() { 1502 Float32x4 reciprocalSqrt() {
1539 double _x = Math.sqrt(1.0 / x); 1503 double _x = Math.sqrt(1.0 / x);
1540 double _y = Math.sqrt(1.0 / y); 1504 double _y = Math.sqrt(1.0 / y);
1541 double _z = Math.sqrt(1.0 / z); 1505 double _z = Math.sqrt(1.0 / z);
1542 double _w = Math.sqrt(1.0 / w); 1506 double _w = Math.sqrt(1.0 / w);
1543 return new NativeFloat32x4._doubles(_x, _y, _z, _w); 1507 return new NativeFloat32x4._doubles(_x, _y, _z, _w);
1544 } 1508 }
1545 } 1509 }
1546 1510
1547
1548 /** 1511 /**
1549 * Interface of Dart Int32x4 and operations. 1512 * Interface of Dart Int32x4 and operations.
1550 * Int32x4 stores 4 32-bit bit-masks in "lanes". 1513 * Int32x4 stores 4 32-bit bit-masks in "lanes".
1551 * The lanes are "x", "y", "z", and "w" respectively. 1514 * The lanes are "x", "y", "z", and "w" respectively.
1552 */ 1515 */
1553 class NativeInt32x4 implements Int32x4 { 1516 class NativeInt32x4 implements Int32x4 {
1554 final int x; 1517 final int x;
1555 final int y; 1518 final int y;
1556 final int z; 1519 final int z;
1557 final int w; 1520 final int w;
1558 1521
1559 static final _list = new NativeInt32List(4); 1522 static final _list = new NativeInt32List(4);
1560 1523
1561 static _truncate(x) { 1524 static _truncate(x) {
1562 _list[0] = x; 1525 _list[0] = x;
1563 return _list[0]; 1526 return _list[0];
1564 } 1527 }
1565 1528
1566 NativeInt32x4(int x, int y, int z, int w) 1529 NativeInt32x4(int x, int y, int z, int w)
1567 : this.x = _truncate(x), 1530 : this.x = _truncate(x),
1568 this.y = _truncate(y), 1531 this.y = _truncate(y),
1569 this.z = _truncate(z), 1532 this.z = _truncate(z),
1570 this.w = _truncate(w) { 1533 this.w = _truncate(w) {
1571 if (x != this.x && x is! int) throw new ArgumentError(x); 1534 if (x != this.x && x is! int) throw new ArgumentError(x);
1572 if (y != this.y && y is! int) throw new ArgumentError(y); 1535 if (y != this.y && y is! int) throw new ArgumentError(y);
1573 if (z != this.z && z is! int) throw new ArgumentError(z); 1536 if (z != this.z && z is! int) throw new ArgumentError(z);
1574 if (w != this.w && w is! int) throw new ArgumentError(w); 1537 if (w != this.w && w is! int) throw new ArgumentError(w);
1575 } 1538 }
1576 1539
1577 NativeInt32x4.bool(bool x, bool y, bool z, bool w) 1540 NativeInt32x4.bool(bool x, bool y, bool z, bool w)
1578 : this.x = x ? -1 : 0, 1541 : this.x = x ? -1 : 0,
1579 this.y = y ? -1 : 0, 1542 this.y = y ? -1 : 0,
1580 this.z = z ? -1 : 0, 1543 this.z = z ? -1 : 0,
1581 this.w = w ? -1 : 0; 1544 this.w = w ? -1 : 0;
1582 1545
1583 /// Returns a bit-wise copy of [f] as a Int32x4. 1546 /// Returns a bit-wise copy of [f] as a Int32x4.
1584 factory NativeInt32x4.fromFloat32x4Bits(Float32x4 f) { 1547 factory NativeInt32x4.fromFloat32x4Bits(Float32x4 f) {
1585 NativeFloat32List floatList = NativeFloat32x4._list; 1548 NativeFloat32List floatList = NativeFloat32x4._list;
1586 floatList[0] = f.x; 1549 floatList[0] = f.x;
1587 floatList[1] = f.y; 1550 floatList[1] = f.y;
1588 floatList[2] = f.z; 1551 floatList[2] = f.z;
1589 floatList[3] = f.w; 1552 floatList[3] = f.w;
1590 NativeInt32List view = floatList.buffer.asInt32List(); 1553 NativeInt32List view = floatList.buffer.asInt32List();
1591 return new NativeInt32x4._truncated(view[0], view[1], view[2], view[3]); 1554 return new NativeInt32x4._truncated(view[0], view[1], view[2], view[3]);
1592 } 1555 }
1593 1556
1594 NativeInt32x4._truncated(this.x, this.y, this.z, this.w); 1557 NativeInt32x4._truncated(this.x, this.y, this.z, this.w);
1595 1558
1596 String toString() => '[$x, $y, $z, $w]'; 1559 String toString() => '[$x, $y, $z, $w]';
1597 1560
1598
1599 /// The bit-wise or operator. 1561 /// The bit-wise or operator.
1600 Int32x4 operator|(Int32x4 other) { 1562 Int32x4 operator |(Int32x4 other) {
1601 // Dart2js uses unsigned results for bit-operations. 1563 // Dart2js uses unsigned results for bit-operations.
1602 // We use "JS" to fall back to the signed versions. 1564 // We use "JS" to fall back to the signed versions.
1603 return new NativeInt32x4._truncated(JS("int", "# | #", x, other.x), 1565 return new NativeInt32x4._truncated(
1604 JS("int", "# | #", y, other.y), 1566 JS("int", "# | #", x, other.x),
1605 JS("int", "# | #", z, other.z), 1567 JS("int", "# | #", y, other.y),
1606 JS("int", "# | #", w, other.w)); 1568 JS("int", "# | #", z, other.z),
1569 JS("int", "# | #", w, other.w));
1607 } 1570 }
1608 1571
1609 /// The bit-wise and operator. 1572 /// The bit-wise and operator.
1610 Int32x4 operator&(Int32x4 other) { 1573 Int32x4 operator &(Int32x4 other) {
1611 // Dart2js uses unsigned results for bit-operations. 1574 // Dart2js uses unsigned results for bit-operations.
1612 // We use "JS" to fall back to the signed versions. 1575 // We use "JS" to fall back to the signed versions.
1613 return new NativeInt32x4._truncated(JS("int", "# & #", x, other.x), 1576 return new NativeInt32x4._truncated(
1614 JS("int", "# & #", y, other.y), 1577 JS("int", "# & #", x, other.x),
1615 JS("int", "# & #", z, other.z), 1578 JS("int", "# & #", y, other.y),
1616 JS("int", "# & #", w, other.w)); 1579 JS("int", "# & #", z, other.z),
1580 JS("int", "# & #", w, other.w));
1617 } 1581 }
1618 1582
1619 /// The bit-wise xor operator. 1583 /// The bit-wise xor operator.
1620 Int32x4 operator^(Int32x4 other) { 1584 Int32x4 operator ^(Int32x4 other) {
1621 // Dart2js uses unsigned results for bit-operations. 1585 // Dart2js uses unsigned results for bit-operations.
1622 // We use "JS" to fall back to the signed versions. 1586 // We use "JS" to fall back to the signed versions.
1623 return new NativeInt32x4._truncated(JS("int", "# ^ #", x, other.x), 1587 return new NativeInt32x4._truncated(
1624 JS("int", "# ^ #", y, other.y), 1588 JS("int", "# ^ #", x, other.x),
1625 JS("int", "# ^ #", z, other.z), 1589 JS("int", "# ^ #", y, other.y),
1626 JS("int", "# ^ #", w, other.w)); 1590 JS("int", "# ^ #", z, other.z),
1591 JS("int", "# ^ #", w, other.w));
1627 } 1592 }
1628 1593
1629 Int32x4 operator+(Int32x4 other) { 1594 Int32x4 operator +(Int32x4 other) {
1630 // Avoid going through the typed array by "| 0" the result. 1595 // Avoid going through the typed array by "| 0" the result.
1631 return new NativeInt32x4._truncated(JS("int", "(# + #) | 0", x, other.x), 1596 return new NativeInt32x4._truncated(
1632 JS("int", "(# + #) | 0", y, other.y), 1597 JS("int", "(# + #) | 0", x, other.x),
1633 JS("int", "(# + #) | 0", z, other.z), 1598 JS("int", "(# + #) | 0", y, other.y),
1634 JS("int", "(# + #) | 0", w, other.w)); 1599 JS("int", "(# + #) | 0", z, other.z),
1600 JS("int", "(# + #) | 0", w, other.w));
1635 } 1601 }
1636 1602
1637 Int32x4 operator-(Int32x4 other) { 1603 Int32x4 operator -(Int32x4 other) {
1638 // Avoid going through the typed array by "| 0" the result. 1604 // Avoid going through the typed array by "| 0" the result.
1639 return new NativeInt32x4._truncated(JS("int", "(# - #) | 0", x, other.x), 1605 return new NativeInt32x4._truncated(
1640 JS("int", "(# - #) | 0", y, other.y), 1606 JS("int", "(# - #) | 0", x, other.x),
1641 JS("int", "(# - #) | 0", z, other.z), 1607 JS("int", "(# - #) | 0", y, other.y),
1642 JS("int", "(# - #) | 0", w, other.w)); 1608 JS("int", "(# - #) | 0", z, other.z),
1609 JS("int", "(# - #) | 0", w, other.w));
1643 } 1610 }
1644 1611
1645 Int32x4 operator-() { 1612 Int32x4 operator -() {
1646 // Avoid going through the typed array by "| 0" the result. 1613 // Avoid going through the typed array by "| 0" the result.
1647 return new NativeInt32x4._truncated(JS("int", "(-#) | 0", x), 1614 return new NativeInt32x4._truncated(
1648 JS("int", "(-#) | 0", y), 1615 JS("int", "(-#) | 0", x),
1649 JS("int", "(-#) | 0", z), 1616 JS("int", "(-#) | 0", y),
1650 JS("int", "(-#) | 0", w)); 1617 JS("int", "(-#) | 0", z),
1618 JS("int", "(-#) | 0", w));
1651 } 1619 }
1652 1620
1653 /// Extract the top bit from each lane return them in the first 4 bits. 1621 /// Extract the top bit from each lane return them in the first 4 bits.
1654 int get signMask { 1622 int get signMask {
1655 int mx = (x & 0x80000000) >> 31; 1623 int mx = (x & 0x80000000) >> 31;
1656 int my = (y & 0x80000000) >> 31; 1624 int my = (y & 0x80000000) >> 31;
1657 int mz = (z & 0x80000000) >> 31; 1625 int mz = (z & 0x80000000) >> 31;
1658 int mw = (w & 0x80000000) >> 31; 1626 int mw = (w & 0x80000000) >> 31;
1659 return mx | my << 1 | mz << 2 | mw << 3; 1627 return mx | my << 1 | mz << 2 | mw << 3;
1660 } 1628 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 } 1685 }
1718 1686
1719 /// Returns a new [Int32x4] copied from [this] with a new w value. 1687 /// Returns a new [Int32x4] copied from [this] with a new w value.
1720 Int32x4 withW(int w) { 1688 Int32x4 withW(int w) {
1721 int _w = _truncate(w); 1689 int _w = _truncate(w);
1722 return new NativeInt32x4._truncated(x, y, z, _w); 1690 return new NativeInt32x4._truncated(x, y, z, _w);
1723 } 1691 }
1724 1692
1725 /// Extracted x value. Returns `false` for 0, `true` for any other value. 1693 /// Extracted x value. Returns `false` for 0, `true` for any other value.
1726 bool get flagX => x != 0; 1694 bool get flagX => x != 0;
1695
1727 /// Extracted y value. Returns `false` for 0, `true` for any other value. 1696 /// Extracted y value. Returns `false` for 0, `true` for any other value.
1728 bool get flagY => y != 0; 1697 bool get flagY => y != 0;
1698
1729 /// Extracted z value. Returns `false` for 0, `true` for any other value. 1699 /// Extracted z value. Returns `false` for 0, `true` for any other value.
1730 bool get flagZ => z != 0; 1700 bool get flagZ => z != 0;
1701
1731 /// Extracted w value. Returns `false` for 0, `true` for any other value. 1702 /// Extracted w value. Returns `false` for 0, `true` for any other value.
1732 bool get flagW => w != 0; 1703 bool get flagW => w != 0;
1733 1704
1734 /// Returns a new [Int32x4] copied from [this] with a new x value. 1705 /// Returns a new [Int32x4] copied from [this] with a new x value.
1735 Int32x4 withFlagX(bool flagX) { 1706 Int32x4 withFlagX(bool flagX) {
1736 int _x = flagX ? -1 : 0; 1707 int _x = flagX ? -1 : 0;
1737 return new NativeInt32x4._truncated(_x, y, z, w); 1708 return new NativeInt32x4._truncated(_x, y, z, w);
1738 } 1709 }
1739 1710
1740 /// Returns a new [Int32x4] copied from [this] with a new y value. 1711 /// Returns a new [Int32x4] copied from [this] with a new y value.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 NativeFloat64x2.zero() : this.splat(0.0); 1780 NativeFloat64x2.zero() : this.splat(0.0);
1810 1781
1811 NativeFloat64x2.fromFloat32x4(Float32x4 v) : this(v.x, v.y); 1782 NativeFloat64x2.fromFloat32x4(Float32x4 v) : this(v.x, v.y);
1812 1783
1813 /// Arguments [x] and [y] must be doubles. 1784 /// Arguments [x] and [y] must be doubles.
1814 NativeFloat64x2._doubles(this.x, this.y); 1785 NativeFloat64x2._doubles(this.x, this.y);
1815 1786
1816 String toString() => '[$x, $y]'; 1787 String toString() => '[$x, $y]';
1817 1788
1818 /// Addition operator. 1789 /// Addition operator.
1819 Float64x2 operator+(Float64x2 other) { 1790 Float64x2 operator +(Float64x2 other) {
1820 return new NativeFloat64x2._doubles(x + other.x, y + other.y); 1791 return new NativeFloat64x2._doubles(x + other.x, y + other.y);
1821 } 1792 }
1822 1793
1823 /// Negate operator. 1794 /// Negate operator.
1824 Float64x2 operator-() { 1795 Float64x2 operator -() {
1825 return new NativeFloat64x2._doubles(-x, -y); 1796 return new NativeFloat64x2._doubles(-x, -y);
1826 } 1797 }
1827 1798
1828 /// Subtraction operator. 1799 /// Subtraction operator.
1829 Float64x2 operator-(Float64x2 other) { 1800 Float64x2 operator -(Float64x2 other) {
1830 return new NativeFloat64x2._doubles(x - other.x, y - other.y); 1801 return new NativeFloat64x2._doubles(x - other.x, y - other.y);
1831 } 1802 }
1803
1832 /// Multiplication operator. 1804 /// Multiplication operator.
1833 Float64x2 operator*(Float64x2 other) { 1805 Float64x2 operator *(Float64x2 other) {
1834 return new NativeFloat64x2._doubles(x * other.x, y * other.y); 1806 return new NativeFloat64x2._doubles(x * other.x, y * other.y);
1835 } 1807 }
1808
1836 /// Division operator. 1809 /// Division operator.
1837 Float64x2 operator/(Float64x2 other) { 1810 Float64x2 operator /(Float64x2 other) {
1838 return new NativeFloat64x2._doubles(x / other.x, y / other.y); 1811 return new NativeFloat64x2._doubles(x / other.x, y / other.y);
1839 } 1812 }
1840 1813
1841 /// Returns a copy of [this] each lane being scaled by [s]. 1814 /// Returns a copy of [this] each lane being scaled by [s].
1842 Float64x2 scale(double s) { 1815 Float64x2 scale(double s) {
1843 return new NativeFloat64x2._doubles(x * s, y * s); 1816 return new NativeFloat64x2._doubles(x * s, y * s);
1844 } 1817 }
1845 1818
1846 /// Returns the absolute value of this [Float64x2]. 1819 /// Returns the absolute value of this [Float64x2].
1847 Float64x2 abs() { 1820 Float64x2 abs() {
1848 return new NativeFloat64x2._doubles(x.abs(), y.abs()); 1821 return new NativeFloat64x2._doubles(x.abs(), y.abs());
1849 } 1822 }
1850 1823
1851 /// Clamps [this] to be in the range [lowerLimit]-[upperLimit]. 1824 /// Clamps [this] to be in the range [lowerLimit]-[upperLimit].
1852 Float64x2 clamp(Float64x2 lowerLimit, 1825 Float64x2 clamp(Float64x2 lowerLimit, Float64x2 upperLimit) {
1853 Float64x2 upperLimit) {
1854 double _lx = lowerLimit.x; 1826 double _lx = lowerLimit.x;
1855 double _ly = lowerLimit.y; 1827 double _ly = lowerLimit.y;
1856 double _ux = upperLimit.x; 1828 double _ux = upperLimit.x;
1857 double _uy = upperLimit.y; 1829 double _uy = upperLimit.y;
1858 double _x = x; 1830 double _x = x;
1859 double _y = y; 1831 double _y = y;
1860 // MAX(MIN(self, upper), lower). 1832 // MAX(MIN(self, upper), lower).
1861 _x = _x > _ux ? _ux : _x; 1833 _x = _x > _ux ? _ux : _x;
1862 _y = _y > _uy ? _uy : _y; 1834 _y = _y > _uy ? _uy : _y;
1863 _x = _x < _lx ? _lx : _x; 1835 _x = _x < _lx ? _lx : _x;
(...skipping 18 matching lines...) Expand all
1882 } 1854 }
1883 1855
1884 /// Returns a new [Float64x2] copied from [this] with a new y value. 1856 /// Returns a new [Float64x2] copied from [this] with a new y value.
1885 Float64x2 withY(double y) { 1857 Float64x2 withY(double y) {
1886 if (y is! num) throw new ArgumentError(y); 1858 if (y is! num) throw new ArgumentError(y);
1887 return new NativeFloat64x2._doubles(x, y); 1859 return new NativeFloat64x2._doubles(x, y);
1888 } 1860 }
1889 1861
1890 /// Returns the lane-wise minimum value in [this] or [other]. 1862 /// Returns the lane-wise minimum value in [this] or [other].
1891 Float64x2 min(Float64x2 other) { 1863 Float64x2 min(Float64x2 other) {
1892 return new NativeFloat64x2._doubles(x < other.x ? x : other.x, 1864 return new NativeFloat64x2._doubles(
1893 y < other.y ? y : other.y); 1865 x < other.x ? x : other.x, y < other.y ? y : other.y);
1894
1895 } 1866 }
1896 1867
1897 /// Returns the lane-wise maximum value in [this] or [other]. 1868 /// Returns the lane-wise maximum value in [this] or [other].
1898 Float64x2 max(Float64x2 other) { 1869 Float64x2 max(Float64x2 other) {
1899 return new NativeFloat64x2._doubles(x > other.x ? x : other.x, 1870 return new NativeFloat64x2._doubles(
1900 y > other.y ? y : other.y); 1871 x > other.x ? x : other.x, y > other.y ? y : other.y);
1901 } 1872 }
1902 1873
1903 /// Returns the lane-wise square root of [this]. 1874 /// Returns the lane-wise square root of [this].
1904 Float64x2 sqrt() { 1875 Float64x2 sqrt() {
1905 return new NativeFloat64x2._doubles(Math.sqrt(x), Math.sqrt(y)); 1876 return new NativeFloat64x2._doubles(Math.sqrt(x), Math.sqrt(y));
1906 } 1877 }
1907 } 1878 }
1908 1879
1909 /// Checks that the value is a Uint32. If not, it's not valid as an array 1880 /// Checks that the value is a Uint32. If not, it's not valid as an array
1910 /// index or offset. Also ensures that the value is non-negative. 1881 /// index or offset. Also ensures that the value is non-negative.
1911 bool _isInvalidArrayIndex(int index) { 1882 bool _isInvalidArrayIndex(int index) {
1912 return (JS('bool', '(# >>> 0 !== #)', index, index)); 1883 return (JS('bool', '(# >>> 0 !== #)', index, index));
1913 } 1884 }
1914 1885
1915 /// Checks that [index] is a valid index into [list] which has length [length]. 1886 /// Checks that [index] is a valid index into [list] which has length [length].
1916 /// 1887 ///
1917 /// That is, [index] is an insteger in the range `0..length - 1`. 1888 /// That is, [index] is an insteger in the range `0..length - 1`.
1918 void _checkValidIndex(int index, List list, int length) { 1889 void _checkValidIndex(int index, List list, int length) {
1919 if (_isInvalidArrayIndex(index) || JS('int', '#', index) >= length) { 1890 if (_isInvalidArrayIndex(index) || JS('int', '#', index) >= length) {
1920 throw diagnoseIndexError(list, index); 1891 throw diagnoseIndexError(list, index);
1921 } 1892 }
1922 } 1893 }
1923 1894
1924 /// Checks that [start] and [end] form a range of a list of length [length]. 1895 /// Checks that [start] and [end] form a range of a list of length [length].
1925 /// 1896 ///
1926 /// That is: `start` and `end` are integers with `0 <= start <= end <= length`. 1897 /// That is: `start` and `end` are integers with `0 <= start <= end <= length`.
1927 /// If `end` is `null` in which case it is considered to be `length` 1898 /// If `end` is `null` in which case it is considered to be `length`
1928 /// 1899 ///
1929 /// Returns the actual value of `end`, which is `length` if `end` is `null`, and 1900 /// Returns the actual value of `end`, which is `length` if `end` is `null`, and
1930 /// the original value of `end` otherwise. 1901 /// the original value of `end` otherwise.
1931 int _checkValidRange(int start, int end, int length) { 1902 int _checkValidRange(int start, int end, int length) {
1932 if (_isInvalidArrayIndex(start) || // Ensures start is non-negative int. 1903 if (_isInvalidArrayIndex(start) || // Ensures start is non-negative int.
1933 ((end == null) ? start > length 1904 ((end == null)
1934 : (_isInvalidArrayIndex(end) || 1905 ? start > length
1935 start > end || 1906 : (_isInvalidArrayIndex(end) || start > end || end > length))) {
1936 end > length))) {
1937 throw diagnoseRangeError(start, end, length); 1907 throw diagnoseRangeError(start, end, length);
1938 } 1908 }
1939 if (end == null) return length; 1909 if (end == null) return length;
1940 return end; 1910 return end;
1941 } 1911 }
OLDNEW
« no previous file with comments | « pkg/dev_compiler/tool/input_sdk/private/native_helper.dart ('k') | pkg/dev_compiler/tool/input_sdk/private/regexp_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698