| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 factory JSArray.markGrowable(allocation) = JSArray<E>.typed; | 29 factory JSArray.markGrowable(allocation) = JSArray<E>.typed; |
| 30 | 30 |
| 31 static List markFixedList(List list) { | 31 static List markFixedList(List list) { |
| 32 // Functions are stored in the hidden class and not as properties in | 32 // 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 | 33 // the object. We never actually look at the value, but only want |
| 34 // to know if the property exists. | 34 // to know if the property exists. |
| 35 JS('void', r'#.fixed$length = Array', list); | 35 JS('void', r'#.fixed$length = Array', list); |
| 36 return list; | 36 return list; |
| 37 } | 37 } |
| 38 | 38 |
| 39 static List markUnmodifiableList(List list) { |
| 40 // Functions are stored in the hidden class and not as properties in |
| 41 // the object. We never actually look at the value, but only want |
| 42 // to know if the property exists. |
| 43 JS('void', r'#.fixed$length = Array', list); |
| 44 JS('void', r'#.immutable$list = Array', list); |
| 45 return JS('JSUnmodifiableArray', '#', list); |
| 46 } |
| 47 |
| 48 checkMutable(reason) { |
| 49 if (JS('bool', r'#.immutable$list', this)) { |
| 50 throw new UnsupportedError(reason); |
| 51 } |
| 52 } |
| 53 |
| 39 checkGrowable(reason) { | 54 checkGrowable(reason) { |
| 40 if (JS('bool', r'#.fixed$length', this)) { | 55 if (JS('bool', r'#.fixed$length', this)) { |
| 41 throw new UnsupportedError(reason); | 56 throw new UnsupportedError(reason); |
| 42 } | 57 } |
| 43 } | 58 } |
| 44 | 59 |
| 45 void add(E value) { | 60 void add(E value) { |
| 46 checkGrowable('add'); | 61 checkGrowable('add'); |
| 47 JS('void', r'#.push(#)', this, value); | 62 JS('void', r'#.push(#)', this, value); |
| 48 } | 63 } |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 JS('void', r'#.length = #', this, newLength); | 322 JS('void', r'#.length = #', this, newLength); |
| 308 } | 323 } |
| 309 | 324 |
| 310 E operator [](int index) { | 325 E operator [](int index) { |
| 311 if (index is !int) throw new ArgumentError(index); | 326 if (index is !int) throw new ArgumentError(index); |
| 312 if (index >= length || index < 0) throw new RangeError.value(index); | 327 if (index >= length || index < 0) throw new RangeError.value(index); |
| 313 return JS('var', '#[#]', this, index); | 328 return JS('var', '#[#]', this, index); |
| 314 } | 329 } |
| 315 | 330 |
| 316 void operator []=(int index, E value) { | 331 void operator []=(int index, E value) { |
| 332 checkMutable('indexed set'); |
| 317 if (index is !int) throw new ArgumentError(index); | 333 if (index is !int) throw new ArgumentError(index); |
| 318 if (index >= length || index < 0) throw new RangeError.value(index); | 334 if (index >= length || index < 0) throw new RangeError.value(index); |
| 319 JS('void', r'#[#] = #', this, index, value); | 335 JS('void', r'#[#] = #', this, index, value); |
| 320 } | 336 } |
| 321 | 337 |
| 322 Map<int, E> asMap() { | 338 Map<int, E> asMap() { |
| 323 return new IterableMixinWorkaround<E>().asMapList(this); | 339 return new IterableMixinWorkaround<E>().asMapList(this); |
| 324 } | 340 } |
| 325 } | 341 } |
| 326 | 342 |
| 327 /** | 343 /** |
| 328 * Dummy subclasses that allow the backend to track more precise | 344 * Dummy subclasses that allow the backend to track more precise |
| 329 * information about arrays through their type. The CPA type inference | 345 * information about arrays through their type. The CPA type inference |
| 330 * relies on the fact that these classes do not override [] nor []=. | 346 * relies on the fact that these classes do not override [] nor []=. |
| 331 */ | 347 */ |
| 332 class JSMutableArray<E> extends JSArray<E> implements JSMutableIndexable {} | 348 class JSMutableArray<E> extends JSArray<E> implements JSMutableIndexable {} |
| 333 class JSFixedArray<E> extends JSMutableArray<E> {} | 349 class JSFixedArray<E> extends JSMutableArray<E> {} |
| 334 class JSExtendableArray<E> extends JSMutableArray<E> {} | 350 class JSExtendableArray<E> extends JSMutableArray<E> {} |
| 351 class JSUnmodifiableArray<E> extends JSArray<E> {} // Already is JSIndexable. |
| OLD | NEW |