Pyrogenesis trunk
Promises.h
Go to the documentation of this file.
1/* Copyright (C) 2024 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_SCRIPTINTERFACE_JOBQUEUE
19#define INCLUDED_SCRIPTINTERFACE_JOBQUEUE
20
21#if MSC_VERSION
22# pragma warning(push, 1)
23#endif
24#include "js/Promise.h"
25#if MSC_VERSION
26# pragma warning(pop)
27#endif
28
29#include <queue>
30
31class ScriptInterface;
32
33namespace Script
34{
35void UnhandledRejectedPromise(JSContext* cx, bool, JS::HandleObject promise,
36 JS::PromiseRejectionHandlingState state, void*);
37
38class JobQueue final : public JS::JobQueue
39{
40public:
41 ~JobQueue() final = default;
42
43 void runJobs(JSContext*) final;
44
45private:
46 JSObject* getIncumbentGlobal(JSContext* cx) final;
47
48 bool enqueuePromiseJob(JSContext* cx, JS::HandleObject, JS::HandleObject job, JS::HandleObject,
49 JS::HandleObject) final;
50
51 bool empty() const final;
52
53 js::UniquePtr<JS::JobQueue::SavedJobQueue> saveJobQueue(JSContext*) final;
54
56 {
58 JS::PersistentRootedObject job;
59 };
60 using QueueType = std::queue<QueueElement>;
62};
63}
64
65#endif // INCLUDED_SCRIPTINTERFACE_JOBQUEUE
static enum @29 state
Abstraction around a SpiderMonkey JS::Realm.
Definition: ScriptInterface.h:72
Definition: Promises.h:39
void runJobs(JSContext *) final
Definition: Promises.cpp:47
bool enqueuePromiseJob(JSContext *cx, JS::HandleObject, JS::HandleObject job, JS::HandleObject, JS::HandleObject) final
Definition: Promises.cpp:67
JSObject * getIncumbentGlobal(JSContext *cx) final
Definition: Promises.cpp:62
js::UniquePtr< JS::JobQueue::SavedJobQueue > saveJobQueue(JSContext *) final
Definition: Promises.cpp:86
QueueType m_Jobs
Definition: Promises.h:61
~JobQueue() final=default
bool empty() const final
Definition: Promises.cpp:81
std::queue< QueueElement > QueueType
Definition: Promises.h:60
Definition: ScriptForward.h:41
Wraps SM APIs for manipulating JS objects.
Definition: JSON.h:35
void UnhandledRejectedPromise(JSContext *cx, bool, JS::HandleObject promise, JS::PromiseRejectionHandlingState state, void *)
Definition: Promises.cpp:31
Definition: ScriptForward.h:45
Definition: Promises.h:56
const ScriptInterface & scriptInterface
Definition: Promises.h:57
JS::PersistentRootedObject job
Definition: Promises.h:58