1/*
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef ECMASCRIPT_JOBS_MICRO_JOB_QUEUE_H
17#define ECMASCRIPT_JOBS_MICRO_JOB_QUEUE_H
18
19#include "ecmascript/js_function.h"
20#include "ecmascript/js_handle.h"
21#include "ecmascript/js_thread.h"
22#include "ecmascript/record.h"
23#include "ecmascript/tagged_array.h"
24
25namespace panda::ecmascript::job {
26
27class MicroJobQueue final : public Record {
28public:
29    static MicroJobQueue *Cast(TaggedObject *object)
30    {
31        ASSERT(JSTaggedValue(object).IsMicroJobQueue());
32        return static_cast<MicroJobQueue *>(object);
33    }
34
35    static uint32_t GetPromiseQueueSize(JSThread *thread, JSHandle<MicroJobQueue> jobQueue);
36    static void EnqueueJob(JSThread *thread, JSHandle<MicroJobQueue> jobQueue, QueueType queueType,
37        const JSHandle<JSFunction> &job, const JSHandle<TaggedArray> &argv);
38    static void ExecutePendingJob(JSThread *thread, JSHandle<MicroJobQueue> jobQueue);
39
40    static constexpr size_t PROMISE_JOB_QUEUE_OFFSET = Record::SIZE;
41    ACCESSORS(PromiseJobQueue, PROMISE_JOB_QUEUE_OFFSET, SCRIPT_JOB_QUEUE_OFFSET);
42    ACCESSORS(ScriptJobQueue, SCRIPT_JOB_QUEUE_OFFSET, SIZE);
43
44    DECL_DUMP()
45
46    DECL_VISIT_OBJECT(PROMISE_JOB_QUEUE_OFFSET, SIZE)
47};
48}  // namespace panda::ecmascript::job
49#endif  // ECMASCRIPT_JOBS_MICRO_JOB_QUEUE_H
50