• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 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_MODULE_DATA_EXTRACTOR_H
17 #define ECMASCRIPT_MODULE_MODULE_DATA_EXTRACTOR_H
18 
19 #include "ecmascript/js_tagged_value-inl.h"
20 #include "ecmascript/module/js_module_source_text.h"
21 #include "ecmascript/jspandafile/js_pandafile.h"
22 
23 namespace panda::ecmascript {
24 using EntityId = panda_file::File::EntityId;
25 
26 class ModuleDataExtractor {
27 private:
28 public:
29     ModuleDataExtractor() = default;
30     virtual ~ModuleDataExtractor() = default;
31 
32     DEFAULT_NOEXCEPT_MOVE_SEMANTIC(ModuleDataExtractor);
33     DEFAULT_COPY_SEMANTIC(ModuleDataExtractor);
34 
35     static void ExtractModuleDatas(JSThread *thread, const JSPandaFile *jsPandaFile,
36                                    panda_file::File::EntityId moduleId,
37                                    JSHandle<SourceTextModule> &moduleRecord,
38                                    [[maybe_unused]]JSPandaFile::JSRecordInfo *recordInfo);
39     static JSHandle<JSTaggedValue> ParseModule(JSThread *thread, const JSPandaFile *jsPandaFile,
40                                                const CString &descriptor, const CString &moduleFilename,
41                                                JSPandaFile::JSRecordInfo *recordInfo);
42     static JSHandle<JSTaggedValue> ParseCjsModule(JSThread *thread, const JSPandaFile *jsPandaFile);
43     static JSHandle<JSTaggedValue> ParseJsonModule(JSThread *thread, const JSPandaFile *jsPandaFile,
44                                                    const CString &moduleFilename, const CString &recordName);
45     static JSHandle<JSTaggedValue> ParseNativeModule(JSThread *thread, const CString &moduleRequestName,
46                                                      const CString &baseFileName, ModuleTypes moduleType);
47     static JSTaggedValue JsonParse(JSThread *thread, const JSPandaFile *jsPandaFile, CString entryPoint);
48     static bool *ModuleLazyImportFlagAccessor(const JSPandaFile *pandaFile,
49         panda_file::File::EntityId module_lazy_import_flag_id);
50 };
51 }  // namespace panda::ecmascript
52 #endif  // ECMASCRIPT_MODULE_MODULE_DATA_EXTRACTOR_H
53