| 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<E> { | 14 class JSArray<E> implements List<E>, JSIndexable<E> { |
| 15 const JSArray(); | 15 const JSArray(); |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Constructor for adding type parameters to an existing JavaScript | 18 * Constructor for adding type parameters to an existing JavaScript |
| 19 * Array. Used for creating literal lists. | 19 * Array. Used for creating literal lists. |
| 20 */ | 20 */ |
| 21 factory JSArray.of(allocation) { | 21 factory JSArray.of(list) { |
| 22 // TODO(sra): Move this to core.List for better readability. | 22 // TODO(sra): Move this to core.List for better readability. |
| 23 // Capture the parameterized ES6 'JSArray' class. | 23 // Capture the parameterized ES6 'JSArray' class. |
| 24 return JS('-dynamic', '#', dart.setType(allocation, JS('', 'JSArray'))); | 24 JS('', '#.__proto__ = JSArray.prototype', list); |
| 25 return JS('-dynamic', '#', list); |
| 25 } | 26 } |
| 26 | 27 |
| 27 // TODO(jmesserly): consider a fixed array subclass instead. | 28 // TODO(jmesserly): consider a fixed array subclass instead. |
| 28 factory JSArray.markFixed(allocation) => | 29 factory JSArray.fixed(list) { |
| 29 new JSArray<E>.of(markFixedList(allocation)); | 30 JS('', '#.__proto__ = JSArray.prototype', list); |
| 31 JS('', r'#.fixed$length = Array', list); |
| 32 return JS('-dynamic', '#', list); |
| 33 } |
| 30 | 34 |
| 31 factory JSArray.markGrowable(allocation) = JSArray<E>.of; | 35 factory JSArray.unmodifiable(list) { |
| 36 JS('', '#.__proto__ = JSArray.prototype', list); |
| 37 JS('', r'#.fixed$length = Array', list); |
| 38 JS('', r'#.immutable$list = Array', list); |
| 39 return JS('-dynamic', '#', list); |
| 40 } |
| 32 | 41 |
| 33 static List markFixedList(List list) { | 42 static void markFixedList(list) { |
| 34 // Functions are stored in the hidden class and not as properties in | 43 // Functions are stored in the hidden class and not as properties in |
| 35 // the object. We never actually look at the value, but only want | 44 // the object. We never actually look at the value, but only want |
| 36 // to know if the property exists. | 45 // to know if the property exists. |
| 37 JS('void', r'#.fixed$length = Array', list); | 46 JS('', r'#.fixed$length = Array', list); |
| 38 return JS('JSFixedArray', '#', list); | |
| 39 } | 47 } |
| 40 | 48 |
| 41 static List markUnmodifiableList(List list) { | 49 static void markUnmodifiableList(list) { |
| 42 // Functions are stored in the hidden class and not as properties in | 50 // Functions are stored in the hidden class and not as properties in |
| 43 // the object. We never actually look at the value, but only want | 51 // the object. We never actually look at the value, but only want |
| 44 // to know if the property exists. | 52 // to know if the property exists. |
| 45 JS('void', r'#.fixed$length = Array', list); | 53 JS('', r'#.fixed$length = Array', list); |
| 46 JS('void', r'#.immutable$list = Array', list); | 54 JS('', r'#.immutable$list = Array', list); |
| 47 return JS('JSUnmodifiableArray', '#', list); | |
| 48 } | 55 } |
| 49 | 56 |
| 50 checkMutable(reason) { | 57 checkMutable(reason) { |
| 51 if (JS('bool', r'#.immutable$list', this)) { | 58 if (JS('bool', r'#.immutable$list', this)) { |
| 52 throw new UnsupportedError(reason); | 59 throw new UnsupportedError(reason); |
| 53 } | 60 } |
| 54 } | 61 } |
| 55 | 62 |
| 56 checkGrowable(reason) { | 63 checkGrowable(reason) { |
| 57 if (JS('bool', r'#.fixed$length', this)) { | 64 if (JS('bool', r'#.fixed$length', this)) { |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 635 | 642 |
| 636 if (_index >= length) { | 643 if (_index >= length) { |
| 637 _current = null; | 644 _current = null; |
| 638 return false; | 645 return false; |
| 639 } | 646 } |
| 640 _current = _iterable[_index]; | 647 _current = _iterable[_index]; |
| 641 _index++; | 648 _index++; |
| 642 return true; | 649 return true; |
| 643 } | 650 } |
| 644 } | 651 } |
| OLD | NEW |