1 /* 2 * Copyright (c) 2021-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_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 static JSHandle<JSTaggedValue> ParseModule(JSThread *thread, const JSPandaFile *jsPandaFile, 38 const CString &descriptor, const CString &moduleFilename); 39 static JSHandle<JSTaggedValue> ParseCjsModule(JSThread *thread, const JSPandaFile *jsPandaFile); 40 static JSHandle<JSTaggedValue> ParseJsonModule(JSThread *thread, const JSPandaFile *jsPandaFile, 41 const CString &moduleFilename, const CString &recordName = nullptr); 42 static JSHandle<JSTaggedValue> ParseNativeModule(JSThread *thread, const CString &moduleRequestName, 43 ModuleTypes moduleType); 44 static JSTaggedValue JsonParse(JSThread *thread, const JSPandaFile *jsPandaFile, CString entryPoint); 45 }; 46 } // namespace panda::ecmascript 47 #endif // ECMASCRIPT_MODULE_MODULE_DATA_EXTRACTOR_H 48