From 3db3b13323150baff0351a51a54f5473649430b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E5=BA=B7=E5=BA=B7?= Date: Mon, 4 Jul 2022 16:21:37 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8F=90=E9=86=92=E4=BB=A3=E7=90=86throw?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖康康 --- frameworks/ans/src/reminder_request.cpp | 5 ++ frameworks/ans/src/reminder_request_alarm.cpp | 6 +-- .../ans/src/reminder_request_calendar.cpp | 54 ++++++++++--------- frameworks/ans/src/reminder_request_timer.cpp | 2 +- .../reminder_request_calendar_test.cpp | 11 ++++ frameworks/js/napi/src/reminder/publish.cpp | 46 +++++++++------- .../js/napi/src/reminder/reminder_common.cpp | 20 +++++-- interfaces/inner_api/reminder_request.h | 1 + .../inner_api/reminder_request_calendar.h | 3 +- 9 files changed, 96 insertions(+), 52 deletions(-) diff --git a/frameworks/ans/src/reminder_request.cpp b/frameworks/ans/src/reminder_request.cpp index db70e2f78..75b7ffbdd 100644 --- a/frameworks/ans/src/reminder_request.cpp +++ b/frameworks/ans/src/reminder_request.cpp @@ -823,6 +823,11 @@ bool ReminderRequest::UpdateNextReminder() return false; } +bool ReminderRequest::SetNextTriggerTime() +{ + return false; +} + void ReminderRequest::UpdateNotificationRequest(UpdateNotificationType type, std::string extra) { switch (type) { diff --git a/frameworks/ans/src/reminder_request_alarm.cpp b/frameworks/ans/src/reminder_request_alarm.cpp index 3a3ee1af6..f041e0dbf 100644 --- a/frameworks/ans/src/reminder_request_alarm.cpp +++ b/frameworks/ans/src/reminder_request_alarm.cpp @@ -57,11 +57,11 @@ void ReminderRequestAlarm::CheckParamValid() const { if (hour_ >= HOURS_PER_DAY) { ANSR_LOGE("setted hour is not between [0, 24)"); - throw std::invalid_argument("setted hour is not between [0, 24)"); + return; } if (minute_ >= MINUTES_PER_HOUR) { ANSR_LOGE("setted minute is not between [0, 60)"); - throw std::invalid_argument("setted minute is not between [0, 60)"); + return; } } @@ -81,7 +81,7 @@ void ReminderRequestAlarm::SetDaysOfWeek(bool set, std::vector daysOfWe } if (daysOfWeek.size() > DAYS_PER_WEEK) { ANSR_LOGE("The length of daysOfWeek should not larger than 7"); - throw std::invalid_argument("The length of daysOfWeek should not larger than 7"); + return; } for (std::vector::iterator it = daysOfWeek.begin(); it != daysOfWeek.end(); ++it) { if (*it < MONDAY || *it > SUNDAY) { diff --git a/frameworks/ans/src/reminder_request_calendar.cpp b/frameworks/ans/src/reminder_request_calendar.cpp index 7cc3a5809..6b6e0dc0e 100644 --- a/frameworks/ans/src/reminder_request_calendar.cpp +++ b/frameworks/ans/src/reminder_request_calendar.cpp @@ -49,26 +49,8 @@ ReminderRequestCalendar::ReminderRequestCalendar(const tm &dateTime, SetRepeatDaysOfMonth(repeatDays); SetSnoozeTimes(DEFAULT_SNOOZE_TIMES); - // 2. get the latest valid trigger time. + // 2. should SetNextTriggerTime() after constructor InitDateTime(dateTime); - hour_ = static_cast(dateTime_.tm_hour); - minute_ = static_cast(dateTime_.tm_min); - uint64_t nextTriggerTime = INVALID_LONG_LONG_VALUE; - if ((nextTriggerTime = GetNextTriggerTime()) != INVALID_LONG_LONG_VALUE) { - time_t target = static_cast(nextTriggerTime / MILLI_SECONDS); - (void)localtime_r(&target, &dateTime_); - } else { - ANSR_LOGW("Not exist next trigger time, please check the param of ReminderRequestCalendar constructor."); - throw std::invalid_argument( - "Not exist next trigger time, please check the param of ReminderRequestCalendar constructor."); - } - - // 2. set the time information (used to transfer to proxy service) which is decided to trigger firstly. - year_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime_.tm_year)); - month_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime_.tm_mon)); - day_ = static_cast(dateTime_.tm_mday); - second_ = 0; - SetTriggerTimeInMilli(nextTriggerTime); } ReminderRequestCalendar::ReminderRequestCalendar(const ReminderRequestCalendar &other) : ReminderRequest(other) @@ -87,6 +69,28 @@ ReminderRequestCalendar::ReminderRequestCalendar(const ReminderRequestCalendar & repeatDay_ = other.repeatDay_; } +bool ReminderRequestCalendar::SetNextTriggerTime() +{ + hour_ = static_cast(dateTime_.tm_hour); + minute_ = static_cast(dateTime_.tm_min); + uint64_t nextTriggerTime = INVALID_LONG_LONG_VALUE; + if ((nextTriggerTime = GetNextTriggerTime()) != INVALID_LONG_LONG_VALUE) { + time_t target = static_cast(nextTriggerTime / MILLI_SECONDS); + (void)localtime_r(&target, &dateTime_); + } else { + ANSR_LOGW("Not exist next trigger time, please check the param of ReminderRequestCalendar constructor."); + return false; + } + + // set the time information (used to transfer to proxy service) which is decided to trigger firstly. + year_ = static_cast(GetActualTime(TimeTransferType::YEAR, dateTime_.tm_year)); + month_ = static_cast(GetActualTime(TimeTransferType::MONTH, dateTime_.tm_mon)); + day_ = static_cast(dateTime_.tm_mday); + second_ = 0; + SetTriggerTimeInMilli(nextTriggerTime); + return true; +} + uint8_t ReminderRequestCalendar::GetDaysOfMonth(const uint16_t &year, const uint8_t &month) { uint8_t days; @@ -297,8 +301,7 @@ void ReminderRequestCalendar::SetRepeatMonths(const std::vector &repeat { if (repeatMonths.size() > MAX_MONTHS_OF_YEAR) { ANSR_LOGW("The length of repeat months array should not larger than %{public}hhu", MAX_MONTHS_OF_YEAR); - throw std::invalid_argument( - "The length of repeat months array should not larger than " + std::to_string(MAX_MONTHS_OF_YEAR)); + return; } repeatMonth_ = 0; for (auto it = repeatMonths.begin(); it != repeatMonths.end(); ++it) { @@ -306,15 +309,14 @@ void ReminderRequestCalendar::SetRepeatMonths(const std::vector &repeat } } -void ReminderRequestCalendar::SetRepeatDaysOfMonth(const std::vector &repeateDays) +void ReminderRequestCalendar::SetRepeatDaysOfMonth(const std::vector &repeatDays) { - if (repeateDays.size() > MAX_DAYS_OF_MONTH) { + if (repeatDays.size() > MAX_DAYS_OF_MONTH) { ANSR_LOGW("The length of repeat days array should not larger than %{public}hhu", MAX_DAYS_OF_MONTH); - throw std::invalid_argument( - "The length of repeat days array should not larger than " + std::to_string(MAX_DAYS_OF_MONTH)); + return; } repeatDay_ = 0; - for (auto it = repeateDays.begin(); it != repeateDays.end(); ++it) { + for (auto it = repeatDays.begin(); it != repeatDays.end(); ++it) { SetDay((*it), true); } } diff --git a/frameworks/ans/src/reminder_request_timer.cpp b/frameworks/ans/src/reminder_request_timer.cpp index 4b5c87814..e469b69a0 100644 --- a/frameworks/ans/src/reminder_request_timer.cpp +++ b/frameworks/ans/src/reminder_request_timer.cpp @@ -85,7 +85,7 @@ void ReminderRequestTimer::CheckParamsValid(const uint64_t countDownTimeInSecond { if (countDownTimeInSeconds == 0 || countDownTimeInSeconds >= (UINT64_MAX / ReminderRequest::MILLI_SECONDS)) { ANSR_LOGE("Illegal count down time, please check the description of the constructor"); - throw std::invalid_argument("Illegal count down time, please check the description of the constructor"); + return; } } diff --git a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp b/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp index 461ce28fc..1c188c792 100644 --- a/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp +++ b/frameworks/ans/test/unittest/reminder_request_calendar_test.cpp @@ -54,6 +54,7 @@ public: repeatMonths.push_back(1); repeatDays.push_back(1); auto calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + calendar->SetNextTriggerTime(); return calendar; } @@ -150,6 +151,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00400, Function | SmallTest | repeatMonths.push_back(1); repeatDays.push_back(1); auto calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + calendar->SetNextTriggerTime(); std::vector actualRepeatMonths = calendar->GetRepeatMonths(); EXPECT_TRUE(ReminderRequestCalendarTest::IsVectorEqual(repeatMonths, actualRepeatMonths)) << "Set repeat month with 1 error."; @@ -157,6 +159,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00400, Function | SmallTest | repeatMonths.clear(); repeatMonths.push_back(12); calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + calendar->SetNextTriggerTime(); actualRepeatMonths = calendar->GetRepeatMonths(); EXPECT_TRUE(ReminderRequestCalendarTest::IsVectorEqual(repeatMonths, actualRepeatMonths)) << "Set repeat month with 12 error."; @@ -166,6 +169,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00400, Function | SmallTest | repeatMonths.push_back(i); } calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + calendar->SetNextTriggerTime(); actualRepeatMonths = calendar->GetRepeatMonths(); EXPECT_TRUE(ReminderRequestCalendarTest::IsVectorEqual(repeatMonths, actualRepeatMonths)) << "Set repeat month with 1~12 error."; @@ -192,12 +196,14 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00500, Function | SmallTest | repeatMonths.push_back(-1); repeatDays.push_back(1); auto calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + calendar->SetNextTriggerTime(); std::vector actualRepeatMonths = calendar->GetRepeatMonths(); EXPECT_TRUE(actualRepeatMonths.size() == 0) << "Set repeat month with -1 error."; repeatMonths.clear(); repeatMonths.push_back(13); calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + calendar->SetNextTriggerTime(); actualRepeatMonths = calendar->GetRepeatMonths(); EXPECT_TRUE(actualRepeatMonths.size() == 0) << "Set repeat month with 13 error."; } @@ -222,6 +228,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00600, Function | SmallTest | repeatMonths.push_back(1); repeatDays.push_back(1); auto calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + calendar->SetNextTriggerTime(); std::vector actualRepeatDays = calendar->GetRepeatDays(); EXPECT_TRUE(ReminderRequestCalendarTest::IsVectorEqual(repeatDays, actualRepeatDays)) << "Set repeat day with 1 error."; @@ -229,6 +236,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00600, Function | SmallTest | repeatDays.clear(); repeatDays.push_back(31); calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + calendar->SetNextTriggerTime(); actualRepeatDays = calendar->GetRepeatDays(); EXPECT_TRUE(ReminderRequestCalendarTest::IsVectorEqual(repeatDays, actualRepeatDays)) << "Set repeat day with 31 error."; @@ -238,6 +246,7 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00600, Function | SmallTest | repeatDays.push_back(i); } calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + calendar->SetNextTriggerTime(); actualRepeatDays = calendar->GetRepeatDays(); EXPECT_TRUE(ReminderRequestCalendarTest::IsVectorEqual(repeatDays, actualRepeatDays)) << "Set repeat day with 1~31 error."; @@ -264,12 +273,14 @@ HWTEST_F(ReminderRequestCalendarTest, initDateTime_00700, Function | SmallTest | repeatMonths.push_back(-1); repeatDays.push_back(-1); auto calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + calendar->SetNextTriggerTime(); std::vector actualRepeatDays = calendar->GetRepeatDays(); EXPECT_TRUE(actualRepeatDays.size() == 0) << "Set repeat day with -1 error."; repeatDays.clear(); repeatDays.push_back(32); calendar = std::make_shared(nowTime, repeatMonths, repeatDays); + calendar->SetNextTriggerTime(); actualRepeatDays = calendar->GetRepeatDays(); EXPECT_TRUE(actualRepeatDays.size() == 0) << "Set repeat day with 32 error."; } diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index c0035876d..f4aed6a5b 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -92,12 +92,6 @@ napi_value ParseParameters( return nullptr; } - // argv[0] : reminderRequest - if (ReminderCommon::GetReminderRequest(env, argv[0], params.reminder) == nullptr) { - ANSR_LOGW("[reminderAgent]CreateReminder returns nullptr"); - return nullptr; - } - // argv[1]: callback if (argc == PUBLISH_PARAM_LEN) { if (GetCallback(env, argv[1], asyncCallbackInfo) == nullptr) { @@ -105,6 +99,13 @@ napi_value ParseParameters( return nullptr; } } + + // argv[0] : reminderRequest + if (ReminderCommon::GetReminderRequest(env, argv[0], params.reminder) == nullptr) { + ANSR_LOGW("[reminderAgent]CreateReminder returns nullptr"); + return nullptr; + } + return NotificationNapi::Common::NapiGetNull(env); } @@ -156,6 +157,14 @@ napi_value ParseCanCelParameter( return nullptr; } + // argv[1]: callback + if (argc >= CANCEL_PARAM_LEN) { + if (GetCallback(env, argv[1], asyncCallbackInfo) == nullptr) { + ANSR_LOGW("GetCallbak is nullptr"); + return nullptr; + } + } + // argv[0]: reminder id int32_t reminderId = -1; if (!ReminderCommon::GetInt32(env, argv[0], nullptr, reminderId, true)) { @@ -167,13 +176,6 @@ napi_value ParseCanCelParameter( } params.reminderId = reminderId; - // argv[1]: callback - if (argc >= CANCEL_PARAM_LEN) { - if (GetCallback(env, argv[1], asyncCallbackInfo) == nullptr) { - ANSR_LOGW("GetCallbak is nullptr"); - return nullptr; - } - } return NotificationNapi::Common::NapiGetNull(env); } @@ -220,6 +222,14 @@ napi_value ParseGetValidParameter( return NotificationNapi::Common::NapiGetNull(env); } +napi_value DealErrorReturn(const napi_env &env, const napi_ref &callbackIn) { + if (callbackIn) { + NotificationNapi::Common::SetCallback(env, callbackIn, NotificationNapi::ERROR, + NotificationNapi::Common::NapiGetNull(env)); + } + return NotificationNapi::Common::JSParaError(env, callbackIn); +} + napi_value CancelReminder(napi_env env, napi_callback_info info) { ANSR_LOGI("Cancel reminder"); @@ -234,7 +244,7 @@ napi_value CancelReminder(napi_env env, napi_callback_info info) // param Parameters params; if (ParseCanCelParameter(env, info, params, *asynccallbackinfo) == nullptr) { - return NotificationNapi::Common::JSParaError(env, asynccallbackinfo->callback); + return DealErrorReturn(env, asynccallbackinfo->callback); } // promise @@ -290,7 +300,7 @@ napi_value CancelAllReminders(napi_env env, napi_callback_info info) // param Parameters params; if (ParseCanCelAllParameter(env, info, params, *asynccallbackinfo) == nullptr) { - return NotificationNapi::Common::JSParaError(env, asynccallbackinfo->callback); + return DealErrorReturn(env, asynccallbackinfo->callback); } // promise @@ -587,7 +597,7 @@ napi_value GetValidReminders(napi_env env, napi_callback_info info) // param Parameters params; if (ParseGetValidParameter(env, info, params, *asynccallbackinfo) == nullptr) { - return NotificationNapi::Common::JSParaError(env, asynccallbackinfo->callback); + return DealErrorReturn(env, asynccallbackinfo->callback); } // promise @@ -652,7 +662,7 @@ napi_value PublishReminder(napi_env env, napi_callback_info info) Parameters params; if (ParseParameters(env, info, params, *asynccallbackinfo) == nullptr) { ANSR_LOGW("Parse params error"); - return NotificationNapi::Common::JSParaError(env, asynccallbackinfo->callback); + return DealErrorReturn(env, asynccallbackinfo->callback); } // promise @@ -722,7 +732,7 @@ napi_value AddSlot(napi_env env, napi_callback_info info) Parameters params; if (ParseSlotParameters(env, info, params, *asynccallbackinfo) == nullptr) { ANSR_LOGW("Parse params error"); - return NotificationNapi::Common::JSParaError(env, asynccallbackinfo->callback); + return DealErrorReturn(env, asynccallbackinfo->callback); } // promise diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index b2924a305..8add8bfb5 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -351,13 +351,14 @@ napi_value ReminderCommon::CreateReminderTimer( return nullptr; } - if (propertyCountDownTime <= 0) { - ANSR_LOGW("Create countDown reminder fail: designated %{public}s should be set larger than 0.", + auto countDownTimeInSeconds = static_cast(propertyCountDownTime); + if (propertyCountDownTime <= 0 || countDownTimeInSeconds >= (UINT64_MAX / ReminderRequest::MILLI_SECONDS)) { + ANSR_LOGW("Create countDown reminder fail: designated %{public}s is illegal.", ReminderAgentNapi::TIMER_COUNT_DOWN_TIME); return nullptr; } - reminder = std::make_shared(static_cast(propertyCountDownTime)); + reminder = std::make_shared(countDownTimeInSeconds); return NotificationNapi::Common::NapiGetNull(env); } @@ -428,18 +429,28 @@ napi_value ReminderCommon::CreateReminderCalendar( } // repeatMonth + const int32_t maxMonthSize = 12; std::vector repeatMonths; if (ParseInt32Array(env, value, ReminderAgentNapi::CALENDAR_REPEAT_MONTHS, repeatMonths, ReminderRequestCalendar::MAX_MONTHS_OF_YEAR) == nullptr) { return nullptr; } + if (repeatMonths.size() > maxMonthSize) { + ANSR_LOGE("The length of repeat months array should not larger than %{public}d", maxMonthSize); + return nullptr; + } // repeatDay + const int32_t maxDaySize = 31; std::vector repeatDays; if (ParseInt32Array(env, value, ReminderAgentNapi::CALENDAR_REPEAT_DAYS, repeatDays, ReminderRequestCalendar::MAX_DAYS_OF_MONTH) == nullptr) { return nullptr; } + if (repeatDays.size() > maxDaySize) { + ANSR_LOGE("The length of repeat days array should not larger than %{public}d", maxDaySize); + return nullptr; + } tm dateTime; dateTime.tm_year = ReminderRequest::GetCTime(ReminderRequest::TimeTransferType::YEAR, propertyYearVal); @@ -450,6 +461,9 @@ napi_value ReminderCommon::CreateReminderCalendar( dateTime.tm_sec = 0; dateTime.tm_isdst = -1; reminder = std::make_shared(dateTime, repeatMonths, repeatDays); + if (!(reminder->SetNextTriggerTime())) { + return nullptr; + } return NotificationNapi::Common::NapiGetNull(env); } diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index 9d93bc5a4..33aa5d0de 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -546,6 +546,7 @@ public: * @return true if next trigger time exist and set success. */ virtual bool UpdateNextReminder(); + virtual bool SetNextTriggerTime(); /** * @brief Update notification attributes. diff --git a/interfaces/inner_api/reminder_request_calendar.h b/interfaces/inner_api/reminder_request_calendar.h index 2e4478e13..241ccccf4 100644 --- a/interfaces/inner_api/reminder_request_calendar.h +++ b/interfaces/inner_api/reminder_request_calendar.h @@ -138,6 +138,7 @@ public: * @return true if read parcel success. */ bool ReadFromParcel(Parcel &parcel) override; + bool SetNextTriggerTime() override; static const uint8_t MAX_MONTHS_OF_YEAR; static const uint8_t MAX_DAYS_OF_MONTH; @@ -180,7 +181,7 @@ private: void SetDay(const uint8_t &day, const bool &isSet); void SetMonth(const uint8_t &month, const bool &isSet); void SetRepeatMonths(const std::vector &repeatMonths); - void SetRepeatDaysOfMonth(const std::vector &repeateDays); + void SetRepeatDaysOfMonth(const std::vector &repeatDays); static const uint8_t JANUARY; static const uint8_t DECEMBER; -- Gitee From 3a11f9c210be1f203d23ec51734678facac76bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E5=BA=B7=E5=BA=B7?= Date: Mon, 4 Jul 2022 17:11:59 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=8F=90=E9=86=92=E4=BB=A3=E7=90=86throw?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖康康 --- frameworks/js/napi/src/reminder/publish.cpp | 3 ++- frameworks/js/napi/src/reminder/reminder_common.cpp | 10 ---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index f4aed6a5b..d70a0a82a 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -222,7 +222,8 @@ napi_value ParseGetValidParameter( return NotificationNapi::Common::NapiGetNull(env); } -napi_value DealErrorReturn(const napi_env &env, const napi_ref &callbackIn) { +napi_value DealErrorReturn(const napi_env &env, const napi_ref &callbackIn) +{ if (callbackIn) { NotificationNapi::Common::SetCallback(env, callbackIn, NotificationNapi::ERROR, NotificationNapi::Common::NapiGetNull(env)); diff --git a/frameworks/js/napi/src/reminder/reminder_common.cpp b/frameworks/js/napi/src/reminder/reminder_common.cpp index 8add8bfb5..14ebcba7a 100644 --- a/frameworks/js/napi/src/reminder/reminder_common.cpp +++ b/frameworks/js/napi/src/reminder/reminder_common.cpp @@ -429,28 +429,18 @@ napi_value ReminderCommon::CreateReminderCalendar( } // repeatMonth - const int32_t maxMonthSize = 12; std::vector repeatMonths; if (ParseInt32Array(env, value, ReminderAgentNapi::CALENDAR_REPEAT_MONTHS, repeatMonths, ReminderRequestCalendar::MAX_MONTHS_OF_YEAR) == nullptr) { return nullptr; } - if (repeatMonths.size() > maxMonthSize) { - ANSR_LOGE("The length of repeat months array should not larger than %{public}d", maxMonthSize); - return nullptr; - } // repeatDay - const int32_t maxDaySize = 31; std::vector repeatDays; if (ParseInt32Array(env, value, ReminderAgentNapi::CALENDAR_REPEAT_DAYS, repeatDays, ReminderRequestCalendar::MAX_DAYS_OF_MONTH) == nullptr) { return nullptr; } - if (repeatDays.size() > maxDaySize) { - ANSR_LOGE("The length of repeat days array should not larger than %{public}d", maxDaySize); - return nullptr; - } tm dateTime; dateTime.tm_year = ReminderRequest::GetCTime(ReminderRequest::TimeTransferType::YEAR, propertyYearVal); -- Gitee From 433674bf8388974421d7766c139022dd5506d1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E5=BA=B7=E5=BA=B7?= Date: Tue, 5 Jul 2022 14:24:35 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=8F=90=E9=86=92=E4=BB=A3=E7=90=86throw?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 廖康康 --- frameworks/js/napi/src/reminder/publish.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/frameworks/js/napi/src/reminder/publish.cpp b/frameworks/js/napi/src/reminder/publish.cpp index d70a0a82a..f29747d75 100644 --- a/frameworks/js/napi/src/reminder/publish.cpp +++ b/frameworks/js/napi/src/reminder/publish.cpp @@ -222,11 +222,11 @@ napi_value ParseGetValidParameter( return NotificationNapi::Common::NapiGetNull(env); } -napi_value DealErrorReturn(const napi_env &env, const napi_ref &callbackIn) +napi_value DealErrorReturn(const napi_env &env, const napi_ref &callbackIn, const napi_value &result) { if (callbackIn) { NotificationNapi::Common::SetCallback(env, callbackIn, NotificationNapi::ERROR, - NotificationNapi::Common::NapiGetNull(env)); + result); } return NotificationNapi::Common::JSParaError(env, callbackIn); } @@ -245,7 +245,7 @@ napi_value CancelReminder(napi_env env, napi_callback_info info) // param Parameters params; if (ParseCanCelParameter(env, info, params, *asynccallbackinfo) == nullptr) { - return DealErrorReturn(env, asynccallbackinfo->callback); + return DealErrorReturn(env, asynccallbackinfo->callback, NotificationNapi::Common::NapiGetNull(env)); } // promise @@ -301,7 +301,7 @@ napi_value CancelAllReminders(napi_env env, napi_callback_info info) // param Parameters params; if (ParseCanCelAllParameter(env, info, params, *asynccallbackinfo) == nullptr) { - return DealErrorReturn(env, asynccallbackinfo->callback); + return DealErrorReturn(env, asynccallbackinfo->callback, NotificationNapi::Common::NapiGetNull(env)); } // promise @@ -598,7 +598,7 @@ napi_value GetValidReminders(napi_env env, napi_callback_info info) // param Parameters params; if (ParseGetValidParameter(env, info, params, *asynccallbackinfo) == nullptr) { - return DealErrorReturn(env, asynccallbackinfo->callback); + return DealErrorReturn(env, asynccallbackinfo->callback, NotificationNapi::Common::NapiGetNull(env)); } // promise @@ -663,7 +663,8 @@ napi_value PublishReminder(napi_env env, napi_callback_info info) Parameters params; if (ParseParameters(env, info, params, *asynccallbackinfo) == nullptr) { ANSR_LOGW("Parse params error"); - return DealErrorReturn(env, asynccallbackinfo->callback); + napi_create_int32(env, -1, &(asynccallbackinfo->result)); + return DealErrorReturn(env, asynccallbackinfo->callback, asynccallbackinfo->result); } // promise @@ -733,7 +734,7 @@ napi_value AddSlot(napi_env env, napi_callback_info info) Parameters params; if (ParseSlotParameters(env, info, params, *asynccallbackinfo) == nullptr) { ANSR_LOGW("Parse params error"); - return DealErrorReturn(env, asynccallbackinfo->callback); + return DealErrorReturn(env, asynccallbackinfo->callback, NotificationNapi::Common::NapiGetNull(env)); } // promise -- Gitee