()
| 18 | } |
| 19 | |
| 20 | func (ai *arrayIterObject) next() Value { |
| 21 | if ai.obj == nil { |
| 22 | return ai.val.runtime.createIterResultObject(_undefined, true) |
| 23 | } |
| 24 | if ta, ok := ai.obj.self.(*typedArrayObject); ok { |
| 25 | ta.viewedArrayBuf.ensureNotDetached(true) |
| 26 | } |
| 27 | l := toLength(ai.obj.self.getStr("length", nil)) |
| 28 | index := ai.nextIdx |
| 29 | if index >= l { |
| 30 | ai.obj = nil |
| 31 | return ai.val.runtime.createIterResultObject(_undefined, true) |
| 32 | } |
| 33 | ai.nextIdx++ |
| 34 | idxVal := valueInt(index) |
| 35 | if ai.kind == iterationKindKey { |
| 36 | return ai.val.runtime.createIterResultObject(idxVal, false) |
| 37 | } |
| 38 | elementValue := nilSafe(ai.obj.self.getIdx(idxVal, nil)) |
| 39 | var result Value |
| 40 | if ai.kind == iterationKindValue { |
| 41 | result = elementValue |
| 42 | } else { |
| 43 | result = ai.val.runtime.newArrayValues([]Value{idxVal, elementValue}) |
| 44 | } |
| 45 | return ai.val.runtime.createIterResultObject(result, false) |
| 46 | } |
| 47 | |
| 48 | func (r *Runtime) createArrayIterator(iterObj *Object, kind iterationKind) Value { |
| 49 | o := &Object{runtime: r} |
nothing calls this directly
no test coverage detected