| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of js.wrapping; | 5 part of js.wrapping; |
| 6 | 6 |
| 7 /// Adapter to handle a js array as a dart [List]. | 7 /// Adapter to handle a js array as a dart [List]. |
| 8 /// You can provide a translator to automatically wrap contained Proxy to some | 8 /// You can provide a translator to automatically wrap contained Proxy to some |
| 9 /// TypedProxy or something else. | 9 /// TypedProxy or something else. |
| 10 class JsArrayToListAdapter<E> extends TypedProxy /*with ListMixin<E>*/ | 10 class JsArrayToListAdapter<E> extends TypedProxy /*with ListMixin<E>*/ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 /// Create a new adapter from a proxy of a Js list. | 28 /// Create a new adapter from a proxy of a Js list. |
| 29 JsArrayToListAdapter.fromProxy(Proxy proxy, [Translator<E> translator]) | 29 JsArrayToListAdapter.fromProxy(Proxy proxy, [Translator<E> translator]) |
| 30 : this._translator = translator, | 30 : this._translator = translator, |
| 31 super.fromProxy(proxy); | 31 super.fromProxy(proxy); |
| 32 | 32 |
| 33 // Iterable | 33 // Iterable |
| 34 @override Iterator<E> get iterator => new _JsIterator<E>(this); | 34 @override Iterator<E> get iterator => new _JsIterator<E>(this); |
| 35 @override int get length => $unsafe.length; | 35 @override int get length => $unsafe.length; |
| 36 | 36 |
| 37 // Collection | 37 // List |
| 38 @override void set last(E value) { |
| 39 if (length == 0) throw new StateError("No element"); |
| 40 this[length - 1] = value; |
| 41 } |
| 38 @override void add(E value) { $unsafe.push(_toJs(value)); } | 42 @override void add(E value) { $unsafe.push(_toJs(value)); } |
| 39 @override void clear() { this.length = 0; } | 43 @override void clear() { this.length = 0; } |
| 40 @override bool remove(Object element) => removeAt(indexOf(element)) != null; | 44 @override bool remove(Object element) => removeAt(indexOf(element)) != null; |
| 41 | 45 |
| 42 // List | |
| 43 @override E operator [](int index) { | 46 @override E operator [](int index) { |
| 44 if (index < 0 || index >= this.length) throw new RangeError.value(index); | 47 if (index < 0 || index >= this.length) throw new RangeError.value(index); |
| 45 return _fromJs($unsafe[index]); | 48 return _fromJs($unsafe[index]); |
| 46 } | 49 } |
| 47 @override void operator []=(int index, E value) { | 50 @override void operator []=(int index, E value) { |
| 48 if (index < 0 || index >= this.length) throw new RangeError.value(index); | 51 if (index < 0 || index >= this.length) throw new RangeError.value(index); |
| 49 $unsafe[index] = _toJs(value); | 52 $unsafe[index] = _toJs(value); |
| 50 } | 53 } |
| 51 @override void set length(int length) { $unsafe.length = length; } | 54 @override void set length(int length) { $unsafe.length = length; } |
| 52 @override void sort([int compare(E a, E b)]) { | 55 @override void sort([int compare(E a, E b)]) { |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 // Iterator | 552 // Iterator |
| 550 @override bool moveNext() { | 553 @override bool moveNext() { |
| 551 if (_currentIndex + 1 < length) { | 554 if (_currentIndex + 1 < length) { |
| 552 _currentIndex++; | 555 _currentIndex++; |
| 553 return true; | 556 return true; |
| 554 } | 557 } |
| 555 return false; | 558 return false; |
| 556 } | 559 } |
| 557 @override E get current => _jsArray[_currentIndex]; | 560 @override E get current => _jsArray[_currentIndex]; |
| 558 } | 561 } |
| OLD | NEW |