• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "libpandabase/macros.h"
25 #include "libpandabase/utils/span.h"
26 #include "libpandafile/file.h"
27 #include "libpandafile/file_items.h"
28 #include "libpandafile/helpers.h"
29 
30 #include "ecmascript/module/js_module_source_text.h"
31 
32 namespace panda::ecmascript {
33 using StringData = panda_file::File::StringData;
34 
35 class ModuleDataAccessor {
36 public:
37     ModuleDataAccessor(const panda_file::File &panda_file, panda_file::File::EntityId module_data_id);
38     ~ModuleDataAccessor() = default;
39     DEFAULT_MOVE_CTOR(ModuleDataAccessor)
40     DEFAULT_COPY_CTOR(ModuleDataAccessor)
41     NO_MOVE_OPERATOR(ModuleDataAccessor);
42     NO_COPY_OPERATOR(ModuleDataAccessor);
43 
44     void EnumerateImportEntry(JSThread *thread, const JSHandle<TaggedArray> &requestModuleArray,
45                               JSHandle<SourceTextModule> &moduleRecord);
46 
47     void EnumerateLocalExportEntry(JSThread *thread, JSHandle<SourceTextModule> &moduleRecord);
48 
49     void EnumerateIndirectExportEntry(JSThread *thread, const JSHandle<TaggedArray> &requestModuleArray,
50                                       JSHandle<SourceTextModule> &moduleRecord);
51 
52     void EnumerateStarExportEntry(JSThread *thread, const JSHandle<TaggedArray> &requestModuleArray,
53                                   JSHandle<SourceTextModule> &moduleRecord);
54 
GetPandaFile()55     const panda_file::File &GetPandaFile() const
56     {
57         return pandaFile_;
58     }
59 
GetModuleDataId()60     panda_file::File::EntityId GetModuleDataId() const
61     {
62         return moduleDataId_;
63     }
64 
getRequestModules()65     const std::vector<uint32_t>& getRequestModules() const
66     {
67         return moduleRequests_;
68     }
69 
70     using ModuleValue = std::variant<uint32_t, StringData>;
71 
72 private:
73     const panda_file::File &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