diff --git a/src/JSObjectProxy.cc b/src/JSObjectProxy.cc index 13b3e609..359b072d 100644 --- a/src/JSObjectProxy.cc +++ b/src/JSObjectProxy.cc @@ -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"); diff --git a/tests/python/test_dict_methods.py b/tests/python/test_dict_methods.py index a303f73a..d0fccba9 100644 --- a/tests/python/test_dict_methods.py +++ b/tests/python/test_dict_methods.py @@ -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) \ No newline at end of file