| 23 | */ |
| 24 | |
| 25 | static bool enqueueWithDelay(JSContext *cx, unsigned argc, JS::Value *vp) { |
| 26 | if (PyErr_Occurred() && PyErr_ExceptionMatches(PyExc_SystemExit)) { |
| 27 | // quit, exit or sys.exit was called (and raised SystemExit) |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
| 32 | JS::HandleValue jobArgVal = args.get(0); |
| 33 | double delaySeconds = args.get(1).toNumber(); |
| 34 | bool repeat = args.get(2).toBoolean(); |
| 35 | JS::HandleValue debugInfo = args.get(3); |
| 36 | |
| 37 | // Convert to a Python function |
| 38 | JS::RootedValue jobArg(cx, jobArgVal); |
| 39 | PyObject *job = pyTypeFactory(cx, jobArg); |
| 40 | // Schedule job to the running Python event-loop |
| 41 | PyEventLoop loop = PyEventLoop::getRunningLoop(); |
| 42 | if (!loop.initialized()) return false; |
| 43 | PyEventLoop::AsyncHandle::id_t handleId = loop.enqueueWithDelay(job, delaySeconds, repeat); |
| 44 | Py_DECREF(job); |
| 45 | |
| 46 | // Set debug info for the WTFPythonMonkey tool |
| 47 | auto handle = PyEventLoop::AsyncHandle::fromId(handleId); |
| 48 | handle->setDebugInfo(pyTypeFactory(cx, debugInfo)); |
| 49 | |
| 50 | // Return the `timeoutID` to use in `clearTimeout` |
| 51 | args.rval().setNumber(handleId); |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | static bool cancelByTimeoutId(JSContext *cx, unsigned argc, JS::Value *vp) { |
| 56 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
no test coverage detected