Chromium Code Reviews| 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; |