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/module.h"
17
18 #include "ecmascript/module/module_path_helper.h"
19
20 namespace panda::ecmascript {
GetOutEntryPoint(EcmaVM * vm,const CString & inputFileName)21 CString GetOutEntryPoint(EcmaVM *vm, const CString &inputFileName)
22 {
23 CString outEntryPoint;
24 // if the inputFileName starts with '.test', the preview test page is started.
25 // in this case, the path ets does not need to be combined.
26 // inputFileName: .test/xxx/xxx.abc
27 if (StringHelper::StringStartWith(inputFileName, ModulePathHelper::PREVIER_TEST_DIR)) {
28 outEntryPoint = base::ConcatToCString(vm->GetBundleName(), PathHelper::SLASH_TAG, vm->GetModuleName(),
29 PathHelper::SLASH_TAG, inputFileName);
30 } else {
31 // inputFileName: xxx/xxx.abc
32 outEntryPoint = base::ConcatToCString(vm->GetBundleName(), PathHelper::SLASH_TAG, vm->GetModuleName(),
33 ModulePathHelper::MODULE_DEFAULE_ETS, inputFileName);
34 }
35 return outEntryPoint;
36 }
37
GetBaseFileName(EcmaVM * vm,CString & moduleRequestName,CString & baseFileName,const CString & bundleName,const CString & moduleName,CString & recordName)38 CString GetBaseFileName(EcmaVM *vm, [[maybe_unused]] CString &moduleRequestName, CString &baseFileName,
39 const CString &bundleName, const CString &moduleName, [[maybe_unused]] CString &recordName)
40 {
41 CVector<CString> currentVec;
42 StringHelper::SplitString(moduleRequestName, currentVec, 0, ModulePathHelper::SEGMENTS_LIMIT_TWO);
43 if (currentVec.size() < ModulePathHelper::SEGMENTS_LIMIT_TWO) { // LCOV_EXCL_BR_LINE
44 LOG_ECMA(FATAL) << " Exceptional module path : " << moduleRequestName << ", abc path: " <<
45 baseFileName << ", current file name: " << recordName;
46 }
47 CString currentModuleName = currentVec[1];
48 PathHelper::DeleteNamespace(currentModuleName);
49 if (bundleName != vm->GetBundleName()) {
50 baseFileName = base::ConcatToCString(ModulePathHelper::BUNDLE_INSTALL_PATH, bundleName, PathHelper::SLASH_TAG,
51 moduleName, PathHelper::SLASH_TAG, moduleName, ModulePathHelper::MERGE_ABC_ETS_MODULES);
52 } else if (currentModuleName != vm->GetModuleName()) {
53 baseFileName = base::ConcatToCString(ModulePathHelper::BUNDLE_INSTALL_PATH, moduleName,
54 ModulePathHelper::MERGE_ABC_ETS_MODULES);
55 }
56 return baseFileName;
57 }
58
CheckEntryPointPreview(JSThread * thread,const CString & entryPoint)59 JSHandle<JSTaggedValue> CheckEntryPointPreview(JSThread *thread, [[maybe_unused]] const CString &entryPoint)
60 {
61 if (entryPoint == ModulePathHelper::PREVIEW_OF_ACROSS_HAP_FLAG) {
62 THROW_SYNTAX_ERROR_AND_RETURN(thread, "", thread->GlobalConstants()->GetHandledUndefined());
63 }
64 return thread->GlobalConstants()->GetHandledNull();
65 }
66 } // namespace panda::ecmascript