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/panda_file_translator.h" 20 #include "ecmascript/js_tagged_value-inl.h" 21 #include "libpandafile/literal_data_accessor-inl.h" 22 23 namespace panda::ecmascript { 24 using EntityId = panda_file::File::EntityId; 25 26 enum class FieldTag : uint8_t { OBJECTLITERAL = 0, ARRAYLITERAL }; 27 28 class LiteralDataExtractor { 29 public: 30 explicit LiteralDataExtractor() = default; 31 virtual ~LiteralDataExtractor() = default; 32 33 DEFAULT_NOEXCEPT_MOVE_SEMANTIC(LiteralDataExtractor); 34 DEFAULT_COPY_SEMANTIC(LiteralDataExtractor); 35 36 static constexpr uint32_t LITERALARRAY_VALUE_LOW_BOUNDARY = 100; 37 38 static void ExtractObjectDatas(JSThread *thread, const JSPandaFile *jsPandaFile, size_t index, 39 JSMutableHandle<TaggedArray> elements, JSMutableHandle<TaggedArray> properties, 40 JSHandle<ConstantPool> constpool, const CString &entryPoint = ""); 41 static JSHandle<TaggedArray> GetDatasIgnoreType(JSThread *thread, const JSPandaFile *jsPandaFile, size_t index, 42 JSHandle<ConstantPool> constpool, const CString &entryPoint = ""); 43 static void ExtractObjectDatas(JSThread *thread, const JSPandaFile *jsPandaFile, panda_file::File::EntityId index, 44 JSMutableHandle<TaggedArray> elements, JSMutableHandle<TaggedArray> properties, 45 JSHandle<ConstantPool> constpool, const CString &entryPoint = ""); 46 static JSHandle<TaggedArray> GetDatasIgnoreType(JSThread *thread, const JSPandaFile *jsPandaFile, 47 panda_file::File::EntityId index, 48 JSHandle<ConstantPool> constpool, const CString &entryPoint = ""); 49 static JSHandle<JSFunction> DefineMethodInLiteral(JSThread *thread, const JSPandaFile *jsPandaFile, 50 JSHandle<Method> method, FunctionKind kind, uint16_t length, 51 const CString &entryPoint = ""); 52 static JSHandle<TaggedArray> GetDatasIgnoreTypeForClass(JSThread *thread, const JSPandaFile *jsPandaFile, 53 size_t index, JSHandle<ConstantPool> constpool, const CString &entryPoint = ""); 54 55 static void PUBLIC_API GetMethodOffsets(const JSPandaFile *jsPandaFile, size_t index, 56 std::vector<uint32_t> &methodOffsets); 57 58 static void PUBLIC_API GetMethodOffsets(const JSPandaFile *jsPandaFile, panda_file::File::EntityId index, 59 std::vector<uint32_t> &methodOffsets); 60 61 static JSHandle<TaggedArray> PUBLIC_API GetTypeLiteral(JSThread *thread, const JSPandaFile *jsPandaFile, 62 panda_file::File::EntityId offset); 63 private: 64 static JSHandle<TaggedArray> EnumerateLiteralVals(JSThread *thread, panda_file::LiteralDataAccessor &lda, 65 const JSPandaFile *jsPandaFile, size_t index, JSHandle<ConstantPool> constpool, 66 const CString &entryPoint = ""); 67 }; 68 } // namespace panda::ecmascript 69 #endif // ECMASCRIPT_JSPANDAFILE_LITERAL_DATA_EXTRACTOR_H 70