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/module/module_path_helper.h"
19
20 namespace panda::ecmascript {
21 using PathHelper = base::PathHelper;
22
23 // use "@bundle" as ohmurl's rules, will be abandon later
ParseAbcEntryPoint(JSThread * thread,const CString & filename,std::string_view entryPoint)24 std::pair<CString, CString> ParseAbcEntryPoint([[maybe_unused]] JSThread *thread, const CString &filename,
25 [[maybe_unused]] std::string_view entryPoint)
26 {
27 CString name;
28 CString entry;
29 [[maybe_unused]] EcmaVM *vm = thread->GetEcmaVM();
30 #if defined(OHOS_UNIT_TEST)
31 return {filename, entryPoint.data()};
32 #endif
33 CString normalName = PathHelper::NormalizePath(filename);
34 ModulePathHelper::ParseAbcPathAndOhmUrl(vm, normalName, name, entry);
35 if (name.empty()) {
36 name = vm->GetAssetPath();
37 }
38 return std::make_pair(name, entry);
39 }
40
GetAssetPath(EcmaVM * vm)41 CString GetAssetPath(EcmaVM *vm)
42 {
43 return vm->GetAssetPath();
44 }
45
LoadJSPandaFileFailLog(const CString & failLog)46 void LoadJSPandaFileFailLog([[maybe_unused]] const CString &failLog)
47 {
48 return;
49 }
50
OpenPandaFileFromMemory(uint8_t * buffer,size_t size)51 std::unique_ptr<const panda_file::File> OpenPandaFileFromMemory(uint8_t *buffer, size_t size)
52 {
53 return panda_file::OpenPandaFileFromMemory(buffer, size);
54 }
55
ParseAndOpenPandaFile(const void * buffer,size_t size,const CString & filename)56 std::unique_ptr<const panda_file::File> ParseAndOpenPandaFile(const void *buffer, size_t size,
57 [[maybe_unused]] const CString &filename)
58 {
59 CString tag = ModulePathHelper::ParseFileNameToVMAName(filename);
60 constexpr size_t PR_SET_VMA_ANON_NAME_MAX_LEN = 80;
61 constexpr size_t ANON_FLAG_LEN = 7; // [anon:]
62 if (tag.length() > PR_SET_VMA_ANON_NAME_MAX_LEN - ANON_FLAG_LEN) {
63 tag = CString(ModulePathHelper::VMA_NAME_ARKTS_CODE);
64 }
65 return panda_file::OpenPandaFileFromMemory(buffer, size, tag.c_str());
66 }
67 } // namespace panda::ecmascript