diff --git a/frameworks/native/ability/native/insight_intent_executor/js_insight_intent_entry.cpp b/frameworks/native/ability/native/insight_intent_executor/js_insight_intent_entry.cpp index c3e585856b92fe2aa5b950aaa9b54c77a3629e60..4b9f84ba4f05a4f1c780fa9d228362c0dc5a6c7f 100644 --- a/frameworks/native/ability/native/insight_intent_executor/js_insight_intent_entry.cpp +++ b/frameworks/native/ability/native/insight_intent_executor/js_insight_intent_entry.cpp @@ -28,6 +28,7 @@ #include "napi_common_util.h" #include "napi_common_want.h" #include "native_reference.h" +#include "string_wrapper.h" #undef STATE_PATTERN_NAIVE_H #define STATE_PATTERN_NAIVE_STATE state_ @@ -213,6 +214,41 @@ void JsInsightIntentEntry::ReplySucceededInner(std::shared_ptr(data); + napi_value resultJs = argv[0]; + if (resultJs == nullptr) { + TAG_LOGE(AAFwkTag::INTENT, "callback invalid"); + JsInsightIntentUtils::ReplyFailed(callback); + return nullptr; + } + + auto resultCpp = GetResultFromJs(env, resultJs); + JsInsightIntentUtils::ReplySucceeded(callback, resultCpp); + return nullptr; +} + +std::shared_ptr JsInsightIntentEntry::GetResultFromJs( + napi_env env, napi_value resultJs) +{ + TAG_LOGD(AAFwkTag::INTENT, "Get result for intent func"); + auto resultCpp = std::make_shared(); + auto resultStr = JsInsightIntentUtils::StringifyObject(env, resultJs); + auto wantParams = std::make_shared(); + wantParams->SetParam("methodResult", AAFwk::String::Box(resultStr)); + resultCpp->result = wantParams; + resultCpp->code = InsightIntentInnerErr::INSIGHT_INTENT_ERR_OK; + return resultCpp; +} + bool JsInsightIntentEntry::HandleResultReturnedFromJsFunc(napi_value resultJs) { TAG_LOGD(AAFwkTag::INTENT, "handle result returned"); @@ -238,7 +274,7 @@ bool JsInsightIntentEntry::HandleResultReturnedFromJsFunc(napi_value resultJs) NAPI_CALL_BASE(env, napi_get_named_property(env, resultJs, "then", &then), ExecuteIntentCheckError()); napi_value resolveCbJs = nullptr; NAPI_CALL_BASE(env, napi_create_function(env, TMP_NAPI_ANONYMOUS_FUNC, strlen(TMP_NAPI_ANONYMOUS_FUNC), - JsInsightIntentUtils::ResolveCbCpp, callback, &resolveCbJs), ExecuteIntentCheckError()); + ResolveCbCpp, callback, &resolveCbJs), ExecuteIntentCheckError()); constexpr size_t argcThen = 1; napi_value argvThen[argcThen] = { resolveCbJs }; NAPI_CALL_BASE(env, napi_call_function(env, resultJs, then, argcThen, argvThen, nullptr), diff --git a/interfaces/kits/native/ability/native/insight_intent_executor/js_insight_intent_entry.h b/interfaces/kits/native/ability/native/insight_intent_executor/js_insight_intent_entry.h index 98762d84697c74f9d46d44cbeeb4a64fd1c0de03..87721ca89f58a253007006668069692b38f2477d 100644 --- a/interfaces/kits/native/ability/native/insight_intent_executor/js_insight_intent_entry.h +++ b/interfaces/kits/native/ability/native/insight_intent_executor/js_insight_intent_entry.h @@ -96,6 +96,10 @@ private: bool PrepareParametersUIExtension(napi_env env, const std::shared_ptr& pageLoader); bool PrepareParametersServiceExtension(napi_env env); + static std::shared_ptr GetResultFromJs(napi_env env, napi_value resultJs); + + static napi_value ResolveCbCpp(napi_env env, napi_callback_info info); + bool AssignObject(napi_env env, const AAFwk::WantParams &wantParams); JsRuntime& runtime_; diff --git a/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp b/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp index cfb1429e9a784ed5dc9a7d9f6747d1652b58e5a8..7f65a1cbaf2a9c73e9cdd5e63d0cce3ffaf33739 100644 --- a/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp +++ b/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp @@ -307,6 +307,7 @@ HWTEST_F(InsightIntentUtilsTest, ConvertExtractInsightIntentGenericInfo_0100, Te TEST_INSIGHT_INTENT_GENERIC_INFO.decoratorType = "@InsightIntentLink"; auto result = utils.ConvertExtractInsightIntentGenericInfo(TEST_INSIGHT_INTENT_GENERIC_INFO, insightIntentInfoForQuery); EXPECT_EQ(result, ERR_OK); + EXPECT_EQ(insightIntentInfoForQuery.intentType, "@InsightIntentLink"); Mock::VerifyAndClear(mockBundleMgr); testing::Mock::AllowLeak(mockBundleMgr); TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentGenericInfo_0100 end.");