mirror of
https://gitee.com/openharmony/distributeddatamgr_datamgr_service
synced 2024-11-23 14:59:46 +00:00
fixed async this reference bugs
Signed-off-by: Sven Wang <wanghancai@huawei.com>
This commit is contained in:
parent
1f3223745a
commit
c99e56064e
@ -91,6 +91,7 @@ private:
|
||||
struct AsyncContext {
|
||||
std::shared_ptr<Context> ctx = nullptr;
|
||||
napi_ref callback = nullptr;
|
||||
napi_ref self = nullptr;
|
||||
napi_deferred defer = nullptr;
|
||||
napi_async_work work = nullptr;
|
||||
};
|
||||
|
@ -39,6 +39,7 @@ AsyncCall::AsyncCall(napi_env env, napi_callback_info info, std::shared_ptr<Cont
|
||||
}
|
||||
context_->ctx = std::move(context);
|
||||
NAPI_CALL_RETURN_VOID(env, (*context_->ctx)(env, argc, argv, self));
|
||||
napi_create_reference(env, self, 1, &context_->self);
|
||||
}
|
||||
|
||||
AsyncCall::~AsyncCall()
|
||||
@ -55,6 +56,10 @@ napi_value AsyncCall::Call(napi_env env, Context::ExecAction exec)
|
||||
if (context_ == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
if (context_->ctx == nullptr) {
|
||||
ZLOGD("context_ ctx is null");
|
||||
return nullptr;
|
||||
}
|
||||
ZLOGD("async call exec");
|
||||
context_->ctx->exec_ = std::move(exec);
|
||||
napi_value promise = nullptr;
|
||||
@ -139,6 +144,7 @@ void AsyncCall::DeleteContext(napi_env env, AsyncContext *context)
|
||||
{
|
||||
if (env != nullptr) {
|
||||
napi_delete_reference(env, context->callback);
|
||||
napi_delete_reference(env, context->self);
|
||||
napi_delete_async_work(env, context->work);
|
||||
}
|
||||
delete context;
|
||||
|
@ -39,6 +39,7 @@ DistributedKv::Options JSUtil::Convert2Options(napi_env env, napi_value jsOption
|
||||
napi_get_value_bool(env, value, &options.backup);
|
||||
}
|
||||
value = nullptr;
|
||||
options.autoSync = false;
|
||||
napi_get_named_property(env, jsOptions, "autoSync", &value);
|
||||
if (value != nullptr) {
|
||||
napi_get_value_bool(env, value, &options.autoSync);
|
||||
|
Loading…
Reference in New Issue
Block a user