• 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 public:
28     ModuleDataExtractor() = default;
29     virtual ~ModuleDataExtractor() = default;
30 
31     DEFAULT_NOEXCEPT_MOVE_SEMANTIC(ModuleDataExtractor);
32     DEFAULT_COPY_SEMANTIC(ModuleDataExtractor);
33 
34     static void ExtractModuleDatas(JSThread *thread, const JSPandaFile *jsPandaFile,
35                                    panda_file::File::EntityId moduleId,
36                                    JSHandle<SourceTextModule> &moduleRecord,
37                                    [[maybe_unused]]JSPandaFile::JSRecordInfo *recordInfo);
38     static JSHandle<JSTaggedValue> ParseModule(JSThread *thread, const JSPandaFile *jsPandaFile,
39                                                const CString &descriptor, const CString &moduleFilename,
40                                                JSPandaFile::JSRecordInfo *recordInfo);
41     static JSHandle<JSTaggedValue> ParseCjsModule(JSThread *thread, const JSPandaFile *jsPandaFile);
42     static JSHandle<JSTaggedValue> ParseJsonModule(JSThread *thread, const JSPandaFile *jsPandaFile,
43                                                    const CString &moduleFilename, const CString &recordName);
44     static JSHandle<JSTaggedValue> ParseNativeModule(JSThread *thread, const CString &moduleRequestName,
45                                                      const CString &baseFileName, ModuleTypes moduleType);
46     static JSTaggedValue JsonParse(JSThread *thread, const JSPandaFile *jsPandaFile, CString entryPoint);
47 
48 private:
49     static bool *ModuleLazyImportFlagAccessor(const JSPandaFile *pandaFile, EntityId lazyImportFlagId);
50 };
51 }  // namespace panda::ecmascript
52 #endif  // ECMASCRIPT_MODULE_MODULE_DATA_EXTRACTOR_H
53