MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / iter_next

Function iter_next

src/PyIterableProxyHandler.cc:25–57  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23
24
25static 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
59static bool iterable_next(JSContext *cx, unsigned argc, JS::Value *vp) {
60 JS::CallArgs args = JS::CallArgsFromVp(argc, vp);

Callers 2

iterable_nextFunction · 0.85
iterator_nextFunction · 0.85

Calls 1

jsTypeFactoryFunction · 0.85

Tested by

no test coverage detected