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_JS_PANDAFILE_EXECUTOR_H 17 #define ECMASCRIPT_JSPANDAFILE_JS_PANDAFILE_EXECUTOR_H 18 19 #include "ecmascript/ecma_context.h" 20 #include "ecmascript/js_tagged_value.h" 21 #include "ecmascript/js_thread.h" 22 #include "ecmascript/jspandafile/js_pandafile.h" 23 #include "ecmascript/module/js_module_execute_type.h" 24 25 namespace panda::ecmascript { 26 class JSPandaFileExecutor { 27 public: 28 static constexpr int ROUTE_SUCCESS = 0; 29 static constexpr int ROUTE_INTERNAL_ERROR = 100001; 30 static constexpr int ROUTE_URI_ERROR = 100002; 31 32 std::pair<CString, CString> ParseEntryPointWithUnifiedRules(EcmaVM *vm, const CString &filename, 33 std::string_view entryPoint); 34 static Expected<JSTaggedValue, bool> ExecuteFromFile(JSThread *thread, const CString &name, 35 CString entry, bool needUpdate = false, 36 const ExecuteTypes &executeType = ExecuteTypes::STATIC); 37 static Expected<JSTaggedValue, bool> ExecuteFromAbsolutePathAbcFile(JSThread *thread, const CString &filename, 38 std::string_view entryPoint, 39 bool needUpdate = false, 40 const ExecuteTypes &executeType = 41 ExecuteTypes::STATIC); 42 static Expected<JSTaggedValue, bool> ExecuteFromAbcFile(JSThread *thread, const CString &filename, 43 std::string_view entryPoint, bool needUpdate = false, 44 const ExecuteTypes &executeType = ExecuteTypes::STATIC); 45 static Expected<JSTaggedValue, bool> ExecuteFromBuffer(JSThread *thread, const void *buffer, size_t size, 46 std::string_view entryPoint, const CString &filename = "", 47 bool needUpdate = false, 48 const ExecuteTypes &executeType = ExecuteTypes::STATIC); 49 static Expected<JSTaggedValue, bool> ExecuteModuleBuffer(JSThread *thread, const void *buffer, size_t size, 50 const CString &filename = "", bool needUpdate = false); 51 static Expected<JSTaggedValue, bool> CommonExecuteBuffer(JSThread *thread, const CString &filename, 52 const CString &entry, const void *buffer, size_t size, 53 const ExecuteTypes &executeType = ExecuteTypes::STATIC); 54 static Expected<JSTaggedValue, bool> Execute(JSThread *thread, const JSPandaFile *jsPandaFile, 55 std::string_view entryPoint, 56 const ExecuteTypes &executeType = ExecuteTypes::STATIC); 57 static void BindPreloadedPandaFilesToAOT(EcmaVM *vm, const std::string &moduleName); 58 static void BindPandaFileToAot(JSPandaFile *jsPandaFile); 59 static Expected<JSTaggedValue, bool> ExecuteSpecialModule(JSThread *thread, const CString &recordName, 60 const CString &filename, const JSPandaFile *jsPandaFile, 61 const JSRecordInfo* recordInfo); 62 static Expected<JSTaggedValue, bool> LazyExecuteModule(JSThread *thread, CString &recordName, 63 const CString &filename, [[maybe_unused]]bool isMergedAbc); 64 // Execute from secure mem 65 static Expected<JSTaggedValue, bool> ExecuteFromBufferSecure(JSThread *thread, uint8_t *buffer, size_t size, 66 std::string_view entryPoint, 67 const CString &filename = "", bool needUpdate = false); 68 static Expected<JSTaggedValue, bool> ExecuteModuleBufferSecure(JSThread *thread, uint8_t *buffer, size_t size, 69 const CString &filename = "", 70 bool needUpdate = false); 71 static Expected<JSTaggedValue, bool> CommonExecuteBuffer(JSThread *thread, const CString &filename, 72 const CString &entry, const JSPandaFile *jsPandaFile); 73 static Expected<JSTaggedValue, bool> ExecuteSecureWithOhmUrl(JSThread *thread, uint8_t *buffer, 74 size_t size, const CString &fileName, 75 const CString &entryPoint); 76 77 static int ExecuteAbcFileWithSingletonPatternFlag(JSThread *thread, 78 [[maybe_unused]] const CString &bundleName, const CString &moduleName, const CString &entry, 79 bool isSingletonPattern); 80 81 static bool IsExecuteModuleInAbcFile(JSThread *thread, [[maybe_unused]] const CString &bundleName, 82 const CString &moduleName, const CString &entry); 83 }; 84 } // namespace panda::ecmascript 85 #endif // ECMASCRIPT_JSPANDAFILE_JS_PANDAFILE_EXECUTOR_H 86