mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-27 09:21:28 +00:00
Description:JsEnvironment support timer.
Sig:SIG_ApplicationFramework Feature or BugFix: Feature Binary Source: No Signed-off-by: zhangyafei.echo <zhangyafei12@huawei.com> Change-Id: I1b74939ac8d8c47cc256edf016f611ab2754ed1a
This commit is contained in:
parent
5ed0fce6a4
commit
539a9e0035
@ -515,7 +515,7 @@ bool JsRuntime::Initialize(const Options& options)
|
||||
if (options.isUnique) {
|
||||
HILOG_INFO("Not supported TimerModule when form render");
|
||||
} else {
|
||||
InitTimerModule(*nativeEngine, *globalObj);
|
||||
InitTimerModule();
|
||||
}
|
||||
|
||||
InitWorkerModule(*nativeEngine, codePath_, options.isDebugVersion, options.isBundle);
|
||||
@ -1075,5 +1075,11 @@ void JsRuntime::FreeNativeReference(std::unique_ptr<NativeReference> uniqueNativ
|
||||
work = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void JsRuntime::InitTimerModule()
|
||||
{
|
||||
CHECK_POINTER(jsEnv_);
|
||||
jsEnv_->InitTimerModule();
|
||||
}
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
@ -182,7 +182,7 @@ NativeValue* StopTimeoutOrInterval(NativeEngine* engine, NativeCallbackInfo* inf
|
||||
}
|
||||
}
|
||||
|
||||
void InitTimerModule(NativeEngine& engine, NativeObject& globalObject)
|
||||
void InitTimer(NativeEngine& engine, NativeObject& globalObject)
|
||||
{
|
||||
HILOG_DEBUG("InitTimerModule begin.");
|
||||
const char *moduleName = "JsTimer";
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
void InitTimerModule(NativeEngine& engine, NativeObject& globalObject);
|
||||
void InitTimer(NativeEngine& engine, NativeObject& globalObject);
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
||||
|
@ -16,6 +16,9 @@
|
||||
#include "ohos_js_environment_impl.h"
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_runtime_utils.h"
|
||||
#include "js_timer.h"
|
||||
#include "js_utils.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AbilityRuntime {
|
||||
@ -39,9 +42,16 @@ void OHOSJsEnvironmentImpl::RemoveTask(const std::string& name)
|
||||
HILOG_DEBUG("called");
|
||||
}
|
||||
|
||||
void OHOSJsEnvironmentImpl::InitTimerModule()
|
||||
void OHOSJsEnvironmentImpl::InitTimerModule(NativeEngine* engine)
|
||||
{
|
||||
HILOG_DEBUG("called");
|
||||
HILOG_DEBUG("Init timer.");
|
||||
CHECK_POINTER(engine);
|
||||
|
||||
HandleScope handleScope(*engine);
|
||||
NativeObject* globalObj = ConvertNativeValueTo<NativeObject>(engine->GetGlobal());
|
||||
CHECK_POINTER(globalObj);
|
||||
|
||||
InitTimer(*engine, *globalObj);
|
||||
}
|
||||
|
||||
void OHOSJsEnvironmentImpl::InitConsoleLogModule()
|
||||
|
@ -29,7 +29,7 @@ public:
|
||||
|
||||
void RemoveTask(const std::string& name) override;
|
||||
|
||||
void InitTimerModule() override;
|
||||
void InitTimerModule(NativeEngine* engine) override;
|
||||
|
||||
void InitConsoleLogModule() override;
|
||||
|
||||
|
@ -141,6 +141,7 @@ private:
|
||||
inline bool IsUseAbilityRuntime(const Options& options) const;
|
||||
void FreeNativeReference(std::unique_ptr<NativeReference> uniqueNativeRef,
|
||||
std::shared_ptr<NativeReference>&& sharedNativeRef);
|
||||
void InitTimerModule();
|
||||
};
|
||||
} // namespace AbilityRuntime
|
||||
} // namespace OHOS
|
||||
|
@ -67,8 +67,13 @@ void JsEnvironment::StopDebugger()
|
||||
|
||||
void JsEnvironment::InitTimerModule()
|
||||
{
|
||||
if (engine_ == nullptr) {
|
||||
JSENV_LOG_E("Invalid native engine.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (impl_ != nullptr) {
|
||||
impl_->InitTimerModule();
|
||||
impl_->InitTimerModule(engine_);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "native_engine/native_engine.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace JsEnv {
|
||||
class JsEnvironmentImpl {
|
||||
@ -29,7 +31,7 @@ public:
|
||||
|
||||
virtual void RemoveTask(const std::string& name) = 0;
|
||||
|
||||
virtual void InitTimerModule() = 0;
|
||||
virtual void InitTimerModule(NativeEngine* engine) = 0;
|
||||
|
||||
virtual void InitConsoleLogModule() = 0;
|
||||
|
||||
|
@ -150,5 +150,27 @@ HWTEST_F(JsEnvironmentTest, LoadScript_0300, TestSize.Level0)
|
||||
|
||||
EXPECT_EQ(jsEnv->LoadScript("/system/etc/strip.native.min.abc"), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: JsEnvInitTimerModule_0100
|
||||
* @tc.desc: Initialize timer module.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6Z5M5
|
||||
*/
|
||||
HWTEST_F(JsEnvironmentTest, JsEnvInitTimerModule_0100, TestSize.Level0)
|
||||
{
|
||||
auto jsEnv = std::make_shared<JsEnvironment>(std::make_unique<AbilityRuntime::OHOSJsEnvironmentImpl>());
|
||||
ASSERT_NE(jsEnv, nullptr);
|
||||
|
||||
// Init timer module when native engine is invalid.
|
||||
jsEnv->InitTimerModule();
|
||||
|
||||
panda::RuntimeOption pandaOption;
|
||||
auto ret = jsEnv->Initialize(pandaOption, static_cast<void*>(this));
|
||||
ASSERT_EQ(ret, true);
|
||||
|
||||
// Init timer module when native engine has created.
|
||||
jsEnv->InitTimerModule();
|
||||
}
|
||||
} // namespace JsEnv
|
||||
} // namespace OHOS
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "hilog_wrapper.h"
|
||||
#include "js_runtime.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
@ -70,14 +71,22 @@ HWTEST_F(OHOSJsEnvironmentTest, PostTask_0100, TestSize.Level0)
|
||||
* @tc.name: InitTimerModule_0100
|
||||
* @tc.desc: Js environment init timer.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI6KODF
|
||||
* @tc.require: issueI6Z5M5
|
||||
*/
|
||||
HWTEST_F(OHOSJsEnvironmentTest, InitTimerModule_0100, TestSize.Level0)
|
||||
{
|
||||
auto jsEnvImpl = std::make_shared<OHOSJsEnvironmentImpl>();
|
||||
auto jsEnvImpl = std::make_unique<OHOSJsEnvironmentImpl>();
|
||||
ASSERT_NE(jsEnvImpl, nullptr);
|
||||
|
||||
jsEnvImpl->InitTimerModule();
|
||||
// Init timer module when native engine is invalid.
|
||||
jsEnvImpl->InitTimerModule(nullptr);
|
||||
|
||||
AbilityRuntime::Runtime::Options options;
|
||||
auto jsRuntime = AbilityRuntime::JsRuntime::Create(options);
|
||||
ASSERT_NE(jsRuntime, nullptr);
|
||||
|
||||
// Init timer module when native engine has created.
|
||||
jsEnvImpl->InitTimerModule(jsRuntime->GetNativeEnginePointer());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user