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

Unified Diff: frog/leg/lib/core.dart

Issue 9148021: Implement for-in. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | frog/leg/resolver.dart » ('j') | frog/leg/resolver.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: frog/leg/lib/core.dart
diff --git a/frog/leg/lib/core.dart b/frog/leg/lib/core.dart
index 30a517b6174dcbb244ba5c8b5817862c489e20a4..b10a1104d0de27bd84c12af3fa28739189fb243a 100644
--- a/frog/leg/lib/core.dart
+++ b/frog/leg/lib/core.dart
@@ -295,16 +295,34 @@ builtin$toString$0(var value) {
}
+builtin$iterator$0(var receiver) {
+ if (isJSArray(receiver)) {
+ return new ListIterator(receiver);
+ }
+ return UNINTERCEPTED(receiver.iterator());
+}
+
+
bool isInt(var v) {
return JS("bool", @"($0 | 0) === $1", v, v);
}
+/* Include when interfaces are implemented
+interface Iterable<T> {
+ Iterator<T> iterator();
+}
+
+interface Iterator<T> {
+ bool hasNext();
+ T next();
+}
+*/
class int {}
class double {}
class String {}
class bool {}
class Object {}
-class List<T> {
+class List<T> /* implements Iterable<T> */ {
static void _checkConstructorInput(n) {
// TODO(ngeoffray): Inline once we support optional parameters or
// bailout.
@@ -320,6 +338,18 @@ class List<T> {
}
}
+class ListIterator<T> /* implements Iterator<T> */ {
ngeoffray 2012/01/11 10:09:22 I'd prefer calling it ForeignListIterator.
+ int i;
+ List<T> list;
+ ListIterator(List<T> list) : this.list = list, i = 0;
+ bool hasNext() => i < JS("int", @"$0.length", list);
+ T next() {
+ var value = JS("Object", @"$0[$1]", list, i);
+ i += 1;
+ return value;
+ }
+}
+
class Expect {
static void equals(var expected, var actual) {
if (expected == actual) return;
« no previous file with comments | « no previous file | frog/leg/resolver.dart » ('j') | frog/leg/resolver.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698