hms模块下沉

Signed-off-by: chenlincl3 <chenlin201@huawei.com>
Change-Id: I0796e62ab8bda18e87cbb126f90c76d34bc7dc34
This commit is contained in:
chenlincl3 2023-12-19 12:06:52 +00:00
parent d639d7517a
commit 9abf45d246
5 changed files with 60 additions and 0 deletions

View File

@ -759,4 +759,34 @@ CString EcmaVM::GetCurrentModuleName()
}
return moduleName;
}
void EcmaVM::SetHmsModuleList(const std::vector<panda::HmsMap> &list)
{
for (size_t i = 0; i < list.size(); i++) {
HmsMap hmsMap = list[i];
hmsModuleList_.emplace(hmsMap.originalPath.c_str(), hmsMap);
}
}
CString EcmaVM::GetHmsModule(const CString &module) const
{
auto it = hmsModuleList_.find(module);
if (it == hmsModuleList_.end()) {
LOG_ECMA(FATAL) << " Get Hms Module failed";
}
HmsMap hmsMap = it->second;
return hmsMap.targetPath.c_str();
}
bool EcmaVM::IsHmsModule(const CString &moduleStr) const
{
if (hmsModuleList_.empty()) {
return false;
}
auto it = hmsModuleList_.find(moduleStr);
if (it == hmsModuleList_.end()) {
return false;
}
return true;
}
} // namespace panda::ecmascript

View File

@ -33,6 +33,7 @@
namespace panda {
class JSNApi;
struct HmsMap;
namespace panda_file {
class File;
} // namespace panda_file
@ -426,6 +427,12 @@ public:
CString GetCurrentModuleName();
void SetHmsModuleList(const std::vector<panda::HmsMap> &list);
bool IsHmsModule(const CString &moduleStr) const;
CString GetHmsModule(const CString &module) const;
#if defined(ECMASCRIPT_SUPPORT_CPUPROFILER)
CpuProfiler *GetProfiler() const
{
@ -587,6 +594,7 @@ private:
CString moduleName_;
CList<CString> deregisterModuleList_;
CMap<CString, CString> mockModuleList_;
CMap<CString, HmsMap> hmsModuleList_;
NativePtrGetter nativePtrGetter_ {nullptr};
SourceMapTranslateCallback sourceMapTranslateCallback_ {nullptr};

View File

@ -94,6 +94,16 @@ JSHandle<JSTaggedValue> SourceTextModule::HostResolveImportedModuleWithMerge(
moduleRequestName = vm->GetMockModule(moduleRequestName);
moduleRequestStr = JSHandle<JSTaggedValue>::Cast(vm->GetFactory()->NewFromUtf8(moduleRequestName.c_str()));
}
/*
* Before: @xxx:****
* After: bundleName/moduleName@namespace/moduleName/xxx/xxx
* Don't load native module
*/
if (vm->IsHmsModule(moduleRequestName)) {
moduleRequestName = vm->GetHmsModule(moduleRequestName);
moduleRequestStr = JSHandle<JSTaggedValue>::Cast(vm->GetFactory()->NewFromUtf8(moduleRequestName.c_str()));
}
auto moduleManager = thread->GetCurrentEcmaContext()->GetModuleManager();
auto [isNative, moduleType] = SourceTextModule::CheckNativeModule(moduleRequestName);

View File

@ -81,6 +81,12 @@ struct AlignedPointer;
}
} // namespace ecmascript
struct HmsMap {
std::string originalPath;
std::string targetPath;
uint32_t sinceVersion;
};
using Deleter = void (*)(void *nativePointer, void *data);
using WeakRefClearCallBack = void (*)(void *);
using EcmaVM = ecmascript::EcmaVM;
@ -1269,6 +1275,7 @@ public:
static void SetBundle(EcmaVM *vm, bool value);
static void SetAssetPath(EcmaVM *vm, const std::string &assetPath);
static void SetMockModuleList(EcmaVM *vm, const std::map<std::string, std::string> &list);
static void SetHmsModuleList(EcmaVM *vm, const std::vector<panda::HmsMap> &list);
static void SetLoop(EcmaVM *vm, void *loop);
static std::string GetAssetPath(EcmaVM *vm);

View File

@ -2500,6 +2500,11 @@ void JSNApi::SetMockModuleList(EcmaVM *vm, const std::map<std::string, std::stri
vm->SetMockModuleList(list);
}
void JSNApi::SetHmsModuleList(EcmaVM *vm, const std::vector<panda::HmsMap> &list)
{
vm->SetHmsModuleList(list);
}
bool JSNApi::InitForConcurrentThread(EcmaVM *vm, ConcurrentCallback cb, void *data)
{
vm->SetConcurrentCallback(cb, data);