MCPcopy Create free account
hub / github.com/dop251/goja / next

Method next

array.go:20–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18}
19
20func (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
48func (r *Runtime) createArrayIterator(iterObj *Object, kind iterationKind) Value {
49 o := &Object{runtime: r}

Callers

nothing calls this directly

Calls 8

toLengthFunction · 0.85
valueIntTypeAlias · 0.85
nilSafeFunction · 0.85
ensureNotDetachedMethod · 0.80
newArrayValuesMethod · 0.80
getStrMethod · 0.65
getIdxMethod · 0.65

Tested by

no test coverage detected