• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "ecmascript/method.h"
17 
18 #include "ecmascript/jspandafile/js_pandafile.h"
19 #include "ecmascript/jspandafile/program_object.h"
20 
21 namespace panda::ecmascript {
ParseFunctionName() const22 std::string Method::ParseFunctionName() const
23 {
24     const JSPandaFile *jsPandaFile = GetJSPandaFile();
25     return MethodLiteral::ParseFunctionName(jsPandaFile, GetMethodId());
26 }
27 
GetMethodName() const28 const char *Method::GetMethodName() const
29 {
30     const JSPandaFile *jsPandaFile = GetJSPandaFile();
31     return MethodLiteral::GetMethodName(jsPandaFile, GetMethodId());
32 }
33 
GetMethodName(const JSPandaFile * file) const34 const char *Method::GetMethodName(const JSPandaFile* file) const
35 {
36     return MethodLiteral::GetMethodName(file, GetMethodId());
37 }
38 
GetRecordName() const39 const CString Method::GetRecordName() const
40 {
41     const JSPandaFile *jsPandaFile = GetJSPandaFile();
42     return MethodLiteral::GetRecordName(jsPandaFile, GetMethodId());
43 }
44 
GetCodeSize() const45 uint32_t Method::GetCodeSize() const
46 {
47     const JSPandaFile *jsPandaFile = GetJSPandaFile();
48     return MethodLiteral::GetCodeSize(jsPandaFile, GetMethodId());
49 }
50 
GetJSPandaFile() const51 const JSPandaFile *Method::GetJSPandaFile() const
52 {
53     JSTaggedValue constpool = GetConstantPool();
54     if (constpool.IsUndefined()) {
55         return nullptr;
56     }
57 
58     const ConstantPool *taggedPool = ConstantPool::Cast(constpool.GetTaggedObject());
59     return taggedPool->GetJSPandaFile();
60 }
61 
GetPandaFile() const62 const panda_file::File *Method::GetPandaFile() const
63 {
64     const JSPandaFile *jsPandaFile = GetJSPandaFile();
65     if (jsPandaFile == nullptr) {
66         return nullptr;
67     }
68     return jsPandaFile->GetPandaFile();
69 }
70 
GetMethodLiteral() const71 MethodLiteral *Method::GetMethodLiteral() const
72 {
73     if (IsAotWithCallField()) {
74         ASSERT(!IsNativeWithCallField());
75         const JSPandaFile *jsPandaFile = GetJSPandaFile();
76         return jsPandaFile->FindMethodLiteral(GetMethodId().GetOffset());
77     }
78     return reinterpret_cast<MethodLiteral *>(GetCodeEntryOrLiteral());
79 }
80 } // namespace panda::ecmascript
81