• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_DEBUGGER_JS_PT_METHOD_H
17 #define ECMASCRIPT_DEBUGGER_JS_PT_METHOD_H
18 
19 #include "ecmascript/jspandafile/js_pandafile.h"
20 
21 #include "libpandafile/code_data_accessor-inl.h"
22 #include "libpandafile/method_data_accessor-inl.h"
23 
24 namespace panda::ecmascript::tooling {
25 class PtMethod {
26 public:
PtMethod(const JSPandaFile * jsPandaFile,EntityId methodId,bool isNative)27     PtMethod(const JSPandaFile *jsPandaFile, EntityId methodId, bool isNative)
28         : jsPandaFile_(jsPandaFile), methodId_(methodId), isNative_(isNative)
29     {
30     }
31     ~PtMethod() = default;
32 
GetJSPandaFile()33     const JSPandaFile *GetJSPandaFile() const
34     {
35         return jsPandaFile_;
36     }
37 
GetMethodId()38     EntityId GetMethodId() const
39     {
40         return methodId_;
41     }
42 
IsNativeMethod()43     bool IsNativeMethod() const
44     {
45         return isNative_;
46     }
47 
48     bool operator==(const PtMethod &method) const
49     {
50         return methodId_ == method.methodId_ &&
51                jsPandaFile_ == method.jsPandaFile_;
52     }
53 
GetCodeSize()54     uint32_t GetCodeSize() const
55     {
56         if (jsPandaFile_ == nullptr) {
57             return 0;
58         }
59         panda_file::MethodDataAccessor mda(*(jsPandaFile_->GetPandaFile()), methodId_);
60         auto codeId = mda.GetCodeId().value();
61         if (!codeId.IsValid()) {
62             return 0;
63         }
64         panda_file::CodeDataAccessor cda(*(jsPandaFile_->GetPandaFile()), codeId);
65         return cda.GetCodeSize();
66     }
67 
68 private:
69     const JSPandaFile *jsPandaFile_ {nullptr};
70     panda_file::File::EntityId methodId_ {0};
71     bool isNative_ {false};
72 };
73 }  // namespace panda::ecmascript::tooling
74 #endif // ECMASCRIPT_DEBUGGER_JS_PT_METHOD_H
75