From fca4ef31091c96cf6c5f5e39965ba4b41387bf7a Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Sat, 4 May 2024 15:54:59 +0900 Subject: [PATCH] lottie/expressions: ++exceptional handling. Add an exceptional handling if interpreting code is failed. --- .../jerry-core/api/jerryscript.cpp | 12 +++++++++ .../jerry-core/include/jerryscript-core.h | 1 + src/loaders/lottie/tvgLottieExpressions.cpp | 7 ++--- src/loaders/lottie/tvgLottieExpressions.h | 27 ++++++++----------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/loaders/lottie/jerryscript/jerry-core/api/jerryscript.cpp b/src/loaders/lottie/jerryscript/jerry-core/api/jerryscript.cpp index a7d87fd8..62d37f30 100644 --- a/src/loaders/lottie/jerryscript/jerry-core/api/jerryscript.cpp +++ b/src/loaders/lottie/jerryscript/jerry-core/api/jerryscript.cpp @@ -180,6 +180,18 @@ jerry_current_realm (void) return ecma_make_object_value (global_obj_p); } /* jerry_current_realm */ +/** + * Check if the specified value is an error or abort value. + * + * @return true - if the specified value is an error value, + * false - otherwise + */ +bool +jerry_value_is_exception (const jerry_value_t value) /**< api value */ +{ + return ecma_is_value_exception (value); +} /* jerry_value_is_exception */ + /** * Check if the specified value is number. * diff --git a/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-core.h b/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-core.h index bbed6dd9..ce2efc9d 100644 --- a/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-core.h +++ b/src/loaders/lottie/jerryscript/jerry-core/include/jerryscript-core.h @@ -29,6 +29,7 @@ jerry_value_t jerry_run (const jerry_value_t script); bool jerry_value_is_undefined (const jerry_value_t value); bool jerry_value_is_number (const jerry_value_t value); bool jerry_value_is_object (const jerry_value_t value); +bool jerry_value_is_exception (const jerry_value_t value); jerry_value_t jerry_value_to_object (const jerry_value_t value); jerry_value_t jerry_value_to_string (const jerry_value_t value); double jerry_value_as_number (const jerry_value_t value); diff --git a/src/loaders/lottie/tvgLottieExpressions.cpp b/src/loaders/lottie/tvgLottieExpressions.cpp index 52db12d2..4b7e1177 100644 --- a/src/loaders/lottie/tvgLottieExpressions.cpp +++ b/src/loaders/lottie/tvgLottieExpressions.cpp @@ -1219,8 +1219,9 @@ jerry_value_t LottieExpressions::evaluate(float frameNo, LottieExpression* exp) //evaluate the code auto eval = jerry_eval((jerry_char_t *) exp->code, strlen(exp->code), JERRY_PARSE_NO_OPTS); - if (jerry_value_is_undefined(eval)) TVGERR("LOTTIE", "Expression error"); - else jerry_value_free(eval); + if (jerry_value_is_exception(eval)) return jerry_undefined(); + + jerry_value_free(eval); return jerry_object_get_sz(global, "$bm_rt"); } @@ -1283,4 +1284,4 @@ void LottieExpressions::retrieve(LottieExpressions* instance) } -#endif //THORVG_LOTTIE_EXPRESSIONS_SUPPORT \ No newline at end of file +#endif //THORVG_LOTTIE_EXPRESSIONS_SUPPORT diff --git a/src/loaders/lottie/tvgLottieExpressions.h b/src/loaders/lottie/tvgLottieExpressions.h index 03d339a1..8dd6ca27 100644 --- a/src/loaders/lottie/tvgLottieExpressions.h +++ b/src/loaders/lottie/tvgLottieExpressions.h @@ -40,7 +40,6 @@ public: template bool result(float frameNo, NumType& out, LottieExpression* exp) { - auto success = true; auto bm_rt = evaluate(frameNo, exp); if (auto prop = static_cast(jerry_object_get_native_ptr(bm_rt, nullptr))) { @@ -49,16 +48,15 @@ public: out = (NumType) jerry_value_as_number(bm_rt); } else { TVGERR("LOTTIE", "Failed dispatching a Value!"); - success = false; + return false; } jerry_value_free(bm_rt); - return success; + return true; } template bool result(float frameNo, Point& out, LottieExpression* exp) { - auto success = true; auto bm_rt = evaluate(frameNo, exp); if (jerry_value_is_object(bm_rt)) { @@ -74,58 +72,55 @@ public: } } else { TVGERR("LOTTIE", "Failed dispatching Point!"); - success = false; + return false; } jerry_value_free(bm_rt); - return success; + return true; } template bool result(float frameNo, RGB24& out, LottieExpression* exp) { - auto success = true; auto bm_rt = evaluate(frameNo, exp); if (auto color = static_cast(jerry_object_get_native_ptr(bm_rt, nullptr))) { out = (*color)(frameNo); } else { TVGERR("LOTTIE", "Failed dispatching Color!"); - success = false; + return false; } jerry_value_free(bm_rt); - return success; + return true; } template bool result(float frameNo, Fill* fill, LottieExpression* exp) { - auto success = true; auto bm_rt = evaluate(frameNo, exp); if (auto colorStop = static_cast(jerry_object_get_native_ptr(bm_rt, nullptr))) { (*colorStop)(frameNo, fill, this); } else { TVGERR("LOTTIE", "Failed dispatching ColorStop!"); - success = false; + return false; } jerry_value_free(bm_rt); - return success; + return true; } template bool result(float frameNo, Array& cmds, Array& pts, Matrix* transform, LottieExpression* exp) { - auto success = true; auto bm_rt = evaluate(frameNo, exp); if (auto pathset = static_cast(jerry_object_get_native_ptr(bm_rt, nullptr))) { (*pathset)(frameNo, cmds, pts, transform); } else { TVGERR("LOTTIE", "Failed dispatching PathSet!"); - success = false; + return false; } jerry_value_free(bm_rt); - return success; + return true; } void update(float curTime); @@ -167,4 +162,4 @@ struct LottieExpressions #endif //THORVG_LOTTIE_EXPRESSIONS_SUPPORT -#endif //_TVG_LOTTIE_EXPRESSIONS_H_ +#endif //_TVG_LOTTIE_EXPRESSIONS_H_ \ No newline at end of file