Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: third_party/pkg/js/lib/src/wrapping/js/array_to_list_adapter.dart

Issue 24740003: Add List.shuffle(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adddress comments Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/corelib/shuffle_test.dart ('k') | tools/dom/src/ImmutableListMixin.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>*/ implement s List<E> { 10 class JsArrayToListAdapter<E> extends TypedProxy /*with ListMixin<E>*/ implement s List<E> {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 } 45 }
46 @override void operator []=(int index, E value) { 46 @override void operator []=(int index, E value) {
47 if (index < 0 || index >= this.length) throw new RangeError.value(index); 47 if (index < 0 || index >= this.length) throw new RangeError.value(index);
48 $unsafe[index] = _toJs(value); 48 $unsafe[index] = _toJs(value);
49 } 49 }
50 @override void set length(int length) { $unsafe.length = length; } 50 @override void set length(int length) { $unsafe.length = length; }
51 @override void sort([int compare(E a, E b)]) { 51 @override void sort([int compare(E a, E b)]) {
52 final sortedList = _asList()..sort(compare); 52 final sortedList = _asList()..sort(compare);
53 setRange(0, sortedList.length, sortedList); 53 setRange(0, sortedList.length, sortedList);
54 } 54 }
55 @override void shuffle() {
56 final shuffledList = _asList()..shuffle();
57 setRange(0, shuffledList.length, shuffledLength);
58 }
55 @override void insert(int index, E element) { 59 @override void insert(int index, E element) {
56 $unsafe.splice(index, 0, _toJs(element)); 60 $unsafe.splice(index, 0, _toJs(element));
57 } 61 }
58 @override E removeAt(int index) { 62 @override E removeAt(int index) {
59 if (index < 0 || index >= this.length) throw new RangeError.value(index); 63 if (index < 0 || index >= this.length) throw new RangeError.value(index);
60 return _fromJs($unsafe.splice(index, 1)[0]); 64 return _fromJs($unsafe.splice(index, 1)[0]);
61 } 65 }
62 @override E removeLast() => _fromJs($unsafe.pop()); 66 @override E removeLast() => _fromJs($unsafe.pop());
63 @override List<E> sublist(int start, [int end]) => 67 @override List<E> sublist(int start, [int end]) =>
64 _asList().sublist(start, end); 68 _asList().sublist(start, end);
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 // Iterator 547 // Iterator
544 @override bool moveNext() { 548 @override bool moveNext() {
545 if (_currentIndex + 1 < length) { 549 if (_currentIndex + 1 < length) {
546 _currentIndex++; 550 _currentIndex++;
547 return true; 551 return true;
548 } 552 }
549 return false; 553 return false;
550 } 554 }
551 @override E get current => _jsArray[_currentIndex]; 555 @override E get current => _jsArray[_currentIndex];
552 } 556 }
OLDNEW
« no previous file with comments | « tests/corelib/shuffle_test.dart ('k') | tools/dom/src/ImmutableListMixin.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698