14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_JOBS_PENDING_JOB_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_JOBS_PENDING_JOB_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include "ecmascript/ecma_macros.h" 204514f5e3Sopenharmony_ci#include "ecmascript/interpreter/interpreter.h" 214514f5e3Sopenharmony_ci#include "ecmascript/jobs/hitrace_scope.h" 224514f5e3Sopenharmony_ci#include "ecmascript/js_function.h" 234514f5e3Sopenharmony_ci#include "ecmascript/js_handle.h" 244514f5e3Sopenharmony_ci#include "ecmascript/object_factory.h" 254514f5e3Sopenharmony_ci#include "ecmascript/record.h" 264514f5e3Sopenharmony_ci#include "ecmascript/tagged_array.h" 274514f5e3Sopenharmony_ci#include "ecmascript/debugger/js_debugger_manager.h" 284514f5e3Sopenharmony_ci#include "ecmascript/mem/c_containers.h" 294514f5e3Sopenharmony_ci 304514f5e3Sopenharmony_cinamespace panda::ecmascript::job { 314514f5e3Sopenharmony_ciclass PendingJob final : public Record { 324514f5e3Sopenharmony_cipublic: 334514f5e3Sopenharmony_ci static PendingJob *Cast(TaggedObject *object) 344514f5e3Sopenharmony_ci { 354514f5e3Sopenharmony_ci ASSERT(JSTaggedValue(object).IsPendingJob()); 364514f5e3Sopenharmony_ci return static_cast<PendingJob *>(object); 374514f5e3Sopenharmony_ci } 384514f5e3Sopenharmony_ci 394514f5e3Sopenharmony_ci static JSTaggedValue ExecutePendingJob(const JSHandle<PendingJob> &pendingJob, JSThread *thread) 404514f5e3Sopenharmony_ci { 414514f5e3Sopenharmony_ci [[maybe_unused]] EcmaHandleScope handleScope(thread); 424514f5e3Sopenharmony_ci EXECUTE_JOB_HITRACE(pendingJob); 434514f5e3Sopenharmony_ci EXECUTE_JOB_TRACE(thread, pendingJob); 444514f5e3Sopenharmony_ci 454514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> job(thread, pendingJob->GetJob()); 464514f5e3Sopenharmony_ci ASSERT(job->IsCallable()); 474514f5e3Sopenharmony_ci JSHandle<TaggedArray> argv(thread, pendingJob->GetArguments()); 484514f5e3Sopenharmony_ci const uint32_t argsLength = argv->GetLength(); 494514f5e3Sopenharmony_ci JSHandle<JSTaggedValue> undefined = thread->GlobalConstants()->GetHandledUndefined(); 504514f5e3Sopenharmony_ci EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, job, undefined, undefined, argsLength); 514514f5e3Sopenharmony_ci RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); 524514f5e3Sopenharmony_ci info->SetCallArg(argsLength, argv); 534514f5e3Sopenharmony_ci return JSFunction::Call(info); 544514f5e3Sopenharmony_ci } 554514f5e3Sopenharmony_ci 564514f5e3Sopenharmony_ci static constexpr size_t JOB_OFFSET = Record::SIZE; 574514f5e3Sopenharmony_ci ACCESSORS(Job, JOB_OFFSET, ARGUMENT_OFFSET); 584514f5e3Sopenharmony_ci#if defined(ENABLE_HITRACE) 594514f5e3Sopenharmony_ci ACCESSORS(Arguments, ARGUMENT_OFFSET, CHAINID_OFFSET); 604514f5e3Sopenharmony_ci ACCESSORS_PRIMITIVE_FIELD(ChainId, uint64_t, CHAINID_OFFSET, SPANID_OFFSET) 614514f5e3Sopenharmony_ci ACCESSORS_PRIMITIVE_FIELD(SpanId, uint64_t, SPANID_OFFSET, PARENTSPANID_OFFSET) 624514f5e3Sopenharmony_ci ACCESSORS_PRIMITIVE_FIELD(ParentSpanId, uint64_t, PARENTSPANID_OFFSET, FLAGS_OFFSET) 634514f5e3Sopenharmony_ci ACCESSORS_PRIMITIVE_FIELD(Flags, uint32_t, FLAGS_OFFSET, JOBID_OFFSET) 644514f5e3Sopenharmony_ci ACCESSORS_PRIMITIVE_FIELD(JobId, uint64_t, JOBID_OFFSET, LAST_OFFSET) 654514f5e3Sopenharmony_ci DEFINE_ALIGN_SIZE(LAST_OFFSET); 664514f5e3Sopenharmony_ci 674514f5e3Sopenharmony_ci DECL_VISIT_OBJECT(JOB_OFFSET, CHAINID_OFFSET) 684514f5e3Sopenharmony_ci#else 694514f5e3Sopenharmony_ci ACCESSORS(Arguments, ARGUMENT_OFFSET, SIZE); 704514f5e3Sopenharmony_ci 714514f5e3Sopenharmony_ci DECL_VISIT_OBJECT(JOB_OFFSET, SIZE) 724514f5e3Sopenharmony_ci#endif 734514f5e3Sopenharmony_ci 744514f5e3Sopenharmony_ci DECL_DUMP() 754514f5e3Sopenharmony_ci}; 764514f5e3Sopenharmony_ci} // namespace panda::ecmascript::job 774514f5e3Sopenharmony_ci#endif // ECMASCRIPT_JOBS_PENDING_JOB_H 78