| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 part of dart._interceptors; | 5 part of dart._interceptors; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * The interceptor class for [List]. The compiler recognizes this | 8 * The interceptor class for [List]. The compiler recognizes this |
| 9 * class as an interceptor, and changes references to [:this:] to | 9 * class as an interceptor, and changes references to [:this:] to |
| 10 * actually use the receiver of the method, which is generated as an extra | 10 * actually use the receiver of the method, which is generated as an extra |
| 11 * argument added to each member. | 11 * argument added to each member. |
| 12 */ | 12 */ |
| 13 @JsPeerInterface(name: 'Array') | 13 @JsPeerInterface(name: 'Array') |
| 14 class JSArray<E> implements List<E>, JSIndexable { | 14 class JSArray<E> implements List<E>, JSIndexable { |
| 15 | 15 |
| 16 const JSArray(); | 16 const JSArray(); |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Constructor for adding type parameters to an existing JavaScript Array. | 19 * Constructor for adding type parameters to an existing JavaScript Array. |
| 20 */ | 20 */ |
| 21 factory JSArray.typed(allocation) => | 21 factory JSArray.typed(allocation) => |
| 22 // TODO(jmesserly): skip this when E is dynamic and Object. | 22 // TODO(jmesserly): skip this when E is dynamic and Object. |
| 23 JS('-dynamic', 'dart.list(#, #)', allocation, E); | 23 JS('-dynamic', 'dart.list(#, #)', allocation, E); |
| 24 | 24 |
| 25 /** |
| 26 * Constructor for adding type parameters to an existing JavaScript |
| 27 * Array. Used for creating literal lists. |
| 28 */ |
| 29 factory JSArray.of(allocation) { |
| 30 // TODO(sra): Move this to core.List for better readability. |
| 31 // Capture the parameterized ES6 'JSArray' class. |
| 32 return JS('-dynamic', 'dart.setType(#, JSArray)', allocation); |
| 33 } |
| 34 |
| 25 // TODO(jmesserly): consider a fixed array subclass instead. | 35 // TODO(jmesserly): consider a fixed array subclass instead. |
| 26 factory JSArray.markFixed(allocation) => | 36 factory JSArray.markFixed(allocation) => |
| 27 new JSArray<E>.typed(markFixedList(allocation)); | 37 new JSArray<E>.typed(markFixedList(allocation)); |
| 28 | 38 |
| 29 factory JSArray.markGrowable(allocation) = JSArray<E>.typed; | 39 factory JSArray.markGrowable(allocation) = JSArray<E>.typed; |
| 30 | 40 |
| 31 static List markFixedList(List list) { | 41 static List markFixedList(List list) { |
| 32 // Functions are stored in the hidden class and not as properties in | 42 // Functions are stored in the hidden class and not as properties in |
| 33 // the object. We never actually look at the value, but only want | 43 // the object. We never actually look at the value, but only want |
| 34 // to know if the property exists. | 44 // to know if the property exists. |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 | 614 |
| 605 if (_index >= length) { | 615 if (_index >= length) { |
| 606 _current = null; | 616 _current = null; |
| 607 return false; | 617 return false; |
| 608 } | 618 } |
| 609 _current = _iterable[_index]; | 619 _current = _iterable[_index]; |
| 610 _index++; | 620 _index++; |
| 611 return true; | 621 return true; |
| 612 } | 622 } |
| 613 } | 623 } |
| OLD | NEW |