(t *table, key int)
| 222 | } |
| 223 | |
| 224 | func (l *State) next(t *table, key int) bool { |
| 225 | i, k := 0, l.stack[key] |
| 226 | if k == nil { // first iteration |
| 227 | } else if i = arrayIndex(k); 0 < i && i <= len(t.array) { |
| 228 | k = nil |
| 229 | } else if _, ok := t.hash[k]; !ok { |
| 230 | l.runtimeError("invalid key to 'next'") // key not found |
| 231 | } else { |
| 232 | i = len(t.array) |
| 233 | } |
| 234 | for ; i < len(t.array); i++ { |
| 235 | if t.array[i] != nil { |
| 236 | l.stack[key] = float64(i + 1) |
| 237 | l.stack[key+1] = t.array[i] |
| 238 | return true |
| 239 | } |
| 240 | } |
| 241 | if t.iterationKeys == nil { |
| 242 | j, keys := 0, make([]value, len(t.hash)) |
| 243 | for hk := range t.hash { |
| 244 | keys[j] = hk |
| 245 | j++ |
| 246 | } |
| 247 | t.iterationKeys = keys |
| 248 | } |
| 249 | found := k == nil |
| 250 | for i, hk := range t.iterationKeys { |
| 251 | if hk == nil { // skip deleted key |
| 252 | } else if _, present := t.hash[hk]; !present { |
| 253 | t.iterationKeys[i] = nil // mark key as deleted |
| 254 | } else if found { |
| 255 | l.stack[key] = hk |
| 256 | l.stack[key+1] = t.hash[hk] |
| 257 | return true |
| 258 | } else if l.equalObjects(hk, k) { |
| 259 | found = true |
| 260 | } |
| 261 | } |
| 262 | return false // no more elements |
| 263 | } |
no test coverage detected