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