• 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_PENDING_JOB_H
17 #define ECMASCRIPT_JOBS_PENDING_JOB_H
18 
19 #include "ecmascript/ecma_macros.h"
20 #include "ecmascript/interpreter/interpreter.h"
21 #include "ecmascript/jobs/hitrace_scope.h"
22 #include "ecmascript/js_function.h"
23 #include "ecmascript/js_handle.h"
24 #include "ecmascript/object_factory.h"
25 #include "ecmascript/record.h"
26 #include "ecmascript/tagged_array.h"
27 #include "ecmascript/debugger/js_debugger_manager.h"
28 #include "ecmascript/mem/c_containers.h"
29 
30 namespace panda::ecmascript::job {
31 class PendingJob final : public Record {
32 public:
Cast(TaggedObject * object)33     static PendingJob *Cast(TaggedObject *object)
34     {
35         ASSERT(JSTaggedValue(object).IsPendingJob());
36         return static_cast<PendingJob *>(object);
37     }
38 
ExecutePendingJob(const JSHandle<PendingJob> & pendingJob,JSThread * thread)39     static JSTaggedValue ExecutePendingJob(const JSHandle<PendingJob> &pendingJob, JSThread *thread)
40     {
41         [[maybe_unused]] EcmaHandleScope handleScope(thread);
42         EXECUTE_JOB_HITRACE(pendingJob);
43 
44         JSHandle<JSTaggedValue> job(thread, pendingJob->GetJob());
45         ASSERT(job->IsCallable());
46         JSHandle<TaggedArray> argv(thread, pendingJob->GetArguments());
47         const uint32_t argsLength = argv->GetLength();
48         JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined();
49         EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, job, undefined, undefined, argsLength);
50         RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread);
51         info->SetCallArg(argsLength, argv);
52         return JSFunction::Call(info);
53     }
54 
55     static constexpr size_t JOB_OFFSET = Record::SIZE;
56     ACCESSORS(Job, JOB_OFFSET, ARGUMENT_OFFSET);
57 #if defined(ENABLE_HITRACE)
58     ACCESSORS(Arguments, ARGUMENT_OFFSET, CHAINID_OFFSET);
59     ACCESSORS_PRIMITIVE_FIELD(ChainId, uint64_t, CHAINID_OFFSET, SPANID_OFFSET)
60     ACCESSORS_PRIMITIVE_FIELD(SpanId, uint64_t, SPANID_OFFSET, PARENTSPANID_OFFSET)
61     ACCESSORS_PRIMITIVE_FIELD(ParentSpanId, uint64_t, PARENTSPANID_OFFSET, FLAGS_OFFSET)
62     ACCESSORS_PRIMITIVE_FIELD(Flags, uint32_t, FLAGS_OFFSET, LAST_OFFSET)
63     DEFINE_ALIGN_SIZE(LAST_OFFSET);
64 
65     DECL_VISIT_OBJECT(JOB_OFFSET, CHAINID_OFFSET)
66 #else
67     ACCESSORS(Arguments, ARGUMENT_OFFSET, SIZE);
68 
69     DECL_VISIT_OBJECT(JOB_OFFSET, SIZE)
70 #endif
71 
72     DECL_DUMP()
73 };
74 }  // namespace panda::ecmascript::job
75 #endif  // ECMASCRIPT_JOBS_PENDING_JOB_H
76