PythonMonkey   v1.0.1 (dev)
Loading...
Searching...
No Matches
JobQueue.hh
Go to the documentation of this file.
1
11#ifndef PythonMonkey_JobQueue_
12#define PythonMonkey_JobQueue_
13
14#include <jsapi.h>
15#include <js/Promise.h>
16
17#include <Python.h>
18
24class JobQueue : public JS::JobQueue {
25
26public:
27explicit JobQueue(JSContext *cx);
28~JobQueue() = default;
29
35bool init(JSContext *cx);
36
44JSObject *getIncumbentGlobal(JSContext *cx) override;
45
55bool enqueuePromiseJob(JSContext *cx, JS::HandleObject promise,
56 JS::HandleObject job, JS::HandleObject allocationSite,
57 JS::HandleObject incumbentGlobal) override;
58
74void runJobs(JSContext *cx) override;
75
79bool empty() const override;
80
84bool isDrainingStopped() const override;
85
91void queueFinalizationRegistryCallback(JSFunction *callback);
92
100bool runFinalizationRegistryCallbacks(JSContext *cx);
101
102private:
103
104using FunctionVector = JS::GCVector<JSFunction *, 0, js::SystemAllocPolicy>;
105JS::PersistentRooted<FunctionVector> *finalizationRegistryCallbacks;
106
116js::UniquePtr<JS::JobQueue::SavedJobQueue> saveJobQueue(JSContext *) override;
117
126static bool dispatchToEventLoop(void *closure, JS::Dispatchable *dispatchable);
127
138static void promiseRejectionTracker(JSContext *cx, bool mutedErrors,
139 JS::HandleObject promise, JS::PromiseRejectionHandlingState state,
140 void *privateData);
141
142}; // class
143
150bool sendJobToMainLoop(PyObject *pyFunc);
151
152#endif
bool sendJobToMainLoop(PyObject *pyFunc)
Send job to the Python event-loop on main thread (Thread-Safe)
Definition JobQueue.cc:113
Implement the ECMAScript Job Queue: https://www.ecma-international.org/ecma-262/9....
Definition JobQueue.hh:24
bool empty() const override
Definition JobQueue.cc:60
bool isDrainingStopped() const override
Definition JobQueue.cc:65
bool init(JSContext *cx)
Initialize PythonMonkey's event-loop job queue.
Definition JobQueue.cc:79
~JobQueue()=default
void queueFinalizationRegistryCallback(JSFunction *callback)
Appends a callback to the queue of FinalizationRegistry callbacks.
Definition JobQueue.cc:166
void runJobs(JSContext *cx) override
Run all jobs in the queue. Running one job may enqueue others; continue to run jobs until the queue i...
Definition JobQueue.cc:56
bool runFinalizationRegistryCallbacks(JSContext *cx)
Runs the accumulated queue of FinalizationRegistry callbacks.
Definition JobQueue.cc:170
bool enqueuePromiseJob(JSContext *cx, JS::HandleObject promise, JS::HandleObject job, JS::HandleObject allocationSite, JS::HandleObject incumbentGlobal) override
Enqueue a reaction job job for promise, which was allocated at allocationSite. Provide incumbentGloba...
Definition JobQueue.cc:33
JSObject * getIncumbentGlobal(JSContext *cx) override
Ask the embedding for the incumbent global.
Definition JobQueue.cc:29