fix the problem of JSPersistent and JSEnvironment

Signed-off-by: yan-shuifeng <yanshuifeng@huawei.com>
Change-Id: If5bdbf2ae80aa6c75f455919398bcd378b161ede
This commit is contained in:
yan-shuifeng 2021-10-27 20:50:25 +08:00
parent 86beb21c59
commit 80c42b0e1b
4 changed files with 19 additions and 15 deletions

View File

@ -15,6 +15,7 @@
#include "bridge/declarative_frontend/jsview/js_environment.h"
#include "base/memory/referenced.h"
#include "core/common/ace_application_info.h"
#include "core/common/container.h"
#include "core/common/environment/environment_proxy.h"
@ -39,13 +40,16 @@ void JSEnvironment::JSBind(BindingTarget globalObj)
void JSEnvironment::ConstructorCallback(const JSCallbackInfo& args)
{
auto obj = new JSEnvironment();
args.SetReturnValue(obj);
auto environment = Referenced::MakeRefPtr<JSEnvironment>();
environment->IncRefCount();
args.SetReturnValue(Referenced::RawPtr(environment));
}
void JSEnvironment::DestructorCallback(JSEnvironment* obj)
void JSEnvironment::DestructorCallback(JSEnvironment* environment)
{
delete obj;
if (environment != nullptr) {
environment->DecRefCount();
}
}
void JSEnvironment::GetAccessibilityEnabled(const JSCallbackInfo& args)

View File

@ -22,7 +22,7 @@
namespace OHOS::Ace::Framework {
class JSEnvironment : public AceType {
class JSEnvironment final : public Referenced {
public:
void GetAccessibilityEnabled(const JSCallbackInfo& args);
void GetColorMode(const JSCallbackInfo& args);

View File

@ -15,6 +15,7 @@
#include "bridge/declarative_frontend/jsview/js_persistent.h"
#include "base/memory/referenced.h"
#include "core/common/ace_engine.h"
#include "core/common/container.h"
#include "core/common/storage/storage_proxy.h"
@ -40,13 +41,16 @@ void JSPersistent::ConstructorCallback(const JSCallbackInfo& args)
needCrossThread = args[0]->ToBoolean();
}
std::string fileName;
auto obj = new JSPersistent(needCrossThread, fileName);
args.SetReturnValue(obj);
auto persistent = Referenced::MakeRefPtr<JSPersistent>(needCrossThread, fileName);
persistent->IncRefCount();
args.SetReturnValue(Referenced::RawPtr(persistent));
}
void JSPersistent::DestructorCallback(JSPersistent* obj)
void JSPersistent::DestructorCallback(JSPersistent* persistent)
{
delete obj;
if (persistent != nullptr) {
persistent->DecRefCount();
}
}
void JSPersistent::Set(const JSCallbackInfo& args)
@ -62,7 +66,6 @@ void JSPersistent::Set(const JSCallbackInfo& args)
LOGW("container is null");
return;
}
auto context = container->GetPipelineContext();
auto executor = container->GetTaskExecutor();
if(!StorageProxy::GetInstance()->GetStorage(executor)) {
return;
@ -89,7 +92,6 @@ void JSPersistent::Get(const JSCallbackInfo& args)
LOGW("container is null");
return;
}
auto context = container->GetPipelineContext();
auto executor = container->GetTaskExecutor();
std::string value = StorageProxy::GetInstance()->GetStorage(executor)->Get(key);
auto returnValue = JSVal(ToJSValue(value));
@ -109,7 +111,6 @@ void JSPersistent::Delete(const JSCallbackInfo& args)
LOGW("container is null");
return;
}
auto context = container->GetPipelineContext();
auto executor = container->GetTaskExecutor();
StorageProxy::GetInstance()->GetStorage(executor)->Delete(key);
}
@ -121,7 +122,6 @@ void JSPersistent::Clear(const JSCallbackInfo& args)
LOGW("container is null");
return;
}
auto context = container->GetPipelineContext();
auto executor = container->GetTaskExecutor();
StorageProxy::GetInstance()->GetStorage(executor)->Clear();
}

View File

@ -22,9 +22,9 @@
namespace OHOS::Ace::Framework {
class JSPersistent : public AceType {
class JSPersistent final : public Referenced {
public:
explicit JSPersistent(bool needCrossThread, const std::string& db)
JSPersistent(bool needCrossThread, const std::string& db)
{
dbFile_ = db;
needCrossThread_ = needCrossThread;