• 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/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_source_text.h"
24 
25 namespace panda::ecmascript {
26 class JSPandaFileExecutor {
27 public:
28     static Expected<JSTaggedValue, bool> ExecuteFromFile(JSThread *thread, const CString &filename,
29                                                          std::string_view entryPoint, bool needUpdate = false,
30                                                          bool excuteFromJob = false);
31     static Expected<JSTaggedValue, bool> ExecuteFromBuffer(JSThread *thread, const void *buffer, size_t size,
32                                                            std::string_view entryPoint, const CString &filename = "",
33                                                            bool needUpdate = false);
34     static Expected<JSTaggedValue, bool> ExecuteModuleBuffer(JSThread *thread, const void *buffer, size_t size,
35                                                              const CString &filename = "", bool needUpdate = false);
36     static Expected<JSTaggedValue, bool> CommonExecuteBuffer(JSThread *thread, bool isBundle, const CString &filename,
37                                                              const CString &entry, const void *buffer, size_t size);
38     static Expected<JSTaggedValue, bool> Execute(JSThread *thread, const JSPandaFile *jsPandaFile,
39                                                  std::string_view entryPoint, bool excuteFromJob = false);
40     static void LoadAOTFilesForFile(EcmaVM *vm, JSPandaFile *jsPandaFile);
41     // Execute from secure mem
42     static Expected<JSTaggedValue, bool> ExecuteFromBufferSecure(JSThread *thread, uint8_t *buffer, size_t size,
43                                                                  std::string_view entryPoint,
44                                                                  const CString &filename = "", bool needUpdate = false);
45     static Expected<JSTaggedValue, bool> ExecuteModuleBufferSecure(JSThread *thread, uint8_t *buffer, size_t size,
46                                                                    const CString &filename = "",
47                                                                    bool needUpdate = false);
48     static Expected<JSTaggedValue, bool> CommonExecuteBuffer(JSThread *thread, const CString &filename,
49                                                              const CString &entry, const JSPandaFile *jsPandaFile);
50 };
51 }  // namespace panda::ecmascript
52 #endif // ECMASCRIPT_JSPANDAFILE_JS_PANDAFILE_EXECUTOR_H
53