• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2025 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_MODULE_ACCESSOR_MODULE_DATA_ACCESSOR_H
17 #define ECMASCRIPT_MODULE_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, JSHandle<SourceTextModule> &moduleRecord);
40 
41     void EnumerateLocalExportEntry(JSThread *thread, JSHandle<SourceTextModule> &moduleRecord);
42 
43     void EnumerateIndirectExportEntry(JSThread *thread, JSHandle<SourceTextModule> &moduleRecord);
44 
45     void EnumerateStarExportEntry(JSThread *thread, JSHandle<SourceTextModule> &moduleRecord);
46     JSHandle<TaggedArray> CreatEntries(JSThread *thread, uint32_t regularImportNum, SharedTypes sharedType);
47 
GetModuleDataId()48     panda_file::File::EntityId GetModuleDataId() const
49     {
50         return moduleDataId_;
51     }
52 
getModuleRequests()53     const std::vector<uint32_t>& getModuleRequests() const
54     {
55         return moduleRequests_;
56     }
57 
58 private:
59     void ReadRegularImportEntry(Span<const uint8_t> *sp, ObjectFactory *factory,
60                                 JSMutableHandle<JSTaggedValue> &importName,
61                                 JSMutableHandle<JSTaggedValue> &localName,
62                                 uint32_t &moduleRequestIdx);
63 
64     void ReadNamespaceImportEntry(Span<const uint8_t> *sp, ObjectFactory *factory,
65                                   JSMutableHandle<JSTaggedValue> &localName,
66                                   uint32_t &moduleRequestIdx);
67 
68     const JSPandaFile *pandaFile_;
69     panda_file::File::EntityId moduleDataId_;
70     uint32_t numModuleRequests_;
71     std::vector<uint32_t> moduleRequests_;
72     Span<const uint8_t> entryDataSp_ {nullptr, nullptr};
73 };
74 }  // namespace panda::ecmascript
75 #endif  // ECMASCRIPT_MODULE_ACCESSOR_MODULE_DATA_ACCESSOR_H
76