Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/JSObjectProxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_iter_next(JSObjectProxy

PyObject *retVal = JSFunctionProxyMethodDefinitions::JSFunctionProxy_call(nextFunction, PyTuple_New(0), NULL);
Py_DECREF(nextFunction);
if (retVal == NULL) {
if (PyErr_Occurred()) {
PyErr_PrintEx(0);
}
PyErr_SetNone(PyExc_StopIteration);
return NULL;
}

// check if end of iteration
key = PyUnicode_FromString("done");
Expand Down
16 changes: 16 additions & 0 deletions tests/python/test_dict_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,19 @@ def test_next_operator():
assert (True)
fourth = next(myit, 'default')
assert fourth == 'default'


def test_next_operator_non_iterator():
make_js_generator = pm.eval("""
function* sliceGenerator(pyIter)
{
yield python.eval('lambda x: next(x)')(pyIter);
}
sliceGenerator;
""")

try:
next(make_js_generator(range(0,5)))
assert (False)
except StopIteration as e:
assert (True)
Loading