• 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         ElementsKind *newKind = nullptr, ClassKind classKind = ClassKind::NON_SENDABLE);
50     static JSHandle<TaggedArray> GetDatasIgnoreTypeForClass(JSThread *thread, const JSPandaFile *jsPandaFile,
51                                                             size_t index, JSHandle<ConstantPool> constpool,
52                                                             const CString &entryPoint = "");
53 
54     static JSHandle<JSFunction> DefineMethodInLiteral(JSThread *thread, const JSPandaFile *jsPandaFile,
55                                                       uint32_t offset, JSHandle<ConstantPool> constpool,
56                                                       FunctionKind kind, uint16_t length,
57                                                       const CString &entryPoint = "",
58                                                       bool isLoadedAOT = false, uint32_t entryIndex = 0,
59                                                       ClassKind classKind = ClassKind::NON_SENDABLE);
60 
61     static void PUBLIC_API GetMethodOffsets(const JSPandaFile *jsPandaFile, size_t index,
62                                             std::vector<uint32_t> &methodOffsets);
63 
64     static void PUBLIC_API GetMethodOffsets(const JSPandaFile *jsPandaFile, EntityId id,
65                                             std::vector<uint32_t> &methodOffsets);
66 private:
67     static JSHandle<JSFunction> CreateJSFunctionInLiteral(EcmaVM *vm, JSHandle<Method> method, FunctionKind kind,
68                                                           ClassKind classKind);
69     static JSHandle<TaggedArray> EnumerateLiteralVals(JSThread *thread, panda_file::LiteralDataAccessor &lda,
70         const JSPandaFile *jsPandaFile, size_t index, JSHandle<ConstantPool> constpool,
71         const CString &entryPoint = "");
72 };
73 }  // namespace panda::ecmascript
74 #endif  // ECMASCRIPT_JSPANDAFILE_LITERAL_DATA_EXTRACTOR_H
75