1 /* 2 * Copyright (c) 2022 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_ACCESSOR_MODULE_DATA_ACCESSOR_H 17 #define ECMASCRIPT_JSPANDAFILE_ACCESSOR_MODULE_DATA_ACCESSOR_H 18 19 #include <cstddef> 20 #include <cstdint> 21 #include <variant> 22 #include <vector> 23 24 #include "ecmascript/module/js_module_source_text.h" 25 26 #include "libpandabase/macros.h" 27 #include "libpandabase/utils/span.h" 28 29 namespace panda::ecmascript { 30 class ModuleDataAccessor { 31 public: 32 ModuleDataAccessor(const JSPandaFile *pandaFile, panda_file::File::EntityId module_data_id); 33 ~ModuleDataAccessor() = default; 34 DEFAULT_MOVE_CTOR(ModuleDataAccessor) 35 DEFAULT_COPY_CTOR(ModuleDataAccessor) 36 NO_MOVE_OPERATOR(ModuleDataAccessor); 37 NO_COPY_OPERATOR(ModuleDataAccessor); 38 39 void EnumerateImportEntry(JSThread *thread, const JSHandle<TaggedArray> &requestModuleArray, 40 JSHandle<SourceTextModule> &moduleRecord); 41 42 void EnumerateLocalExportEntry(JSThread *thread, JSHandle<SourceTextModule> &moduleRecord); 43 44 void EnumerateIndirectExportEntry(JSThread *thread, const JSHandle<TaggedArray> &requestModuleArray, 45 JSHandle<SourceTextModule> &moduleRecord); 46 47 void EnumerateStarExportEntry(JSThread *thread, const JSHandle<TaggedArray> &requestModuleArray, 48 JSHandle<SourceTextModule> &moduleRecord); 49 JSHandle<TaggedArray> CreatEntries(JSThread *thread, uint32_t regularImportNum, SharedTypes sharedType); 50 GetModuleDataId() const51 panda_file::File::EntityId GetModuleDataId() const 52 { 53 return moduleDataId_; 54 } 55 getRequestModules() const56 const std::vector<uint32_t>& getRequestModules() const 57 { 58 return moduleRequests_; 59 } 60 61 private: 62 void ReadRegularImportEntry(Span<const uint8_t> *sp, ObjectFactory *factory, 63 const JSHandle<TaggedArray> &requestModuleArray, 64 JSMutableHandle<JSTaggedValue> &importName, 65 JSMutableHandle<JSTaggedValue> &localName, 66 JSMutableHandle<JSTaggedValue> &moduleRequest); 67 68 void ReadNamespaceImportEntry(Span<const uint8_t> *sp, ObjectFactory *factory, 69 const JSHandle<TaggedArray> &requestModuleArray, 70 JSMutableHandle<JSTaggedValue> &localName, 71 JSMutableHandle<JSTaggedValue> &moduleRequest); 72 73 const JSPandaFile *pandaFile_; 74 panda_file::File::EntityId moduleDataId_; 75 uint32_t numModuleRequests_; 76 std::vector<uint32_t> moduleRequests_; 77 Span<const uint8_t> entryDataSp_ {nullptr, nullptr}; 78 }; 79 } // namespace panda::ecmascript 80 #endif // ECMASCRIPT_JSPANDAFILE_ACCESSOR_MODULE_DATA_ACCESSOR_H 81