mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-14 11:23:02 +02:00
6e15846d0f
* Added Context to HTML methods * Fixed unit tests * Updated timeout * Fixed WAIT_CLASS timeout
38 lines
739 B
Go
38 lines
739 B
Go
package common
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/MontFerret/ferret/pkg/drivers"
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
)
|
|
|
|
type Iterator struct {
|
|
node drivers.HTMLElement
|
|
pos values.Int
|
|
}
|
|
|
|
func NewIterator(
|
|
node drivers.HTMLElement,
|
|
) (core.Iterator, error) {
|
|
if node == nil {
|
|
return nil, core.Error(core.ErrMissedArgument, "result")
|
|
}
|
|
|
|
return &Iterator{node, 0}, nil
|
|
}
|
|
|
|
func (iterator *Iterator) Next(ctx context.Context) (value core.Value, key core.Value, err error) {
|
|
if iterator.node.Length() > iterator.pos {
|
|
idx := iterator.pos
|
|
val := iterator.node.GetChildNode(ctx, idx)
|
|
|
|
iterator.pos++
|
|
|
|
return val, idx, nil
|
|
}
|
|
|
|
return values.None, values.None, nil
|
|
}
|