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 // List | 37 // Collection |
38 @override void set last(E value) { | |
39 if (length == 0) throw new StateError("No element"); | |
40 this[length - 1] = value; | |
41 } | |
42 @override void add(E value) { $unsafe.push(_toJs(value)); } | 38 @override void add(E value) { $unsafe.push(_toJs(value)); } |
43 @override void clear() { this.length = 0; } | 39 @override void clear() { this.length = 0; } |
44 @override bool remove(Object element) => removeAt(indexOf(element)) != null; | 40 @override bool remove(Object element) => removeAt(indexOf(element)) != null; |
45 | 41 |
| 42 // List |
46 @override E operator [](int index) { | 43 @override E operator [](int index) { |
47 if (index < 0 || index >= this.length) throw new RangeError.value(index); | 44 if (index < 0 || index >= this.length) throw new RangeError.value(index); |
48 return _fromJs($unsafe[index]); | 45 return _fromJs($unsafe[index]); |
49 } | 46 } |
50 @override void operator []=(int index, E value) { | 47 @override void operator []=(int index, E value) { |
51 if (index < 0 || index >= this.length) throw new RangeError.value(index); | 48 if (index < 0 || index >= this.length) throw new RangeError.value(index); |
52 $unsafe[index] = _toJs(value); | 49 $unsafe[index] = _toJs(value); |
53 } | 50 } |
54 @override void set length(int length) { $unsafe.length = length; } | 51 @override void set length(int length) { $unsafe.length = length; } |
55 @override void sort([int compare(E a, E b)]) { | 52 @override void sort([int compare(E a, E b)]) { |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 // Iterator | 549 // Iterator |
553 @override bool moveNext() { | 550 @override bool moveNext() { |
554 if (_currentIndex + 1 < length) { | 551 if (_currentIndex + 1 < length) { |
555 _currentIndex++; | 552 _currentIndex++; |
556 return true; | 553 return true; |
557 } | 554 } |
558 return false; | 555 return false; |
559 } | 556 } |
560 @override E get current => _jsArray[_currentIndex]; | 557 @override E get current => _jsArray[_currentIndex]; |
561 } | 558 } |
OLD | NEW |