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