!748 修复异常抛出捕获问题

Merge pull request !748 from Hollokin/OpenHarmony-4.0-Beta1
This commit is contained in:
openharmony_ci 2023-06-01 12:48:00 +00:00 committed by Gitee
commit 952bd3b040
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
14 changed files with 86 additions and 77 deletions

View File

@ -308,7 +308,7 @@ napi_value JsInputMethodEngineSetting::Subscribe(napi_env env, napi_callback_inf
std::string type = "";
napi_status status = JsUtils::GetValue(env, argv[ARGC_ZERO], type);
NAPI_ASSERT_BASE(env, status == napi_ok, "get type failed!", nullptr);
CHECK_RETURN(status == napi_ok, "get type failed!", nullptr);
IMSA_HILOGE("event type is: %{public}s", type.c_str());
napi_valuetype valueType = napi_undefined;
@ -376,13 +376,13 @@ napi_value JsInputMethodEngineSetting::CreatePanel(napi_env env, napi_callback_i
auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
JsPanel *jsPanel = nullptr;
napi_value constructor = JsPanel::Init(env);
NAPI_ASSERT_BASE(env, constructor != nullptr, "get jsPanel constructor failed!", napi_generic_failure);
CHECK_RETURN(constructor != nullptr, "get jsPanel constructor failed!", napi_generic_failure);
napi_status status = napi_new_instance(env, constructor, 0, nullptr, result);
NAPI_ASSERT_BASE(env, status == napi_ok, "get jsPanel instance failed!", napi_generic_failure);
CHECK_RETURN(status == napi_ok, "get jsPanel instance failed!", napi_generic_failure);
status = napi_unwrap(env, *result, (void **)(&jsPanel));
NAPI_ASSERT_BASE(env, (status == napi_ok) && (jsPanel != nullptr), "get jsPanel failed", napi_generic_failure);
CHECK_RETURN((status == napi_ok) && (jsPanel != nullptr), "get jsPanel failed", napi_generic_failure);
jsPanel->SetNative(ctxt->panel);
return napi_ok;
};
@ -403,14 +403,14 @@ napi_value JsInputMethodEngineSetting::DestroyPanel(napi_env env, napi_callback_
PARAM_CHECK_RETURN(env, valueType == napi_object, " target: ", TYPE_OBJECT, napi_invalid_arg);
bool isPanel = false;
napi_value constructor = JsPanel::Init(env);
NAPI_ASSERT_BASE(env, constructor != nullptr, "Failed to get panel constructor.", napi_invalid_arg);
CHECK_RETURN(constructor != nullptr, "Failed to get panel constructor.", napi_invalid_arg);
napi_status status = napi_instanceof(env, argv[0], constructor, &isPanel);
NAPI_ASSERT_BASE(env, (status == napi_ok) && isPanel, "It's not expected panel instance!", status);
CHECK_RETURN((status == napi_ok) && isPanel, "It's not expected panel instance!", status);
JsPanel *jsPanel = nullptr;
status = napi_unwrap(env, argv[0], (void **)(&jsPanel));
NAPI_ASSERT_BASE(env, (status == napi_ok) && (jsPanel != nullptr), "Can not unwrap to JsPanel!", status);
CHECK_RETURN((status == napi_ok) && (jsPanel != nullptr), "Can not unwrap to JsPanel!", status);
ctxt->panel = jsPanel->GetNative();
NAPI_ASSERT_BASE(env, (ctxt->panel != nullptr), "not get valid inputMathodPanel!", napi_invalid_arg);
CHECK_RETURN((ctxt->panel != nullptr), "not get valid inputMathodPanel!", napi_invalid_arg);
return status;
};
@ -419,7 +419,7 @@ napi_value JsInputMethodEngineSetting::DestroyPanel(napi_env env, napi_callback_
};
auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
NAPI_ASSERT_BASE(env, (ctxt->panel != nullptr), "inputMethodPanel is nullptr!", napi_generic_failure);
CHECK_RETURN((ctxt->panel != nullptr), "inputMethodPanel is nullptr!", napi_generic_failure);
auto errCode = InputMethodAbility::GetInstance()->DestroyPanel(ctxt->panel);
if (errCode != ErrorCode::NO_ERROR) {
IMSA_HILOGE("DestroyPanel failed, errCode = %{public}d", errCode);

View File

@ -61,7 +61,7 @@ private:
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override

View File

@ -27,7 +27,7 @@ struct HideKeyboardContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -47,7 +47,7 @@ struct HideContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override

View File

@ -33,7 +33,7 @@ napi_value JsPanel::Init(napi_env env)
std::lock_guard<std::mutex> lock(panelConstructorMutex_);
if (panelConstructorRef_ != nullptr) {
napi_status status = napi_get_reference_value(env, panelConstructorRef_, &constructor);
NAPI_ASSERT_BASE(env, status == napi_ok, "Failed to get jsPanel constructor.", nullptr);
CHECK_RETURN(status == napi_ok, "Failed to get jsPanel constructor.", nullptr);
return constructor;
}
const napi_property_descriptor properties[] = {
@ -48,7 +48,7 @@ napi_value JsPanel::Init(napi_env env)
};
NAPI_CALL(env, napi_define_class(env, CLASS_NAME.c_str(), CLASS_NAME.size(), JsNew, nullptr,
sizeof(properties) / sizeof(napi_property_descriptor), properties, &constructor));
NAPI_ASSERT(env, constructor != nullptr, "napi_define_class failed!");
CHECK_RETURN(constructor != nullptr, "napi_define_class failed!", nullptr);
NAPI_CALL(env, napi_create_reference(env, constructor, 1, &panelConstructorRef_));
return constructor;
}
@ -57,11 +57,11 @@ napi_value JsPanel::JsNew(napi_env env, napi_callback_info info)
{
IMSA_HILOGD("JsPanel, create panel instance in.");
JsPanel *panel = new (std::nothrow) JsPanel();
NAPI_ASSERT(env, panel != nullptr, "no memory for JsPanel");
CHECK_RETURN(panel != nullptr, "no memory for JsPanel", nullptr);
auto finalize = [](napi_env env, void *data, void *hint) {
IMSA_HILOGI("jsPanel finalize.");
auto *jsPanel = reinterpret_cast<JsPanel *>(data);
NAPI_ASSERT_RETURN_VOID(env, jsPanel != nullptr, "finalize null!");
CHECK_RETURN_VOID(jsPanel != nullptr, "finalize null!");
jsPanel->GetNative() = nullptr;
delete jsPanel;
};
@ -100,12 +100,12 @@ napi_value JsPanel::SetUiContent(napi_env env, napi_callback_info info)
PARAM_CHECK_RETURN(env, argc >= 1, "should 1 or 2 parameters!", TYPE_NONE, status);
// 0 means the first param path<std::string>
status = JsUtils::GetValue(env, argv[0], ctxt->path);
NAPI_ASSERT_BASE(env, status == napi_ok, "get path failed!", status);
CHECK_RETURN(status == napi_ok, "get path failed!", status);
// if type of argv[1] is object, we will get value of 'storage' from it.
if (argc >= 2) {
napi_valuetype valueType = napi_undefined;
napi_status status = napi_typeof(env, argv[1], &valueType);
NAPI_ASSERT_BASE(env, status == napi_ok, "get valueType failed!", status);
CHECK_RETURN(status == napi_ok, "get valueType failed!", status);
if (valueType == napi_object) {
NativeValue *storage = nullptr;
storage = reinterpret_cast<NativeValue *>(argv[1]);
@ -121,10 +121,10 @@ napi_value JsPanel::SetUiContent(napi_env env, napi_callback_info info)
auto exec = [ctxt](AsyncCall::Context *ctx) { ctxt->SetState(napi_ok); };
auto output = [ctxt](napi_env env, napi_value *result) -> napi_status {
NAPI_ASSERT_BASE(env, ctxt->inputMethodPanel != nullptr, "inputMethodPanel is nullptr!", napi_generic_failure);
CHECK_RETURN(ctxt->inputMethodPanel != nullptr, "inputMethodPanel is nullptr!", napi_generic_failure);
auto code = ctxt->inputMethodPanel->SetUiContent(
ctxt->path, *(reinterpret_cast<NativeEngine *>(env)), ctxt->contentStorage);
NAPI_ASSERT_BASE(env, code == ErrorCode::NO_ERROR, "SetUiContent failed!", napi_generic_failure);
CHECK_RETURN(code == ErrorCode::NO_ERROR, "SetUiContent failed!", napi_generic_failure);
return napi_ok;
};
ctxt->SetAction(std::move(input), std::move(output));
@ -141,10 +141,10 @@ napi_value JsPanel::Resize(napi_env env, napi_callback_info info)
PARAM_CHECK_RETURN(env, argc > 1, "should 2 or 3 parameters!", TYPE_NONE, status);
// 0 means the first param width<uint32_t>
status = JsUtils::GetValue(env, argv[0], ctxt->width);
NAPI_ASSERT_BASE(env, status == napi_ok, "get width failed!", status);
CHECK_RETURN(status == napi_ok, "get width failed!", status);
// 1 means the second param height<uint32_t>
status = JsUtils::GetValue(env, argv[1], ctxt->height);
NAPI_ASSERT_BASE(env, status == napi_ok, "get height failed!", status);
CHECK_RETURN(status == napi_ok, "get height failed!", status);
return napi_ok;
};
@ -171,10 +171,10 @@ napi_value JsPanel::MoveTo(napi_env env, napi_callback_info info)
PARAM_CHECK_RETURN(env, argc > 1, " should 2 or 3 parameters! ", TYPE_NONE, status);
// 0 means the first param x<int32_t>
status = JsUtils::GetValue(env, argv[0], ctxt->x);
NAPI_ASSERT_BASE(env, status == napi_ok, "get x failed!", status);
CHECK_RETURN(status == napi_ok, "get x failed!", status);
// 1 means the second param y<int32_t>
status = JsUtils::GetValue(env, argv[1], ctxt->y);
NAPI_ASSERT_BASE(env, status == napi_ok, "get y failed!", status);
CHECK_RETURN(status == napi_ok, "get y failed!", status);
return napi_ok;
};
@ -237,10 +237,10 @@ napi_value JsPanel::ChangeFlag(napi_env env, napi_callback_info info)
int32_t panelFlag = 0;
// 0 means the first param flag<PanelFlag>
napi_status status = JsUtils::GetValue(env, argv[0], panelFlag);
NAPI_ASSERT(env, status == napi_ok, "get panelFlag failed!");
CHECK_RETURN(status == napi_ok, "get panelFlag failed!", nullptr);
auto inputMethodPanel = UnwrapPanel(env, thisVar);
auto ret = inputMethodPanel->ChangePanelFlag(PanelFlag(panelFlag));
NAPI_ASSERT(env, ret == ErrorCode::NO_ERROR, "ChangePanelFlag failed!");
CHECK_RETURN(ret == ErrorCode::NO_ERROR, "ChangePanelFlag failed!", nullptr);
return nullptr;
}
@ -252,7 +252,7 @@ napi_value JsPanel::Subscribe(napi_env env, napi_callback_info info)
napi_value thisVar = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
// 2 means it has two params.
NAPI_ASSERT(env, (argc >= 2) && (argc <= ARGC_MAX), "err number of argument!");
CHECK_RETURN((argc >= 2) && (argc <= ARGC_MAX), "err number of argument!", nullptr);
std::string type = "";
// 0 means the first param type<std::string>
JsUtils::GetValue(env, argv[0], type);
@ -260,7 +260,7 @@ napi_value JsPanel::Subscribe(napi_env env, napi_callback_info info)
napi_valuetype valuetype = napi_undefined;
napi_typeof(env, argv[1], &valuetype);
NAPI_ASSERT(env, valuetype == napi_function, "callback is not a function");
CHECK_RETURN(valuetype == napi_function, "callback is not a function", nullptr);
std::shared_ptr<PanelListenerImpl> observer = PanelListenerImpl::GetInstance();
auto inputMethodPanel = UnwrapPanel(env, thisVar);
// 1 means the second param callback.
@ -277,7 +277,7 @@ napi_value JsPanel::UnSubscribe(napi_env env, napi_callback_info info)
napi_value argv[ARGC_MAX] = { nullptr };
napi_value thisVar = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
NAPI_ASSERT(env, argc >= 1, "Wrong number of arguments, requires 1 or 2");
CHECK_RETURN(argc >= 1, "Wrong number of arguments, requires 1 or 2", nullptr);
std::string type = "";
// 0 means the first param type<std::string>
JsUtils::GetValue(env, argv[0], type);
@ -295,13 +295,13 @@ std::shared_ptr<InputMethodPanel> JsPanel::UnwrapPanel(napi_env env, napi_value
{
void *native = nullptr;
napi_status status = napi_unwrap(env, thisVar, &native);
NAPI_ASSERT_BASE(env, (status == napi_ok && native != nullptr), "napi_unwrap failed!", nullptr);
CHECK_RETURN((status == napi_ok && native != nullptr), "napi_unwrap failed!", nullptr);
auto jsPanel = reinterpret_cast<JsPanel *>(native);
if (jsPanel == nullptr) {
return nullptr;
}
auto &inputMethodPanel = jsPanel->GetNative();
NAPI_ASSERT_BASE(env, inputMethodPanel != nullptr, "inputMethodPanel is nullptr", nullptr);
CHECK_RETURN(inputMethodPanel != nullptr, "inputMethodPanel is nullptr", nullptr);
return inputMethodPanel;
}
} // namespace MiscServices

View File

@ -68,7 +68,7 @@ private:
PanelContentContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)){};
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override

View File

@ -148,7 +148,7 @@ napi_status JsTextInputClientEngine::GetSelectRange(napi_env env, napi_value arg
status = napi_get_named_property(env, argv, "start", &napiValue);
PARAM_CHECK_RETURN(env, status == napi_ok, "missing start parameter.", TYPE_NONE, status);
status = JsUtils::GetValue(env, napiValue, ctxt->start);
NAPI_ASSERT_BASE(env, status == napi_ok, "failed to get start value", status);
CHECK_RETURN(status == napi_ok, "failed to get start value", status);
status = napi_get_named_property(env, argv, "end", &napiValue);
PARAM_CHECK_RETURN(env, status == napi_ok, "missing end parameter.", TYPE_NONE, status);

View File

@ -31,7 +31,7 @@ struct SendKeyFunctionContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
@ -53,7 +53,7 @@ struct MoveCursorContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -75,7 +75,7 @@ struct DeleteForwardContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -97,7 +97,7 @@ struct DeleteBackwardContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -119,7 +119,7 @@ struct InsertTextContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -141,7 +141,7 @@ struct GetForwardContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -163,7 +163,7 @@ struct GetBackwardContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -185,7 +185,7 @@ struct GetEditorAttributeContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -207,7 +207,7 @@ struct SelectContext : public AsyncCall::Context {
SelectContext(InputAction input, OutputAction output) : Context(std::move(input), std::move(output)){};
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
};
@ -221,7 +221,7 @@ struct GetTextIndexAtCursorContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -241,7 +241,7 @@ struct SendExtendActionContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override

View File

@ -31,7 +31,7 @@ struct HandleContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -53,7 +53,7 @@ struct AttachContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -73,7 +73,7 @@ struct SetCallingWindowContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -93,7 +93,7 @@ struct UpdateCursorContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -115,7 +115,7 @@ struct ChangeSelectionContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -136,7 +136,7 @@ struct UpdateAttributeContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override

View File

@ -392,15 +392,15 @@ napi_value JsGetInputMethodSetting::Subscribe(napi_env env, napi_callback_info i
napi_value thisVar = nullptr;
void *data = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
NAPI_ASSERT(env, argc > ARGC_ONE, "Wrong number of arguments, requires least 2");
CHECK_RETURN(argc > ARGC_ONE, "Wrong number of arguments, requires least 2", nullptr);
std::string type;
JsUtils::GetValue(env, argv[ARGC_ZERO], type);
NAPI_ASSERT(env, EVENT_TYPE.find(type) != EVENT_TYPE.end(), "subscribe type error");
CHECK_RETURN(EVENT_TYPE.find(type) != EVENT_TYPE.end(), "subscribe type error", nullptr);
napi_valuetype valuetype = napi_undefined;
napi_typeof(env, argv[ARGC_ONE], &valuetype);
NAPI_ASSERT(env, valuetype == napi_function, "callback is not a function");
CHECK_RETURN(valuetype == napi_function, "callback is not a function", nullptr);
auto engine = reinterpret_cast<JsGetInputMethodSetting *>(JsUtils::GetNativeSelf(env, info));
if (engine == nullptr) {
@ -455,11 +455,11 @@ napi_value JsGetInputMethodSetting::UnSubscribe(napi_env env, napi_callback_info
napi_value thisVar = nullptr;
void *data = nullptr;
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, &data));
NAPI_ASSERT(env, argc > ARGC_ZERO, "Wrong number of arguments, requires least 1");
CHECK_RETURN(argc > ARGC_ZERO, "Wrong number of arguments, requires least 1", nullptr);
std::string type;
JsUtils::GetValue(env, argv[ARGC_ZERO], type);
NAPI_ASSERT(env, EVENT_TYPE.find(type) != EVENT_TYPE.end(), "subscribe type error");
CHECK_RETURN(EVENT_TYPE.find(type) != EVENT_TYPE.end(), "subscribe type error", nullptr);
auto engine = reinterpret_cast<JsGetInputMethodSetting *>(JsUtils::GetNativeSelf(env, info));
if (engine == nullptr) {
return nullptr;
@ -468,7 +468,7 @@ napi_value JsGetInputMethodSetting::UnSubscribe(napi_env env, napi_callback_info
if (argc > ARGC_ONE) {
napi_valuetype valuetype = napi_undefined;
napi_typeof(env, argv[ARGC_ONE], &valuetype);
NAPI_ASSERT(env, valuetype == napi_function, "callback is not a function");
CHECK_RETURN(valuetype == napi_function, "callback is not a function", nullptr);
}
engine->UnRegisterListener(argv[ARGC_ONE], type);
napi_value result = nullptr;

View File

@ -36,7 +36,7 @@ struct ListInputContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -58,7 +58,7 @@ struct DisplayOptionalInputMethodContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override
@ -80,7 +80,7 @@ struct GetInputMethodControllerContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override

View File

@ -52,21 +52,21 @@ napi_status JsInputMethod::GetInputMethodProperty(
napi_value result = nullptr;
napi_get_named_property(env, argv, "name", &result);
status = JsUtils::GetValue(env, result, ctxt->packageName);
NAPI_ASSERT_BASE(env, status == napi_ok, "get ctxt->packageName failed!", status);
CHECK_RETURN(status == napi_ok, "get ctxt->packageName failed!", status);
result = nullptr;
napi_get_named_property(env, argv, "id", &result);
status = JsUtils::GetValue(env, result, ctxt->methodId);
NAPI_ASSERT_BASE(env, status == napi_ok, "get ctxt->methodId failed!", status);
CHECK_RETURN(status == napi_ok, "get ctxt->methodId failed!", status);
if (ctxt->packageName.empty() || ctxt->methodId.empty()) {
result = nullptr;
napi_get_named_property(env, argv, "packageName", &result);
status = JsUtils::GetValue(env, result, ctxt->packageName);
NAPI_ASSERT_BASE(env, status == napi_ok, "get ctxt->packageName failed!", status);
CHECK_RETURN(status == napi_ok, "get ctxt->packageName failed!", status);
result = nullptr;
napi_get_named_property(env, argv, "methodId", &result);
status = JsUtils::GetValue(env, result, ctxt->methodId);
NAPI_ASSERT_BASE(env, status == napi_ok, "get ctxt->methodId failed!", status);
CHECK_RETURN(status == napi_ok, "get ctxt->methodId failed!", status);
}
PARAM_CHECK_RETURN(env, (!ctxt->packageName.empty() && !ctxt->methodId.empty()), "JsInputMethod, Parameter error.",
TYPE_NONE, napi_invalid_arg);
@ -85,12 +85,12 @@ napi_status JsInputMethod::GetInputMethodSubProperty(
status = napi_get_named_property(env, argv, "name", &result);
PARAM_CHECK_RETURN(env, status == napi_ok, " name ", TYPE_STRING, status);
status = JsUtils::GetValue(env, result, ctxt->name);
NAPI_ASSERT_BASE(env, status == napi_ok, "get ctxt->name failed!", status);
CHECK_RETURN(status == napi_ok, "get ctxt->name failed!", status);
result = nullptr;
status = napi_get_named_property(env, argv, "id", &result);
PARAM_CHECK_RETURN(env, status == napi_ok, " id ", TYPE_STRING, status);
status = JsUtils::GetValue(env, result, ctxt->id);
NAPI_ASSERT_BASE(env, status == napi_ok, "get ctxt->id failed!", status);
CHECK_RETURN(status == napi_ok, "get ctxt->id failed!", status);
IMSA_HILOGI("name:%{public}s and id:%{public}s", ctxt->name.c_str(), ctxt->id.c_str());
}
return status;

View File

@ -35,7 +35,7 @@ struct SwitchInputMethodContext : public AsyncCall::Context {
napi_status operator()(napi_env env, size_t argc, napi_value *argv, napi_value self) override
{
NAPI_ASSERT_BASE(env, self != nullptr, "self is nullptr", napi_invalid_arg);
CHECK_RETURN(self != nullptr, "self is nullptr", napi_invalid_arg);
return Context::operator()(env, argc, argv, self);
}
napi_status operator()(napi_env env, napi_value *result) override

View File

@ -211,10 +211,10 @@ void *JsUtils::GetNativeSelf(napi_env env, napi_callback_info info)
napi_value argv[ARGC_MAX] = { nullptr };
napi_status status = napi_invalid_arg;
napi_get_cb_info(env, info, &argc, argv, &self, nullptr);
NAPI_ASSERT(env, (self != nullptr && argc <= ARGC_MAX), "napi_get_cb_info failed!");
CHECK_RETURN((self != nullptr && argc <= ARGC_MAX), "napi_get_cb_info failed!", nullptr);
status = napi_unwrap(env, self, &native);
NAPI_ASSERT(env, (status == napi_ok && native != nullptr), "napi_unwrap failed!");
CHECK_RETURN((status == napi_ok && native != nullptr), "napi_unwrap failed!", nullptr);
return native;
}
@ -222,7 +222,7 @@ napi_status JsUtils::GetValue(napi_env env, napi_value in, int32_t &out)
{
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, in, &type);
NAPI_ASSERT_BASE(env, (status == napi_ok) && (type == napi_number), "invalid type", napi_generic_failure);
CHECK_RETURN((status == napi_ok) && (type == napi_number), "invalid type", napi_generic_failure);
return napi_get_value_int32(env, in, &out);
}
@ -231,7 +231,7 @@ napi_status JsUtils::GetValue(napi_env env, napi_value in, uint32_t &out)
{
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, in, &type);
NAPI_ASSERT_BASE(env, (status == napi_ok) && (type == napi_number), "invalid type", napi_generic_failure);
CHECK_RETURN((status == napi_ok) && (type == napi_number), "invalid type", napi_generic_failure);
return napi_get_value_uint32(env, in, &out);
}
@ -239,7 +239,7 @@ napi_status JsUtils::GetValue(napi_env env, napi_value in, bool &out)
{
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, in, &type);
NAPI_ASSERT_BASE(env, (status == napi_ok) && (type == napi_boolean), "invalid type", napi_generic_failure);
CHECK_RETURN((status == napi_ok) && (type == napi_boolean), "invalid type", napi_generic_failure);
return napi_get_value_bool(env, in, &out);
}
@ -247,7 +247,7 @@ napi_status JsUtils::GetValue(napi_env env, napi_value in, double &out)
{
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, in, &type);
NAPI_ASSERT_BASE(env, (status == napi_ok) && (type == napi_number), "invalid double type", napi_generic_failure);
CHECK_RETURN((status == napi_ok) && (type == napi_number), "invalid double type", napi_generic_failure);
return napi_get_value_double(env, in, &out);
}
@ -257,7 +257,7 @@ napi_status JsUtils::GetValue(napi_env env, napi_value in, std::string &out)
IMSA_HILOGD("JsUtils get string value in.");
napi_valuetype type = napi_undefined;
napi_status status = napi_typeof(env, in, &type);
NAPI_ASSERT_BASE(env, (status == napi_ok) && (type == napi_string), "invalid type", napi_generic_failure);
CHECK_RETURN((status == napi_ok) && (type == napi_string), "invalid type", napi_generic_failure);
size_t maxLen = STR_MAX_LENGTH;
status = napi_get_value_string_utf8(env, in, NULL, 0, &maxLen);
@ -297,19 +297,19 @@ napi_status JsUtils::GetValue(napi_env env, napi_value in, PanelInfo &out)
IMSA_HILOGD("napi_value -> PanelInfo ");
napi_value propType = nullptr;
napi_status status = napi_get_named_property(env, in, "type", &propType);
NAPI_ASSERT_BASE(env, (status == napi_ok), "no property type ", status);
CHECK_RETURN((status == napi_ok), "no property type ", status);
int32_t panelType = 0;
status = GetValue(env, propType, panelType);
NAPI_ASSERT_BASE(env, (status == napi_ok), "no value of type ", status);
CHECK_RETURN((status == napi_ok), "no value of type ", status);
// flag is optional. flag isn't need when panelType is status_bar.
int32_t panelFlag = 0;
if (panelType != PanelType::STATUS_BAR) {
napi_value propFlag = nullptr;
status = napi_get_named_property(env, in, "flag", &propFlag);
NAPI_ASSERT_BASE(env, (status == napi_ok), "no property flag ", status);
CHECK_RETURN((status == napi_ok), "no property flag ", status);
status = JsUtils::GetValue(env, propFlag, panelFlag);
NAPI_ASSERT_BASE(env, (status == napi_ok), "no value of flag ", status);
CHECK_RETURN((status == napi_ok), "no value of flag ", status);
}
out.panelType = PanelType(panelType);

View File

@ -77,6 +77,15 @@ enum TypeCode : int32_t {
} \
} while (0)
/* check condition, return and logging. */
#define CHECK_RETURN(condition, message, retVal) \
do { \
if (!(condition)) { \
IMSA_HILOGE("test (" #condition ") failed: " message); \
return retVal; \
} \
} while (0)
class JsUtils {
public:
using ArgsProvider = std::function<bool(napi_value args[], uint8_t argc, std::shared_ptr<JSCallbackObject>)>;