/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ECMASCRIPT_JSPANDAFILE_LITERAL_DATA_EXTRACTOR_H #define ECMASCRIPT_JSPANDAFILE_LITERAL_DATA_EXTRACTOR_H #include "ecmascript/jspandafile/js_pandafile.h" #include "ecmascript/js_tagged_value-inl.h" #include "libpandafile/literal_data_accessor-inl.h" namespace panda::ecmascript { class LiteralDataExtractor { public: LiteralDataExtractor() = default; virtual ~LiteralDataExtractor() = default; DEFAULT_NOEXCEPT_MOVE_SEMANTIC(LiteralDataExtractor); DEFAULT_COPY_SEMANTIC(LiteralDataExtractor); static constexpr uint32_t LITERALARRAY_VALUE_LOW_BOUNDARY = 100; // Parameter 'size_t index' is for old isa, and 'EntityId id' for new isa. static void ExtractObjectDatas(JSThread *thread, const JSPandaFile *jsPandaFile, size_t index, JSMutableHandle elements, JSMutableHandle properties, JSHandle constpool, const CString &entryPoint = ""); static PUBLIC_API void ExtractObjectDatas(JSThread *thread, const JSPandaFile *jsPandaFile, EntityId id, JSMutableHandle elements, JSMutableHandle properties, JSHandle constpool, const CString &entryPoint = "", bool isLoadedAOT = false, JSHandle entryIndexes = JSHandle()); static JSHandle GetDatasIgnoreType(JSThread *thread, const JSPandaFile *jsPandaFile, size_t index, JSHandle constpool, const CString &entryPoint = ""); static PUBLIC_API JSHandle GetDatasIgnoreType(JSThread *thread, const JSPandaFile *jsPandaFile, EntityId id, JSHandle constpool, const CString &entryPoint = "", bool isLoadedAOT = false, JSHandle entryIndexes = JSHandle(), ElementsKind *newKind = nullptr, JSHandle sendableEnv = JSHandle(), ClassKind classKind = ClassKind::NON_SENDABLE); static PUBLIC_API JSHandle GetDatasIgnoreTypeForClass(JSThread *thread, const JSPandaFile *jsPandaFile, EntityId id, JSHandle constpool, const CString &entryPoint = "", bool isLoadedAOT = false, JSHandle entryIndexes = JSHandle(), ElementsKind *newKind = nullptr, JSHandle sendableEnv = JSHandle(), ClassKind classKind = ClassKind::NON_SENDABLE); static JSHandle GetDatasIgnoreTypeForClass(JSThread *thread, const JSPandaFile *jsPandaFile, size_t index, JSHandle constpool, const CString &entryPoint = ""); static JSHandle DefineMethodInLiteral(JSThread *thread, const JSPandaFile *jsPandaFile, uint32_t offset, JSHandle constpool, FunctionKind kind, uint16_t length, const CString &entryPoint = "", bool isLoadedAOT = false, uint32_t entryIndex = 0, JSHandle sendableEnv = JSHandle(), ClassKind classKind = ClassKind::NON_SENDABLE); static void PUBLIC_API GetMethodOffsets(const JSPandaFile *jsPandaFile, size_t index, std::vector &methodOffsets); static void PUBLIC_API GetMethodOffsets(const JSPandaFile *jsPandaFile, EntityId id, std::vector &methodOffsets); private: static JSHandle DefineFunctionTemplate(JSThread *thread, const JSPandaFile *jsPandaFile, uint32_t offset, JSHandle constpool, FunctionKind kind, uint16_t length, const CString &entryPoint = "", bool isLoadedAOT = false, uint32_t entryIndex = 0, JSHandle sendableEnv = JSHandle(), ClassKind classKind = ClassKind::NON_SENDABLE); static JSHandle CreateJSFunctionInLiteral(EcmaVM *vm, const JSHandle &method, FunctionKind kind, ClassKind classKind); static JSHandle EnumerateLiteralVals(JSThread *thread, panda_file::LiteralDataAccessor &lda, const JSPandaFile *jsPandaFile, size_t index, JSHandle constpool, const CString &entryPoint = ""); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_JSPANDAFILE_LITERAL_DATA_EXTRACTOR_H