• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_handle.h"
20 #include "ecmascript/js_thread.h"
21 #include "ecmascript/record.h"
22 #include "ecmascript/tagged_array.h"
23 
24 namespace panda::ecmascript::job {
25 enum class QueueType : uint8_t {
26     QUEUE_PROMISE,
27     QUEUE_SCRIPT,
28 };
29 
30 class MicroJobQueue final : public Record {
31 public:
Cast(TaggedObject * object)32     static MicroJobQueue *Cast(TaggedObject *object)
33     {
34         ASSERT(JSTaggedValue(object).IsMicroJobQueue());
35         return static_cast<MicroJobQueue *>(object);
36     }
37 
38     static void EnqueueJob(JSThread *thread, JSHandle<MicroJobQueue> jobQueue, QueueType queueType,
39         const JSHandle<JSFunction> &job, const JSHandle<TaggedArray> &argv);
40     static void ExecutePendingJob(JSThread *thread, JSHandle<MicroJobQueue> jobQueue);
41 
42     static constexpr size_t PROMISE_JOB_QUEUE_OFFSET = Record::SIZE;
43     ACCESSORS(PromiseJobQueue, PROMISE_JOB_QUEUE_OFFSET, SCRIPT_JOB_QUEUE_OFFSET);
44     ACCESSORS(ScriptJobQueue, SCRIPT_JOB_QUEUE_OFFSET, SIZE);
45 
46     DECL_DUMP()
47 
48     DECL_VISIT_OBJECT(PROMISE_JOB_QUEUE_OFFSET, SIZE)
49 };
50 }  // namespace panda::ecmascript::job
51 #endif  // ECMASCRIPT_JOBS_MICRO_JOB_QUEUE_H
52