| 23 | |
| 24 | |
| 25 | static bool iter_next(JSContext *cx, JS::CallArgs args, PyObject *it) { |
| 26 | JS::RootedObject result(cx, JS_NewPlainObject(cx)); |
| 27 | |
| 28 | PyObject *(*iternext)(PyObject *) = *Py_TYPE(it)->tp_iternext; |
| 29 | |
| 30 | PyObject *item = iternext(it); |
| 31 | |
| 32 | if (item == NULL) { |
| 33 | if (PyErr_Occurred()) { |
| 34 | if (PyErr_ExceptionMatches(PyExc_StopIteration) || |
| 35 | PyErr_ExceptionMatches(PyExc_SystemError)) { // TODO this handles a result like SystemError: Objects/dictobject.c:1778: bad argument to internal function. Why are we getting that? |
| 36 | PyErr_Clear(); |
| 37 | } |
| 38 | else { |
| 39 | return false; |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | JS::RootedValue done(cx, JS::BooleanValue(true)); |
| 44 | if (!JS_SetProperty(cx, result, "done", done)) return false; |
| 45 | args.rval().setObject(*result); |
| 46 | return result; |
| 47 | } |
| 48 | |
| 49 | JS::RootedValue done(cx, JS::BooleanValue(false)); |
| 50 | if (!JS_SetProperty(cx, result, "done", done)) return false; |
| 51 | |
| 52 | JS::RootedValue value(cx, jsTypeFactory(cx, item)); |
| 53 | if (!JS_SetProperty(cx, result, "value", value)) return false; |
| 54 | |
| 55 | args.rval().setObject(*result); |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | static bool iterable_next(JSContext *cx, unsigned argc, JS::Value *vp) { |
| 60 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
no test coverage detected