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

Unified Diff: sdk/lib/html/dart2js/html_dart2js.dart

Issue 11410086: Use iterator, moveNext(), current. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Created 8 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/html/dart2js/html_dart2js.dart
diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
index 8f57237866b59614b7124ae17e72be5eccd71d55..48df3202f20a669ceffd65679ee95b04e2b1e0c4 100644
--- a/sdk/lib/html/dart2js/html_dart2js.dart
+++ b/sdk/lib/html/dart2js/html_dart2js.dart
@@ -5310,7 +5310,7 @@ class DOMMimeTypeArray implements JavaScriptIndexingBehavior, List<DOMMimeType>
// From Iterable<DOMMimeType>:
- Iterator<DOMMimeType> iterator() {
+ Iterator<DOMMimeType> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -5449,7 +5449,7 @@ class DOMPluginArray implements JavaScriptIndexingBehavior, List<DOMPlugin> nati
// From Iterable<DOMPlugin>:
- Iterator<DOMPlugin> iterator() {
+ Iterator<DOMPlugin> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -6801,7 +6801,7 @@ class _ChildrenElementList implements List {
Element addLast(Element value) => add(value);
- Iterator<Element> iterator() => _toList().iterator();
+ Iterator<Element> get iterator => _toList().iterator;
void addAll(Collection<Element> collection) {
for (Element element in collection) {
@@ -6938,7 +6938,7 @@ class _FrozenElementList implements List {
throw new UnsupportedError('');
}
- Iterator<Element> iterator() => new _FrozenElementListIterator(this);
+ Iterator<Element> get iterator => new _FrozenElementListIterator(this);
void addAll(Collection<Element> collection) {
throw new UnsupportedError('');
@@ -6987,21 +6987,29 @@ class _FrozenElementListIterator implements Iterator<Element> {
_FrozenElementListIterator(this._list);
/**
- * Gets the next element in the iteration. Throws a
- * [StateError("No more elements")] if no element is left.
+ * Moves to the next element. Returns true if the iterator is positioned
+ * at an element. Returns false if it is positioned after the last element.
*/
- Element next() {
- if (!hasNext) {
- throw new StateError("No more elements");
- }
-
- return _list[_index++];
+ bool moveNext() {
+ _index++;
+ if (_index < _list.length) return true;
+ _index = _list.length;
+ return false;
}
/**
- * Returns whether the [Iterator] has elements left.
+ * Returns the element the [Iterator] is positioned at.
+ *
+ * Throws a [StateError] if the iterator is positioned before the first, or
+ * after the last element.
*/
- bool get hasNext => _index < _list.length;
+ bool get current {
+ if (0 <= _index && _index < _list.length) {
+ return _list[_index];
+ }
+ // TODO(floitsch): adapt the error message.
+ throw new StateError("No more elements");
+ }
}
/**
@@ -8594,7 +8602,7 @@ class Float32Array extends ArrayBufferView implements JavaScriptIndexingBehavior
// From Iterable<num>:
- Iterator<num> iterator() {
+ Iterator<num> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -8703,7 +8711,7 @@ class Float64Array extends ArrayBufferView implements JavaScriptIndexingBehavior
// From Iterable<num>:
- Iterator<num> iterator() {
+ Iterator<num> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -9069,7 +9077,7 @@ class HTMLAllCollection implements JavaScriptIndexingBehavior, List<Node> native
// From Iterable<Node>:
- Iterator<Node> iterator() {
+ Iterator<Node> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -9172,7 +9180,7 @@ class HTMLCollection implements JavaScriptIndexingBehavior, List<Node> native "*
// From Iterable<Node>:
- Iterator<Node> iterator() {
+ Iterator<Node> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -10740,7 +10748,7 @@ class Int16Array extends ArrayBufferView implements JavaScriptIndexingBehavior,
// From Iterable<int>:
- Iterator<int> iterator() {
+ Iterator<int> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -10849,7 +10857,7 @@ class Int32Array extends ArrayBufferView implements JavaScriptIndexingBehavior,
// From Iterable<int>:
- Iterator<int> iterator() {
+ Iterator<int> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -10958,7 +10966,7 @@ class Int8Array extends ArrayBufferView implements JavaScriptIndexingBehavior, L
// From Iterable<int>:
- Iterator<int> iterator() {
+ Iterator<int> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -13108,7 +13116,7 @@ class NamedNodeMap implements JavaScriptIndexingBehavior, List<Node> native "*Na
// From Iterable<Node>:
- Iterator<Node> iterator() {
+ Iterator<Node> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -13360,7 +13368,7 @@ class _ChildNodeListLazy implements List {
_this.$dom_replaceChild(value, this[index]);
}
- Iterator<Node> iterator() => _this.$dom_childNodes.iterator();
+ Iterator<Node> get iterator => _this.$dom_childNodes.iterator;
// TODO(jacobr): We can implement these methods much more efficiently by
// looking up the nodeList only once instead of once per iteration.
@@ -13653,7 +13661,7 @@ class _ListWrapper<E> implements List<E> {
_ListWrapper(List this._list);
- Iterator<E> iterator() => _list.iterator();
+ Iterator<E> get iterator => _list.iterator;
bool contains(E element) => _list.contains(element);
@@ -13733,7 +13741,7 @@ class NodeList implements JavaScriptIndexingBehavior, List<Node> native "*NodeLi
// From Iterable<Node>:
- Iterator<Node> iterator() {
+ Iterator<Node> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -15424,7 +15432,7 @@ class SQLResultSetRowList implements JavaScriptIndexingBehavior, List<Map> nativ
// From Iterable<Map>:
- Iterator<Map> iterator() {
+ Iterator<Map> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -15938,7 +15946,7 @@ class SourceBufferList extends EventTarget implements JavaScriptIndexingBehavior
// From Iterable<SourceBuffer>:
- Iterator<SourceBuffer> iterator() {
+ Iterator<SourceBuffer> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -16091,7 +16099,7 @@ class SpeechGrammarList implements JavaScriptIndexingBehavior, List<SpeechGramma
// From Iterable<SpeechGrammar>:
- Iterator<SpeechGrammar> iterator() {
+ Iterator<SpeechGrammar> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -17110,7 +17118,7 @@ class TextTrackCueList implements List<TextTrackCue>, JavaScriptIndexingBehavior
// From Iterable<TextTrackCue>:
- Iterator<TextTrackCue> iterator() {
+ Iterator<TextTrackCue> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -17216,7 +17224,7 @@ class TextTrackList extends EventTarget implements JavaScriptIndexingBehavior, L
// From Iterable<TextTrack>:
- Iterator<TextTrack> iterator() {
+ Iterator<TextTrack> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -17440,7 +17448,7 @@ class TouchList implements JavaScriptIndexingBehavior, List<Touch> native "*Touc
// From Iterable<Touch>:
- Iterator<Touch> iterator() {
+ Iterator<Touch> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -17714,7 +17722,7 @@ class Uint16Array extends ArrayBufferView implements JavaScriptIndexingBehavior,
// From Iterable<int>:
- Iterator<int> iterator() {
+ Iterator<int> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -17823,7 +17831,7 @@ class Uint32Array extends ArrayBufferView implements JavaScriptIndexingBehavior,
// From Iterable<int>:
- Iterator<int> iterator() {
+ Iterator<int> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -17932,7 +17940,7 @@ class Uint8Array extends ArrayBufferView implements JavaScriptIndexingBehavior,
// From Iterable<int>:
- Iterator<int> iterator() {
+ Iterator<int> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -20118,7 +20126,7 @@ class _CSSRuleList implements JavaScriptIndexingBehavior, List<CSSRule> native "
// From Iterable<CSSRule>:
- Iterator<CSSRule> iterator() {
+ Iterator<CSSRule> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -20215,7 +20223,7 @@ class _CSSValueList extends CSSValue implements List<CSSValue>, JavaScriptIndexi
// From Iterable<CSSValue>:
- Iterator<CSSValue> iterator() {
+ Iterator<CSSValue> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -20312,7 +20320,7 @@ class _ClientRectList implements JavaScriptIndexingBehavior, List<ClientRect> na
// From Iterable<ClientRect>:
- Iterator<ClientRect> iterator() {
+ Iterator<ClientRect> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -20418,7 +20426,7 @@ class _DOMStringList implements JavaScriptIndexingBehavior, List<String> native
// From Iterable<String>:
- Iterator<String> iterator() {
+ Iterator<String> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -20840,7 +20848,7 @@ class _EntryArray implements JavaScriptIndexingBehavior, List<Entry> native "*En
// From Iterable<Entry>:
- Iterator<Entry> iterator() {
+ Iterator<Entry> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -20937,7 +20945,7 @@ class _EntryArraySync implements JavaScriptIndexingBehavior, List<EntrySync> nat
// From Iterable<EntrySync>:
- Iterator<EntrySync> iterator() {
+ Iterator<EntrySync> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -21043,7 +21051,7 @@ class _FileList implements JavaScriptIndexingBehavior, List<File> native "*FileL
// From Iterable<File>:
- Iterator<File> iterator() {
+ Iterator<File> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -21169,7 +21177,7 @@ class _GamepadList implements JavaScriptIndexingBehavior, List<Gamepad> native "
// From Iterable<Gamepad>:
- Iterator<Gamepad> iterator() {
+ Iterator<Gamepad> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -21319,7 +21327,7 @@ class _MediaStreamList implements JavaScriptIndexingBehavior, List<MediaStream>
// From Iterable<MediaStream>:
- Iterator<MediaStream> iterator() {
+ Iterator<MediaStream> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -21579,7 +21587,7 @@ class _SpeechInputResultList implements JavaScriptIndexingBehavior, List<SpeechI
// From Iterable<SpeechInputResult>:
- Iterator<SpeechInputResult> iterator() {
+ Iterator<SpeechInputResult> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -21685,7 +21693,7 @@ class _SpeechRecognitionResultList implements JavaScriptIndexingBehavior, List<S
// From Iterable<SpeechRecognitionResult>:
- Iterator<SpeechRecognitionResult> iterator() {
+ Iterator<SpeechRecognitionResult> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -21782,7 +21790,7 @@ class _StyleSheetList implements JavaScriptIndexingBehavior, List<StyleSheet> na
// From Iterable<StyleSheet>:
- Iterator<StyleSheet> iterator() {
+ Iterator<StyleSheet> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -21903,7 +21911,7 @@ class _WebKitAnimationList implements JavaScriptIndexingBehavior, List<Animation
// From Iterable<Animation>:
- Iterator<Animation> iterator() {
+ Iterator<Animation> get iterator {
// Note: NodeLists are not fixed size. And most probably length shouldn't
// be cached in both iterator _and_ forEach method. For now caching it
// for consistency.
@@ -23161,7 +23169,7 @@ class _Collections {
}
static bool isEmpty(Iterable<Object> iterable) {
- return !iterable.iterator().hasNext;
+ return !iterable.iterator.moveNext();
}
}
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file

Powered by Google App Engine
This is Rietveld 408576698