|
@@ -2625,7 +2625,15 @@ func (r *Runtime) getIterator(obj Value, method func(FunctionCall) Value) *itera
|
|
iter := r.toObject(method(FunctionCall{
|
|
iter := r.toObject(method(FunctionCall{
|
|
This: obj,
|
|
This: obj,
|
|
}))
|
|
}))
|
|
- next := toMethod(iter.self.getStr("next", nil))
|
|
|
|
|
|
+
|
|
|
|
+ var next func(FunctionCall) Value
|
|
|
|
+
|
|
|
|
+ if obj, ok := iter.self.getStr("next", nil).(*Object); ok {
|
|
|
|
+ if call, ok := obj.self.assertCallable(); ok {
|
|
|
|
+ next = call
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
return &iteratorRecord{
|
|
return &iteratorRecord{
|
|
iterator: iter,
|
|
iterator: iter,
|
|
next: next,
|
|
next: next,
|
|
@@ -2636,10 +2644,9 @@ func (ir *iteratorRecord) iterate(step func(Value)) {
|
|
r := ir.iterator.runtime
|
|
r := ir.iterator.runtime
|
|
for {
|
|
for {
|
|
if ir.next == nil {
|
|
if ir.next == nil {
|
|
- panic(r.NewTypeError("object null is not a function"))
|
|
|
|
|
|
+ panic(r.NewTypeError("iterator.next is missing or not a function"))
|
|
}
|
|
}
|
|
- nextVal := ir.next(FunctionCall{This: ir.iterator})
|
|
|
|
- res := r.toObject(nextVal)
|
|
|
|
|
|
+ res := r.toObject(ir.next(FunctionCall{This: ir.iterator}))
|
|
if nilSafe(res.self.getStr("done", nil)).ToBoolean() {
|
|
if nilSafe(res.self.getStr("done", nil)).ToBoolean() {
|
|
break
|
|
break
|
|
}
|
|
}
|