| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
package org.mozilla.javascript; |
| 8 |
|
| 9 |
public final class NativeArrayIterator extends ES6Iterator { |
| 10 |
private static final long serialVersionUID = 1L; |
| 11 |
private static final String ITERATOR_TAG = "ArrayIterator"; |
| 12 |
|
| 13 |
static void init(ScriptableObject scope, boolean sealed) { |
| 14 |
ES6Iterator.init(scope, sealed, new NativeArrayIterator(), ITERATOR_TAG); |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
private NativeArrayIterator() { |
| 21 |
super(); |
| 22 |
} |
| 23 |
|
| 24 |
public NativeArrayIterator(Scriptable scope, Scriptable arrayLike) { |
| 25 |
super(scope); |
| 26 |
this.index = 0; |
| 27 |
this.arrayLike = arrayLike; |
| 28 |
} |
| 29 |
|
| 30 |
@Override |
| 31 |
public String getClassName() { |
| 32 |
return "Array Iterator"; |
| 33 |
} |
| 34 |
|
| 35 |
@Override |
| 36 |
protected boolean isDone(Context cx, Scriptable scope) { |
| 37 |
return index >= NativeArray.getLengthProperty(cx, arrayLike); |
| 38 |
} |
| 39 |
|
| 40 |
@Override |
| 41 |
protected Object nextValue(Context cx, Scriptable scope) { |
| 42 |
Object value = arrayLike.get(index++, arrayLike); |
| 43 |
if (value == ScriptableObject.NOT_FOUND) { |
| 44 |
value = Undefined.instance; |
| 45 |
} |
| 46 |
return value; |
| 47 |
} |
| 48 |
|
| 49 |
@Override |
| 50 |
protected String getTag() { |
| 51 |
return ITERATOR_TAG; |
| 52 |
} |
| 53 |
|
| 54 |
private Scriptable arrayLike; |
| 55 |
private int index; |
| 56 |
} |
| 57 |
|