diff --git a/frameworks/jskitsimpl/distributeddata/include/js_field_node.h b/frameworks/jskitsimpl/distributeddata/include/js_field_node.h index 693c499a72900903842bcfa2eea268be820b9887..3b0e382701cfc9b9d7cf46ad298f5842d960a9fa 100644 --- a/frameworks/jskitsimpl/distributeddata/include/js_field_node.h +++ b/frameworks/jskitsimpl/distributeddata/include/js_field_node.h @@ -42,7 +42,12 @@ private: static napi_value SetNullable(napi_env env, napi_callback_info info); static napi_value GetValueType(napi_env env, napi_callback_info info); static napi_value SetValueType(napi_env env, napi_callback_info info); - + static std::map valueTypeToString_; + + template + static napi_value GetContextValue(napi_env env, std::shared_ptr &ctxt, T &value); + static JsFieldNode* GetFieldNode(napi_env env, napi_callback_info info, std::shared_ptr &ctxt); + std::string ValueToString(JSUtil::KvStoreVariant value); std::string ValueTypeToString(uint32_t type); diff --git a/frameworks/jskitsimpl/distributeddata/include/js_schema.h b/frameworks/jskitsimpl/distributeddata/include/js_schema.h index 961de71b0dabc3befb4e8cbecf54aa85392408d4..2396bf8ab3bdce7c3686fdae27321ef791dbf4a0 100644 --- a/frameworks/jskitsimpl/distributeddata/include/js_schema.h +++ b/frameworks/jskitsimpl/distributeddata/include/js_schema.h @@ -42,6 +42,11 @@ private: static napi_value GetIndexes(napi_env env, napi_callback_info info); static napi_value SetIndexes(napi_env env, napi_callback_info info); + template + static napi_value GetContextValue(napi_env env, std::shared_ptr& ctxt, T &value); + + static JsSchema* GetSchema(napi_env env, napi_callback_info info, std::shared_ptr &ctxt); + enum { SCHEMA_MODE_SLOPPY, SCHEMA_MODE_STRICT, diff --git a/frameworks/jskitsimpl/distributeddata/include/napi_queue.h b/frameworks/jskitsimpl/distributeddata/include/napi_queue.h index afb65f967eaf26cffef7697213c01c69c1720867..0febdaf3dbe6f6df5238fec07f1d15370007c43f 100644 --- a/frameworks/jskitsimpl/distributeddata/include/napi_queue.h +++ b/frameworks/jskitsimpl/distributeddata/include/napi_queue.h @@ -62,7 +62,7 @@ private: }; /* check condition related to argc/argv, return and logging. */ -#define CHECK_ARGS(ctxt, condition, message) \ +#define CHECK_ARGS_RETURN_VOID(ctxt, condition, message) \ do { \ if (!(condition)) { \ (ctxt)->status = napi_invalid_arg; \ @@ -72,7 +72,7 @@ private: } \ } while (0) -#define CHECK_STATUS(ctxt, message) \ +#define CHECK_STATUS_RETURN_VOID(ctxt, message) \ do { \ if ((ctxt)->status != napi_ok) { \ (ctxt)->error = std::string(message); \ diff --git a/frameworks/jskitsimpl/distributeddata/src/js_device_kv_store.cpp b/frameworks/jskitsimpl/distributeddata/src/js_device_kv_store.cpp index 15e513ff39b18620547a3a0bade600735fd437d9..7034d5883b2a0c7ca555d661e3ead15484ff6684 100644 --- a/frameworks/jskitsimpl/distributeddata/src/js_device_kv_store.cpp +++ b/frameworks/jskitsimpl/distributeddata/src/js_device_kv_store.cpp @@ -86,11 +86,11 @@ napi_value JsDeviceKVStore::Get(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // number 2 means: required 2 arguments, + - CHECK_ARGS(ctxt, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->deviceId); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid deviceId!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid deviceId!"); ctxt->status = JSUtil::GetValue(env, argv[1], ctxt->key); - CHECK_STATUS(ctxt, "invalid arg[1], i.e. invalid key!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[1], i.e. invalid key!"); }; ctxt->GetCbInfo(env, info, input); @@ -103,11 +103,11 @@ napi_value JsDeviceKVStore::Get(napi_env env, napi_callback_info info) ZLOGD("kvStore->Get return %{public}d", status); ctxt->value = JSUtil::Blob2VariantValue(value); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->Get() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->Get() failed!"); }; auto output = [env, ctxt](napi_value& result) { ctxt->status = JSUtil::SetValue(env, ctxt->value, result); - CHECK_STATUS(ctxt, "output failed"); + CHECK_STATUS_RETURN_VOID(ctxt, "output failed"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output); } @@ -181,7 +181,7 @@ napi_value JsDeviceKVStore::GetEntries(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { ctxt->status = GetVariantArgs(env, argc, argv, ctxt->va); - CHECK_STATUS(ctxt, "invalid arguments!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arguments!"); }; ctxt->GetCbInfo(env, info, input); @@ -204,11 +204,11 @@ napi_value JsDeviceKVStore::GetEntries(napi_env env, napi_callback_info info) ZLOGD("kvStore->GetEntriesWithQuery() return %{public}d", status); } ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->GetEntries() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->GetEntries() failed!"); }; auto output = [env, ctxt](napi_value& result) { ctxt->status = JSUtil::SetValue(env, ctxt->entries, result); - CHECK_STATUS(ctxt, "output failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "output failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output); } @@ -235,10 +235,10 @@ napi_value JsDeviceKVStore::GetResultSet(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { ctxt->status = GetVariantArgs(env, argc, argv, ctxt->va); - CHECK_STATUS(ctxt, "invalid arguments!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arguments!"); ctxt->ref = JSUtil::NewWithRef(env, 0, nullptr, (void**)(&ctxt->resultSet), JsKVStoreResultSet::Constructor(env)); - CHECK_ARGS(ctxt, ctxt->resultSet != nullptr, "KVStoreResultSet::New failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, ctxt->resultSet != nullptr, "KVStoreResultSet::New failed!"); }; ctxt->GetCbInfo(env, info, input); @@ -262,13 +262,13 @@ napi_value JsDeviceKVStore::GetResultSet(napi_env env, napi_callback_info info) ZLOGD("kvStore->GetEntriesWithQuery() return %{public}d", status); } ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->GetResultSet() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->GetResultSet() failed!"); ctxt->resultSet->SetNative(kvResultSet); }; auto output = [env, ctxt](napi_value& result) { ctxt->status = napi_get_reference_value(env, ctxt->ref, &result); napi_delete_reference(env, ctxt->ref); - CHECK_STATUS(ctxt, "output KvResultSet failed"); + CHECK_STATUS_RETURN_VOID(ctxt, "output KvResultSet failed"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output); } @@ -287,13 +287,13 @@ napi_value JsDeviceKVStore::CloseResultSet(napi_env env, napi_callback_info info auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); napi_valuetype type = napi_undefined; ctxt->status = napi_typeof(env, argv[0], &type); - CHECK_ARGS(ctxt, type == napi_object, "invalid arg[0], i.e. invalid resultSet!"); + CHECK_ARGS_RETURN_VOID(ctxt, type == napi_object, "invalid arg[0], i.e. invalid resultSet!"); ctxt->status = JSUtil::Unwrap(env, argv[0], (void**)(&ctxt->resultSet), JsKVStoreResultSet::Constructor(env)); - CHECK_ARGS(ctxt, ctxt->resultSet != nullptr, "invalid arg[0], i.e. invalid resultSet!"); + CHECK_ARGS_RETURN_VOID(ctxt, ctxt->resultSet != nullptr, "invalid arg[0], i.e. invalid resultSet!"); }; ctxt->GetCbInfo(env, info, input); @@ -302,7 +302,7 @@ napi_value JsDeviceKVStore::CloseResultSet(napi_env env, napi_callback_info info Status status = kvStore->CloseResultSet(ctxt->resultSet->GetNative()); ZLOGD("kvStore->CloseResultSet return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->CloseResultSet failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->CloseResultSet failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -325,9 +325,9 @@ napi_value JsDeviceKVStore::GetResultSize(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { ctxt->status = GetVariantArgs(env, argc, argv, ctxt->va); - CHECK_ARGS(ctxt, (ctxt->va.type == ArgsType::DEVICEID_QUERY) || (ctxt->va.type == ArgsType::QUERY), + CHECK_ARGS_RETURN_VOID(ctxt, (ctxt->va.type == ArgsType::DEVICEID_QUERY) || (ctxt->va.type == ArgsType::QUERY), "invalid arguments!"); - CHECK_STATUS(ctxt, "invalid arguments!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arguments!"); }; ctxt->GetCbInfo(env, info, input); @@ -340,11 +340,11 @@ napi_value JsDeviceKVStore::GetResultSize(napi_env env, napi_callback_info info) Status status = kvStore->GetCountWithQuery(query.ToString(), ctxt->resultSize); ZLOGD("kvStore->GetCountWithQuery() return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->GetCountWithQuery() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->GetCountWithQuery() failed!"); }; auto output = [env, ctxt](napi_value& result) { ctxt->status = JSUtil::SetValue(env, static_cast(ctxt->resultSize), result); - CHECK_STATUS(ctxt, "output resultSize failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "output resultSize failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output); } @@ -363,9 +363,9 @@ napi_value JsDeviceKVStore::RemoveDeviceData(napi_env env, napi_callback_info in auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->deviceId); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid deviceId!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid deviceId!"); }; ctxt->GetCbInfo(env, info, input); @@ -374,7 +374,7 @@ napi_value JsDeviceKVStore::RemoveDeviceData(napi_env env, napi_callback_info in Status status = kvStore->RemoveDeviceData(ctxt->deviceId); ZLOGD("kvStore->RemoveDeviceData return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->RemoveDeviceData() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->RemoveDeviceData() failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -392,12 +392,12 @@ napi_value JsDeviceKVStore::Sync(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 2 arguments :: + - CHECK_ARGS(ctxt, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->deviceIdList); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid deviceIdList!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid deviceIdList!"); ctxt->status = JSUtil::GetValue(env, argv[1], ctxt->mode); - CHECK_STATUS(ctxt, "invalid arg[1], i.e. invalid mode!"); - CHECK_ARGS(ctxt, ctxt->mode <= uint32_t(SyncMode::PUSH_PULL), "invalid arg[1], i.e. invalid mode!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[1], i.e. invalid mode!"); + CHECK_ARGS_RETURN_VOID(ctxt, ctxt->mode <= uint32_t(SyncMode::PUSH_PULL), "invalid arg[1], i.e. invalid mode!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -416,10 +416,10 @@ napi_value JsDeviceKVStore::New(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt, &storeId](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], storeId); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid storeId!"); - CHECK_ARGS(ctxt, !storeId.empty(), "invalid arg[0], i.e. invalid storeId!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid storeId!"); + CHECK_ARGS_RETURN_VOID(ctxt, !storeId.empty(), "invalid arg[0], i.e. invalid storeId!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); diff --git a/frameworks/jskitsimpl/distributeddata/src/js_field_node.cpp b/frameworks/jskitsimpl/distributeddata/src/js_field_node.cpp index ea5b8b230dcbd3bac9488f6944826b8f4c360c40..c18072280a2c22449e46e005b3a664f48d710f18 100644 --- a/frameworks/jskitsimpl/distributeddata/src/js_field_node.cpp +++ b/frameworks/jskitsimpl/distributeddata/src/js_field_node.cpp @@ -22,13 +22,22 @@ using namespace OHOS::DistributedKv; namespace OHOS::DistributedData { -static std::string FIELDNAME = "FIELDNAME"; -static std::string VALUETYPE = "VALUETYPE"; -static std::string DEFAULTVALUE = "DEFAULTVALUE"; -static std::string ISWITHDEFAULTVALUE = "ISWITHDEFAULTVALUE"; -static std::string ISNULLABLE = "ISNULLABLE"; +static std::string FIELD_NAME = "FIELD_NAME"; +static std::string VALUE_TYPE = "VALUE_TYPE"; +static std::string DEFAULT_VALUE = "DEFAULT_VALUE"; +static std::string IS_DEFAULT_VALUE = "IS_DEFAULT_VALUE"; +static std::string IS_NULLABLE = "IS_NULLABLE"; static std::string CHILDREN = "CHILDREN"; +std::map JsFieldNode::valueTypeToString_ = { + { JSUtil::STRING, std::string("STRING") }, + { JSUtil::INTEGER, std::string("INTEGER") }, + { JSUtil::FLOAT, std::string("FLOAT") }, + { JSUtil::BYTE_ARRAY, std::string("BYTE_ARRAY") }, + { JSUtil::BOOLEAN, std::string("BOOLEAN") }, + { JSUtil::DOUBLE, std::string("DOUBLE") } +}; + JsFieldNode::JsFieldNode(const std::string& fName) : fieldName(fName) { @@ -41,20 +50,15 @@ std::string JsFieldNode::GetFieldName() JsFieldNode::json JsFieldNode::GetValueForJson() { - if (!fields.empty()) { - /* example: - { "field_root": { - "field_child1": "LONG, NOT NULL, DEFAULT 88", - "field_child2": "LONG, NOT NULL, DEFAULT 88" } } */ - json jsFields; - for (auto fld : fields) { - jsFields[fld->fieldName] = fld->GetValueForJson(); - } - return jsFields; + if (fields.empty()) { + return ValueTypeToString(valueType) + "," + (isNullable ? "NULL" : "NOT NULL"); } - /* example: { "field_name": "LONG, NOT NULL, DEFAULT 88" } */ - return ValueTypeToString(valueType) + "," + (isNullable ? "NULL" : "NOT NULL"); + json jsFields; + for (auto fld : fields) { + jsFields[fld->fieldName] = fld->GetValueForJson(); + } + return jsFields; } napi_value JsFieldNode::Constructor(napi_env env) @@ -76,10 +80,10 @@ napi_value JsFieldNode::New(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt, &fieldName](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], fieldName); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid fieldName!"); - CHECK_ARGS(ctxt, !fieldName.empty(), "invalid arg[0], i.e. invalid fieldName!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid fieldName!"); + CHECK_ARGS_RETURN_VOID(ctxt, !fieldName.empty(), "invalid arg[0], i.e. invalid fieldName!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -104,10 +108,10 @@ napi_value JsFieldNode::AppendChild(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt, &child](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::Unwrap(env, argv[0], (void**)(&child), JsFieldNode::Constructor(env)); - CHECK_STATUS(ctxt, "napi_unwrap to FieldNode failed"); - CHECK_ARGS(ctxt, child != nullptr, "invalid arg[0], i.e. invalid FieldNode!"); + CHECK_STATUS_RETURN_VOID(ctxt, "napi_unwrap to FieldNode failed"); + CHECK_ARGS_RETURN_VOID(ctxt, child != nullptr, "invalid arg[0], i.e. invalid FieldNode!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -119,18 +123,28 @@ napi_value JsFieldNode::AppendChild(napi_env env, napi_callback_info info) return ctxt->output; } -napi_value JsFieldNode::GetDefaultValue(napi_env env, napi_callback_info info) +JsFieldNode* JsFieldNode::GetFieldNode(napi_env env, napi_callback_info info, std::shared_ptr& ctxt) { - ZLOGD("FieldNode::GetDefaultValue"); - auto ctxt = std::make_shared(); ctxt->GetCbInfoSync(env, info); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); + return reinterpret_cast(ctxt->native); +} - auto fieldNode = reinterpret_cast(ctxt->native); - JSUtil::SetValue(env, fieldNode->defaultValue, ctxt->output); +template +napi_value JsFieldNode::GetContextValue(napi_env env, std::shared_ptr &ctxt, T &value) +{ + JSUtil::SetValue(env, value, ctxt->output); return ctxt->output; } +napi_value JsFieldNode::GetDefaultValue(napi_env env, napi_callback_info info) +{ + ZLOGD("FieldNode::GetDefaultValue"); + auto ctxt = std::make_shared(); + auto fieldNode = GetFieldNode(env, info, ctxt); + return GetContextValue(env, ctxt, fieldNode->defaultValue); +} + napi_value JsFieldNode::SetDefaultValue(napi_env env, napi_callback_info info) { ZLOGD("FieldNode::SetDefaultValue"); @@ -138,9 +152,9 @@ napi_value JsFieldNode::SetDefaultValue(napi_env env, napi_callback_info info) JSUtil::KvStoreVariant vv; auto input = [env, ctxt, &vv](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], vv); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid defaultValue!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid defaultValue!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -154,12 +168,8 @@ napi_value JsFieldNode::GetNullable(napi_env env, napi_callback_info info) { ZLOGD("FieldNode::GetNullable"); auto ctxt = std::make_shared(); - ctxt->GetCbInfoSync(env, info); - NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); - - auto fieldNode = reinterpret_cast(ctxt->native); - JSUtil::SetValue(env, fieldNode->isNullable, ctxt->output); - return ctxt->output; + auto fieldNode = GetFieldNode(env, info, ctxt); + return GetContextValue(env, ctxt, fieldNode->isNullable); } napi_value JsFieldNode::SetNullable(napi_env env, napi_callback_info info) @@ -169,9 +179,9 @@ napi_value JsFieldNode::SetNullable(napi_env env, napi_callback_info info) bool isNullable = false; auto input = [env, ctxt, &isNullable](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], isNullable); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid isNullable!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid isNullable!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -183,14 +193,10 @@ napi_value JsFieldNode::SetNullable(napi_env env, napi_callback_info info) napi_value JsFieldNode::GetValueType(napi_env env, napi_callback_info info) { - ZLOGD("FieldNode::New"); + ZLOGD("FieldNode::GetValueType"); auto ctxt = std::make_shared(); - ctxt->GetCbInfoSync(env, info); - NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); - - auto fieldNode = reinterpret_cast(ctxt->native); - JSUtil::SetValue(env, fieldNode->valueType, ctxt->output); - return ctxt->output; + auto fieldNode = GetFieldNode(env, info, ctxt); + return GetContextValue(env, ctxt, fieldNode->valueType); } napi_value JsFieldNode::SetValueType(napi_env env, napi_callback_info info) @@ -200,10 +206,10 @@ napi_value JsFieldNode::SetValueType(napi_env env, napi_callback_info info) uint32_t type = 0; auto input = [env, ctxt, &type](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], type); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid valueType!"); - CHECK_ARGS(ctxt, (JSUtil::STRING <= type) && (type <= JSUtil::DOUBLE), + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid valueType!"); + CHECK_ARGS_RETURN_VOID(ctxt, (JSUtil::STRING <= type) && (type <= JSUtil::DOUBLE), "invalid arg[0], i.e. invalid valueType!"); }; ctxt->GetCbInfoSync(env, info, input); @@ -243,25 +249,14 @@ std::string JsFieldNode::ValueToString(JSUtil::KvStoreVariant value) std::string JsFieldNode::ValueTypeToString(uint32_t type) { // DistributedDB::FieldType - switch (type) { - case JSUtil::STRING: - return std::string("STRING"); - case JSUtil::INTEGER: - return std::string("INTEGER"); - case JSUtil::FLOAT: - return std::string("FLOAT"); - case JSUtil::BYTE_ARRAY: - return std::string("BYTE_ARRAY"); - case JSUtil::BOOLEAN: - return std::string("BOOLEAN"); - case JSUtil::DOUBLE: - return std::string("DOUBLE"); - default: - ZLOGE("ValueType is INVALID"); - break; + auto it = valueTypeToString_.find(type); + if (valueTypeToString_.find(type) != valueTypeToString_.end()) { + return it->second; + } else { + return std::string(); } - return std::string(); } + std::string JsFieldNode::Dump() { json jsFields; @@ -270,11 +265,11 @@ std::string JsFieldNode::Dump() } json jsNode = { - { FIELDNAME, fieldName }, - { VALUETYPE, ValueTypeToString(valueType) }, - { DEFAULTVALUE, ValueToString(defaultValue) }, - { ISWITHDEFAULTVALUE, isWithDefaultValue }, - { ISNULLABLE, isNullable }, + { FIELD_NAME, fieldName }, + { VALUE_TYPE, ValueTypeToString(valueType) }, + { DEFAULT_VALUE, ValueToString(defaultValue) }, + { IS_DEFAULT_VALUE, isWithDefaultValue }, + { IS_NULLABLE, isNullable }, { CHILDREN, jsFields.dump() } }; return jsNode.dump(); diff --git a/frameworks/jskitsimpl/distributeddata/src/js_kv_manager.cpp b/frameworks/jskitsimpl/distributeddata/src/js_kv_manager.cpp index 5073d5c1b7cb918719c809e1a1d2ee7e87908ed9..75964896209cad8ef30ebdbee72dfdff682ed265 100644 --- a/frameworks/jskitsimpl/distributeddata/src/js_kv_manager.cpp +++ b/frameworks/jskitsimpl/distributeddata/src/js_kv_manager.cpp @@ -60,13 +60,13 @@ napi_value JsKVManager::CreateKVManager(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); std::string bundleName; ctxt->status = JSUtil::GetNamedProperty(env, argv[0], "bundleName", bundleName); - CHECK_ARGS(ctxt, (ctxt->status == napi_ok) && !bundleName.empty(), "invalid bundleName!"); + CHECK_ARGS_RETURN_VOID(ctxt, (ctxt->status == napi_ok) && !bundleName.empty(), "invalid bundleName!"); ctxt->ref = JSUtil::NewWithRef(env, argc, argv, (void**)&ctxt->kvManger, JsKVManager::Constructor(env)); - CHECK_ARGS(ctxt, ctxt->kvManger != nullptr, "KVManager::New failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, ctxt->kvManger != nullptr, "KVManager::New failed!"); }; ctxt->GetCbInfo(env, info, input); @@ -74,7 +74,7 @@ napi_value JsKVManager::CreateKVManager(napi_env env, napi_callback_info info) auto output = [env, ctxt](napi_value& result) { ctxt->status = napi_get_reference_value(env, ctxt->ref, &result); napi_delete_reference(env, ctxt->ref); - CHECK_STATUS(ctxt, "output KVManager failed"); + CHECK_STATUS_RETURN_VOID(ctxt, "output KVManager failed"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), noExecute, output); } @@ -89,12 +89,12 @@ struct GetKVStoreContext : public ContextBase { { auto input = [env, this](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(this, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(this, argc == 2, "invalid arguments!"); status = JSUtil::GetValue(env, argv[0], storeId); - CHECK_ARGS(this, (status == napi_ok) && !storeId.empty(), "invalid storeId!"); + CHECK_ARGS_RETURN_VOID(this, (status == napi_ok) && !storeId.empty(), "invalid storeId!"); status = JSUtil::GetValue(env, argv[1], options); - CHECK_STATUS(this, "invalid options!"); - CHECK_ARGS(this, IsStoreTypeSupported(options), "invalid options.KvStoreType"); + CHECK_STATUS_RETURN_VOID(this, "invalid options!"); + CHECK_ARGS_RETURN_VOID(this, IsStoreTypeSupported(options), "invalid options.KvStoreType"); ZLOGD("GetKVStore kvStoreType=%{public}d", options.kvStoreType); if (options.kvStoreType == KvStoreType::DEVICE_COLLABORATION) { ref = JSUtil::NewWithRef(env, argc, argv, (void**)&kvStore, JsDeviceKVStore::Constructor(env)); @@ -121,20 +121,20 @@ napi_value JsKVManager::GetKVStore(napi_env env, napi_callback_info info) auto execute = [ctxt]() { auto kvm = reinterpret_cast(ctxt->native); - CHECK_ARGS(ctxt, kvm != nullptr, "KVManager is null, failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, kvm != nullptr, "KVManager is null, failed!"); AppId appId = { kvm->bundleName_ }; StoreId storeId = { ctxt->storeId }; std::shared_ptr kvStore; Status status = kvm->kvDataManager_.GetSingleKvStore(ctxt->options, appId, storeId, kvStore); ZLOGD("GetSingleKvStore return status:%{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "KVManager->GetSingleKvStore() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "KVManager->GetSingleKvStore() failed!"); ctxt->kvStore->SetNative(kvStore); }; auto output = [env, ctxt](napi_value& result) { ctxt->status = napi_get_reference_value(env, ctxt->ref, &result); napi_delete_reference(env, ctxt->ref); - CHECK_STATUS(ctxt, "output KvStore failed"); + CHECK_STATUS_RETURN_VOID(ctxt, "output KvStore failed"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output); } @@ -155,15 +155,15 @@ napi_value JsKVManager::CloseKVStore(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 3 arguments :: - CHECK_ARGS(ctxt, argc == 3, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 3, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->appId); - CHECK_ARGS(ctxt, (ctxt->status == napi_ok) && !ctxt->appId.empty(), "invalid appId!"); + CHECK_ARGS_RETURN_VOID(ctxt, (ctxt->status == napi_ok) && !ctxt->appId.empty(), "invalid appId!"); ctxt->status = JSUtil::GetValue(env, argv[1], ctxt->storeId); - CHECK_ARGS(ctxt, (ctxt->status == napi_ok) && !ctxt->storeId.empty(), "invalid storeId!"); - CHECK_ARGS(ctxt, argv[2] != nullptr, "kvStore is nullptr!"); + CHECK_ARGS_RETURN_VOID(ctxt, (ctxt->status == napi_ok) && !ctxt->storeId.empty(), "invalid storeId!"); + CHECK_ARGS_RETURN_VOID(ctxt, argv[2] != nullptr, "kvStore is nullptr!"); bool isSingle = JsKVStore::IsInstanceOf(env, argv[2], ctxt->storeId, JsSingleKVStore::Constructor(env)); bool isDevice = JsKVStore::IsInstanceOf(env, argv[2], ctxt->storeId, JsDeviceKVStore::Constructor(env)); - CHECK_ARGS(ctxt, isSingle || isDevice, "kvStore unmatch to storeId!"); + CHECK_ARGS_RETURN_VOID(ctxt, isSingle || isDevice, "kvStore unmatch to storeId!"); }; ctxt->GetCbInfo(env, info, input); @@ -195,12 +195,12 @@ napi_value JsKVManager::DeleteKVStore(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc >= 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc >= 2, "invalid arguments!"); size_t index = 0; ctxt->status = JSUtil::GetValue(env, argv[index++], ctxt->appId); - CHECK_ARGS(ctxt, !ctxt->appId.empty(), "invalid appId"); + CHECK_ARGS_RETURN_VOID(ctxt, !ctxt->appId.empty(), "invalid appId"); ctxt->status = JSUtil::GetValue(env, argv[index++], ctxt->storeId); - CHECK_ARGS(ctxt, !ctxt->storeId.empty(), "invalid storeId"); + CHECK_ARGS_RETURN_VOID(ctxt, !ctxt->storeId.empty(), "invalid storeId"); }; ctxt->GetCbInfo(env, info, input); @@ -230,15 +230,15 @@ napi_value JsKVManager::GetAllKVStoreId(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->appId); - CHECK_ARGS(ctxt, !ctxt->appId.empty(), "invalid appId!"); + CHECK_ARGS_RETURN_VOID(ctxt, !ctxt->appId.empty(), "invalid appId!"); }; ctxt->GetCbInfo(env, info, input); auto execute = [ctxt]() { auto kvm = reinterpret_cast(ctxt->native); - CHECK_ARGS(ctxt, kvm != nullptr, "KVManager is null, failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, kvm != nullptr, "KVManager is null, failed!"); AppId appId { ctxt->appId }; Status status = kvm->kvDataManager_.GetAllKvStoreId(appId, ctxt->storeIdList); ZLOGD("execute status:%{public}d", status); @@ -256,19 +256,19 @@ napi_value JsKVManager::On(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments!"); std::string event; ctxt->status = JSUtil::GetValue(env, argv[0], event); ZLOGI("subscribe to event:%{public}s", event.c_str()); - CHECK_ARGS(ctxt, event == "distributedDataServiceDie", "invalid arg[0], i.e. invalid event!"); + CHECK_ARGS_RETURN_VOID(ctxt, event == "distributedDataServiceDie", "invalid arg[0], i.e. invalid event!"); napi_valuetype valueType = napi_undefined; ctxt->status = napi_typeof(env, argv[1], &valueType); - CHECK_STATUS(ctxt, "napi_typeof failed!"); - CHECK_ARGS(ctxt, valueType == napi_function, "callback is not a function"); + CHECK_STATUS_RETURN_VOID(ctxt, "napi_typeof failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, valueType == napi_function, "callback is not a function"); JsKVManager* proxy = reinterpret_cast(ctxt->native); - CHECK_ARGS(ctxt, proxy != nullptr, "there is no native kv manager"); + CHECK_ARGS_RETURN_VOID(ctxt, proxy != nullptr, "there is no native kv manager"); std::lock_guard lck(proxy->deathMutex_); for (auto& it : proxy->deathRecipient_) { @@ -294,18 +294,18 @@ napi_value JsKVManager::Off(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 or 2 arguments :: [callback] - CHECK_ARGS(ctxt, (argc == 1) || (argc == 2), "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, (argc == 1) || (argc == 2), "invalid arguments!"); std::string event; ctxt->status = JSUtil::GetValue(env, argv[0], event); // required 1 arguments :: ZLOGI("unsubscribe to event:%{public}s %{public}s specified", event.c_str(), (argc == 1) ? "without": "with"); - CHECK_ARGS(ctxt, event == "distributedDataServiceDie", "invalid arg[0], i.e. invalid event!"); + CHECK_ARGS_RETURN_VOID(ctxt, event == "distributedDataServiceDie", "invalid arg[0], i.e. invalid event!"); // have 2 arguments :: have the [callback] if (argc == 2) { napi_valuetype valueType = napi_undefined; ctxt->status = napi_typeof(env, argv[1], &valueType); - CHECK_STATUS(ctxt, "napi_typeof failed!"); - CHECK_ARGS(ctxt, valueType == napi_function, "callback is not a function"); + CHECK_STATUS_RETURN_VOID(ctxt, "napi_typeof failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, valueType == napi_function, "callback is not a function"); } JsKVManager* proxy = reinterpret_cast(ctxt->native); std::lock_guard lck(proxy->deathMutex_); @@ -348,10 +348,10 @@ napi_value JsKVManager::New(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt, &bundleName](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetNamedProperty(env, argv[0], "bundleName", bundleName); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid bundleName!"); - CHECK_ARGS(ctxt, !bundleName.empty(), "invalid arg[0], i.e. invalid bundleName!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid bundleName!"); + CHECK_ARGS_RETURN_VOID(ctxt, !bundleName.empty(), "invalid arg[0], i.e. invalid bundleName!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); diff --git a/frameworks/jskitsimpl/distributeddata/src/js_kv_store.cpp b/frameworks/jskitsimpl/distributeddata/src/js_kv_store.cpp index d5b4885ceea86fab0920536f69f2efda2f7265aa..3cee8d1fc15fe685c4dd7aa9c004232e579b5fa1 100644 --- a/frameworks/jskitsimpl/distributeddata/src/js_kv_store.cpp +++ b/frameworks/jskitsimpl/distributeddata/src/js_kv_store.cpp @@ -111,12 +111,12 @@ napi_value JsKVStore::Put(napi_env env, napi_callback_info info) ctxt->GetCbInfo(env, info, [env, ctxt](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->key); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid key!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid key!"); JSUtil::KvStoreVariant vv; ctxt->status = JSUtil::GetValue(env, argv[1], vv); - CHECK_STATUS(ctxt, "invalid arg[1], i.e. invalid value!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[1], i.e. invalid value!"); DistributedKv::Blob blob = JSUtil::VariantValue2Blob(vv); ctxt->value = blob.Data(); }); @@ -128,7 +128,7 @@ napi_value JsKVStore::Put(napi_env env, napi_callback_info info) Status status = kvStore->Put(key, value); ZLOGD("kvStore->Put return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->Put() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->Put() failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -150,9 +150,9 @@ napi_value JsKVStore::Delete(napi_env env, napi_callback_info info) ctxt->GetCbInfo(env, info, [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->key); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid key!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid key!"); }); return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), [ctxt]() { @@ -161,7 +161,7 @@ napi_value JsKVStore::Delete(napi_env env, napi_callback_info info) Status status = kvStore->Delete(key); ZLOGD("kvStore->Put return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->Delete() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->Delete() failed!"); }); } @@ -177,12 +177,12 @@ napi_value JsKVStore::OnEvent(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 2 arguments :: [...] - CHECK_ARGS(ctxt, argc >= 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc >= 2, "invalid arguments!"); std::string event; ctxt->status = JSUtil::GetValue(env, argv[0], event); ZLOGI("subscribe to event:%{public}s", event.c_str()); auto handle = onEventHandlers_.find(event); - CHECK_ARGS(ctxt, handle != onEventHandlers_.end(), "invalid arg[0], i.e. unsupported event"); + CHECK_ARGS_RETURN_VOID(ctxt, handle != onEventHandlers_.end(), "invalid arg[0], i.e. unsupported event"); // shift 1 argument, for JsKVStore::Exec. handle->second(env, argc - 1, &argv[1], ctxt); }; @@ -203,12 +203,12 @@ napi_value JsKVStore::OffEvent(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: [callback] - CHECK_ARGS(ctxt, argc >= 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc >= 1, "invalid arguments!"); std::string event; ctxt->status = JSUtil::GetValue(env, argv[0], event); ZLOGI("unsubscribe to event:%{public}s", event.c_str()); auto handle = offEventHandlers_.find(event); - CHECK_ARGS(ctxt, handle != offEventHandlers_.end(), "invalid arg[0], i.e. unsupported event"); + CHECK_ARGS_RETURN_VOID(ctxt, handle != offEventHandlers_.end(), "invalid arg[0], i.e. unsupported event"); // shift 1 argument, for JsKVStore::Exec. handle->second(env, argc - 1, &argv[1], ctxt); }; @@ -233,9 +233,9 @@ napi_value JsKVStore::PutBatch(napi_env env, napi_callback_info info) ctxt->GetCbInfo(env, info, [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->entries); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid entries!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid entries!"); }); auto execute = [ctxt]() { @@ -243,7 +243,7 @@ napi_value JsKVStore::PutBatch(napi_env env, napi_callback_info info) Status status = kvStore->PutBatch(ctxt->entries); ZLOGD("kvStore->DeleteBatch return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->PutBatch() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->PutBatch() failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -263,9 +263,9 @@ napi_value JsKVStore::DeleteBatch(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); JSUtil::GetValue(env, argv[0], ctxt->keys); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid keys!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid keys!"); }; ctxt->GetCbInfo(env, info, input); @@ -279,7 +279,7 @@ napi_value JsKVStore::DeleteBatch(napi_env env, napi_callback_info info) Status status = kvStore->DeleteBatch(keys); ZLOGD("kvStore->DeleteBatch return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->DeleteBatch failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->DeleteBatch failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -301,7 +301,7 @@ napi_value JsKVStore::StartTransaction(napi_env env, napi_callback_info info) Status status = kvStore->StartTransaction(); ZLOGD("kvStore->StartTransaction return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->StartTransaction() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->StartTransaction() failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -323,7 +323,7 @@ napi_value JsKVStore::Commit(napi_env env, napi_callback_info info) Status status = kvStore->Commit(); ZLOGD("kvStore->Commit return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->Commit() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->Commit() failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -345,7 +345,7 @@ napi_value JsKVStore::Rollback(napi_env env, napi_callback_info info) Status status = kvStore->Rollback(); ZLOGD("kvStore->Commit return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->Rollback() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->Rollback() failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -365,9 +365,9 @@ napi_value JsKVStore::EnableSync(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = napi_get_value_bool(env, argv[0], &ctxt->enable); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid enabled!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid enabled!"); }; ctxt->GetCbInfo(env, info, input); @@ -376,7 +376,7 @@ napi_value JsKVStore::EnableSync(napi_env env, napi_callback_info info) Status status = kvStore->SetCapabilityEnabled(ctxt->enable); ZLOGD("kvStore->SetCapabilityEnabled return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->SetCapabilityEnabled() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->SetCapabilityEnabled() failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -397,11 +397,11 @@ napi_value JsKVStore::SetSyncRange(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->localLabels); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid localLabels!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid localLabels!"); ctxt->status = JSUtil::GetValue(env, argv[1], ctxt->remoteSupportLabels); - CHECK_STATUS(ctxt, "invalid arg[1], i.e. invalid remoteSupportLabels!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[1], i.e. invalid remoteSupportLabels!"); }; ctxt->GetCbInfo(env, info, input); @@ -410,7 +410,7 @@ napi_value JsKVStore::SetSyncRange(napi_env env, napi_callback_info info) Status status = kvStore->SetCapabilityRange(ctxt->localLabels, ctxt->remoteSupportLabels); ZLOGD("kvStore->SetCapabilityRange return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->SetCapabilityRange() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->SetCapabilityRange() failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -423,17 +423,17 @@ napi_value JsKVStore::SetSyncRange(napi_env env, napi_callback_info info) void JsKVStore::OnDataChange(napi_env env, size_t argc, napi_value* argv, std::shared_ptr ctxt) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc == 2, "invalid arguments on dataChange!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments on dataChange!"); int32_t type = SUBSCRIBE_COUNT; ctxt->status = napi_get_value_int32(env, argv[0], &type); - CHECK_STATUS(ctxt, "napi_get_value_int32 failed!"); - CHECK_ARGS(ctxt, ValidSubscribeType(type), "invalid arg[1], i.e. invalid subscribeType"); + CHECK_STATUS_RETURN_VOID(ctxt, "napi_get_value_int32 failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, ValidSubscribeType(type), "invalid arg[1], i.e. invalid subscribeType"); napi_valuetype valueType = napi_undefined; ctxt->status = napi_typeof(env, argv[1], &valueType); - CHECK_STATUS(ctxt, "napi_typeof failed!"); - CHECK_ARGS(ctxt, valueType == napi_function, "invalid arg[2], i.e. invalid callback"); + CHECK_STATUS_RETURN_VOID(ctxt, "napi_typeof failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, valueType == napi_function, "invalid arg[2], i.e. invalid callback"); ZLOGI("subscribe data change type %{public}d", type); auto proxy = reinterpret_cast(ctxt->native); @@ -448,7 +448,7 @@ void JsKVStore::OnDataChange(napi_env env, size_t argc, napi_value* argv, std::s std::shared_ptr observer = std::make_shared(env, argv[1]); ctxt->status = proxy->Subscribe(type, observer); - CHECK_STATUS(ctxt, "Subscribe failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "Subscribe failed!"); } /* @@ -461,13 +461,13 @@ void JsKVStore::OnDataChange(napi_env env, size_t argc, napi_value* argv, std::s void JsKVStore::OffDataChange(napi_env env, size_t argc, napi_value* argv, std::shared_ptr ctxt) { // required 1 arguments :: [callback] - CHECK_ARGS(ctxt, argc <= 1, "invalid arguments off dataChange!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc <= 1, "invalid arguments off dataChange!"); // have 1 arguments :: have the callback if (argc == 1) { napi_valuetype valueType = napi_undefined; ctxt->status = napi_typeof(env, argv[0], &valueType); - CHECK_STATUS(ctxt, "napi_typeof failed!"); - CHECK_ARGS(ctxt, valueType == napi_function, "invalid arg[1], i.e. invalid callback"); + CHECK_STATUS_RETURN_VOID(ctxt, "napi_typeof failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, valueType == napi_function, "invalid arg[1], i.e. invalid callback"); } ZLOGI("unsubscribe dataChange, %{public}s specified observer.", (argc == 0) ? "without": "with"); @@ -499,7 +499,7 @@ void JsKVStore::OffDataChange(napi_env env, size_t argc, napi_value* argv, std:: } } found = (argc == 0) || found; // no specified observer, don't care about found or not. - CHECK_ARGS(ctxt, found, "not Subscribed!"); + CHECK_ARGS_RETURN_VOID(ctxt, found, "not Subscribed!"); } /* @@ -510,16 +510,16 @@ void JsKVStore::OffDataChange(napi_env env, size_t argc, napi_value* argv, std:: void JsKVStore::OnSyncComplete(napi_env env, size_t argc, napi_value* argv, std::shared_ptr ctxt) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments on syncComplete!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments on syncComplete!"); napi_valuetype valueType = napi_undefined; ctxt->status = napi_typeof(env, argv[0], &valueType); - CHECK_STATUS(ctxt, "napi_typeof failed!"); - CHECK_ARGS(ctxt, valueType == napi_function, "invalid arg[1], i.e. invalid callback"); + CHECK_STATUS_RETURN_VOID(ctxt, "napi_typeof failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, valueType == napi_function, "invalid arg[1], i.e. invalid callback"); std::shared_ptr callback = std::make_shared(env, argv[0]); auto proxy = reinterpret_cast(ctxt->native); ctxt->status = proxy->RegisterSyncCallback(callback); - CHECK_STATUS(ctxt, "RegisterSyncCallback failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "RegisterSyncCallback failed!"); } /* @@ -530,21 +530,21 @@ void JsKVStore::OnSyncComplete(napi_env env, size_t argc, napi_value* argv, std: void JsKVStore::OffSyncComplete(napi_env env, size_t argc, napi_value* argv, std::shared_ptr ctxt) { // required 1 arguments :: [callback] - CHECK_ARGS(ctxt, argc <= 1, "invalid arguments off syncComplete!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc <= 1, "invalid arguments off syncComplete!"); auto proxy = reinterpret_cast(ctxt->native); // have 1 arguments :: have the callback if (argc == 1) { napi_valuetype valueType = napi_undefined; ctxt->status = napi_typeof(env, argv[0], &valueType); - CHECK_STATUS(ctxt, "napi_typeof failed!"); - CHECK_ARGS(ctxt, valueType == napi_function, "invalid arg[1], i.e. invalid callback"); + CHECK_STATUS_RETURN_VOID(ctxt, "napi_typeof failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, valueType == napi_function, "invalid arg[1], i.e. invalid callback"); auto observer = std::static_pointer_cast(proxy->syncObserver_); - CHECK_ARGS(ctxt, *observer == argv[0], "invalid arg[1], not Subscribed"); + CHECK_ARGS_RETURN_VOID(ctxt, *observer == argv[0], "invalid arg[1], not Subscribed"); } ZLOGI("unsubscribe syncComplete, %{public}s specified observer.", (argc == 0) ? "without": "with"); ctxt->status = proxy->UnRegisterSyncCallback(); - CHECK_STATUS(ctxt, "UnRegisterSyncCallback failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "UnRegisterSyncCallback failed!"); } /* diff --git a/frameworks/jskitsimpl/distributeddata/src/js_kv_store_resultset.cpp b/frameworks/jskitsimpl/distributeddata/src/js_kv_store_resultset.cpp index c3c5e76ce064394615a91028b4f95123398c512e..4605d44c74ff711455705107e650588f2a9f53a5 100644 --- a/frameworks/jskitsimpl/distributeddata/src/js_kv_store_resultset.cpp +++ b/frameworks/jskitsimpl/distributeddata/src/js_kv_store_resultset.cpp @@ -164,7 +164,7 @@ napi_value JsKVStoreResultSet::Move(napi_env env, napi_callback_info info) /* bo auto ctxt = std::make_shared(); auto input = [env, ctxt, &offset](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = napi_get_value_int32(env, argv[0], (int32_t*)&offset); }; ctxt->GetCbInfoSync(env, info, input); @@ -183,7 +183,7 @@ napi_value JsKVStoreResultSet::MoveToPosition(napi_env env, napi_callback_info i auto ctxt = std::make_shared(); auto input = [env, ctxt, &position](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = napi_get_value_int32(env, argv[0], (int32_t*)&position); }; ctxt->GetCbInfoSync(env, info, input); diff --git a/frameworks/jskitsimpl/distributeddata/src/js_query.cpp b/frameworks/jskitsimpl/distributeddata/src/js_query.cpp index 5791a96593d55bf180e682aa08ad86a02e5d2347..7f59047edac5293c1857f4d410ca055ec01bbb14 100644 --- a/frameworks/jskitsimpl/distributeddata/src/js_query.cpp +++ b/frameworks/jskitsimpl/distributeddata/src/js_query.cpp @@ -104,11 +104,11 @@ struct ValueContext : public ContextBase { { auto input = [this, env](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(this, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(this, argc == 2, "invalid arguments!"); status = JSUtil::GetValue(env, argv[0], field); - CHECK_STATUS(this, "invalid arg[0], i.e. invalid field!"); + CHECK_STATUS_RETURN_VOID(this, "invalid arg[0], i.e. invalid field!"); status = JSUtil::GetValue(env, argv[1], vv); - CHECK_STATUS(this, "invalid arg[1], i.e. invalid value!"); + CHECK_STATUS_RETURN_VOID(this, "invalid arg[1], i.e. invalid value!"); }; GetCbInfoSync(env, info, input); } @@ -271,9 +271,9 @@ napi_value JsQuery::IsNull(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt, &field](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], field); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid field!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid field!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -305,9 +305,9 @@ struct NumbersContext : public ContextBase { { auto input = [this, env](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(this, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(this, argc == 2, "invalid arguments!"); status = JSUtil::GetValue(env, argv[0], field); - CHECK_STATUS(this, "invalid arg[0], i.e. invalid field!"); + CHECK_STATUS_RETURN_VOID(this, "invalid arg[0], i.e. invalid field!"); bool isTypedArray = false; status = napi_is_typedarray(env, argv[1], &isTypedArray); @@ -319,7 +319,7 @@ struct NumbersContext : public ContextBase { size_t offset = 0; void* data = nullptr; status = napi_get_typedarray_info(env, argv[1], &type, &length, &data, &buffer, &offset); - CHECK_STATUS(this, "invalid arg[1], i.e. invalid number array!"); + CHECK_STATUS_RETURN_VOID(this, "invalid arg[1], i.e. invalid number array!"); if (type < napi_uint32_array) { status = JSUtil::GetValue(env, argv[1], intList); innerType = NumberType::NUMBER_INT; @@ -333,10 +333,10 @@ struct NumbersContext : public ContextBase { } else { bool isArray = false; status = napi_is_array(env, argv[1], &isArray); - CHECK_ARGS(this, isArray, "invalid arg[1], i.e. invalid number array!"); + CHECK_ARGS_RETURN_VOID(this, isArray, "invalid arg[1], i.e. invalid number array!"); ZLOGD("arg[1] %{public}s a Array, treat as array of double.", isTypedArray ? "is" : "is not"); status = JSUtil::GetValue(env, argv[1], doubleList); - CHECK_STATUS(this, "invalid arg[1], i.e. invalid number array!"); + CHECK_STATUS_RETURN_VOID(this, "invalid arg[1], i.e. invalid number array!"); innerType = NumberType::NUMBER_DOUBLE; }; }; @@ -370,11 +370,11 @@ napi_value JsQuery::InString(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->field); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid field!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid field!"); ctxt->status = JSUtil::GetValue(env, argv[1], ctxt->valueList); - CHECK_STATUS(ctxt, "invalid arg[1], i.e. invalid valueList!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[1], i.e. invalid valueList!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -411,11 +411,11 @@ napi_value JsQuery::NotInString(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->field); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid field!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid field!"); ctxt->status = JSUtil::GetValue(env, argv[1], ctxt->valueList); - CHECK_STATUS(ctxt, "invalid arg[1], i.e. invalid valueList!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[1], i.e. invalid valueList!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -435,11 +435,11 @@ napi_value JsQuery::Like(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->field); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid field!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid field!"); ctxt->status = JSUtil::GetValue(env, argv[1], ctxt->value); - CHECK_STATUS(ctxt, "invalid arg[1], i.e. invalid value!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[1], i.e. invalid value!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -459,11 +459,11 @@ napi_value JsQuery::Unlike(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->field); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid field!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid field!"); ctxt->status = JSUtil::GetValue(env, argv[1], ctxt->value); - CHECK_STATUS(ctxt, "invalid arg[1], i.e. invalid value!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[1], i.e. invalid value!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -504,9 +504,9 @@ napi_value JsQuery::OrderByAsc(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt, &field](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], field); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid field!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid field!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -523,9 +523,9 @@ napi_value JsQuery::OrderByDesc(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt, &field](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], field); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid field!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid field!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -544,11 +544,11 @@ napi_value JsQuery::Limit(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments!"); ctxt->status = napi_get_value_int32(env, argv[0], &ctxt->number); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid number!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid number!"); ctxt->status = napi_get_value_int32(env, argv[1], &ctxt->offset); - CHECK_STATUS(ctxt, "invalid arg[1], i.e. invalid offset!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[1], i.e. invalid offset!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -564,9 +564,9 @@ napi_value JsQuery::IsNotNull(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt, &field](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], field); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid field!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid field!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -605,9 +605,9 @@ napi_value JsQuery::PrefixKey(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt, &prefix](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], prefix); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid prefix!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid prefix!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -623,9 +623,9 @@ napi_value JsQuery::SetSuggestIndex(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt, &suggestIndex](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], suggestIndex); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid suggestIndex!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid suggestIndex!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -641,9 +641,9 @@ napi_value JsQuery::DeviceId(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt, &deviceId](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], deviceId); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid deviceId!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid deviceId!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); diff --git a/frameworks/jskitsimpl/distributeddata/src/js_schema.cpp b/frameworks/jskitsimpl/distributeddata/src/js_schema.cpp index 1aaeef14361c616c41109e38901dc7c2e0201b1b..5a457bb065273113e29029408e853284d7e4a27d 100644 --- a/frameworks/jskitsimpl/distributeddata/src/js_schema.cpp +++ b/frameworks/jskitsimpl/distributeddata/src/js_schema.cpp @@ -85,14 +85,25 @@ napi_status JsSchema::ToJson(napi_env env, napi_value inner, JsSchema*& out) return JSUtil::Unwrap(env, inner, (void**)(&out), JsSchema::Constructor(env)); } -napi_value JsSchema::GetRootNode(napi_env env, napi_callback_info info) +JsSchema* JsSchema::GetSchema(napi_env env, napi_callback_info info, std::shared_ptr& ctxt) { - ZLOGD("Schema::GetRootNode"); - auto ctxt = std::make_shared(); ctxt->GetCbInfoSync(env, info); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); + return reinterpret_cast(ctxt->native); +} - auto schema = reinterpret_cast(ctxt->native); +template +napi_value JsSchema::GetContextValue(napi_env env, std::shared_ptr& ctxt, T& value) +{ + JSUtil::SetValue(env, value, ctxt->output); + return ctxt->output; +} + +napi_value JsSchema::GetRootNode(napi_env env, napi_callback_info info) +{ + ZLOGD("Schema::GetRootNode"); + auto ctxt = std::make_shared(); + auto schema = GetSchema(env, info, ctxt); if (schema->rootNode == nullptr) { int argc = 1; napi_value argv[1] = { nullptr }; @@ -112,18 +123,18 @@ napi_value JsSchema::SetRootNode(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); JsFieldNode* node = nullptr; ctxt->status = JSUtil::Unwrap(env, argv[0], (void**)(&node), JsFieldNode::Constructor(env)); - CHECK_STATUS(ctxt, "napi_unwrap to FieldNode failed"); - CHECK_ARGS(ctxt, node != nullptr, "invalid arg[0], i.e. invalid node!"); + CHECK_STATUS_RETURN_VOID(ctxt, "napi_unwrap to FieldNode failed"); + CHECK_ARGS_RETURN_VOID(ctxt, node != nullptr, "invalid arg[0], i.e. invalid node!"); auto schema = reinterpret_cast(ctxt->native); if (schema->ref != nullptr) { napi_delete_reference(env, schema->ref); } ctxt->status = napi_create_reference(env, argv[0], 1, &schema->ref); - CHECK_STATUS(ctxt, "napi_create_reference to FieldNode failed"); + CHECK_STATUS_RETURN_VOID(ctxt, "napi_create_reference to FieldNode failed"); schema->rootNode = node; }; ctxt->GetCbInfoSync(env, info, input); @@ -133,13 +144,10 @@ napi_value JsSchema::SetRootNode(napi_env env, napi_callback_info info) napi_value JsSchema::GetMode(napi_env env, napi_callback_info info) { + ZLOGD("Schema::GetMode"); auto ctxt = std::make_shared(); - ctxt->GetCbInfoSync(env, info); - NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); - - auto schema = reinterpret_cast(ctxt->native); - JSUtil::SetValue(env, schema->mode, ctxt->output); - return ctxt->output; + auto schema = GetSchema(env, info, ctxt); + return GetContextValue(env, ctxt, schema->mode); } napi_value JsSchema::SetMode(napi_env env, napi_callback_info info) @@ -148,9 +156,9 @@ napi_value JsSchema::SetMode(napi_env env, napi_callback_info info) uint32_t mode = false; auto input = [env, ctxt, &mode](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], mode); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid mode!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid mode!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -162,13 +170,10 @@ napi_value JsSchema::SetMode(napi_env env, napi_callback_info info) napi_value JsSchema::GetSkip(napi_env env, napi_callback_info info) { + ZLOGD("Schema::GetSkip"); auto ctxt = std::make_shared(); - ctxt->GetCbInfoSync(env, info); - NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); - - auto schema = reinterpret_cast(ctxt->native); - JSUtil::SetValue(env, schema->skip, ctxt->output); - return ctxt->output; + auto schema = GetSchema(env, info, ctxt); + return GetContextValue(env, ctxt, schema->skip); } napi_value JsSchema::SetSkip(napi_env env, napi_callback_info info) @@ -177,9 +182,9 @@ napi_value JsSchema::SetSkip(napi_env env, napi_callback_info info) uint32_t skip = false; auto input = [env, ctxt, &skip](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], skip); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid skip size!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid skip size!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); @@ -191,13 +196,10 @@ napi_value JsSchema::SetSkip(napi_env env, napi_callback_info info) napi_value JsSchema::GetIndexes(napi_env env, napi_callback_info info) { + ZLOGD("Schema::GetIndexes"); auto ctxt = std::make_shared(); - ctxt->GetCbInfoSync(env, info); - NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); - - auto schema = reinterpret_cast(ctxt->native); - JSUtil::SetValue(env, schema->indexes, ctxt->output); - return ctxt->output; + auto schema = GetSchema(env, info, ctxt); + return GetContextValue(env, ctxt, schema->indexes); } napi_value JsSchema::SetIndexes(napi_env env, napi_callback_info info) @@ -206,9 +208,9 @@ napi_value JsSchema::SetIndexes(napi_env env, napi_callback_info info) std::vector indexes; auto input = [env, ctxt, &indexes](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], indexes); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid indexes!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid indexes!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); diff --git a/frameworks/jskitsimpl/distributeddata/src/js_single_kv_store.cpp b/frameworks/jskitsimpl/distributeddata/src/js_single_kv_store.cpp index 71f2fc1f3a0ef0fd6b45e70a6c99f5223828589f..1444f488b5975671b6cf2cb6a8bed187f499c467 100644 --- a/frameworks/jskitsimpl/distributeddata/src/js_single_kv_store.cpp +++ b/frameworks/jskitsimpl/distributeddata/src/js_single_kv_store.cpp @@ -75,10 +75,10 @@ napi_value JsSingleKVStore::Get(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->key); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid key!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid key!"); }; ctxt->GetCbInfo(env, info, input); ZLOGD("key=%{public}.8s", ctxt->key.c_str()); @@ -91,11 +91,11 @@ napi_value JsSingleKVStore::Get(napi_env env, napi_callback_info info) ZLOGD("kvStore->Get return %{public}d", status); ctxt->value = JSUtil::Blob2VariantValue(value); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->Get() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->Get() failed!"); }; auto output = [env, ctxt](napi_value& result) { ctxt->status = JSUtil::SetValue(env, ctxt->value, result); - CHECK_STATUS(ctxt, "output failed"); + CHECK_STATUS_RETURN_VOID(ctxt, "output failed"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output); } @@ -150,9 +150,9 @@ napi_value JsSingleKVStore::GetEntries(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = GetVariantArgs(env, argc, argv, ctxt->va); - CHECK_STATUS(ctxt, "invalid arguments!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arguments!"); }; ctxt->GetCbInfo(env, info, input); @@ -169,11 +169,11 @@ napi_value JsSingleKVStore::GetEntries(napi_env env, napi_callback_info info) ZLOGD("kvStore->GetEntriesWithQuery() return %{public}d", status); } ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->GetEntries() failed"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->GetEntries() failed"); }; auto output = [env, ctxt](napi_value& result) { ctxt->status = JSUtil::SetValue(env, ctxt->entries, result); - CHECK_STATUS(ctxt, "output failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "output failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output); } @@ -197,13 +197,13 @@ napi_value JsSingleKVStore::GetResultSet(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = GetVariantArgs(env, argc, argv, ctxt->va); - CHECK_STATUS(ctxt, "invalid arguments!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arguments!"); ctxt->ref = JSUtil::NewWithRef(env, 0, nullptr, (void**)(&ctxt->resultSet), JsKVStoreResultSet::Constructor(env)); - CHECK_ARGS(ctxt, ctxt->resultSet != nullptr, "KVStoreResultSet::New failed!"); - CHECK_ARGS(ctxt, ctxt->ref != nullptr, "KVStoreResultSet::New failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, ctxt->resultSet != nullptr, "KVStoreResultSet::New failed!"); + CHECK_ARGS_RETURN_VOID(ctxt, ctxt->ref != nullptr, "KVStoreResultSet::New failed!"); }; ctxt->GetCbInfo(env, info, input); @@ -221,13 +221,13 @@ napi_value JsSingleKVStore::GetResultSet(napi_env env, napi_callback_info info) ZLOGD("kvStore->GetEntriesWithQuery() return %{public}d", status); } ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->GetResultSet() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->GetResultSet() failed!"); ctxt->resultSet->SetNative(kvResultSet); }; auto output = [env, ctxt](napi_value& result) { ctxt->status = napi_get_reference_value(env, ctxt->ref, &result); napi_delete_reference(env, ctxt->ref); - CHECK_STATUS(ctxt, "output kvResultSet failed"); + CHECK_STATUS_RETURN_VOID(ctxt, "output kvResultSet failed"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output); } @@ -246,13 +246,13 @@ napi_value JsSingleKVStore::CloseResultSet(napi_env env, napi_callback_info info auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); napi_valuetype type = napi_undefined; ctxt->status = napi_typeof(env, argv[0], &type); - CHECK_ARGS(ctxt, type == napi_object, "invalid arg[0], i.e. invalid resultSet!"); + CHECK_ARGS_RETURN_VOID(ctxt, type == napi_object, "invalid arg[0], i.e. invalid resultSet!"); ctxt->status = JSUtil::Unwrap(env, argv[0], (void**)(&ctxt->resultSet), JsKVStoreResultSet::Constructor(env)); - CHECK_ARGS(ctxt, ctxt->resultSet != nullptr, "invalid arg[0], i.e. invalid resultSet!"); + CHECK_ARGS_RETURN_VOID(ctxt, ctxt->resultSet != nullptr, "invalid arg[0], i.e. invalid resultSet!"); }; ctxt->GetCbInfo(env, info, input); @@ -261,7 +261,7 @@ napi_value JsSingleKVStore::CloseResultSet(napi_env env, napi_callback_info info Status status = kvStore->CloseResultSet(ctxt->resultSet->GetNative()); ZLOGD("kvStore->CloseResultSet return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->CloseResultSet failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->CloseResultSet failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -280,12 +280,12 @@ napi_value JsSingleKVStore::GetResultSize(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); napi_valuetype type = napi_undefined; ctxt->status = napi_typeof(env, argv[0], &type); - CHECK_ARGS(ctxt, type == napi_object, "invalid arg[0], i.e. invalid query!"); + CHECK_ARGS_RETURN_VOID(ctxt, type == napi_object, "invalid arg[0], i.e. invalid query!"); ctxt->status = JSUtil::Unwrap(env, argv[0], (void**)(&ctxt->query), JsQuery::Constructor(env)); - CHECK_ARGS(ctxt, ctxt->query != nullptr, "invalid arg[0], i.e. invalid query!"); + CHECK_ARGS_RETURN_VOID(ctxt, ctxt->query != nullptr, "invalid arg[0], i.e. invalid query!"); }; ctxt->GetCbInfo(env, info, input); @@ -295,11 +295,11 @@ napi_value JsSingleKVStore::GetResultSize(napi_env env, napi_callback_info info) Status status = kvStore->GetCountWithQuery(query.ToString(), ctxt->resultSize); ZLOGD("kvStore->GetCountWithQuery() return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->GetCountWithQuery() failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->GetCountWithQuery() failed!"); }; auto output = [env, ctxt](napi_value& result) { ctxt->status = JSUtil::SetValue(env, static_cast(ctxt->resultSize), result); - CHECK_STATUS(ctxt, "output resultSize failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "output resultSize failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output); } @@ -318,9 +318,9 @@ napi_value JsSingleKVStore::RemoveDeviceData(napi_env env, napi_callback_info in auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->deviceId); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid deviceId!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid deviceId!"); }; ctxt->GetCbInfo(env, info, input); @@ -329,7 +329,7 @@ napi_value JsSingleKVStore::RemoveDeviceData(napi_env env, napi_callback_info in Status status = kvStore->RemoveDeviceData(ctxt->deviceId); ZLOGD("kvStore->RemoveDeviceData return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "kvStore->RemoveDeviceData failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "kvStore->RemoveDeviceData failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -348,16 +348,16 @@ napi_value JsSingleKVStore::Sync(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 3 arguments :: [allowedDelayMs] - CHECK_ARGS(ctxt, (argc == 2) || (argc == 3), "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, (argc == 2) || (argc == 3), "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->deviceIdList); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid deviceIdList!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid deviceIdList!"); ctxt->status = JSUtil::GetValue(env, argv[1], ctxt->mode); - CHECK_STATUS(ctxt, "invalid arg[1], i.e. invalid mode!"); - CHECK_ARGS(ctxt, ctxt->mode <= uint32_t(SyncMode::PUSH_PULL), "invalid arg[1], i.e. invalid mode!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[1], i.e. invalid mode!"); + CHECK_ARGS_RETURN_VOID(ctxt, ctxt->mode <= uint32_t(SyncMode::PUSH_PULL), "invalid arg[1], i.e. invalid mode!"); // have 3 arguments :: have the allowedDelayMs if (argc == 3) { ctxt->status = JSUtil::GetValue(env, argv[2], ctxt->allowedDelayMs); - CHECK_STATUS(ctxt, "invalid arg[1], i.e. invalid allowedDelayMs!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[1], i.e. invalid allowedDelayMs!"); } }; ctxt->GetCbInfoSync(env, info, input); @@ -386,9 +386,9 @@ napi_value JsSingleKVStore::SetSyncParam(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt](size_t argc, napi_value* argv) { // required 1 arguments :: - CHECK_ARGS(ctxt, argc == 1, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 1, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], ctxt->allowedDelayMs); - CHECK_STATUS(ctxt, "get allowedDelayMs failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "get allowedDelayMs failed!"); }; ctxt->GetCbInfo(env, info, input); @@ -398,7 +398,7 @@ napi_value JsSingleKVStore::SetSyncParam(napi_env env, napi_callback_info info) Status status = kvStore->SetSyncParam(syncParam); ZLOGD("kvStore->SetSyncParam return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "output failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "output failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute); } @@ -422,11 +422,11 @@ napi_value JsSingleKVStore::GetSecurityLevel(napi_env env, napi_callback_info in Status status = kvStore->GetSecurityLevel(ctxt->securityLevel); ZLOGD("kvStore->GetSecurityLevel return %{public}d", status); ctxt->status = (status == Status::SUCCESS) ? napi_ok : napi_generic_failure; - CHECK_STATUS(ctxt, "GetSecurityLevel failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "GetSecurityLevel failed!"); }; auto output = [env, ctxt](napi_value& result) { ctxt->status = JSUtil::SetValue(env, static_cast(ctxt->securityLevel), result); - CHECK_STATUS(ctxt, "output failed!"); + CHECK_STATUS_RETURN_VOID(ctxt, "output failed!"); }; return NapiQueue::AsyncWork(env, ctxt, std::string(__FUNCTION__), execute, output); } @@ -438,10 +438,10 @@ napi_value JsSingleKVStore::New(napi_env env, napi_callback_info info) auto ctxt = std::make_shared(); auto input = [env, ctxt, &storeId](size_t argc, napi_value* argv) { // required 2 arguments :: - CHECK_ARGS(ctxt, argc == 2, "invalid arguments!"); + CHECK_ARGS_RETURN_VOID(ctxt, argc == 2, "invalid arguments!"); ctxt->status = JSUtil::GetValue(env, argv[0], storeId); - CHECK_STATUS(ctxt, "invalid arg[0], i.e. invalid storeId!"); - CHECK_ARGS(ctxt, !storeId.empty(), "invalid arg[0], i.e. invalid storeId!"); + CHECK_STATUS_RETURN_VOID(ctxt, "invalid arg[0], i.e. invalid storeId!"); + CHECK_ARGS_RETURN_VOID(ctxt, !storeId.empty(), "invalid arg[0], i.e. invalid storeId!"); }; ctxt->GetCbInfoSync(env, info, input); NAPI_ASSERT(env, ctxt->status == napi_ok, "invalid arguments!"); diff --git a/frameworks/jskitsimpl/distributeddata/src/napi_queue.cpp b/frameworks/jskitsimpl/distributeddata/src/napi_queue.cpp index fa51b8906d69eed27621074a2d19db55f8df567c..e09d7ac179b5a76a23be0266756cbe08ddaa4326 100644 --- a/frameworks/jskitsimpl/distributeddata/src/napi_queue.cpp +++ b/frameworks/jskitsimpl/distributeddata/src/napi_queue.cpp @@ -39,12 +39,12 @@ void ContextBase::GetCbInfo(napi_env envi, napi_callback_info info, NapiCbInfoPa size_t argc = ARGC_MAX; napi_value argv[ARGC_MAX] = { nullptr }; status = napi_get_cb_info(env, info, &argc, argv, &self, nullptr); - CHECK_STATUS(this, "napi_get_cb_info failed!"); - CHECK_ARGS(this, argc <= ARGC_MAX, "too many arguments!"); - CHECK_ARGS(this, self != nullptr, "no JavaScript this argument!"); + CHECK_STATUS_RETURN_VOID(this, "napi_get_cb_info failed!"); + CHECK_ARGS_RETURN_VOID(this, argc <= ARGC_MAX, "too many arguments!"); + CHECK_ARGS_RETURN_VOID(this, self != nullptr, "no JavaScript this argument!"); napi_create_reference(env, self, 1, &selfRef); status = napi_unwrap(env, self, &native); - CHECK_STATUS(this, "self unwrap failed!"); + CHECK_STATUS_RETURN_VOID(this, "self unwrap failed!"); if (!sync && (argc > 0)) { // get the last arguments :: @@ -53,7 +53,7 @@ void ContextBase::GetCbInfo(napi_env envi, napi_callback_info info, NapiCbInfoPa napi_status tyst = napi_typeof(env, argv[index], &type); if ((tyst == napi_ok) && (type == napi_function)) { status = napi_create_reference(env, argv[index], 1, &callbackRef); - CHECK_STATUS(this, "ref callback failed!"); + CHECK_STATUS_RETURN_VOID(this, "ref callback failed!"); argc = index; ZLOGD("async callback, no promise"); } else { @@ -64,7 +64,7 @@ void ContextBase::GetCbInfo(napi_env envi, napi_callback_info info, NapiCbInfoPa if (parse) { parse(argc, argv); } else { - CHECK_ARGS(this, argc == 0, "required no arguments!"); + CHECK_ARGS_RETURN_VOID(this, argc == 0, "required no arguments!"); } }