diff --git a/frameworks/src/core/modules/router_module.cpp b/frameworks/src/core/modules/router_module.cpp index 54ff44ef30731da7d55a3400a0a8e6e576858f5b..b70ea3c2508f298835e71ebb89ad49672882c16c 100644 --- a/frameworks/src/core/modules/router_module.cpp +++ b/frameworks/src/core/modules/router_module.cpp @@ -18,20 +18,22 @@ #include "js_app_context.h" #include "js_profiler.h" #include "jsi/internal/jsi_internal.h" +#include "jsi.h" +#include "jsi_types.h" namespace OHOS { namespace ACELite { void InitRouterModule(JSIValue exports) { JSI::SetModuleAPI(exports, "replace", RouterModule::Replace); + JSI::SetModuleAPI(exports, "replaceUrl", RouterModule::Replace); } JSIValue RouterModule::Replace(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum) { if (argsNum != 1 || args == nullptr) { HILOG_ERROR(HILOG_MODULE_ACE, "Replace args invalid, args num(%{public}d).", argsNum); - return AS_JSI_VALUE(jerry_create_error(JERRY_ERROR_TYPE, - reinterpret_cast("params should only be one object."))); + return JSI::CreateErrorWithCode(JSI_ERR_CODE_PARAM_CHECK_FAILED, "params should only be one object."); } jerry_value_t object = AS_JERRY_VALUE(args[0]); // router.replace({uri: 'About', params: {id:'1'}} diff --git a/frameworks/src/core/router/js_page_state_machine.cpp b/frameworks/src/core/router/js_page_state_machine.cpp index 4e1923fd303799818cc7d434a8039f31c070e3b0..f80775819e8fbf7c29a7efb39cae8dfe4835c6f3 100644 --- a/frameworks/src/core/router/js_page_state_machine.cpp +++ b/frameworks/src/core/router/js_page_state_machine.cpp @@ -28,6 +28,8 @@ #include "module_manager.h" #include "root_view.h" #include "securec.h" +#include "jsi_types.h" +#include "jsi/internal/jsi_internal.h" namespace OHOS { namespace ACELite { @@ -184,8 +186,8 @@ bool StateMachine::BindUri(jerry_value_t &jsRes) if (!jerry_value_is_string(uriValue)) { jerry_release_value(uriValue); HILOG_ERROR(HILOG_MODULE_ACE, "statemachine init failed as uri is invalid."); - jsRes = jerry_create_error(JERRY_ERROR_TYPE, - reinterpret_cast("uri value type should be string.")); + jsRes = AS_JERRY_VALUE(JSI::CreateErrorWithCode(JSI_ERR_CODE_PARAM_CHECK_FAILED, + "uri value type should be string.")); return false; } uri_ = MallocStringOf(uriValue); @@ -218,8 +220,7 @@ bool StateMachine::BindUri(jerry_value_t &jsRes) ace_free(uri_); uri_ = nullptr; HILOG_ERROR(HILOG_MODULE_ACE, "statemachine init failed as js file isn't existed."); - jsRes = jerry_create_error(JERRY_ERROR_URI, - reinterpret_cast("route target doesn't existed.")); + jsRes = AS_JERRY_VALUE(JSI::CreateErrorWithCode(ERR_CODE_URL_NOTEXIST, "route target doesn't existed.")); return false; } return true; diff --git a/frameworks/src/core/router/js_page_state_machine.h b/frameworks/src/core/router/js_page_state_machine.h index 134c636d644c22bf67a875b579e86a1d70123894..4970488b16d3f555b17000eb83a8828950b8e2e7 100644 --- a/frameworks/src/core/router/js_page_state_machine.h +++ b/frameworks/src/core/router/js_page_state_machine.h @@ -50,6 +50,9 @@ constexpr char PAGE_LIFECYCLE_CALLBACK_ON_SHOW[] = "onShow"; constexpr char PAGE_LIFECYCLE_CALLBACK_ON_HIDE[] = "onHide"; constexpr char PAGE_LIFECYCLE_CALLBACK_ON_DESTROY[] = "onDestroy"; +// uniform error code for error throwing +constexpr uint32_t ERR_CODE_URL_NOTEXIST = 200002; + #if JS_PAGE_SPECIFIC extern JSPageSpecific jsPageSpecific; #endif diff --git a/test/moduletest/common/test_app/ui_auto_test/config.json b/test/moduletest/common/test_app/ui_auto_test/config.json index f06137d2a2e9b481d18a60ceffa7d1c7a4610c07..753b93b236db7953356190ee98bf97d20ebdaf30 100755 --- a/test/moduletest/common/test_app/ui_auto_test/config.json +++ b/test/moduletest/common/test_app/ui_auto_test/config.json @@ -106,6 +106,7 @@ "pages/router/02/index", "pages/router/03/index", "pages/router/04/index", + "pages/router/05/index", "pages/router/page2/page2", "pages/router/page3/page3", "pages/swiper/SwiperA06/index", diff --git a/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/04/index.hml b/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/04/index.hml index ea5920d4e13eb78ff72d3556f056ddd4362f78b2..7756c52f3c9f76e80595df9e5dfc17c75f6fcd0f 100644 --- a/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/04/index.hml +++ b/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/04/index.hml @@ -25,12 +25,13 @@ limitations under the License.
- +
+
\ No newline at end of file diff --git a/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/04/index.js b/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/04/index.js index c330c8d982f51342f774410ff7568d73677ecadd..4e5fc11751952352c9a718f395935ddacd3ba67a 100644 --- a/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/04/index.js +++ b/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/04/index.js @@ -25,5 +25,5 @@ export default { button3() { router.replace({ path: "123" }); }, - ...routePage("pages/router/03/index", "") + ...routePage("pages/router/03/index", "pages/router/05/index") }; \ No newline at end of file diff --git a/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/05/index.css b/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/05/index.css new file mode 100644 index 0000000000000000000000000000000000000000..5ee6c9c5856837c9d736054a331a5c595f6bb4c2 --- /dev/null +++ b/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/05/index.css @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +.container { + left:0px; + top:0px; + width:454px; + height:454px; + flex-direction: column; + border-radius: 227px; + border-width: 2px; + border-color: #00ff00; +} + +.divBlock { + width:454px; + height:54px; +} + +.buttonBlock { + width: 300px; + height: 50px; +} + +.divFrame { + width:454px; + height:50px; + justify-content:center; + align-items:center; +} \ No newline at end of file diff --git a/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/05/index.hml b/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/05/index.hml new file mode 100644 index 0000000000000000000000000000000000000000..9e673497a5875f6f4edfb0ad62e43395ff304d7e --- /dev/null +++ b/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/05/index.hml @@ -0,0 +1,36 @@ + + +
+
+ Router_Replace_Test_005 +
+
+
+ + this is the first page + +
+ + + +
+
+
+
+ + +
+
\ No newline at end of file diff --git a/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/05/index.js b/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/05/index.js new file mode 100644 index 0000000000000000000000000000000000000000..d7936a1c9d00e22f1554063e1ecd85bc7fcf5316 --- /dev/null +++ b/test/moduletest/common/test_app/ui_auto_test/src/main/js/default/pages/router/05/index.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import router from "@system.router"; +import { routePage } from "../../../common/js/general"; +export default { + data: {}, + button1() { + router.replaceUrl(); + }, + button2() { + router.replaceUrl({ uri: 1 }); + }, + button3() { + router.replaceUrl({ uri: "pages/page2/" }); + }, + ...routePage("pages/router/04/index", "") +}; \ No newline at end of file