mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-07 16:13:49 +00:00
Delete ohmurl “@module”
issues:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I6HOKT Signed-off-by: changjiaxing <changjiaxing2@huawei.com> Change-Id: I5c52b4bad545e87913d6830fe3517423a6dd74fe
This commit is contained in:
parent
e2b5ae218e
commit
bde7ad041a
@ -43,7 +43,7 @@ public:
|
|||||||
static constexpr char BUNDLE_SUB_INSTALL_PATH[] = "/data/storage/el1/";
|
static constexpr char BUNDLE_SUB_INSTALL_PATH[] = "/data/storage/el1/";
|
||||||
static constexpr char PREVIEW_OF_ACROSS_HAP_FLAG[] = "[preview]";
|
static constexpr char PREVIEW_OF_ACROSS_HAP_FLAG[] = "[preview]";
|
||||||
|
|
||||||
static constexpr size_t MAX_PACKGE_LEVEL = 1;
|
static constexpr size_t MAX_PACKAGE_LEVEL = 1;
|
||||||
static constexpr size_t SEGMENTS_LIMIT_TWO = 2;
|
static constexpr size_t SEGMENTS_LIMIT_TWO = 2;
|
||||||
static constexpr size_t EXT_NAME_ABC_LEN = 4;
|
static constexpr size_t EXT_NAME_ABC_LEN = 4;
|
||||||
static constexpr size_t EXT_NAME_ETS_LEN = 4;
|
static constexpr size_t EXT_NAME_ETS_LEN = 4;
|
||||||
@ -161,18 +161,14 @@ public:
|
|||||||
|
|
||||||
static CString ParseNewPagesUrl(EcmaVM *vm, const CString &entryPoint)
|
static CString ParseNewPagesUrl(EcmaVM *vm, const CString &entryPoint)
|
||||||
{
|
{
|
||||||
auto errorFun = [entryPoint](const size_t &pos) {
|
CVector<CString> vec;
|
||||||
if (pos == CString::npos) {
|
SplitString(entryPoint, vec, 0, SEGMENTS_LIMIT_TWO);
|
||||||
LOG_ECMA(FATAL) << "ParseNewPagesUrl failed, please check Url " << entryPoint;
|
if (vec.size() < SEGMENTS_LIMIT_TWO) {
|
||||||
}
|
LOG_ECMA(ERROR) << "ParseNewPagesUrl SplitString filed, please check Url" << entryPoint;
|
||||||
};
|
return CString();
|
||||||
size_t bundleEndPos = entryPoint.find('/');
|
}
|
||||||
errorFun(bundleEndPos);
|
CString bundleName = vec[0];
|
||||||
CString bundleName = entryPoint.substr(0, bundleEndPos);
|
CString moduleName = vec[1];
|
||||||
size_t moduleStartPos = bundleEndPos + 1;
|
|
||||||
size_t moduleEndPos = entryPoint.find('/', moduleStartPos);
|
|
||||||
errorFun(moduleEndPos);
|
|
||||||
CString moduleName = entryPoint.substr(moduleStartPos, moduleEndPos - moduleStartPos);
|
|
||||||
CString baseFileName;
|
CString baseFileName;
|
||||||
if (bundleName != vm->GetBundleName()) {
|
if (bundleName != vm->GetBundleName()) {
|
||||||
// Cross-application
|
// Cross-application
|
||||||
@ -182,7 +178,7 @@ public:
|
|||||||
// Intra-application cross hap
|
// Intra-application cross hap
|
||||||
baseFileName = BUNDLE_INSTALL_PATH + moduleName + MERGE_ABC_ETS_MODULES;
|
baseFileName = BUNDLE_INSTALL_PATH + moduleName + MERGE_ABC_ETS_MODULES;
|
||||||
} else {
|
} else {
|
||||||
baseFileName = "";
|
baseFileName = CString();
|
||||||
}
|
}
|
||||||
return baseFileName;
|
return baseFileName;
|
||||||
}
|
}
|
||||||
@ -198,7 +194,7 @@ public:
|
|||||||
return hapPath.substr(0, pos).c_str();
|
return hapPath.substr(0, pos).c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "";
|
return std::string();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CroppingRecord(CString &recordName)
|
static void CroppingRecord(CString &recordName)
|
||||||
@ -241,26 +237,36 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static CString ParsePreixBundle(const JSPandaFile *jsPandaFile, CString &baseFilename, CString moduleRecordName,
|
static CString ParsePrefixBundle(JSThread *thread, const JSPandaFile *jsPandaFile,
|
||||||
CString moduleRequestName)
|
[[maybe_unused]] CString &baseFileName, CString moduleRequestName)
|
||||||
{
|
{
|
||||||
CString entryPoint;
|
|
||||||
moduleRequestName = moduleRequestName.substr(PREFIX_BUNDLE_LEN);
|
moduleRequestName = moduleRequestName.substr(PREFIX_BUNDLE_LEN);
|
||||||
entryPoint = moduleRequestName;
|
CString entryPoint = moduleRequestName;
|
||||||
if (jsPandaFile->IsNewRecord()) {
|
if (jsPandaFile->IsNewRecord()) {
|
||||||
CVector<CString> vec;
|
CVector<CString> vec;
|
||||||
size_t index = 0;
|
|
||||||
SplitString(moduleRequestName, vec, 0, SEGMENTS_LIMIT_TWO);
|
SplitString(moduleRequestName, vec, 0, SEGMENTS_LIMIT_TWO);
|
||||||
if (vec.size() < SEGMENTS_LIMIT_TWO) {
|
if (vec.size() < SEGMENTS_LIMIT_TWO) {
|
||||||
LOG_ECMA(ERROR) << "SplitString filed, please check moduleRequestName";
|
LOG_ECMA(ERROR) << "SplitString filed, please check moduleRequestName";
|
||||||
return CString();
|
return CString();
|
||||||
}
|
}
|
||||||
CString bundleName = vec[index++];
|
CString bundleName = vec[0];
|
||||||
if (!StringStartWith(moduleRecordName, bundleName, bundleName.size())) {
|
CString moduleName = vec[1];
|
||||||
CString moduleName = vec[index];
|
EcmaVM *vm = thread->GetEcmaVM();
|
||||||
baseFilename = BUNDLE_INSTALL_PATH + bundleName + '/' + moduleName + '/' + moduleName +
|
#if !defined(PANDA_TARGET_WINDOWS) && !defined(PANDA_TARGET_MACOS)
|
||||||
MERGE_ABC_ETS_MODULES;
|
if (bundleName != vm->GetBundleName()) {
|
||||||
|
baseFileName =
|
||||||
|
BUNDLE_INSTALL_PATH + bundleName + '/' + moduleName + '/' + moduleName + MERGE_ABC_ETS_MODULES;
|
||||||
|
} else if (moduleName != vm->GetModuleName()) {
|
||||||
|
baseFileName = BUNDLE_INSTALL_PATH + moduleName + MERGE_ABC_ETS_MODULES;
|
||||||
|
} else {
|
||||||
|
baseFileName = vm->GetAssetPath();
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
if (bundleName != vm->GetBundleName() || moduleName != vm->GetModuleName()) {
|
||||||
|
entryPoint = PREVIEW_OF_ACROSS_HAP_FLAG;
|
||||||
|
LOG_NO_TAG(ERROR) << "[ArkRuntime Log] Importing shared package is not supported in the Previewer.";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
CroppingRecord(entryPoint);
|
CroppingRecord(entryPoint);
|
||||||
}
|
}
|
||||||
@ -280,9 +286,8 @@ public:
|
|||||||
LOG_ECMA(ERROR) << "SplitString filed, please check moduleRequestName and moduleRecordName";
|
LOG_ECMA(ERROR) << "SplitString filed, please check moduleRequestName and moduleRecordName";
|
||||||
return CString();
|
return CString();
|
||||||
}
|
}
|
||||||
size_t index = 0;
|
CString bundleName = vec[0];
|
||||||
CString bundleName = vec[index++];
|
CString moduleName = vec[1];
|
||||||
CString moduleName = vec[index];
|
|
||||||
baseFilename = BUNDLE_INSTALL_PATH + moduleName + MERGE_ABC_ETS_MODULES;
|
baseFilename = BUNDLE_INSTALL_PATH + moduleName + MERGE_ABC_ETS_MODULES;
|
||||||
entryPoint = bundleName + '/' + moduleRequestName;
|
entryPoint = bundleName + '/' + moduleRequestName;
|
||||||
#else
|
#else
|
||||||
@ -292,7 +297,7 @@ public:
|
|||||||
return entryPoint;
|
return entryPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CString MakeNewRecord(const JSPandaFile *jsPandaFile, CString &baseFilename, const CString &recordName,
|
static CString MakeNewRecord(const JSPandaFile *jsPandaFile, CString &baseFileName, const CString &recordName,
|
||||||
const CString &requestName)
|
const CString &requestName)
|
||||||
{
|
{
|
||||||
CString entryPoint;
|
CString entryPoint;
|
||||||
@ -316,16 +321,16 @@ public:
|
|||||||
if (jsPandaFile->HasRecord(entryPoint)) {
|
if (jsPandaFile->HasRecord(entryPoint)) {
|
||||||
return entryPoint;
|
return entryPoint;
|
||||||
}
|
}
|
||||||
entryPoint = ParseThirdPartyPackge(jsPandaFile, recordName, requestName);
|
entryPoint = ParseThirdPartyPackage(jsPandaFile, recordName, requestName);
|
||||||
if (jsPandaFile->HasRecord(entryPoint)) {
|
if (jsPandaFile->HasRecord(entryPoint)) {
|
||||||
return entryPoint;
|
return entryPoint;
|
||||||
}
|
}
|
||||||
// Execute abc locally
|
// Execute abc locally
|
||||||
pos = baseFilename.rfind('/');
|
pos = baseFileName.rfind('/');
|
||||||
if (pos != CString::npos) {
|
if (pos != CString::npos) {
|
||||||
baseFilename = baseFilename.substr(0, pos + 1) + moduleRequestName + EXT_NAME_ABC;
|
baseFileName = baseFileName.substr(0, pos + 1) + moduleRequestName + EXT_NAME_ABC;
|
||||||
} else {
|
} else {
|
||||||
baseFilename = moduleRequestName + EXT_NAME_ABC;
|
baseFileName = moduleRequestName + EXT_NAME_ABC;
|
||||||
}
|
}
|
||||||
pos = moduleRequestName.rfind('/');
|
pos = moduleRequestName.rfind('/');
|
||||||
if (pos != CString::npos) {
|
if (pos != CString::npos) {
|
||||||
@ -354,7 +359,7 @@ public:
|
|||||||
const CString &packagePath)
|
const CString &packagePath)
|
||||||
{
|
{
|
||||||
CString entryPoint;
|
CString entryPoint;
|
||||||
for (size_t level = 0; level <= MAX_PACKGE_LEVEL; ++level) {
|
for (size_t level = 0; level <= MAX_PACKAGE_LEVEL; ++level) {
|
||||||
CString levelStr = std::to_string(level).c_str();
|
CString levelStr = std::to_string(level).c_str();
|
||||||
CString key = packagePath + "/" + levelStr + '/' + requestName;
|
CString key = packagePath + "/" + levelStr + '/' + requestName;
|
||||||
entryPoint = FindNpmEntryPoint(jsPandaFile, key);
|
entryPoint = FindNpmEntryPoint(jsPandaFile, key);
|
||||||
@ -365,36 +370,39 @@ public:
|
|||||||
return CString();
|
return CString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static CString ParseThirdPartyPackge(const JSPandaFile *jsPandaFile, const CString &recordName,
|
static CString ParseThirdPartyPackage(const JSPandaFile *jsPandaFile, const CString &recordName,
|
||||||
const CString &requestName, const CString &packagePath)
|
const CString &requestName, const CString &packagePath)
|
||||||
{
|
{
|
||||||
CString entryPoint;
|
CString entryPoint;
|
||||||
size_t pos = recordName.find(packagePath);
|
if (StringStartWith(recordName, packagePath, packagePath.size())) {
|
||||||
CString key = "";
|
|
||||||
if (pos != CString::npos) {
|
|
||||||
auto info = const_cast<JSPandaFile *>(jsPandaFile)->FindRecordInfo(recordName);
|
auto info = const_cast<JSPandaFile *>(jsPandaFile)->FindRecordInfo(recordName);
|
||||||
CString PackageName = info.npmPackageName;
|
CString PackageName = info.npmPackageName;
|
||||||
while ((pos = PackageName.rfind(packagePath)) != CString::npos) {
|
size_t pos = 0;
|
||||||
key = PackageName + '/' + packagePath + "/" + requestName;
|
while (true) {
|
||||||
|
CString key = PackageName + '/' + packagePath + "/" + requestName;
|
||||||
entryPoint = FindNpmEntryPoint(jsPandaFile, key);
|
entryPoint = FindNpmEntryPoint(jsPandaFile, key);
|
||||||
if (!entryPoint.empty()) {
|
if (!entryPoint.empty()) {
|
||||||
return entryPoint;
|
return entryPoint;
|
||||||
}
|
}
|
||||||
PackageName = PackageName.substr(0, pos > 0 ? pos - 1 : 0);
|
pos = PackageName.rfind(packagePath) - 1;
|
||||||
|
if (pos == CString::npos || pos < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
PackageName = PackageName.erase(pos, PackageName.size() - pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
entryPoint = FindPackageInTopLevel(jsPandaFile, requestName, packagePath);
|
entryPoint = FindPackageInTopLevel(jsPandaFile, requestName, packagePath);
|
||||||
return entryPoint;
|
return entryPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CString ParseThirdPartyPackge(const JSPandaFile *jsPandaFile, const CString &recordName,
|
static CString ParseThirdPartyPackage(const JSPandaFile *jsPandaFile, const CString &recordName,
|
||||||
const CString &requestName)
|
const CString &requestName)
|
||||||
{
|
{
|
||||||
CString entryPoint = ParseThirdPartyPackge(jsPandaFile, recordName, requestName, PACKAGE_PATH_SEGMENT);
|
CString entryPoint = ParseThirdPartyPackage(jsPandaFile, recordName, requestName, PACKAGE_PATH_SEGMENT);
|
||||||
if (!entryPoint.empty()) {
|
if (!entryPoint.empty()) {
|
||||||
return entryPoint;
|
return entryPoint;
|
||||||
}
|
}
|
||||||
return ParseThirdPartyPackge(jsPandaFile, recordName, requestName, NPM_PATH_SEGMENT);
|
return ParseThirdPartyPackage(jsPandaFile, recordName, requestName, NPM_PATH_SEGMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsImportFile(const CString &moduleRequestName)
|
static bool IsImportFile(const CString &moduleRequestName)
|
||||||
@ -425,23 +433,23 @@ public:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CString ConcatFileNameWithMerge(JSThread *thread, const JSPandaFile *jsPandaFile, CString &baseFilename,
|
static CString ConcatFileNameWithMerge(JSThread *thread, const JSPandaFile *jsPandaFile, CString &baseFileName,
|
||||||
CString recordName, CString requestName)
|
CString recordName, CString requestName)
|
||||||
{
|
{
|
||||||
CString entryPoint;
|
CString entryPoint;
|
||||||
if (StringStartWith(requestName, PREFIX_BUNDLE, PREFIX_BUNDLE_LEN)) {
|
if (StringStartWith(requestName, PREFIX_BUNDLE, PREFIX_BUNDLE_LEN)) {
|
||||||
entryPoint = ParsePreixBundle(jsPandaFile, baseFilename, recordName, requestName);
|
entryPoint = ParsePrefixBundle(thread, jsPandaFile, baseFileName, requestName);
|
||||||
} else if (StringStartWith(requestName, PREFIX_MODULE, PREFIX_MODULE_LEN)) {
|
} else if (StringStartWith(requestName, PREFIX_MODULE, PREFIX_MODULE_LEN)) {
|
||||||
entryPoint = ParsePreixModule(baseFilename, recordName, requestName);
|
entryPoint = ParsePreixModule(baseFileName, recordName, requestName);
|
||||||
} else if (StringStartWith(requestName, PREFIX_PACKAGE, PREFIX_PACKAGE_LEN)) {
|
} else if (StringStartWith(requestName, PREFIX_PACKAGE, PREFIX_PACKAGE_LEN)) {
|
||||||
entryPoint = requestName.substr(PREFIX_PACKAGE_LEN);
|
entryPoint = requestName.substr(PREFIX_PACKAGE_LEN);
|
||||||
} else if (IsImportFile(requestName)) {
|
} else if (IsImportFile(requestName)) {
|
||||||
entryPoint = MakeNewRecord(jsPandaFile, baseFilename, recordName, requestName);
|
entryPoint = MakeNewRecord(jsPandaFile, baseFileName, recordName, requestName);
|
||||||
} else {
|
} else {
|
||||||
entryPoint = ParseThirdPartyPackge(jsPandaFile, recordName, requestName);
|
entryPoint = ParseThirdPartyPackage(jsPandaFile, recordName, requestName);
|
||||||
}
|
}
|
||||||
if (entryPoint.empty()) {
|
if (entryPoint.empty()) {
|
||||||
LOG_ECMA(ERROR) << "Failed to resolve the requested entryPoint. BaseFilename : '" << baseFilename <<
|
LOG_ECMA(ERROR) << "Failed to resolve the requested entryPoint. baseFileName : '" << baseFileName <<
|
||||||
"'. RecordName : '" << recordName << "'. RequestName : '" << requestName << "'.";
|
"'. RecordName : '" << recordName << "'. RequestName : '" << requestName << "'.";
|
||||||
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
ObjectFactory *factory = thread->GetEcmaVM()->GetFactory();
|
||||||
CString msg = "Failed to load file '" + requestName + "'. Please check the target path.";
|
CString msg = "Failed to load file '" + requestName + "'. Please check the target path.";
|
||||||
|
@ -166,7 +166,8 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv)
|
|||||||
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, CatchException(thread, reject));
|
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, CatchException(thread, reject));
|
||||||
}
|
}
|
||||||
|
|
||||||
entryPoint = PathHelper::ConcatFileNameWithMerge(thread, jsPandaFile, baseFilename, recordNameStr, requestModule);
|
entryPoint =
|
||||||
|
PathHelper::ConcatFileNameWithMerge(thread, jsPandaFile, baseFilename, recordNameStr, requestModule);
|
||||||
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject));
|
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, CatchException(thread, reject));
|
||||||
fileNameStr = baseFilename;
|
fileNameStr = baseFilename;
|
||||||
moduleName = vm->GetFactory()->NewFromUtf8(entryPoint);
|
moduleName = vm->GetFactory()->NewFromUtf8(entryPoint);
|
||||||
@ -183,7 +184,7 @@ JSTaggedValue BuiltinsPromiseJob::DynamicImportJob(EcmaRuntimeCallInfo *argv)
|
|||||||
JSMutableHandle<JSTaggedValue> moduleNamespace(thread, JSTaggedValue::Undefined());
|
JSMutableHandle<JSTaggedValue> moduleNamespace(thread, JSTaggedValue::Undefined());
|
||||||
if (!vm->GetModuleManager()->IsImportedModuleLoaded(moduleName.GetTaggedValue())) {
|
if (!vm->GetModuleManager()->IsImportedModuleLoaded(moduleName.GetTaggedValue())) {
|
||||||
if (!JSPandaFileExecutor::ExecuteFromFile(thread, fileNameStr.c_str(), entryPoint.c_str(), false, true)) {
|
if (!JSPandaFileExecutor::ExecuteFromFile(thread, fileNameStr.c_str(), entryPoint.c_str(), false, true)) {
|
||||||
LOG_ECMA(ERROR) << "Try to load record " << entryPoint << " in abc : " << fileNameStr;
|
LOG_ECMA(INFO) << "Try to load record " << entryPoint << " in abc : " << fileNameStr;
|
||||||
CString msg = "Cannot execute request dynamic-imported module : " + entryPoint;
|
CString msg = "Cannot execute request dynamic-imported module : " + entryPoint;
|
||||||
JSTaggedValue error = factory->GetJSError(ErrorType::REFERENCE_ERROR, msg.c_str()).GetTaggedValue();
|
JSTaggedValue error = factory->GetJSError(ErrorType::REFERENCE_ERROR, msg.c_str()).GetTaggedValue();
|
||||||
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, CatchException(thread, reject));
|
THROW_NEW_ERROR_AND_RETURN_VALUE(thread, error, CatchException(thread, reject));
|
||||||
|
@ -75,7 +75,7 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromFile(JSThread *thr
|
|||||||
bool isModule = jsPandaFile->IsModule(thread, entry.c_str());
|
bool isModule = jsPandaFile->IsModule(thread, entry.c_str());
|
||||||
if (thread->HasPendingException()) {
|
if (thread->HasPendingException()) {
|
||||||
vm->HandleUncaughtException(thread->GetException());
|
vm->HandleUncaughtException(thread->GetException());
|
||||||
return JSTaggedValue::Undefined();
|
return Unexpected(false);
|
||||||
}
|
}
|
||||||
if (isModule) {
|
if (isModule) {
|
||||||
[[maybe_unused]] EcmaHandleScope scope(thread);
|
[[maybe_unused]] EcmaHandleScope scope(thread);
|
||||||
@ -91,7 +91,7 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::ExecuteFromFile(JSThread *thr
|
|||||||
if (!excuteFromJob) {
|
if (!excuteFromJob) {
|
||||||
vm->HandleUncaughtException(thread->GetException());
|
vm->HandleUncaughtException(thread->GetException());
|
||||||
}
|
}
|
||||||
return JSTaggedValue::Undefined();
|
return Unexpected(false);
|
||||||
}
|
}
|
||||||
JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleRecord);
|
JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleRecord);
|
||||||
module->SetStatus(ModuleStatus::INSTANTIATED);
|
module->SetStatus(ModuleStatus::INSTANTIATED);
|
||||||
@ -178,7 +178,7 @@ Expected<JSTaggedValue, bool> JSPandaFileExecutor::CommonExecuteBuffer(JSThread
|
|||||||
SourceTextModule::Instantiate(thread, moduleRecord);
|
SourceTextModule::Instantiate(thread, moduleRecord);
|
||||||
if (thread->HasPendingException()) {
|
if (thread->HasPendingException()) {
|
||||||
vm->HandleUncaughtException(thread->GetException());
|
vm->HandleUncaughtException(thread->GetException());
|
||||||
return JSTaggedValue::Undefined();
|
return Unexpected(false);
|
||||||
}
|
}
|
||||||
JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleRecord);
|
JSHandle<SourceTextModule> module = JSHandle<SourceTextModule>::Cast(moduleRecord);
|
||||||
module->SetStatus(ModuleStatus::INSTANTIATED);
|
module->SetStatus(ModuleStatus::INSTANTIATED);
|
||||||
|
Loading…
Reference in New Issue
Block a user