Skip to content

Commit

Permalink
Merge pull request #438 from Distributive-Network/philippe/fix-435
Browse files Browse the repository at this point in the history
Detect exception in iterator next call and StopIteration
  • Loading branch information
philippedistributive authored Sep 11, 2024
2 parents 2cf0918 + 9c9ecf9 commit ee8a0f5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/JSObjectProxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ PyObject *JSObjectProxyMethodDefinitions::JSObjectProxy_iter_next(JSObjectProxy

PyObject *retVal = JSFunctionProxyMethodDefinitions::JSFunctionProxy_call(nextFunction, PyTuple_New(0), NULL);
Py_DECREF(nextFunction);
if (retVal == NULL) {
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 pm.SpiderMonkeyError as e:
assert "'range' object is not an iterator" in str(e)

0 comments on commit ee8a0f5

Please sign in to comment.