mirror of
https://github.com/openharmony/ability_ability_runtime.git
synced 2026-08-24 22:21:36 -04:00
jsruntime Use Case Supplement
Issue:https://gitcode.com/openharmony/ability_ability_runtime/issues/15874?ref=&did=4225421#tid-4225421 Signed-off-by: rentangyu <rentangyu@huawei.com> AI[0%] Human Fixed[0%] Human[100%] AI Adopted[0%]
This commit is contained in:
@@ -483,7 +483,7 @@ bool JsRuntime::LoadRepairPatch(const std::string& hqfFile, const std::string& h
|
||||
auto vm = GetEcmaVm();
|
||||
CHECK_POINTER_AND_RETURN(vm, false);
|
||||
|
||||
InitSourceMap(hqfFile);
|
||||
HqfInitSourceMap(hqfFile);
|
||||
|
||||
std::string patchFile;
|
||||
auto hqfSafeData = GetSafeData(hqfFile, patchFile);
|
||||
@@ -788,7 +788,7 @@ bool JsRuntime::Initialize(const Options& options)
|
||||
}
|
||||
|
||||
if (!options.preload) {
|
||||
SourceMapInit(options.bundleName);
|
||||
InitSourceMap(options.bundleName);
|
||||
|
||||
if (options.isUnique) {
|
||||
TAG_LOGD(AAFwkTag::JSRUNTIME, "Not supported TimerModule when form render");
|
||||
@@ -1004,7 +1004,7 @@ void JsRuntime::CreatePluginDefaultNamespace(const std::string &lddictionaries)
|
||||
moduleManager->InheritNamespaceEachOther(currentNamespace, pluginDefaultNamespace);
|
||||
}
|
||||
|
||||
void JsRuntime::SourceMapInit(const std::string bundleName)
|
||||
void JsRuntime::InitSourceMap(const std::string bundleName)
|
||||
{
|
||||
HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__);
|
||||
CHECK_POINTER(jsEnv_);
|
||||
@@ -1026,7 +1026,7 @@ void JsRuntime::SourceMapInit(const std::string bundleName)
|
||||
ffrt::submit(init, {}, {}, ffrt::task_attr().qos(ffrt::qos_user_initiated));
|
||||
}
|
||||
|
||||
void JsRuntime::InitSourceMap(const std::string hqfFilePath)
|
||||
void JsRuntime::HqfInitSourceMap(const std::string hqfFilePath)
|
||||
{
|
||||
std::string patchSoureMapFile;
|
||||
std::vector<uint8_t> soureMapBuffer;
|
||||
@@ -1686,7 +1686,7 @@ void JsRuntime::RegisterQuickFixQueryFunc(const std::map<std::string, std::strin
|
||||
CHECK_POINTER(vm);
|
||||
for (auto it = moduleAndPath.begin(); it != moduleAndPath.end(); it++) {
|
||||
std::string hqfFile(AbilityBase::GetLoadPath(it->second));
|
||||
InitSourceMap(hqfFile);
|
||||
HqfInitSourceMap(hqfFile);
|
||||
}
|
||||
panda::JSNApi::RegisterQuickFixQueryFunc(vm, JsQuickfixCallback(moduleAndPath));
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ class FileMapper;
|
||||
|
||||
namespace JsEnv {
|
||||
class JsEnvironment;
|
||||
class SourceMapOperator;
|
||||
struct ErrorObject;
|
||||
struct UncaughtExceptionInfo;
|
||||
using UncatchableTask = std::function<void(std::string summary, const JsEnv::ErrorObject errorObject, napi_env env,
|
||||
@@ -147,8 +146,8 @@ public:
|
||||
bool isABC = true);
|
||||
static std::shared_ptr<AbilityBase::FileMapper> GetSafeData(const std::string& path, std::string& fileFullName);
|
||||
|
||||
void SourceMapInit(const std::string bundleName);
|
||||
void InitSourceMap(const std::string hqfFilePath);
|
||||
void InitSourceMap(const std::string bundleName);
|
||||
void HqfInitSourceMap(const std::string hqfFilePath);
|
||||
void FreeNativeReference(std::unique_ptr<NativeReference> reference);
|
||||
void FreeNativeReference(std::shared_ptr<NativeReference>&& reference);
|
||||
void StartProfiler(const DebugOption debugOption) override;
|
||||
|
||||
@@ -2387,5 +2387,104 @@ HWTEST_F(JsRuntimeTest, LoadSystemModule_0200, TestSize.Level1)
|
||||
|
||||
TAG_LOGI(AAFwkTag::TEST, "LoadSystemModule_0200 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InitSourceMap_0100
|
||||
* @tc.desc: JsRuntime test for InitSourceMap with jsEnv_ nullptr.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(JsRuntimeTest, InitSourceMap_0100, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0100 start");
|
||||
|
||||
auto jsRuntime = std::make_unique<JsRuntime>();
|
||||
ASSERT_NE(jsRuntime, nullptr);
|
||||
jsRuntime->jsEnv_ = nullptr;
|
||||
std::string bundleName = TEST_BUNDLE_NAME;
|
||||
jsRuntime->InitSourceMap(bundleName);
|
||||
// jsEnv_ is nullptr, CHECK_POINTER returns early, no crash
|
||||
jsRuntime.reset();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0100 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InitSourceMap_0200
|
||||
* @tc.desc: JsRuntime test for InitSourceMap with empty bundleName.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(JsRuntimeTest, InitSourceMap_0200, TestSize.Level2)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0200 start");
|
||||
|
||||
auto jsRuntime = std::make_unique<JsRuntime>();
|
||||
ASSERT_NE(jsRuntime, nullptr);
|
||||
jsRuntime->jsEnv_ = std::make_shared<JsEnv::JsEnvironment>();
|
||||
std::string bundleName = "";
|
||||
jsRuntime->InitSourceMap(bundleName);
|
||||
// empty bundleName, GetHapPathList returns empty, no crash
|
||||
jsRuntime.reset();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0200 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: InitSourceMap_0300
|
||||
* @tc.desc: JsRuntime test for InitSourceMap with valid bundleName.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(JsRuntimeTest, InitSourceMap_0300, TestSize.Level2)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0300 start");
|
||||
|
||||
auto jsRuntime = std::make_unique<JsRuntime>();
|
||||
ASSERT_NE(jsRuntime, nullptr);
|
||||
jsRuntime->jsEnv_ = std::make_shared<JsEnv::JsEnvironment>();
|
||||
std::string bundleName = TEST_BUNDLE_NAME;
|
||||
jsRuntime->InitSourceMap(bundleName);
|
||||
// valid bundleName but no real hap files in test env, ffrt task runs safely
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
jsRuntime.reset();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
TAG_LOGI(AAFwkTag::TEST, "InitSourceMap_0300 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HqfInitSourceMap_0100
|
||||
* @tc.desc: JsRuntime test for HqfInitSourceMap with invalid hqfFilePath.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(JsRuntimeTest, HqfInitSourceMap_0100, TestSize.Level1)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "HqfInitSourceMap_0100 start");
|
||||
|
||||
auto jsRuntime = std::make_unique<JsRuntime>();
|
||||
ASSERT_NE(jsRuntime, nullptr);
|
||||
std::string hqfFilePath = "/invalid/path/test.hqf";
|
||||
jsRuntime->HqfInitSourceMap(hqfFilePath);
|
||||
// GetFileBuffer fails with invalid path, returns early, no crash
|
||||
jsRuntime.reset();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
TAG_LOGI(AAFwkTag::TEST, "HqfInitSourceMap_0100 end");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HqfInitSourceMap_0200
|
||||
* @tc.desc: JsRuntime test for HqfInitSourceMap with empty hqfFilePath.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(JsRuntimeTest, HqfInitSourceMap_0200, TestSize.Level2)
|
||||
{
|
||||
TAG_LOGI(AAFwkTag::TEST, "HqfInitSourceMap_0200 start");
|
||||
|
||||
auto jsRuntime = std::make_unique<JsRuntime>();
|
||||
ASSERT_NE(jsRuntime, nullptr);
|
||||
std::string hqfFilePath = "";
|
||||
jsRuntime->HqfInitSourceMap(hqfFilePath);
|
||||
// empty path, GetFileBuffer fails, returns early, no crash
|
||||
jsRuntime.reset();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(200));
|
||||
TAG_LOGI(AAFwkTag::TEST, "HqfInitSourceMap_0200 end");
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
Reference in New Issue
Block a user