1 /*
2 * Copyright (c) 2025 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 #include "ecmascript/platform/pandafile.h"
17
18 #include "ecmascript/log_wrapper.h"
19 #include "ecmascript/module/module_path_helper.h"
20
21 namespace panda::ecmascript {
22 using PathHelper = base::PathHelper;
23
24 // use "@bundle" as ohmurl's rules, will be abandon later
ParseAbcEntryPoint(JSThread * thread,const CString & filename,std::string_view entryPoint)25 std::pair<CString, CString> ParseAbcEntryPoint(JSThread *thread, const CString &filename,
26 [[maybe_unused]] std::string_view entryPoint)
27 {
28 CString name;
29 CString entry;
30 [[maybe_unused]] EcmaVM *vm = thread->GetEcmaVM();
31 #if defined(OHOS_UNIT_TEST)
32 return {filename, entryPoint.data()};
33 #endif
34 CString normalName = PathHelper::NormalizePath(filename);
35 ModulePathHelper::ParseAbcPathAndOhmUrl(vm, normalName, name, entry);
36 CString assetPath = vm->GetAssetPath();
37 name = assetPath + "\\" + JSPandaFile::MERGE_ABC_NAME;
38 return std::make_pair(name, entry);
39 }
40
GetAssetPath(EcmaVM * vm)41 CString GetAssetPath(EcmaVM *vm)
42 {
43 CString assetPath = vm->GetAssetPath();
44 CString name = assetPath + "\\" + JSPandaFile::MERGE_ABC_NAME;
45 return name;
46 }
47
LoadJSPandaFileFailLog(const CString & failLog)48 void LoadJSPandaFileFailLog([[maybe_unused]] const CString &failLog)
49 {
50 LOG_NO_TAG(ERROR) << failLog;
51 }
52
OpenPandaFileFromMemory(uint8_t * buffer,size_t size)53 std::unique_ptr<const panda_file::File> OpenPandaFileFromMemory(uint8_t *buffer, size_t size)
54 {
55 return panda_file::OpenPandaFileFromSecureMemory(buffer, size);
56 }
57
ParseAndOpenPandaFile(const void * buffer,size_t size,const CString & filename)58 std::unique_ptr<const panda_file::File> ParseAndOpenPandaFile(const void *buffer, size_t size,
59 [[maybe_unused]] const CString &filename)
60 {
61 return panda_file::OpenPandaFileFromMemory(buffer, size);
62 }
63 } // namespace panda::ecmascript