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 GetModuleDataId()50 panda_file::File::EntityId GetModuleDataId() const 51 { 52 return moduleDataId_; 53 } 54 getRequestModules()55 const std::vector<uint32_t>& getRequestModules() const 56 { 57 return moduleRequests_; 58 } 59 60 private: 61 const JSPandaFile *pandaFile_; 62 panda_file::File::EntityId moduleDataId_; 63 uint32_t numModuleRequests_; 64 std::vector<uint32_t> moduleRequests_; 65 Span<const uint8_t> entryDataSp_ {nullptr, nullptr}; 66 }; 67 } // namespace panda::ecmascript 68 #endif // ECMASCRIPT_JSPANDAFILE_ACCESSOR_MODULE_DATA_ACCESSOR_H 69