• 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_JSPANDAFILE_LITERAL_DATA_EXTRACTOR_H
17 #define ECMASCRIPT_JSPANDAFILE_LITERAL_DATA_EXTRACTOR_H
18 
19 #include "ecmascript/jspandafile/js_pandafile.h"
20 #include "ecmascript/js_tagged_value-inl.h"
21 #include "libpandafile/literal_data_accessor-inl.h"
22 
23 namespace panda::ecmascript {
24 class LiteralDataExtractor {
25 public:
26     LiteralDataExtractor() = default;
27     virtual ~LiteralDataExtractor() = default;
28 
29     DEFAULT_NOEXCEPT_MOVE_SEMANTIC(LiteralDataExtractor);
30     DEFAULT_COPY_SEMANTIC(LiteralDataExtractor);
31 
32     static constexpr uint32_t LITERALARRAY_VALUE_LOW_BOUNDARY = 100;
33 
34     // Parameter 'size_t index' is for old isa, and 'EntityId id' for new isa.
35     static void ExtractObjectDatas(JSThread *thread, const JSPandaFile *jsPandaFile, size_t index,
36                                    JSMutableHandle<TaggedArray> elements, JSMutableHandle<TaggedArray> properties,
37                                    JSHandle<ConstantPool> constpool, const CString &entryPoint = "");
38     static void ExtractObjectDatas(JSThread *thread, const JSPandaFile *jsPandaFile, EntityId id,
39                                    JSMutableHandle<TaggedArray> elements, JSMutableHandle<TaggedArray> properties,
40                                    JSHandle<ConstantPool> constpool, const CString &entryPoint = "",
41                                    bool isLoadedAOT = false,
42                                    JSHandle<AOTLiteralInfo> entryIndexes = JSHandle<AOTLiteralInfo>());
43 
44     static JSHandle<TaggedArray> GetDatasIgnoreType(JSThread *thread, const JSPandaFile *jsPandaFile, size_t index,
45                                                     JSHandle<ConstantPool> constpool, const CString &entryPoint = "");
46     static JSHandle<TaggedArray> GetDatasIgnoreType(JSThread *thread, const JSPandaFile *jsPandaFile, EntityId id,
47         JSHandle<ConstantPool> constpool, const CString &entryPoint = "",
48         bool isLoadedAOT = false, JSHandle<AOTLiteralInfo> entryIndexes = JSHandle<AOTLiteralInfo>());
49     static JSHandle<TaggedArray> GetDatasIgnoreTypeForClass(JSThread *thread, const JSPandaFile *jsPandaFile,
50                                                             size_t index, JSHandle<ConstantPool> constpool,
51                                                             const CString &entryPoint = "");
52 
53     static JSHandle<JSFunction> DefineMethodInLiteral(JSThread *thread, const JSPandaFile *jsPandaFile,
54                                                       uint32_t offset, JSHandle<ConstantPool> constpool,
55                                                       FunctionKind kind, uint16_t length,
56                                                       const CString &entryPoint = "",
57                                                       bool isLoadedAOT = false, uint32_t entryIndex = 0);
58 
59     static void PUBLIC_API GetMethodOffsets(const JSPandaFile *jsPandaFile, size_t index,
60                                             std::vector<uint32_t> &methodOffsets);
61 
62     static void PUBLIC_API GetMethodOffsets(const JSPandaFile *jsPandaFile, EntityId id,
63                                             std::vector<uint32_t> &methodOffsets);
64 private:
65     static JSHandle<TaggedArray> EnumerateLiteralVals(JSThread *thread, panda_file::LiteralDataAccessor &lda,
66         const JSPandaFile *jsPandaFile, size_t index, JSHandle<ConstantPool> constpool,
67         const CString &entryPoint = "");
68 };
69 }  // namespace panda::ecmascript
70 #endif  // ECMASCRIPT_JSPANDAFILE_LITERAL_DATA_EXTRACTOR_H
71